Skip to content
Open
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
7 changes: 6 additions & 1 deletion poly2tri/sweep/sweep_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ void SweepContext::AddHole(const std::vector<Point*>& polyline)
{
InitEdges(polyline);
for (auto i : polyline) {
points_.push_back(i);
if (point_set_.insert(i).second) {
points_.push_back(i);
}
}
}

void SweepContext::AddPoint(Point* point) {
if (!point_set_.insert(point).second) {
throw std::runtime_error("Point already exists");
}
points_.push_back(point);
}

Expand Down
2 changes: 2 additions & 0 deletions poly2tri/sweep/sweep_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <list>
#include <vector>
#include <cstddef>
#include <unordered_set>

namespace p2t {

Expand Down Expand Up @@ -136,6 +137,7 @@ friend class Sweep;
std::vector<Triangle*> triangles_;
std::list<Triangle*> map_;
std::vector<Point*> points_;
std::unordered_set<Point*> point_set_;

// Advancing front
AdvancingFront* front_;
Expand Down
32 changes: 32 additions & 0 deletions unittest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ BOOST_AUTO_TEST_CASE(PolygonTest04)
}
}

BOOST_AUTO_TEST_CASE(TouchingHolesTest)
{
std::list<p2t::Point> points;
auto point = [&points](double a, double b){
points.emplace_back(a, b);
return &points.back();
};
std::vector<p2t::Point*> polyline{
point(0, 0),
point(1, 0),
point(0.5, 1),
};
auto point_02_02 = p2t::Point(0.2, 0.2);
std::vector<p2t::Point*> hole0 {
point(0.1, 0.1),
point(0.2, 0.1),
&point_02_02,
};
std::vector<p2t::Point*> hole1 {
&point_02_02,
point(0.3, 0.2),
point(0.3, 0.3),
};
p2t::CDT cdt{ polyline };
cdt.AddHole(hole0);
cdt.AddHole(hole1);
BOOST_CHECK_NO_THROW(cdt.Triangulate());
const auto result = cdt.GetTriangles();
BOOST_REQUIRE_EQUAL(result.size(), 9);
BOOST_CHECK(p2t::IsDelaunay(result));
}

BOOST_AUTO_TEST_CASE(TestbedFilesTest)
{
for (const auto& filename : { "custom.dat", "diamond.dat", "star.dat", "test.dat" }) {
Expand Down