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 Aug 21, 2023
1 parent ff71b3b commit 7742315
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 @@ -427,6 +427,13 @@ CDT_EXPORT T distance(const V2d<T>& a, const V2d<T>& b);
template <typename T>
CDT_EXPORT T distanceSquared(const V2d<T>& a, const V2d<T>& b);

/// 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 @@ -300,4 +300,19 @@ T distanceSquared(const V2d<T>& a, const V2d<T>& b)
return distanceSquared(a.x, a.y, b.x, b.y);
}

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 @@ -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<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 @@ -1285,22 +1285,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 @@ -1385,7 +1369,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 @@ -1406,7 +1393,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 @@ -1462,9 +1449,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 7742315

Please sign in to comment.