Skip to content

Commit

Permalink
Fix the bug and add a regression test
Browse files Browse the repository at this point in the history
During the refactoring isFlipNeeded stopped checking if the edge to be flipped is constrained.
  • Loading branch information
artem-ogre committed Mar 1, 2023
1 parent d6bae25 commit 37de473
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CDT/include/Triangulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,8 @@ void Triangulation<T, TNearPointLocator>::edgeFlipInfo(
* 3. None of the vertices are super-tri: normal circumcircle test
*/
/*
* v4 original edge: (v1, v3)
* /|\ flip-candidate edge: (v, v2)
* v4 original edge: (v2, v4)
* /|\ flip-candidate edge: (v1, v3)
* / | \
* / | \
* / | \
Expand All @@ -1242,6 +1242,8 @@ bool Triangulation<T, TNearPointLocator>::isFlipNeeded(
const VertInd iV3,
const VertInd iV4) const
{
if(fixedEdges.count(Edge(iV2, iV4)))
return false; // flip not needed if the original edge is fixed
const V2d<T>& v2 = vertices[iV2];
const V2d<T>& v3 = vertices[iV3];
const V2d<T>& v4 = vertices[iV4];
Expand Down
37 changes: 30 additions & 7 deletions CDT/tests/cdt.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using namespace CDT;

constexpr bool updateFiles = false;

using CoordTypes = std::tuple<float, double>;
template <class CoordType>
using Vertices = std::vector<V2d<CoordType> >;
Expand Down Expand Up @@ -516,8 +518,7 @@ TEMPLATE_LIST_TEST_CASE(
"regression_issue_38_wrong_hull_small.txt",
"square with crack.txt",
"test_data_small.txt",
"unit square.txt"
);
"unit square.txt");

const auto typeSpecific = std::unordered_set<std::string>{
"guitar no box.txt",
Expand Down Expand Up @@ -550,8 +551,6 @@ TEMPLATE_LIST_TEST_CASE(
REQUIRE(CDT::verifyTopology(cdt));

// make true to update expected files (development purposes only)
const bool updateFiles = false;

const auto outputFileBase = "expected/" +
inputFile.substr(0, inputFile.size() - 4) +
"__" + typeString + to_string(order) + "_" +
Expand Down Expand Up @@ -644,8 +643,6 @@ TEMPLATE_LIST_TEST_CASE(
REQUIRE(CDT::verifyTopology(cdt));

// make true to update expected files (development purposes only)
const bool updateFiles = false;

const auto outputFileBase =
"expected/" + inputFile.substr(0, inputFile.size() - 4) +
"__conforming_" + typeString + to_string(order) + "_" +
Expand Down Expand Up @@ -682,7 +679,6 @@ TEMPLATE_LIST_TEST_CASE("Ground truth tests: crossing edges", "", CoordTypes)
triangulationType == "" ? cdt.insertEdges(ee) : cdt.conformToEdges(ee);
REQUIRE(CDT::verifyTopology(cdt));
// make true to update expected files (development purposes only)
const bool updateFiles = false;
const auto outputFileBase = "expected/" +
inputFile.substr(0, inputFile.size() - 4) +
"__" + triangulationType + to_string(order) +
Expand Down Expand Up @@ -758,3 +754,30 @@ TEMPLATE_LIST_TEST_CASE("Benchmarks", "[benchmark][.]", CoordTypes)
};
}
}

TEST_CASE("Don't flip constraint edge when resolving intersection", "")
{
const auto inputFile =
std::string("dont_flip_constraint_when_resolving_intersection.txt");
const auto order = VertexInsertionOrder::AsProvided;
const auto intersectingEdgesStrategy = IntersectingConstraintEdges::Resolve;
const auto minDistToConstraintEdge = 1e-6;
const auto outFile = "expected/" +
inputFile.substr(0, inputFile.size() - 4) + "__f64_" +
to_string(order) + "_" +
to_string(intersectingEdgesStrategy) + "_all.txt";

const auto [vv, ee] = readInputFromFile<double>("inputs/" + inputFile);
auto cdt = Triangulation<double>(
order, intersectingEdgesStrategy, minDistToConstraintEdge);
cdt.insertVertices(vv);
cdt.insertEdges(ee);
REQUIRE(CDT::verifyTopology(cdt));

if(updateFiles)
topologyToFile(outFile, cdt);
else
{
REQUIRE(topologyString(cdt) == topologyString(outFile));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
15
0 1 7 4294967295 6 3
0 3 2 2 7 4294967295
0 6 3 3 10 1
0 7 6 0 14 2
1 2 4 4294967295 8 5
1 4 5 4 12 6
1 5 7 5 13 0
2 3 8 1 9 8
2 8 4 7 9 4
3 4 8 11 8 7
3 6 9 2 14 11
3 9 4 10 12 9
4 9 5 11 13 5
5 9 7 12 14 6
6 7 9 3 13 10

5
3 4
3 9
4 9
5 9
6 9

2
3 9 0
5 9 0

4
3 9
1
3 5
4 9
1
4 6
5 9
1
3 5
6 9
1
4 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
6 3
2 8
12 11
12 10
2 7
12 8
5 10
0 1
0 2
1 3

0 comments on commit 37de473

Please sign in to comment.