From 77423153e3dc0c7b87fe5f7ecac592d3b61c8996 Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Mon, 21 Aug 2023 11:16:19 +0200 Subject: [PATCH] #7 Refactor vertex encroaching on edge --- CDT/include/CDTUtils.h | 7 +++++++ CDT/include/CDTUtils.hpp | 15 +++++++++++++++ CDT/include/Triangulation.h | 2 -- CDT/include/Triangulation.hpp | 31 ++++++++++--------------------- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/CDT/include/CDTUtils.h b/CDT/include/CDTUtils.h index 8d594e4b..3452f46e 100644 --- a/CDT/include/CDTUtils.h +++ b/CDT/include/CDTUtils.h @@ -427,6 +427,13 @@ CDT_EXPORT T distance(const V2d& a, const V2d& b); template CDT_EXPORT T distanceSquared(const V2d& a, const V2d& b); +/// 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 2d58bb1c..f068cac8 100644 --- a/CDT/include/CDTUtils.hpp +++ b/CDT/include/CDTUtils.hpp @@ -300,4 +300,19 @@ T distanceSquared(const V2d& a, const V2d& b) return distanceSquared(a.x, a.y, b.x, b.y); } +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 9e96e67c..3911abe5 100644 --- a/CDT/include/Triangulation.h +++ b/CDT/include/Triangulation.h @@ -521,8 +521,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 1c4a0b70..3f08e30f 100644 --- a/CDT/include/Triangulation.hpp +++ b/CDT/include/Triangulation.hpp @@ -1285,22 +1285,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, @@ -1385,7 +1369,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); } @@ -1406,7 +1393,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); } @@ -1462,9 +1449,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); }