diff --git a/CDT/include/CDTUtils.h b/CDT/include/CDTUtils.h index f1a84f8..55d915b 100644 --- a/CDT/include/CDTUtils.h +++ b/CDT/include/CDTUtils.h @@ -430,6 +430,13 @@ CDT_EXPORT T distanceSquared(const V2d& a, const V2d& b); /// Check if any of triangle's vertices belongs to a super-triangle CDT_INLINE_IF_HEADER_ONLY bool touchesSuperTriangle(const Triangle& t); +/// Check if vertex V is encroaching on diametral circle of an edge +template +CDT_EXPORT bool isEncroachingOnEdge( + const V2d& v, + const V2d& edgeStart, + const V2d& edgeEnd); + } // namespace CDT #ifndef CDT_USE_AS_COMPILED_LIBRARY diff --git a/CDT/include/CDTUtils.hpp b/CDT/include/CDTUtils.hpp index bd9af3a..e87341e 100644 --- a/CDT/include/CDTUtils.hpp +++ b/CDT/include/CDTUtils.hpp @@ -305,4 +305,19 @@ bool touchesSuperTriangle(const Triangle& t) return t.vertices[0] < 3 || t.vertices[1] < 3 || t.vertices[2] < 3; } +template +bool isEncroachingOnEdge( + const V2d& v, + const V2d& edgeStart, + const V2d& edgeEnd) +{ + /* + * Contains a point in its diametral circle: + * the angle between v and edge end points is obtuse + */ + return (edgeStart.x - v.x) * (edgeEnd.x - v.x) + + (edgeStart.y - v.y) * (edgeEnd.y - v.y) <= + T(0); +} + } // namespace CDT diff --git a/CDT/include/Triangulation.h b/CDT/include/Triangulation.h index a278ee2..f463520 100644 --- a/CDT/include/Triangulation.h +++ b/CDT/include/Triangulation.h @@ -513,8 +513,6 @@ class CDT_EXPORT Triangulation VertInd iV3, VertInd iV4) const; TriInd edgeTriangle(Edge edge) const; - /// Checks if edge e is encroached by vertex v - bool isEncroached(const V2d& v, Edge e) const; bool isBadTriangle( const Triangle& tri, RefineTriangles::Enum refinement, diff --git a/CDT/include/Triangulation.hpp b/CDT/include/Triangulation.hpp index 482151f..040f9a3 100644 --- a/CDT/include/Triangulation.hpp +++ b/CDT/include/Triangulation.hpp @@ -1252,22 +1252,6 @@ TriInd Triangulation::edgeTriangle(const Edge edge) const return iT; } -/* - * Contains a point in its diametral circle - * same as checking if the angle between v and edge end points is obtuse - */ -template -bool Triangulation::isEncroached( - const V2d& v, - const Edge edge) const -{ - const V2d v1 = - V2d::make(vertices[edge.v1()].x - v.x, vertices[edge.v1()].y - v.y); - const V2d v2 = - V2d::make(vertices[edge.v2()].x - v.x, vertices[edge.v2()].y - v.y); - return (v1.x * v2.x + v1.y * v2.y) < T(0); -} - template bool Triangulation::isBadTriangle( const Triangle& tri, @@ -1352,7 +1336,10 @@ EdgeQue Triangulation::detectEncroachedEdges() const Triangle& tOpo = triangles[iTopo]; VertInd v1 = opposedVertex(t, iTopo); VertInd v2 = opposedVertex(tOpo, iT); - if(isEncroached(vertices[v1], edge) || isEncroached(vertices[v2], edge)) + const V2d& edgeStart = vertices[edge.v1()]; + const V2d& edgeEnd = vertices[edge.v2()]; + if(isEncroachingOnEdge(vertices[v1], edgeStart, edgeEnd) || + isEncroachingOnEdge(vertices[v2], edgeStart, edgeEnd)) { encroachedEdges.push(edge); } @@ -1373,7 +1360,7 @@ Triangulation::detectEncroachedEdges(const V2d& v) ++cit) { const Edge edge = *cit; - if(isEncroached(v, edge)) + if(isEncroachingOnEdge(v, vertices[edge.v1()], vertices[edge.v2()])) { encroachedEdges.push(edge); } @@ -1429,9 +1416,11 @@ Triangulation::resolveEncroachedEdges( const Triangle& tOpo = triangles[iTopo]; VertInd v1 = opposedVertex(t, iTopo); VertInd v2 = opposedVertex(tOpo, iT); - if(isEncroached(vertices[v1], edge) || - isEncroached(vertices[v2], edge) || - (validV && isEncroached(v, edge))) + const V2d& edgeStart = vertices[edge.v1()]; + const V2d& edgeEnd = vertices[edge.v2()]; + if(isEncroachingOnEdge(vertices[v1], edgeStart, edgeEnd) || + isEncroachingOnEdge(vertices[v2], edgeStart, edgeEnd) || + (validV && isEncroachingOnEdge(v, edgeStart, edgeEnd))) { encroachedEdges.push(edge); }