From e4a16a735968a8a4fc7934ab5d740d81116c0bd6 Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Mon, 21 Aug 2023 15:15:03 +0200 Subject: [PATCH] #7 Refactor edgeTriangle --- CDT/include/Triangulation.h | 2 +- CDT/include/Triangulation.hpp | 60 +++++++++++++++-------------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/CDT/include/Triangulation.h b/CDT/include/Triangulation.h index 267afff..0e52e25 100644 --- a/CDT/include/Triangulation.h +++ b/CDT/include/Triangulation.h @@ -516,7 +516,6 @@ class CDT_EXPORT Triangulation VertInd iV2, VertInd iV3, VertInd iV4) const; - TriInd edgeTriangle(Edge edge) const; bool isRefinementNeeded( const Triangle& tri, RefinementCriterion::Enum refinementCriterion, @@ -615,6 +614,7 @@ class CDT_EXPORT Triangulation VertInd superGeomVertCount, V2d boxMin, V2d boxMax); + std::pair edgeTriangles(VertInd a, VertInd b) const; bool hasEdge(VertInd a, VertInd b) const; void setAdjacentTriangle(const VertInd v, const TriInd t); void pivotVertexTriangleCW(VertInd v); diff --git a/CDT/include/Triangulation.hpp b/CDT/include/Triangulation.hpp index 4855dcb..59a666e 100644 --- a/CDT/include/Triangulation.hpp +++ b/CDT/include/Triangulation.hpp @@ -1262,26 +1262,6 @@ bool Triangulation::isFlipNeeded( return isInCircumcircle(v, v2, v3, v4); } -template -TriInd Triangulation::edgeTriangle(const Edge edge) const -{ - TriInd iT = invalidIndex; - const TriInd start = m_vertTris[edge.v1()]; - TriInd currTri = start; - do - { - const Triangle& t = triangles[currTri]; - if(t.next(edge.v1()).second == edge.v2()) - { - iT = currTri; - break; - } - currTri = t.next(edge.v1()).first; - } while(currTri != start); - assert(iT != invalidIndex); - return iT; -} - template bool Triangulation::isRefinementNeeded( const Triangle& tri, @@ -1314,8 +1294,9 @@ EdgeQue Triangulation::detectEncroachedEdges() ++cit) { const Edge edge = *cit; - const TriInd iT = edgeTriangle(edge); - const TriInd iTopo = edgeNeighbor(triangles[iT], edge.v1(), edge.v2()); + TriInd iT, iTopo; + std::tie(iT, iTopo) = edgeTriangles(edge.v1(), edge.v2()); + assert(iT != invalidIndex && iTopo != invalidIndex); const Triangle& t = triangles[iT]; const Triangle& tOpo = triangles[iTopo]; VertInd v1 = opposedVertex(t, iTopo); @@ -1372,13 +1353,11 @@ TriIndVec Triangulation::resolveEncroachedEdges( { continue; } - TriInd iT = edgeTriangle(edge); - const Triangle& t = triangles[iT]; - VertInd i = splitEncroachedEdge( - edge, - iT, - edgeNeighbor(triangles[iT], edge.v1(), edge.v2()), - steinerVerticesOffset); + TriInd iT, iTopo; + std::tie(iT, iTopo) = edgeTriangles(edge.v1(), edge.v2()); + assert(iT != invalidIndex && iTopo != invalidIndex); + const VertInd i = + splitEncroachedEdge(edge, iT, iTopo, steinerVerticesOffset); --newVertBudget; TriInd start = m_vertTris[i]; @@ -2210,23 +2189,34 @@ void Triangulation::insertVertices_KDTreeBFS( } template -bool Triangulation::hasEdge( +std::pair Triangulation::edgeTriangles( const VertInd a, const VertInd b) const { const TriInd triStart = m_vertTris[a]; assert(triStart != noNeighbor); - TriInd iT = triStart; + TriInd iT = triStart, iTNext = triStart; VertInd iV = noVertex; do { const Triangle& t = triangles[iT]; - tie(iT, iV) = t.next(a); - assert(iT != noNeighbor); + tie(iTNext, iV) = t.next(a); + assert(iTNext != noNeighbor); if(iV == b) - return true; + { + return std::make_pair(iT, iTNext); + } + iT = iTNext; } while(iT != triStart); - return false; + return std::make_pair(invalidIndex, invalidIndex); +} + +template +bool Triangulation::hasEdge( + const VertInd a, + const VertInd b) const +{ + return edgeTriangles(a, b).first != invalidIndex; } template