From 423596a6557491bc482e518a596c608276a58736 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 29 Sep 2015 15:40:39 -0700 Subject: [PATCH] Port fix for https://github.com/mapbox/earcut/issues/29 Refs https://github.com/mapbox/earcut.hpp/issues/6 --- include/earcut.hpp | 3 ++- test/fixtures/geometries.hpp | 1 + test/fixtures/issue29.cpp | 12 ++++++++++++ test/test.cpp | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/issue29.cpp diff --git a/include/earcut.hpp b/include/earcut.hpp index a5300d6..aeafe95 100644 --- a/include/earcut.hpp +++ b/include/earcut.hpp @@ -683,7 +683,8 @@ Earcut::getLeftmost(Node* start) { // check if a diagonal between two polygon nodes is valid (lies in polygon interior) template bool Earcut::isValidDiagonal(Node* a, Node* b) { - return !intersectsPolygon(a, a, b) && + return a->next->i != b->i && a->prev->i != b->i && + !intersectsPolygon(a, a, b) && locallyInside(a, b) && locallyInside(b, a) && middleInside(a, a->v, b->v); } diff --git a/test/fixtures/geometries.hpp b/test/fixtures/geometries.hpp index a15d760..3e6a9e4 100644 --- a/test/fixtures/geometries.hpp +++ b/test/fixtures/geometries.hpp @@ -31,6 +31,7 @@ extern const DoublePolygon dude; extern const IntegerPolygon empty_square; extern const DoublePolygon issue16; extern const DoublePolygon issue17; +extern const DoublePolygon issue29; extern const IntegerPolygon water_huge; extern const IntegerPolygon water_huge2; extern const IntegerPolygon water; diff --git a/test/fixtures/issue29.cpp b/test/fixtures/issue29.cpp new file mode 100644 index 0000000..f5346e8 --- /dev/null +++ b/test/fixtures/issue29.cpp @@ -0,0 +1,12 @@ +#include "geometries.hpp" + +namespace mapbox { +namespace fixtures { + +const DoublePolygon issue29 = { + {{200.95000055654114,69.90565782485673},{201.73186418809928,76.50881049432792},{204.05247248713854,82.73234962527638},{207.79442497901618,88.23839184455574},{212.7323883100471,92.70045673093409},{218.58296075442922,95.86217257360113},{225.00460918453172,97.53918036725955},{231.66534446463922,97.66082593216561},{238.15796607054654,96.21973398409901},{244.1176358256489,93.27806596420706},{249.2188404462824,88.99822680730722},{253.15628113771672,83.64108043884043},{255.70631344406866,77.51111824424007},{256.73126424155197,70.93641692795792},{256.19351709797047,64.30797780468129},{254.1057433114911,57.996416078653425},{250.56431880965246,52.346517799043795},{245.8112865351897,47.719993951247304},{240.07834375849924,44.33761266223155},{233.71343464441597,42.419284673407674},{227.06488359675492,42.055728640102465},{220.51757991796475,43.257153422775446},{214.45449861431845,45.97523169373744},{209.20995664413203,50.053084840223896},{205.06721924245355,55.271000209450726},{202.29122001552022,61.30178454495035},{201.02451470680535,67.8368895214051}}, + {{242.34999892718187,69.90549289577612},{240.7584948063828,76.30057721128688},{236.31611852571368,81.17358751371503},{230.07699953842675,83.34595728587593},{223.55761859836056,82.33733346881347},{218.2910646148026,78.34856240227819},{215.5668820463121,72.34290095195175},{215.9904494531453,65.75019118711353},{219.47497291108593,60.1536534355022},{225.2189893186092,56.88651757836341},{231.8100271829404,56.72041164720431},{237.70269737243652,59.67713584899902},{241.47838292121884,65.0856644153595}}, +}; + +} +} diff --git a/test/test.cpp b/test/test.cpp index ead4eff..4880f23 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -121,6 +121,7 @@ int main() { areaTest("water4", mapbox::fixtures::water4); areaTest("issue16", mapbox::fixtures::issue16); areaTest("issue17", mapbox::fixtures::issue17); + areaTest("issue29", mapbox::fixtures::issue29); areaTest("park", mapbox::fixtures::park); areaTest("issue34", mapbox::fixtures::issue34);