Merge pull request #19 from pierre-dejoue/master

Add one exception case in Triangle::NeighborAcross
This commit is contained in:
Jan Niklas Hasse 2020-08-06 23:54:23 +02:00 committed by GitHub
commit a269fb4743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 10 deletions

View File

@ -14,7 +14,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install dependencies - name: Install dependencies
run: dnf install -yq cmake ninja-build clang-tools-extra python3-PyYAML run: dnf install -yq cmake ninja-build gcc-c++ clang-tools-extra python3-PyYAML
- name: Build with GCC - name: Build with GCC
run: | run: |

View File

@ -352,12 +352,18 @@ void Triangle::SetDelunayEdgeCW(const Point& p, bool e)
// The neighbor across to given point // The neighbor across to given point
Triangle& Triangle::NeighborAcross(const Point& opoint) Triangle& Triangle::NeighborAcross(const Point& opoint)
{ {
Triangle* neighbor = nullptr;
if (&opoint == points_[0]) { if (&opoint == points_[0]) {
return *neighbors_[0]; neighbor = neighbors_[0];
} else if (&opoint == points_[1]) { } else if (&opoint == points_[1]) {
return *neighbors_[1]; neighbor = neighbors_[1];
} else {
neighbor = neighbors_[2];
} }
return *neighbors_[2]; if (neighbor == nullptr) {
throw std::runtime_error("NeighborAcross - null neighbor");
}
return *neighbor;
} }
void Triangle::DebugPrint() void Triangle::DebugPrint()

View File

@ -54,8 +54,8 @@ void Sweep::SweepPoints(SweepContext& tcx)
for (size_t i = 1; i < tcx.point_count(); i++) { for (size_t i = 1; i < tcx.point_count(); i++) {
Point& point = *tcx.GetPoint(i); Point& point = *tcx.GetPoint(i);
Node* node = &PointEvent(tcx, point); Node* node = &PointEvent(tcx, point);
for (unsigned int i = 0; i < point.edge_list.size(); i++) { for (unsigned int j = 0; j < point.edge_list.size(); j++) {
EdgeEvent(tcx, point.edge_list[i], node); EdgeEvent(tcx, point.edge_list[j], node);
} }
} }
} }
@ -123,8 +123,7 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl
triangle = &triangle->NeighborAcross(point); triangle = &triangle->NeighborAcross(point);
EdgeEvent( tcx, ep, *p1, triangle, *p1 ); EdgeEvent( tcx, ep, *p1, triangle, *p1 );
} else { } else {
std::runtime_error("EdgeEvent - collinear points not supported"); throw std::runtime_error("EdgeEvent - collinear points not supported");
assert(0);
} }
return; return;
} }
@ -140,8 +139,7 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl
triangle = &triangle->NeighborAcross(point); triangle = &triangle->NeighborAcross(point);
EdgeEvent( tcx, ep, *p2, triangle, *p2 ); EdgeEvent( tcx, ep, *p2, triangle, *p2 );
} else { } else {
std::runtime_error("EdgeEvent - collinear points not supported"); throw std::runtime_error("EdgeEvent - collinear points not supported");
assert(0);
} }
return; return;
} }

View File

@ -0,0 +1,4 @@
0.0 0.0
1.0e-05 0.0
1.1e-04 3.0e-07
1.0e-04 3.0e-07

View File

@ -5,6 +5,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <stdexcept>
BOOST_AUTO_TEST_CASE(BasicTest) BOOST_AUTO_TEST_CASE(BasicTest)
{ {
@ -40,6 +41,22 @@ BOOST_AUTO_TEST_CASE(QuadTest)
} }
} }
BOOST_AUTO_TEST_CASE(QuadTestThrow)
{
// Very narrow quad that demonstrates a failure case during triangulation
std::vector<p2t::Point*> polyline {
new p2t::Point(0.0, 0.0),
new p2t::Point(1.0e-05, 0.0),
new p2t::Point(1.1e-04, 3.0e-07),
new p2t::Point(1.0e-04, 3.0e-07)
};
p2t::CDT cdt{ polyline };
BOOST_CHECK_THROW(cdt.Triangulate(), std::runtime_error);
for (const auto p : polyline) {
delete p;
}
}
BOOST_AUTO_TEST_CASE(TestbedFilesTest) BOOST_AUTO_TEST_CASE(TestbedFilesTest)
{ {
for (const auto& filename : { "custom.dat", "diamond.dat", "star.dat", "test.dat" }) { for (const auto& filename : { "custom.dat", "diamond.dat", "star.dat", "test.dat" }) {