Skip to content

Commit

Permalink
Fix a bug with incorrect topology in pseudo-polygon triangulation
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-ogre committed Oct 16, 2023
1 parent cf4df31 commit 750600e
Show file tree
Hide file tree
Showing 3 changed files with 20,023 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,14 @@ void Triangulation<T, TNearPointLocator>::triangulatePseudopolygon(
std::vector<TriangulatePseudopolygonTask>& iterations)
{
assert(poly.size() > 2);

// note: needed for proper linking with outer triangles
// during pseudo-polygon triangulation, vertex triangle
// will be set back, see asserts at the end
for(std::size_t i = 1; i < outerTris.size(); ++i)
if(outerTris[i] == noNeighbor)
m_vertTris[poly[i]] = noNeighbor;

// note: uses interation instead of recursion to avoid stack overflows
iterations.clear();
iterations.push_back(make_tuple(
Expand All @@ -1569,6 +1577,10 @@ void Triangulation<T, TNearPointLocator>::triangulatePseudopolygon(
{
triangulatePseudopolygonIteration(poly, outerTris, iterations);
}

// make sure adjacent triangles were restored
for(std::size_t i = 0; i < poly.size(); ++i)
assert(m_vertTris[poly[i]] != noNeighbor);
}

template <typename T, typename TNearPointLocator>
Expand Down
10 changes: 10 additions & 0 deletions CDT/tests/cdt.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,3 +852,13 @@ TEST_CASE("Regression: multiple hanging edges", "")
REQUIRE(topologyString(cdt) == topologyString(outFile));
}
}

TEST_CASE("Regression test", "")
{
const auto inputFile = std::string("debug2.txt");
const auto [vv, ee] = readInputFromFile<double>("inputs/" + inputFile);
auto cdt = Triangulation<double>(VertexInsertionOrder::Auto);
cdt.insertVertices(vv);
cdt.insertEdges(ee);
REQUIRE(CDT::verifyTopology(cdt));
}
Loading

0 comments on commit 750600e

Please sign in to comment.