diff --git a/dsc.h b/dsc.h index cde82c6..d4cfbf1 100644 --- a/dsc.h +++ b/dsc.h @@ -47,7 +47,7 @@ public: Vector n2, double d2); double Element(int i); - bool Equals(Vector v); + bool Equals(Vector v, double tol=LENGTH_EPS); bool EqualsExactly(Vector v); Vector Plus(Vector b); Vector Minus(Vector b); diff --git a/mesh.cpp b/mesh.cpp index db8e630..c68ab2f 100644 --- a/mesh.cpp +++ b/mesh.cpp @@ -588,9 +588,9 @@ void SKdNode::FindEdgeOn(Vector a, Vector b, int *n, int *nOther, if(tr->tag == cnt) continue; - if((a.EqualsExactly(tr->b) && b.EqualsExactly(tr->a)) || - (a.EqualsExactly(tr->c) && b.EqualsExactly(tr->b)) || - (a.EqualsExactly(tr->a) && b.EqualsExactly(tr->c))) + if((a.Equals(tr->b, KDTREE_EPS) && b.Equals(tr->a, KDTREE_EPS)) || + (a.Equals(tr->c, KDTREE_EPS) && b.Equals(tr->b, KDTREE_EPS)) || + (a.Equals(tr->a, KDTREE_EPS) && b.Equals(tr->c, KDTREE_EPS))) { (*n)++; if(tr->meta.face != m.face) { @@ -643,7 +643,9 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, bool emphasized) { FindEdgeOn(a, b, &n, &nOther, tr->meta, cnt++); if(n != 1) { if(!emphasized) { - if(n == 0) sel->AddEdge(a, b); + if(n == 0 && (a.Minus(b).Magnitude()) > KDTREE_EPS) { + sel->AddEdge(a, b); + } } else { // dbp("hanging: n=%d (%.3f %.3f %.3f) (%.3f %.3f %.3f)", // n, CO(a), CO(b)); diff --git a/util.cpp b/util.cpp index be84d64..b28d88d 100644 --- a/util.cpp +++ b/util.cpp @@ -290,13 +290,13 @@ double Vector::Element(int i) { } } -bool Vector::Equals(Vector v) { +bool Vector::Equals(Vector v, double tol) { // Quick axis-aligned tests before going further - double dx = v.x - x; if(dx < -LENGTH_EPS || dx > LENGTH_EPS) return false; - double dy = v.y - y; if(dy < -LENGTH_EPS || dy > LENGTH_EPS) return false; - double dz = v.z - z; if(dz < -LENGTH_EPS || dz > LENGTH_EPS) return false; + double dx = v.x - x; if(dx < -tol || dx > tol) return false; + double dy = v.y - y; if(dy < -tol || dy > tol) return false; + double dz = v.z - z; if(dz < -tol || dz > tol) return false; - return (this->Minus(v)).MagSquared() < LENGTH_EPS*LENGTH_EPS; + return (this->Minus(v)).MagSquared() < tol*tol; } bool Vector::EqualsExactly(Vector v) {