diff --git a/geometry.cc b/geometry.cc index eb8cc585..ea26bf54 100644 --- a/geometry.cc +++ b/geometry.cc @@ -302,9 +302,6 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) { // guaranteed that at least one point in the polygon is strictly // inside its parent (not on one of its boundary lines). - // Once we have that, we can run through the outer rings that have - // an even number of parents, - std::vector rings; decode_rings(t, rings); std::sort(rings.begin(), rings.end()); @@ -319,10 +316,15 @@ static void decode_clipped(ClipperLib::PolyNode *t, drawvec &out) { } } } -nextring: + nextring: ; } + // Then reverse the winding order of any rings that turned out + // to actually be inner when they are outer, or vice versa. + // (A ring is outer if it has no parent or if its parent is + // an inner ring.) + for (size_t ii = rings.size(); ii > 0; ii--) { size_t i = ii - 1; @@ -339,6 +341,10 @@ nextring: } } + // Then run through the rings again, outputting each outer ring + // followed by its direct children, and checking to make sure + // there are no child rings whose parents weren't identified. + for (size_t ii = rings.size(); ii > 0; ii--) { size_t i = ii - 1; @@ -535,11 +541,11 @@ void check_polygon(drawvec &geom, drawvec &before) { if (t > 0 && t < 1 && s > 0 && s < 1) { printf("Internal error: self-intersecting polygon. %lld,%lld to %lld,%lld intersects %lld,%lld to %lld,%lld\n", - geom[i + 0].x, geom[i + 0].y, - geom[i + 1].x, geom[i + 1].y, - geom[j + 0].x, geom[j + 0].y, - geom[j + 1].x, geom[j + 1].y); - dump(before); + geom[i + 0].x, geom[i + 0].y, + geom[i + 1].x, geom[i + 1].y, + geom[j + 0].x, geom[j + 0].y, + geom[j + 1].x, geom[j + 1].y); + dump(before); } } }