diff --git a/demo/js/bundle.js b/demo/js/bundle.js index 5d07547..f5eff76 100644 --- a/demo/js/bundle.js +++ b/demo/js/bundle.js @@ -1781,6 +1781,8 @@ //var martinez = require('../../dist/martinez.min'); + window.martinez = boolean; + var mode = window.location.hash.substring(1); var path = '../test/fixtures/'; var file; @@ -1849,6 +1851,9 @@ case 'rectangles': file = 'rectangles.geojson'; break; + case 'boxes_overlap': + file = 'boxes_overlap.geojson'; + break; default: file = 'hole_hole.geojson'; break; @@ -1897,6 +1902,7 @@ fetch(path) .then(function (r) { return r.json(); }) .then(function (json) { + window.data = json; drawnItems.addData(json); map.fitBounds(drawnItems.getBounds().pad(0.05), { animate: false }); }); diff --git a/demo/js/index.js b/demo/js/index.js index b709130..f745154 100644 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -4,6 +4,8 @@ import './booleanopcontrol'; import martinez from '../../src/index'; //var martinez = require('../../dist/martinez.min'); +window.martinez = martinez; + let mode = window.location.hash.substring(1); let path = '../test/fixtures/'; const ext = '.geojson'; @@ -79,6 +81,9 @@ switch (mode) { case 'rectangles': file = 'rectangles.geojson'; break; + case 'boxes_overlap': + file = 'boxes_overlap.geojson'; + break; default: file = 'hole_hole.geojson'; break; @@ -127,6 +132,7 @@ function loadData(path) { fetch(path) .then((r) => r.json()) .then((json) => { + window.data = json; drawnItems.addData(json); map.fitBounds(drawnItems.getBounds().pad(0.05), { animate: false }); }); diff --git a/dist/martinez.umd.js b/dist/martinez.umd.js index ec5578c..5f77308 100644 --- a/dist/martinez.umd.js +++ b/dist/martinez.umd.js @@ -1,5 +1,5 @@ /** - * martinez v0.4.1 + * martinez v0.4.0 * Martinez polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor * * @author Alex Milevski diff --git a/test/edge_cases.test.js b/test/edge_cases.test.js index 9c12ba1..24e3322 100644 --- a/test/edge_cases.test.js +++ b/test/edge_cases.test.js @@ -438,5 +438,39 @@ tap.test('Edge cases', (main) => { t.end(); }); + + main.test('issue #80', (t) => { + const shapes = load.sync(path.join(__dirname, 'fixtures', 'boxes_overlap.geojson')); + const subject = shapes.features[0]; + const clipping = shapes.features[1]; + + console.log(shapes); + + + t.test('difference', (t) => { + const result = martinez.diff( + subject.geometry.coordinates, + clipping.geometry.coordinates + ); + t.deepEqual(result, [[[ + [10, 10], + [20, 10], + [20, 80], + [10, 80], + [10, 10] + ]], [[ + [30, 10], + [80, 10], + [80, 80], + [30, 80], + [30, 10] + ]]]); + + t.end(); + }); + + t.end(); + }); + main.end(); }); diff --git a/test/fixtures/boxes_overlap.geojson b/test/fixtures/boxes_overlap.geojson new file mode 100644 index 0000000..9906f50 --- /dev/null +++ b/test/fixtures/boxes_overlap.geojson @@ -0,0 +1,65 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 10, + 10 + ], + [ + 80, + 10 + ], + [ + 80, + 80 + ], + [ + 10, + 80 + ], + [ + 10, + 10 + ] + ] + ] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + 20, + 10 + ], + [ + 30, + 10 + ], + [ + 30, + 80 + ], + [ + 20, + 80 + ], + [ + 20, + 10 + ] + ] + ] + } + } + ] +}