Skip to content

Commit

Permalink
#7 Refactor edgeTriangle
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-ogre committed Aug 21, 2023
1 parent a4eed27 commit e4a16a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -615,6 +614,7 @@ class CDT_EXPORT Triangulation
VertInd superGeomVertCount,
V2d<T> boxMin,
V2d<T> boxMax);
std::pair<TriInd, TriInd> 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);
Expand Down
60 changes: 25 additions & 35 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,26 +1262,6 @@ bool Triangulation<T, TNearPointLocator>::isFlipNeeded(
return isInCircumcircle(v, v2, v3, v4);
}

template <typename T, typename TNearPointLocator>
TriInd Triangulation<T, TNearPointLocator>::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 <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::isRefinementNeeded(
const Triangle& tri,
Expand Down Expand Up @@ -1314,8 +1294,9 @@ EdgeQue Triangulation<T, TNearPointLocator>::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);
Expand Down Expand Up @@ -1372,13 +1353,11 @@ TriIndVec Triangulation<T, TNearPointLocator>::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];
Expand Down Expand Up @@ -2210,23 +2189,34 @@ void Triangulation<T, TNearPointLocator>::insertVertices_KDTreeBFS(
}

template <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::hasEdge(
std::pair<TriInd, TriInd> Triangulation<T, TNearPointLocator>::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 <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::hasEdge(
const VertInd a,
const VertInd b) const
{
return edgeTriangles(a, b).first != invalidIndex;
}

template <typename T, typename TNearPointLocator>
Expand Down

0 comments on commit e4a16a7

Please sign in to comment.