Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary holes from output #149

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/connect_edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/issue69.geojson
Original file line number Diff line number Diff line change
@@ -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]]]
}
}
]
}