From 70da00716915401f2eac3475cf1020728c7a9f1e Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Mon, 4 Apr 2022 22:33:15 +1000 Subject: [PATCH 1/3] Remove unnecessary holes from output --- src/connect_edges.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/connect_edges.js b/src/connect_edges.js index 0ce5c43..8e232b8 100644 --- a/src/connect_edges.js +++ b/src/connect_edges.js @@ -96,7 +96,13 @@ function initializeContourFromContext(event, contours, contourId) { // in an earlier iteration, otherwise it wouldn't be possible that it is "previous in // result". const lowerContourId = prevInResult.outputContourId; - const lowerResultTransition = prevInResult.resultTransition; + let lowerResultTransition = prevInResult.resultTransition; + if (!event.isExteriorRing && !event.isSubject) { + contour.cull = true; + } else if (!event.isExteriorRing && prevInResult.isExteriorRing) { + lowerResultTransition = 1; + } + if (lowerResultTransition > 0) { // We are inside. Now we have to check if the thing below us is another hole or // an exterior contour. @@ -182,5 +188,5 @@ export default function connectEdges(sortedEvents) { contours.push(contour); } - return contours; + return contours.filter(c => c.cull !== true); } From 6a940e80b146a5f2d0910a236352bc1aa27f6a07 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Mon, 4 Apr 2022 22:34:03 +1000 Subject: [PATCH 2/3] add test fixture --- test/fixtures/issue69.geojson | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/fixtures/issue69.geojson diff --git a/test/fixtures/issue69.geojson b/test/fixtures/issue69.geojson new file mode 100644 index 0000000..98db265 --- /dev/null +++ b/test/fixtures/issue69.geojson @@ -0,0 +1,21 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[2, 0],[10, 10],[10, 0],[2, 0]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[5, 1],[12, 1],[12, 9],[5, 9],[5, 1]],[[6, 2],[11, 8],[6, 8],[6, 2]]] + } + } + ] +} \ No newline at end of file From 5bacc2775d00860cea449d1ffeec6999e34223b6 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Mon, 4 Apr 2022 22:44:49 +1000 Subject: [PATCH 3/3] adjust approach to retain indexes --- src/connect_edges.js | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connect_edges.js b/src/connect_edges.js index 8e232b8..48daeb9 100644 --- a/src/connect_edges.js +++ b/src/connect_edges.js @@ -188,5 +188,5 @@ export default function connectEdges(sortedEvents) { contours.push(contour); } - return contours.filter(c => c.cull !== true); + return contours; } diff --git a/src/index.js b/src/index.js index b3a3f69..c92e5b1 100644 --- a/src/index.js +++ b/src/index.js @@ -80,7 +80,7 @@ export default function boolean(subject, clipping, operation) { const polygons = []; for (let i = 0; i < contours.length; i++) { let contour = contours[i]; - if (contour.isExterior()) { + if (contour.isExterior() && contour.cull !== true) { // The exterior ring goes first let rings = [contour.points]; // Followed by holes if any