mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-30 01:03:30 +01:00
Throw in Triangle::NeighborAcross in case of null pointer
Add an example quad for which the exception is throwni in the tests
This commit is contained in:
parent
06b0f14b29
commit
2c6bec64c0
@ -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()
|
||||||
|
4
testbed/data/deadly_quad.dat
Normal file
4
testbed/data/deadly_quad.dat
Normal 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
|
@ -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" }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user