diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 1ad113b0..decef7bd 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -1219,6 +1219,25 @@ class Polygon { return list; } + // return true if any line segments on either poly crosses the other + // this is a shallow test and does not inspect inners + intersects(poly) { + let p0 = this.points.slice(); p0.push(p0[0]); + let p1 = poly.points.slice(); p1.push(p1[0]); + for (let i=1; i b.area() - a.area()); + for (let i=0; i o); + set.appendAll(xor); + continue outer; + } + } + } + // exit when no change to set occur + break; + } + return set; +} /** * Slice.doProjectedFills() diff --git a/src/geo/slicer.js b/src/geo/slicer.js index 36508749..6301a042 100644 --- a/src/geo/slicer.js +++ b/src/geo/slicer.js @@ -387,6 +387,9 @@ async function sliceZ(z, points, options = {}) { let rval = { z, lines }; if (groupFn) { let groups = groupFn(lines, z, options); + if (options.xor) { + groups = POLY.xor(groups); + } if (options.union) { let points = groups.map(p => p.length).reduce((a,b) => a + b); // simplistic healing of non-manifold meshes