Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isFlipNeeded #67

Merged
merged 2 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 48 additions & 21 deletions CDT/include/CDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,37 +473,64 @@ void Triangulation<T, TNearPointLocator>::insertVertex(const VertInd iVert)
*/
template <typename T, typename TNearPointLocator>
bool Triangulation<T, TNearPointLocator>::isFlipNeeded(
const V2d<T>& pos,
const V2d<T>& v,
const TriInd iT,
const TriInd iTopo,
const VertInd iVert) const
const VertInd iV) const
{
/*
* v3 original edge: (v1, v3)
* /|\ flip-candidate edge: (v, v2)
* / | \
* / | \
* / | \
* new vertex--> v | v2
* \ | /
* \ | /
* \ | /
* \|/
* v1
*/
const Triangle& tOpo = triangles[iTopo];
const Index i = opposedVertexInd(tOpo, iT);
const VertInd iVopo = tOpo.vertices[i];
const VertInd iVcw = tOpo.vertices[cw(i)];
const VertInd iVccw = tOpo.vertices[ccw(i)];
const V2d<T>& v1 = vertices[iVcw];
const V2d<T>& v2 = vertices[iVopo];
const V2d<T>& v3 = vertices[iVccw];
const VertInd iV2 = tOpo.vertices[i];
const VertInd iV1 = tOpo.vertices[cw(i)];
const VertInd iV3 = tOpo.vertices[ccw(i)];
const V2d<T>& v1 = vertices[iV1];
const V2d<T>& v2 = vertices[iV2];
const V2d<T>& v3 = vertices[iV3];
if(m_superGeomType == SuperGeometryType::SuperTriangle)
{
if(iVert < 3 || iVopo < 3) // flip-candidate edge touches super-triangle
// If flip-candidate edge touches super-triangle in-circumference test
// has to be replaced with orient2d test against the line formed by two
// non-artificial vertices (that don't belong to super-triangle)
if(iV < 3) // flip-candidate edge touches super-triangle
{
if(iVcw < 3 || iVccw < 3) // but so does original edge
{
// let the normal circumcircle test decide
return isInCircumcircle(pos, v1, v2, v3);
}
return false; // no flip is needed
// does original edge also touch super-triangle?
if(iV1 < 3)
return locatePointLine(v1, v2, v3) ==
locatePointLine(v, v2, v3);
if(iV3 < 3)
return locatePointLine(v3, v1, v2) ==
locatePointLine(v, v1, v2);
return false; // original edge does not touch super-triangle
}

if(iVcw < 3)
return locatePointLine(v1, v2, v3) == locatePointLine(pos, v2, v3);
if(iVccw < 3)
return locatePointLine(v3, v1, v2) == locatePointLine(pos, v1, v2);
if(iV2 < 3) // flip-candidate edge touches super-triangle
{
// does original edge also touch super-triangle?
if(iV1 < 3)
return locatePointLine(v1, v, v3) == locatePointLine(v2, v, v3);
if(iV3 < 3)
return locatePointLine(v3, v1, v) == locatePointLine(v2, v1, v);
return false; // original edge does not touch super-triangle
}
// flip-candidate edge does not touch super-triangle
if(iV1 < 3)
return locatePointLine(v1, v2, v3) == locatePointLine(v, v2, v3);
if(iV3 < 3)
return locatePointLine(v3, v1, v2) == locatePointLine(v, v1, v2);
}
return isInCircumcircle(pos, v1, v2, v3);
return isInCircumcircle(v, v1, v2, v3);
}

/* Insert point into triangle: split into 3 triangles:
Expand Down
4 changes: 4 additions & 0 deletions visualizer/data/issue-65-wrong-edges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 0
1 0
0 0.251
-1 0