From 8a70efed05880195c53b71021331155a6c113cf2 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Tue, 1 Jul 2008 20:32:24 -0800 Subject: [PATCH] Make sliver triangle tests work on the minimum altitude, not on area. [git-p4: depot-paths = "//depot/solvespace/": change = 1816] --- mesh.cpp | 6 +++--- polygon.cpp | 10 +++++++++- polygon.h | 1 + solvespace.h | 2 +- util.cpp | 5 +---- wishlist.txt | 1 + 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mesh.cpp b/mesh.cpp index 586fba28..b41e05a1 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -67,8 +67,8 @@ void SMesh::Simplify(int start) { int i, j; for(i = start; i < l.n; i++) { STriangle *tr = &(l.elem[i]); - if((tr->Normal()).Magnitude() < LENGTH_EPS*LENGTH_EPS) { - tr->tag = 0; + if(tr->MinAltitude() < LENGTH_EPS) { + tr->tag = 1; } else { tr->tag = 0; } @@ -171,7 +171,7 @@ void SMesh::Simplify(int start) { for(i = 0; i < convc - 2; i++) { STriangle tr = STriangle::From(meta, conv[0], conv[i+1], conv[i+2]); - if((tr.Normal()).Magnitude() > LENGTH_EPS*LENGTH_EPS) { + if(tr.MinAltitude() > LENGTH_EPS) { tout[toutc++] = tr; } } diff --git a/polygon.cpp b/polygon.cpp index 06555692..57914020 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -5,9 +5,17 @@ Vector STriangle::Normal(void) { return ab.Cross(bc); } +double STriangle::MinAltitude(void) { + double altA = a.DistanceToLine(b, c.Minus(b)), + altB = b.DistanceToLine(c, a.Minus(c)), + altC = c.DistanceToLine(a, b.Minus(a)); + + return min(altA, min(altB, altC)); +} + bool STriangle::ContainsPoint(Vector p) { Vector n = Normal(); - if(n.Magnitude() < LENGTH_EPS*LENGTH_EPS) { + if(MinAltitude() < LENGTH_EPS) { // shouldn't happen; zero-area triangle return false; } diff --git a/polygon.h b/polygon.h index fafe332e..54b84aaa 100644 --- a/polygon.h +++ b/polygon.h @@ -124,6 +124,7 @@ public: static STriangle From(STriMeta meta, Vector a, Vector b, Vector c); Vector Normal(void); void FlipNormal(void); + double MinAltitude(void); int WindingNumberForPoint(Vector p); bool ContainsPoint(Vector p); bool ContainsPointProjd(Vector n, Vector p); diff --git a/solvespace.h b/solvespace.h index 8fea9c0d..d0b1cf93 100644 --- a/solvespace.h +++ b/solvespace.h @@ -24,7 +24,7 @@ inline int WRAP(int v, int n) { #define ZERO(v) memset((v), 0, sizeof(*(v))) #define CO(v) (v).x, (v).y, (v).z -#define LENGTH_EPS (0.0000001) +#define LENGTH_EPS (1e-7) #define isforname(c) (isalnum(c) || (c) == '_' || (c) == '-' || (c) == '#') diff --git a/util.cpp b/util.cpp index eccfbd9a..ea9c5040 100644 --- a/util.cpp +++ b/util.cpp @@ -269,10 +269,7 @@ Vector Vector::From(hParam x, hParam y, hParam z) { } bool Vector::Equals(Vector v) { - if(fabs(x - v.x) > LENGTH_EPS) return false; - if(fabs(y - v.y) > LENGTH_EPS) return false; - if(fabs(z - v.z) > LENGTH_EPS) return false; - return true; + return (this->Minus(v)).Magnitude() < LENGTH_EPS; } Vector Vector::Plus(Vector b) { diff --git a/wishlist.txt b/wishlist.txt index 21508c2b..e0ca8716 100644 --- a/wishlist.txt +++ b/wishlist.txt @@ -8,6 +8,7 @@ auto-generate circles and faces when lathing copy the section geometry to other end when sweeping cylindrical faces draw explicit edges +symmetric about line segment long term