This BSP split and simplify thing is stupid, but a hard-coded limit

on the number of pieces that we know how to reassemble is even
stupider. Now dynamically allocated.

[git-p4: depot-paths = "//depot/solvespace/": change = 1837]
solver
Jonathan Westhues 2008-07-13 04:58:52 -08:00
parent 88fc69116f
commit f70bbb3e7f
3 changed files with 9 additions and 4 deletions

View File

@ -51,15 +51,14 @@ void SMesh::GetBounding(Vector *vmax, Vector *vmin) {
} }
void SMesh::Simplify(int start) { void SMesh::Simplify(int start) {
#define MAX_TRIANGLES 2000 int maxTriangles = (l.n - start) + 10;
if(l.n - start > MAX_TRIANGLES) oops();
STriMeta meta = l.elem[start].meta; STriMeta meta = l.elem[start].meta;
STriangle tout[MAX_TRIANGLES]; STriangle *tout = (STriangle *)AllocTemporary(maxTriangles*sizeof(*tout));
int toutc = 0; int toutc = 0;
Vector n, conv[MAX_TRIANGLES*3]; Vector n, *conv = (Vector *)AllocTemporary(maxTriangles*3*sizeof(*conv));
int convc = 0; int convc = 0;
int start0 = start; int start0 = start;
@ -181,6 +180,8 @@ void SMesh::Simplify(int start) {
for(i = 0; i < toutc; i++) { for(i = 0; i < toutc; i++) {
AddTriangle(&(tout[i])); AddTriangle(&(tout[i]));
} }
FreeTemporary(tout);
FreeTemporary(conv);
} }
void SMesh::AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3) { void SMesh::AddAgainstBsp(SMesh *srcm, SBsp3 *bsp3) {

View File

@ -101,6 +101,7 @@ DWORD CnfThawDWORD(DWORD v, char *name);
float CnfThawFloat(float v, char *name); float CnfThawFloat(float v, char *name);
void *AllocTemporary(int n); void *AllocTemporary(int n);
void FreeTemporary(void *p);
void FreeAllTemporary(void); void FreeAllTemporary(void);
void *MemRealloc(void *p, int n); void *MemRealloc(void *p, int n);
void *MemAlloc(int n); void *MemAlloc(int n);

View File

@ -120,6 +120,9 @@ void *AllocTemporary(int n)
if(!v) oops(); if(!v) oops();
return v; return v;
} }
void FreeTemporary(void *p) {
HeapFree(Temp, HEAP_NO_SERIALIZE, p);
}
void FreeAllTemporary(void) void FreeAllTemporary(void)
{ {
if(Temp) HeapDestroy(Temp); if(Temp) HeapDestroy(Temp);