Skip to content

Commit

Permalink
#7 Refactor vertex encroaching on edge
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-ogre committed Oct 6, 2023
1 parent 84c6470 commit 5380aff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CDT/include/CDTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ CDT_EXPORT T distanceSquared(const V2d<T>& a, const V2d<T>& 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 <typename T>
CDT_EXPORT bool isEncroachingOnEdge(
const V2d<T>& v,
const V2d<T>& edgeStart,
const V2d<T>& edgeEnd);

} // namespace CDT

#ifndef CDT_USE_AS_COMPILED_LIBRARY
Expand Down
15 changes: 15 additions & 0 deletions CDT/include/CDTUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,19 @@ bool touchesSuperTriangle(const Triangle& t)
return t.vertices[0] < 3 || t.vertices[1] < 3 || t.vertices[2] < 3;
}

template <typename T>
bool isEncroachingOnEdge(
const V2d<T>& v,
const V2d<T>& edgeStart,
const V2d<T>& 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
2 changes: 0 additions & 2 deletions CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>& v, Edge e) const;
bool isBadTriangle(
const Triangle& tri,
RefineTriangles::Enum refinement,
Expand Down
31 changes: 10 additions & 21 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,22 +1252,6 @@ TriInd Triangulation<T, TNearPointLocator>::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 <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::isEncroached(
const V2d<T>& v,
const Edge edge) const
{
const V2d<T> v1 =
V2d<T>::make(vertices[edge.v1()].x - v.x, vertices[edge.v1()].y - v.y);
const V2d<T> v2 =
V2d<T>::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 <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::isBadTriangle(
const Triangle& tri,
Expand Down Expand Up @@ -1352,7 +1336,10 @@ EdgeQue Triangulation<T, TNearPointLocator>::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<T>& edgeStart = vertices[edge.v1()];
const V2d<T>& edgeEnd = vertices[edge.v2()];
if(isEncroachingOnEdge(vertices[v1], edgeStart, edgeEnd) ||
isEncroachingOnEdge(vertices[v2], edgeStart, edgeEnd))
{
encroachedEdges.push(edge);
}
Expand All @@ -1373,7 +1360,7 @@ Triangulation<T, TNearPointLocator>::detectEncroachedEdges(const V2d<T>& v)
++cit)
{
const Edge edge = *cit;
if(isEncroached(v, edge))
if(isEncroachingOnEdge(v, vertices[edge.v1()], vertices[edge.v2()]))
{
encroachedEdges.push(edge);
}
Expand Down Expand Up @@ -1429,9 +1416,11 @@ Triangulation<T, TNearPointLocator>::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<T>& edgeStart = vertices[edge.v1()];
const V2d<T>& edgeEnd = vertices[edge.v2()];
if(isEncroachingOnEdge(vertices[v1], edgeStart, edgeEnd) ||
isEncroachingOnEdge(vertices[v2], edgeStart, edgeEnd) ||
(validV && isEncroachingOnEdge(v, edgeStart, edgeEnd)))
{
encroachedEdges.push(edge);
}
Expand Down

0 comments on commit 5380aff

Please sign in to comment.