From 04141aa59d5dc6bdc31d1eb397ddd7d6d6806336 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 7 Feb 2008 01:57:59 -0800 Subject: [PATCH] Go back to randomizing the faces before adding to the BSP, rather than sorting by area. I had hoped that would help with normal accuracy, but I don't think it helped much, and it sometimes became very slow. [git-p4: depot-paths = "//depot/solvespace/": change = 1850] --- bsp.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/bsp.cpp b/bsp.cpp index adfeab4d..177ea296 100644 --- a/bsp.cpp +++ b/bsp.cpp @@ -3,22 +3,6 @@ SBsp2 *SBsp2::Alloc(void) { return (SBsp2 *)AllocTemporary(sizeof(SBsp2)); } SBsp3 *SBsp3::Alloc(void) { return (SBsp3 *)AllocTemporary(sizeof(SBsp3)); } -static int ByArea(const void *av, const void *bv) { - STriangle *a = (STriangle *)av; - STriangle *b = (STriangle *)bv; - - double fa = a->Normal().Magnitude(); - double fb = b->Normal().Magnitude(); - - if(fa > fb) { - return -1; - } else if(fa < fb) { - return 1; - } else { - return 0; - } -} - SBsp3 *SBsp3::FromMesh(SMesh *m) { SBsp3 *bsp3 = NULL; int i; @@ -28,10 +12,13 @@ SBsp3 *SBsp3::FromMesh(SMesh *m) { mc.AddTriangle(&(m->l.elem[i])); } - // The larger-area triangles have more trustworthy normals. By inserting - // those first, we hope to improve the numerical accuracy of our - // split planes. - qsort(mc.l.elem, mc.l.n, sizeof(mc.l.elem[0]), ByArea); + srand(0); // Let's be deterministic, at least! + int n = mc.l.n; + while(n > 1) { + int k = rand() % n; + n--; + SWAP(STriangle, mc.l.elem[k], mc.l.elem[n]); + } for(i = 0; i < mc.l.n; i++) { bsp3 = bsp3->Insert(&(mc.l.elem[i]), NULL);