From eb8a43d22b4d274d7f0635b9076028873e435203 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Thu, 29 May 2008 23:32:30 -0800 Subject: [PATCH] Fix stupidity in the triangle simplification; I didn't handle the case where you bolt a triangle onto a convex poly, and both remaining edges of the tri are coincident with the neighbours from the poly. That was a big source of zero-area triangles. And tweak some colors a bit. [git-p4: depot-paths = "//depot/solvespace/": change = 1758] --- mesh.cpp | 14 ++++++++++---- sketch.cpp | 2 +- solvespace.h | 4 ++++ textwin.cpp | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/mesh.cpp b/mesh.cpp index b7f048c..ed92a6f 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -69,7 +69,7 @@ void SMesh::Simplify(int start) { for(i = start; i < l.n; i++) { STriangle *tr = &(l.elem[i]); if((tr->Normal()).Magnitude() < LENGTH_EPS*LENGTH_EPS) { - tr->tag = 1; + tr->tag = 0; } else { tr->tag = 0; } @@ -128,8 +128,14 @@ void SMesh::Simplify(int start) { bDot /= min(ab.Magnitude(), bc.Magnitude()); dDot /= min(cd.Magnitude(), de.Magnitude()); - - if(fabs(bDot) < LENGTH_EPS && dDot > 0) { + + if(fabs(bDot) < LENGTH_EPS && fabs(dDot) < LENGTH_EPS) { + conv[WRAP((j+1), convc)] = c; + // and remove the vertex at j, which is a dup + memmove(conv+j, conv+j+1, + (convc - j - 1)*sizeof(conv[0])); + convc--; + } else if(fabs(bDot) < LENGTH_EPS && dDot > 0) { conv[j] = c; } else if(fabs(dDot) < LENGTH_EPS && bDot > 0) { conv[WRAP((j+1), convc)] = c; @@ -161,7 +167,7 @@ void SMesh::Simplify(int start) { double bDot = (ab.Cross(bc)).Dot(n); bDot /= min(ab.Magnitude(), bc.Magnitude()); - if(bDot < 0) return; + if(bDot < 0) oops(); } for(i = 0; i < convc - 2; i++) { diff --git a/sketch.cpp b/sketch.cpp index f797517..d4e6ad8 100644 --- a/sketch.cpp +++ b/sketch.cpp @@ -79,7 +79,7 @@ void Group::MenuGroup(int id) { case GraphicsWindow::MNU_GROUP_EXTRUDE: g.type = EXTRUDE; g.opA = SS.GW.activeGroup; - g.color = RGB(150, 150, 150); + g.color = RGB(100, 100, 100); g.wrkpl.entityB = SS.GW.ActiveWorkplane(); g.subtype = ONE_SIDED; g.name.strcpy("extrude"); diff --git a/solvespace.h b/solvespace.h index a3e09ce..930ee18 100644 --- a/solvespace.h +++ b/solvespace.h @@ -72,6 +72,10 @@ void PaintGraphics(void); SDWORD GetMilliseconds(void); void dbp(char *str, ...); +#define DBPTRI(tri) \ + dbp("tri: (%.3f %.3f %.3f) (%.3f %.3f %.3f) (%.3f %.3f %.3f)", \ + CO((tri).a), CO((tri).b), CO((tri).c)) + void Error(char *str, ...); void *AllocTemporary(int n); diff --git a/textwin.cpp b/textwin.cpp index b0bd08c..babb1b2 100644 --- a/textwin.cpp +++ b/textwin.cpp @@ -29,7 +29,7 @@ void TextWindow::Init(void) { modelColor[1] = RGB(100, 100, 100); modelColor[2] = RGB( 30, 30, 30); modelColor[3] = RGB(150, 0, 0); - modelColor[4] = RGB( 0, 150, 0); + modelColor[4] = RGB( 0, 100, 0); modelColor[5] = RGB( 0, 80, 80); modelColor[6] = RGB( 0, 0, 150); modelColor[7] = RGB( 80, 0, 80);