From 89338f65df46c095e27ed93f410c1722df4fcc54 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Fri, 21 Feb 2020 14:38:06 +0200 Subject: [PATCH 1/2] Added generic test case handling (#117) * implemented generic test cases * made geojson conform to specs * added more test cases * updated test cases * removed duplicate 'fatal' test cases * made polygon_trapezoid_edge_overlap.geojson a test case * made overlap_loop.geojson a test case * made overlap_y.geojson a test case * made touching_boxes.geojson a test case * made 'disjoint union nesting' a test case * made 'collapsed edges removed' a test case * made 'rectangles' a test case * added filling rectangle test case * removed duplicated tests * made test case geojsons valid geojsons (missing properties) Co-authored-by: Rowan Winsemius --- package-lock.json | 6 + package.json | 1 + test/edge_cases.test.js | 479 ------------------ test/fixtures/fatal1.geojson | 38 -- test/fixtures/fatal2.geojson | 21 - test/fixtures/fatal3.geojson | 7 - test/fixtures/fatal4.geojson | 6 - test/fixtures/hourglasses.geojson | 16 - test/fixtures/issue103.geojson | 18 - test/fixtures/overlap_loop.geojson | 16 - test/fixtures/overlap_y.geojson | 16 - .../polygon_trapezoid_edge_overlap.geojson | 16 - test/fixtures/rectangles.geojson | 30 -- test/fixtures/touching_boxes.geojson | 16 - test/genericTestCases.test.js | 84 +++ test/genericTestCases/_new.geojson.template | 34 ++ .../collapsed_edges_removed.geojson | 63 +++ .../disjoint_union_nesting.geojson | 100 ++++ test/genericTestCases/fatal1.geojson | 100 ++++ test/genericTestCases/fatal2.geojson | 437 ++++++++++++++++ test/genericTestCases/fatal3.geojson | 109 ++++ test/genericTestCases/fatal4.geojson | 105 ++++ .../filling_rectangle.geojson | 32 ++ test/genericTestCases/hourglasses.geojson | 122 +++++ test/genericTestCases/issue103.geojson | 158 ++++++ test/genericTestCases/issue76.geojson | 107 ++++ test/genericTestCases/overlap_loop.geojson | 83 +++ test/genericTestCases/overlap_y.geojson | 73 +++ .../polygon_trapezoid_edge_overlap.geojson | 66 +++ test/genericTestCases/tie.geojson | 37 ++ test/genericTestCases/touching_boxes.geojson | 58 +++ 31 files changed, 1775 insertions(+), 679 deletions(-) delete mode 100644 test/edge_cases.test.js delete mode 100644 test/fixtures/fatal1.geojson delete mode 100644 test/fixtures/fatal2.geojson delete mode 100644 test/fixtures/fatal3.geojson delete mode 100644 test/fixtures/fatal4.geojson delete mode 100644 test/fixtures/hourglasses.geojson delete mode 100644 test/fixtures/issue103.geojson delete mode 100644 test/fixtures/overlap_loop.geojson delete mode 100644 test/fixtures/overlap_y.geojson delete mode 100644 test/fixtures/polygon_trapezoid_edge_overlap.geojson delete mode 100644 test/fixtures/rectangles.geojson delete mode 100644 test/fixtures/touching_boxes.geojson create mode 100644 test/genericTestCases.test.js create mode 100644 test/genericTestCases/_new.geojson.template create mode 100644 test/genericTestCases/collapsed_edges_removed.geojson create mode 100644 test/genericTestCases/disjoint_union_nesting.geojson create mode 100644 test/genericTestCases/fatal1.geojson create mode 100644 test/genericTestCases/fatal2.geojson create mode 100644 test/genericTestCases/fatal3.geojson create mode 100644 test/genericTestCases/fatal4.geojson create mode 100644 test/genericTestCases/filling_rectangle.geojson create mode 100644 test/genericTestCases/hourglasses.geojson create mode 100644 test/genericTestCases/issue103.geojson create mode 100644 test/genericTestCases/issue76.geojson create mode 100644 test/genericTestCases/overlap_loop.geojson create mode 100644 test/genericTestCases/overlap_y.geojson create mode 100644 test/genericTestCases/polygon_trapezoid_edge_overlap.geojson create mode 100644 test/genericTestCases/tie.geojson create mode 100644 test/genericTestCases/touching_boxes.geojson diff --git a/package-lock.json b/package-lock.json index d84c5da..803dba9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1342,6 +1342,12 @@ "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, + "json-stringify-pretty-compact": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/json-stringify-pretty-compact/-/json-stringify-pretty-compact-2.0.0.tgz", + "integrity": "sha512-WRitRfs6BGq4q8gTgOy4ek7iPFXjbra0H3PmDLKm2xnZ+Gh1HUhiKGgCZkSPNULlP7mvfu6FV/mOLhCarspADQ==", + "dev": true + }, "jsts": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/jsts/-/jsts-1.3.0.tgz", diff --git a/package.json b/package.json index ae9faa9..4566148 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "eslint-plugin-jsdoc": "^20.0.2", "eslint-plugin-promise": "^3.8.0", "geojson-project": "^1.0.0", + "json-stringify-pretty-compact": "^2.0.0", "http-server": "^0.12.1", "leaflet": "^1.2.0", "leaflet-editable": "^1.1.0", diff --git a/test/edge_cases.test.js b/test/edge_cases.test.js deleted file mode 100644 index 1ae596f..0000000 --- a/test/edge_cases.test.js +++ /dev/null @@ -1,479 +0,0 @@ -import tap from 'tape'; -import * as martinez from '../index'; -import load from 'load-json-file'; -import path from 'path'; - -tap.test('Edge cases', (main) => { - - main.test('touching hourglasses', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'hourglasses.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0.5],[0.25,0.75],[0,1],[0,0.5]]],[[[0.75,0.75],[1,0.5],[1,1],[0.75,0.75]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[0.5,0.5],[0.25,0.75],[0.5,1],[0,1.5],[0,1],[0,0.5],[0,0]]],[[[0.5,0.5],[1,0],[1,0.5],[1,1],[1,1.5],[0.5,1],[0.75,0.75],[0.5,0.5]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[0.5,0.5],[0.25,0.75],[0,0.5],[0,0]]],[[[0.5,0.5],[1,0],[1,0.5],[0.75,0.75],[0.5,0.5]]]]); - - t.end(); - }); - - t.test('difference 2', (t) => { - const result = martinez.diff( - clipping.geometry.coordinates, - subject.geometry.coordinates - ); - t.deepEqual(result, [[[[0,1],[0.25,0.75],[0.5,1],[0,1.5],[0,1]]],[[[0.5,1],[0.75,0.75],[1,1],[1,1.5],[0.5,1]]]]); - - t.end(); - }); - - t.end(); - }); - - main.test('polygon + trapezoid', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'polygon_trapezoid_edge_overlap.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', function(t) { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[3.5,3.5],[7,0],[14,0],[17.5,3.5],[3.5,3.5]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[7,0],[14,0],[21,0],[21,3.5],[17.5,3.5],[21,7],[0,7],[3.5,3.5],[0,3.5],[0,0]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[7,0],[3.5,3.5],[0,3.5],[0,0]]],[[[14,0],[21,0],[21,3.5],[17.5,3.5],[14,0]]]]); - - t.end(); - }); - - t.end(); - }); - - main.test('overlapping edge + one inside', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'overlap_loop.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[57.8,-49.1],[177.8,-49.1],[177.8,-37.1],[57.8,-37.1],[57.8,-49.1]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[57.8,-97.1],[196.4,-97.1],[196.4,-11.5],[57.8,-11.5],[57.8,-37.1],[57.8,-49.1],[57.8,-97.1]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, []); - - t.end(); - }); - - t.end(); - }); - - main.test('overlapping Y shift', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'overlap_y.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', function(t) { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[-1883,-8.5],[-1783,-8.5],[-1783,-3],[-1883,-3],[-1883,-8.5]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[-1883,-25],[-1783,-25],[-1783,-8.5],[-1783,-3],[-1783,75],[-1883,75],[-1883,-3],[-1883,-8.5],[-1883,-25]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, []); - - t.end(); - }); - - t.end(); - }); - - main.test('touching boxes', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'touching_boxes.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, []); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[3,0],[3,1],[4,1],[4,2],[3,2],[3,3],[0,3],[0,0]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[0,0],[3,0],[3,1],[3,2],[3,3],[0,3],[0,0]]]]); - - t.end(); - }); - - t.end(); - }); - - main.test('disjoint union nesting', (t) => { // issue #47 - const p1 = [[[12.91,6.09],[12.91,6.91],[12.09,6.91],[12.09,6.09],[12.91,6.09]] - ]; - const p2 = [ - [[12.75,6.25],[12.75,6.75],[11.75,6.75],[11.75,8.25],[12.75,8.25],[12.75,8.75],[11.75,8.75],[11.75,9.75],[11.25,9.75],[11.25,8.75],[10.25,8.75],[10.25,8.25],[11.25,8.25],[11.25,6.75],[10.25,6.75],[10.25,6.25],[12.75,6.25]], - [[4.75,2.25],[4.75,2.75],[4.25,2.75],[4.25,2.25],[4.75,2.25]] - ]; - t.deepEqual(martinez.union(p1, p2), [[[[[[4.25,2.25],[4.75,2.25],[4.75,2.75],[4.25,2.75],[4.25,2.25]]]]],[[[10.25,6.25],[12.09,6.25],[12.09,6.09],[12.91,6.09],[12.91,6.91],[12.09,6.91],[12.09,6.75],[11.75,6.75],[11.75,8.25],[12.75,8.25],[12.75,8.75],[11.75,8.75],[11.75,9.75],[11.25,9.75],[11.25,8.75],[10.25,8.75],[10.25,8.25],[11.25,8.25],[11.25,6.75],[10.25,6.75],[10.25,6.25]]]]); - t.end(); - }); - - main.test('infinite loop crash', (t) => { - const p1 = [[ - [180.60987101280907, 22.943242898435663], - [280.6098710128091, 22.943242898435663], - [280.6098710128091, 62.94324289843566], - [180.60987101280907, 62.94324289843566], - [180.60987101280907, 22.943242898435663] - ]]; - const p2 = [[ - [-5.65625, 110.828125], - [-7.53125, 202.234375], - [366.0625, 202.234375], - [356.6875, 65.828125], - [260.125, 59.265625], - [253.09375, 40.984375], - [189.34375, 19.890625], - [141.0625, 36.765625], - [111.53125, 6.765625], - [73.5625, 36.765625], - [67.46875, 10.984375], - [41.21875, 10.515625], - [36.0625, 42.390625], - [65.59375, 53.171875], - [-5.65625, 110.828125] - ]]; - const r = [[[ - [198.56943964860557, 22.943242898435663], - [253.09375, 40.984375], - [260.125, 59.265625], - [280.6098710128091, 60.657800699899646], - [280.6098710128091, 62.94324289843566] - ]]]; - - t.deepEqual(martinez.intersection(p1, p2), r); - t.end(); - }); - - main.test('collapsed edges removed', (t) => { - const p1 = [[ - [355,139], - [420,202], - [384,237], - [353,205], - [330,230], - [330,230], - [291,197] - ]]; - const p2 =[[ - [355,139], - [420,202], - [384,237], - [353,205], - - [330,230], - [330,230], - [291,197] - ]]; - - t.deepEqual(martinez.intersection(p1, p2), [[[[291,197],[330,230],[353,205],[384,237],[420,202],[355,139]]]]); - t.end(); - }); - - main.test('fatal 1', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'fatal1.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - //console.log('intersection', JSON.stringify(result)); - t.deepEqual(result, [[[[117.63171592083741,3.271053337273843],[117.63180470386554,3.2708954059271265],[117.6320843,3.2708497],[117.6321104,3.2709415],[117.63171592083741,3.271053337273843]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - //console.log('union', JSON.stringify(result)); - t.deepEqual(result, [[[[117.62484785200004,3.283270575000117],[117.63171592083741,3.271053337273843],[117.6315993,3.2710864],[117.631605,3.2711063],[117.6315403,3.2711246],[117.6314897,3.2709469],[117.63180470386554,3.2708954059271265],[117.63331139400017,3.268215236000103],[117.659922722,3.255275783000087],[117.62484785200004,3.283270575000117]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - //console.log('diff', JSON.stringify(result)); - t.deepEqual(result, [[[[117.62484785200004,3.283270575000117],[117.63171592083741,3.271053337273843],[117.6321104,3.2709415],[117.6320843,3.2708497],[117.63180470386554,3.2708954059271265],[117.63331139400017,3.268215236000103],[117.659922722,3.255275783000087],[117.62484785200004,3.283270575000117]]]]); - - t.end(); - }); - - t.end(); - }); - - - main.test('fatal 2', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'fatal2.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[-79.887688,40.444658],[-79.88768799972165,40.44465799897759],[-79.88768795318525,40.44465798378203],[-79.887688,40.444658]]],[[[-79.88768796122203,40.444657857562895],[-79.88724301621599,40.443023510093695],[-79.887574,40.44424199906833],[-79.88768796122203,40.444657857562895]]],[[[-79.88761078560448,40.44463125072726],[-79.8875759999999,40.44461799906841],[-79.887472,40.44457999906844],[-79.887351,40.44453499906845],[-79.88724,40.44449899906847],[-79.887128,40.44446399906846],[-79.8871280003921,40.44446400013584],[-79.88761078560448,40.44463125072726]]],[[[-79.88711873229528,40.44256717591859],[-79.88685922414403,40.4416281542633],[-79.88690199999989,40.44178499906848],[-79.887067,40.4423799990685],[-79.88711873229528,40.44256717591859]]]]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [ - [ - [ - [-79.894363,40.44117499906849],[-79.894272,40.44123699906842],[-79.894179,40.44123699906842], - [-79.89357,40.441237999068484],[-79.893368,40.441238999068446],[-79.893169,40.441239999068465], - [-79.8925749999999,40.441243999068476],[-79.892543,40.44124499906835],[-79.892377,40.44125199906844], - [-79.892264,40.44125599906838],[-79.892213,40.44125799906857],[-79.891928,40.441241999068474], - [-79.891816,40.44123699906842],[-79.891702,40.441229999068575],[-79.891555,40.44122299906853], - [-79.891502,40.441215999068476],[-79.891437,40.44120099906849],[-79.891368,40.44117599906851], - [-79.891262,40.441137999068566],[-79.890921,40.44101499906854],[-79.89092,40.44101499906854], - [-79.889892,40.44067299906851],[-79.88955,40.440559999068554],[-79.889376,40.44050199906853], - [-79.888857,40.44032999906851],[-79.888684,40.440272999068426],[-79.888579,40.440237999068586], - [-79.888264,40.44013299906854],[-79.888159,40.44009899906841],[-79.88793,40.440022999068574], - [-79.8872429999999,40.43979699906849],[-79.887015,40.43972199906852],[-79.886931,40.43969399906849], - [-79.886921,40.43969299906843],[-79.886882,40.43968999906852],[-79.886626,40.43968799906853], - [-79.886528,40.43968799906853],[-79.886501,40.43968699906842],[-79.88642,40.43968699906842], - [-79.886393,40.43968699906842],[-79.886406,40.43974199906857],[-79.886445,40.43990699906852], - [-79.886458,40.43996299906853],[-79.886476,40.440069999068506],[-79.88648,40.44009399906854], - [-79.88652999999987,40.44039399906853],[-79.886548,40.44050199906853],[-79.886608,40.44071799906848], - [-79.88661599999989,40.440745999068476],[-79.886788,40.4413689990685],[-79.886848,40.441586999068434], - [-79.88685922414403,40.4416281542633],[-79.886548,40.440502],[-79.886393,40.439687],[-79.885782,40.436843], - [-79.882656,40.436087],[-79.881163,40.438717],[-79.880716,40.439506],[-79.879353,40.441889], - [-79.880724,40.442343],[-79.887128,40.444464],[-79.8871280003921,40.44446400013584], - [-79.887182,40.44461099906854],[-79.887176,40.44464599906839],[-79.887158,40.4447569990685], - [-79.887134,40.444810999068544],[-79.88695099999988,40.445137999068415],[-79.886934,40.44516499906851], - [-79.886837,40.44533099906844],[-79.886745,40.44548899906847],[-79.886472,40.44596399906852], - [-79.886381,40.446122999068365],[-79.886335,40.44620099906844],[-79.886199,40.4464369990684], - [-79.886155,40.44651599906838],[-79.88611,40.44659399906846],[-79.885974,40.446827999068454], - [-79.88593,40.44690699906842],[-79.886143,40.446980999068494],[-79.88638,40.447058999068375], - [-79.887733,40.44750899906847],[-79.888184,40.44765899906843],[-79.888318,40.44771499906848], - [-79.888366,40.44773499906852],[-79.888406,40.44777299906845], - [-79.888547,40.447843999068475],[-79.888729,40.448060999068524],[-79.889005,40.448329999068356], - [-79.8892419999999,40.448540999068435],[-79.889816,40.44905099906851],[-79.890444,40.44945899906849], - [-79.89107299999988,40.4497789990684],[-79.891154,40.449820999068436],[-79.891768,40.45009799906849], - [-79.892038,40.45017699906838],[-79.892372,40.45025199906842],[-79.892423,40.45026599906851], - [-79.892423,40.45017299906844],[-79.892423,40.45010299906852],[-79.892424,40.45006999906842], - [-79.892429,40.44997199906848],[-79.892431,40.44993999906836],[-79.892436,40.449918999068366], - [-79.892452,40.44985699906839], - [-79.892458,40.44983699906852],[-79.892529,40.44956799906845],[-79.892742,40.44876399906836], - [-79.892759,40.44870099906847],[-79.892788,40.44858799906836],[-79.892802,40.44851799906848], - [-79.892996,40.4475889990685],[-79.893015,40.44750399906845],[-79.893021,40.447475999068395], - [-79.893163,40.44684999906851],[-79.893225,40.44649399906848],[-79.893242,40.44640399906853], - [-79.893338,40.44599099906845],[-79.893428,40.44549099906846], - [-79.893578,40.444658999068416],[-79.893584,40.44458899906848],[-79.893751,40.443836999068466], - [-79.893782,40.443722999068385],[-79.893841,40.44344499906848],[-79.893923,40.443065999068416], - [-79.893999,40.44271799906857],[-79.894005,40.442688999068444],[-79.894085,40.44231599906855], - [-79.894169,40.441928999068494],[-79.894172,40.44191599906846],[-79.894231,40.44163799906855], - [-79.894242,40.44160999906841],[-79.894257,40.44156199906851],[-79.894279,40.44148399906843], - [-79.894336,40.44128999906837],[-79.894344,40.4412529990685],[-79.894363,40.44117499906849]]], - [[[-79.887688,40.444657999068475], - [-79.88768796122203,40.444657857562895],[-79.88768799972165,40.44465799897759],[-79.887688,40.444657999068475]]], - [[[-79.88768795318525,40.44465798378203],[-79.88761078560448,40.44463125072726],[-79.887639,40.44464199906838],[-79.88768795318525,40.44465798378203]]],[[[-79.88724301621599,40.443023510093695],[-79.887235,40.442993999068484], - [-79.887122,40.44257899906844],[-79.88711873229528,40.44256717591859],[-79.887122,40.442579],[-79.88724301621599,40.443023510093695]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[[-79.88768799972165,40.44465799897759],[-79.88768796122203,40.444657857562895],[-79.887574,40.44424199906833],[-79.88724301621599,40.443023510093695],[-79.887122,40.442579],[-79.88711873229528,40.44256717591859],[-79.887067,40.4423799990685],[-79.88690199999989,40.44178499906848],[-79.88685922414403,40.4416281542633],[-79.886548,40.440502],[-79.886393,40.439687],[-79.885782,40.436843],[-79.882656,40.436087],[-79.881163,40.438717],[-79.880716,40.439506],[-79.879353,40.441889],[-79.880724,40.442343],[-79.887128,40.444464],[-79.8871280003921,40.44446400013584],[-79.887128,40.44446399906846],[-79.88724,40.44449899906847],[-79.887351,40.44453499906845],[-79.887472,40.44457999906844],[-79.8875759999999,40.44461799906841],[-79.88761078560448,40.44463125072726],[-79.88768795318525,40.44465798378203],[-79.88768799972165,40.44465799897759]]]]); - - t.end(); - }); - - t.end(); - }); - - - main.test('issue #76', (t) => { - const shapes = load.sync(path.join(__dirname, 'fixtures', 'rectangles.geojson')); - const subject = shapes.features[0]; - const clipping = shapes.features[1]; - - t.test('intersection', (t) => { - const result = martinez.intersection( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [ [ [ - [ -19.3046867422006, -126.63400219275148 ], - [ -19.3046867422006, -107.63400219275148 ], - [ 10.695313257799395, -107.63400219275148 ], - [ 10.695313257799395, -126.63400219275148 ], - [ -19.3046867422006, -126.63400219275148 ] - ] ] ]); - - t.end(); - }); - - t.test('union', (t) => { - const result = martinez.union( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[ - [[-96.66033269728321,-126.63400219275148], - [-19.3046867422006,-126.63400219275148], - [-19.304686742200587,-357.48241878255635], - [10.695313257799413,-357.48241878255635], - [10.695313257799395,-126.63400219275148], - [13.370917302716792,-126.63400219275148], - [13.370917302716792,-107.63400219275148], - [10.695313257799395,-107.63400219275148], - [10.695313257799384,126.92383121744365], - [-19.304686742200616,126.92383121744365], - [-19.3046867422006,-107.63400219275148]]]]); - - t.end(); - }); - - t.test('difference', (t) => { - const result = martinez.diff( - subject.geometry.coordinates, - clipping.geometry.coordinates - ); - t.deepEqual(result, [[[ - [-19.304686742200616,126.92383121744365], - [-19.3046867422006,-107.63400219275148], - [10.695313257799395,-107.63400219275148], - [10.695313257799384,126.92383121744365], - [10.695313257799413,-357.48241878255635], - [10.695313257799395,-126.63400219275148], - [-19.3046867422006,-126.63400219275148], - [-19.304686742200587,-357.48241878255635] - ]]]); - - t.end(); - }); - - t.end(); - }); - - main.end(); -}); diff --git a/test/fixtures/fatal1.geojson b/test/fixtures/fatal1.geojson deleted file mode 100644 index 3812ab9..0000000 --- a/test/fixtures/fatal1.geojson +++ /dev/null @@ -1,38 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [117.659922722, 3.255275783000087], - [117.63331139400017, 3.268215236000103], - [117.62484785200004, 3.283270575000117], - [117.659922722, 3.255275783000087] - ] - ] - } - }, - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [117.6315403, 3.2711246], - [117.631605, 3.2711063], - [117.6315993, 3.2710864], - [117.6321104, 3.2709415], - [117.6320843, 3.2708497], - [117.6314897, 3.2709469], - [117.6315403, 3.2711246] - ] - ] - } - } - ] -} diff --git a/test/fixtures/fatal2.geojson b/test/fixtures/fatal2.geojson deleted file mode 100644 index eb02ea1..0000000 --- a/test/fixtures/fatal2.geojson +++ /dev/null @@ -1,21 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [[ [-79.887128,40.444464], [-79.880724,40.442343], [-79.879353,40.441889], [-79.880716,40.439506], [-79.881163,40.438717], [-79.882656,40.436087], [-79.885782,40.436843], [-79.886393,40.439687], [-79.886548,40.440502], [-79.887122,40.442579], [-79.887688,40.444658], [-79.887128,40.444464]]] - } - }, - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [[ [ -79.88648, 40.440093999068537 ], [ -79.886476, 40.440069999068506 ], [ -79.886458, 40.439962999068527 ], [ -79.886445, 40.439906999068519 ], [ -79.886406, 40.439741999068573 ], [ -79.886393, 40.439686999068421 ], [ -79.88642, 40.439686999068421 ], [ -79.886501, 40.439686999068421 ], [ -79.886528, 40.439687999068532 ], [ -79.886626, 40.439687999068532 ], [ -79.886882, 40.43968999906852 ], [ -79.886921, 40.439692999068427 ], [ -79.886931, 40.439693999068488 ], [ -79.887015, 40.439721999068517 ], [ -79.887242999999899, 40.439796999068491 ], [ -79.88793, 40.440022999068574 ], [ -79.888159, 40.440098999068411 ], [ -79.888264, 40.440132999068538 ], [ -79.888579, 40.440237999068586 ], [ -79.888684, 40.440272999068426 ], [ -79.888857, 40.44032999906851 ], [ -79.889376, 40.44050199906853 ], [ -79.88955, 40.440559999068554 ], [ -79.889892, 40.440672999068511 ], [ -79.89092, 40.441014999068543 ], [ -79.890921, 40.441014999068543 ], [ -79.891262, 40.441137999068566 ], [ -79.891368, 40.441175999068513 ], [ -79.891437, 40.441200999068492 ], [ -79.891502, 40.441215999068476 ], [ -79.891555, 40.441222999068529 ], [ -79.891702, 40.441229999068575 ], [ -79.891816, 40.441236999068423 ], [ -79.891928, 40.441241999068474 ], [ -79.892213, 40.441257999068569 ], [ -79.892264, 40.441255999068382 ], [ -79.892377, 40.441251999068442 ], [ -79.892543, 40.441244999068353 ], [ -79.892574999999894, 40.441243999068476 ], [ -79.893169, 40.441239999068465 ], [ -79.893368, 40.441238999068446 ], [ -79.89357, 40.441237999068484 ], [ -79.894179, 40.441236999068423 ], [ -79.894272, 40.441236999068423 ], [ -79.894363, 40.441174999068487 ], [ -79.894344, 40.441252999068503 ], [ -79.894336, 40.441289999068367 ], [ -79.894279, 40.441483999068431 ], [ -79.894257, 40.441561999068512 ], [ -79.894242, 40.441609999068412 ], [ -79.894231, 40.441637999068547 ], [ -79.894172, 40.441915999068463 ], [ -79.894169, 40.441928999068494 ], [ -79.894085, 40.442315999068548 ], [ -79.894005, 40.442688999068444 ], [ -79.893999, 40.44271799906857 ], [ -79.893923, 40.443065999068416 ], [ -79.893841, 40.443444999068483 ], [ -79.893782, 40.443722999068385 ], [ -79.893751, 40.443836999068466 ], [ -79.893584, 40.444588999068479 ], [ -79.893578, 40.444658999068416 ], [ -79.893428, 40.445490999068461 ], [ -79.893338, 40.445990999068449 ], [ -79.893242, 40.446403999068529 ], [ -79.893225, 40.44649399906848 ], [ -79.893163, 40.446849999068512 ], [ -79.893021, 40.447475999068395 ], [ -79.893015, 40.447503999068452 ], [ -79.892996, 40.4475889990685 ], [ -79.892802, 40.448517999068478 ], [ -79.892788, 40.448587999068359 ], [ -79.892759, 40.448700999068471 ], [ -79.892742, 40.448763999068362 ], [ -79.892529, 40.449567999068449 ], [ -79.892458, 40.449836999068523 ], [ -79.892452, 40.449856999068388 ], [ -79.892436, 40.449918999068366 ], [ -79.892431, 40.449939999068363 ], [ -79.892429, 40.449971999068481 ], [ -79.892424, 40.450069999068418 ], [ -79.892423, 40.45010299906852 ], [ -79.892423, 40.450172999068442 ], [ -79.892423, 40.450265999068513 ], [ -79.892372, 40.450251999068421 ], [ -79.892038, 40.450176999068383 ], [ -79.891768, 40.45009799906849 ], [ -79.891154, 40.449820999068436 ], [ -79.891072999999878, 40.4497789990684 ], [ -79.890444, 40.44945899906849 ], [ -79.889816, 40.449050999068511 ], [ -79.889241999999896, 40.448540999068435 ], [ -79.889005, 40.448329999068356 ], [ -79.888729, 40.448060999068524 ], [ -79.888547, 40.447843999068475 ], [ -79.888406, 40.447772999068448 ], [ -79.888366, 40.447734999068523 ], [ -79.888318, 40.447714999068481 ], [ -79.888184, 40.44765899906843 ], [ -79.887733, 40.447508999068468 ], [ -79.88638, 40.447058999068375 ], [ -79.886143, 40.446980999068494 ], [ -79.88593, 40.446906999068418 ], [ -79.885974, 40.446827999068454 ], [ -79.88611, 40.446593999068462 ], [ -79.886155, 40.446515999068382 ], [ -79.886199, 40.446436999068403 ], [ -79.886335, 40.446200999068438 ], [ -79.886381, 40.446122999068365 ], [ -79.886472, 40.445963999068518 ], [ -79.886745, 40.445488999068473 ], [ -79.886837, 40.445330999068439 ], [ -79.886934, 40.44516499906851 ], [ -79.886950999999883, 40.445137999068415 ], [ -79.887134, 40.444810999068544 ], [ -79.887158, 40.444756999068503 ], [ -79.887176, 40.444645999068392 ], [ -79.887182, 40.444610999068537 ], [ -79.887128, 40.444463999068461 ], [ -79.88724, 40.444498999068472 ], [ -79.887351, 40.444534999068452 ], [ -79.887472, 40.444579999068438 ], [ -79.887575999999896, 40.444617999068413 ], [ -79.887639, 40.444641999068381 ], [ -79.887688, 40.444657999068475 ], [ -79.887574, 40.444241999068332 ], [ -79.887235, 40.442993999068484 ], [ -79.887122, 40.442578999068438 ], [ -79.887067, 40.4423799990685 ], [ -79.886901999999893, 40.441784999068481 ], [ -79.886848, 40.441586999068434 ], [ -79.886788, 40.441368999068501 ], [ -79.88661599999989, 40.440745999068476 ], [ -79.886608, 40.440717999068482 ], [ -79.886548, 40.44050199906853 ], [ -79.886529999999865, 40.440393999068533 ], [ -79.88648, 40.440093999068537 ] ] ] - } - } - ] -} diff --git a/test/fixtures/fatal3.geojson b/test/fixtures/fatal3.geojson deleted file mode 100644 index c416cbf..0000000 --- a/test/fixtures/fatal3.geojson +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [ - { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [[[180.60987101280907, 22.943242898435663], [280.6098710128091, 22.943242898435663], [280.6098710128091, 62.94324289843566], [180.60987101280907, 62.94324289843566], [180.60987101280907, 22.943242898435663]]] } }, - { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [[[-5.65625, 110.828125], [-7.53125, 202.234375], [366.0625, 202.234375], [356.6875, 65.828125], [260.125, 59.265625], [253.09375, 40.984375], [189.34375, 19.890625], [141.0625, 36.765625], [111.53125, 6.765625], [73.5625, 36.765625], [67.46875, 10.984375], [41.21875, 10.515625], [36.0625, 42.390625], [65.59375, 53.171875], [-5.65625, 110.828125]]] } } - ] -} diff --git a/test/fixtures/fatal4.geojson b/test/fixtures/fatal4.geojson deleted file mode 100644 index c0e794b..0000000 --- a/test/fixtures/fatal4.geojson +++ /dev/null @@ -1,6 +0,0 @@ -{"type":"FeatureCollection", -"features":[ - {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[3.846028904999335,7.51285572161238],[13.846028904999335,7.51285572161238],[13.846028904999335,11.512855721612379],[3.846028904999335,11.512855721612379],[3.846028904999335,7.51285572161238]]]}}, - {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-0.565625,11.0828125],[-0.753125,20.2234375],[36.60625,20.2234375],[35.66875,6.5828125],[26.0125,5.9265625],[25.309375,4.0984375],[18.934375,1.9890625],[14.10625,3.6765625],[11.153125,0.6765625],[7.35625,3.6765625],[6.746875,1.0984375],[4.121875,1.0515625],[3.60625,4.2390625],[6.559375,5.3171875],[-0.565625,11.0828125]]]}} - ] -} diff --git a/test/fixtures/hourglasses.geojson b/test/fixtures/hourglasses.geojson deleted file mode 100644 index b5acd9b..0000000 --- a/test/fixtures/hourglasses.geojson +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [ [ [0,0], [0,1], [1,0], [1,1], [0,0] ] ] - } - },{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [ [ [0, 0.5], [0, 1.5], [1, 0.5], [1, 1.5], [0, 0.5] ] ] - } - }] -} diff --git a/test/fixtures/issue103.geojson b/test/fixtures/issue103.geojson deleted file mode 100644 index b6f46b3..0000000 --- a/test/fixtures/issue103.geojson +++ /dev/null @@ -1,18 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [[[-24.820450799231946, 81.60424965743837],[-66.98439939287994, 65.9251157774066],[-67.17837257682962, 65.5743714314538],[-23.564139586577383, 84.46172863817043],[-35.3782801119441, 162.91715665949576],[-37.42674770001716, 159.79423125392117], [-24.820450799231946, 81.60424965743837]]] - } - },{ - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [[[-23.564139586577383, 84.46172863817043],[-67.17837257682962, 65.5743714314538],[-24.85941638876879, 26.87535085545798],[-23.564139586577383, 84.46172863817043]]] - } - }] -} diff --git a/test/fixtures/overlap_loop.geojson b/test/fixtures/overlap_loop.geojson deleted file mode 100644 index f18a53c..0000000 --- a/test/fixtures/overlap_loop.geojson +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[57.8,-37.1],[57.8,-49.1],[177.8,-49.1],[177.8,-37.1],[57.8,-37.1]]] - } - },{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[57.8,-97.1],[196.4,-97.1],[196.4,-11.5],[57.8,-11.5],[57.8,-97.1]]] - } - }] -} diff --git a/test/fixtures/overlap_y.geojson b/test/fixtures/overlap_y.geojson deleted file mode 100644 index 76a63d9..0000000 --- a/test/fixtures/overlap_y.geojson +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[-1883,-3],[-1883,-8.5],[-1783,-8.5],[-1783,-3],[-1883,-3]]] - } - },{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[-1883,-25],[-1783,-25],[-1783,75],[-1883,75],[-1883,-25]]] - } - }] -} diff --git a/test/fixtures/polygon_trapezoid_edge_overlap.geojson b/test/fixtures/polygon_trapezoid_edge_overlap.geojson deleted file mode 100644 index 1163766..0000000 --- a/test/fixtures/polygon_trapezoid_edge_overlap.geojson +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [ [ [ 0, 3.5 ], [ 0, 0 ], [ 21, 0 ], [ 21, 3.5 ], [ 0, 3.5 ] ] ] - } - },{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [ [ [ 21, 7 ], [ 0, 7 ], [ 7, 0 ], [ 14, 0 ], [ 21, 7 ] ] ] - } - }] -} diff --git a/test/fixtures/rectangles.geojson b/test/fixtures/rectangles.geojson deleted file mode 100644 index d574263..0000000 --- a/test/fixtures/rectangles.geojson +++ /dev/null @@ -1,30 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [[-19.304686742200616, 126.92383121744365], - [-19.304686742200587, -357.48241878255635], - [10.695313257799413, -357.48241878255635], - [10.695313257799384, 126.92383121744365]] - ] - } - }, - { - "type": "Feature", - "properties": {}, - "geometry": { - "type": "Polygon", - "coordinates": [ - [[-96.66033269728321, -107.63400219275148], - [13.370917302716792, -107.63400219275148], - [13.370917302716792, -126.63400219275148], - [-96.66033269728321, -126.63400219275148]] - ] - } - } - ] -} diff --git a/test/fixtures/touching_boxes.geojson b/test/fixtures/touching_boxes.geojson deleted file mode 100644 index f8ac7b9..0000000 --- a/test/fixtures/touching_boxes.geojson +++ /dev/null @@ -1,16 +0,0 @@ -{ - "type": "FeatureCollection", - "features": [{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]] - } - },{ - "type": "Feature", - "geometry": { - "type": "Polygon", - "coordinates": [[[3, 1], [4, 1], [4, 2], [3, 2], [3, 1]]] - } - }] -} diff --git a/test/genericTestCases.test.js b/test/genericTestCases.test.js new file mode 100644 index 0000000..ceae7f8 --- /dev/null +++ b/test/genericTestCases.test.js @@ -0,0 +1,84 @@ +import tap from 'tape'; +import path from 'path'; +import glob from 'glob'; +import load from 'load-json-file'; +import fs from 'fs'; +import stringify from 'json-stringify-pretty-compact'; +import * as martinez from '../index'; + + +function extractExpectedResults(features) { + return features.map(feature => { + let mode = feature.properties.operation; + var op; + switch (mode) { + case "union": + op = martinez.union; + break; + case "intersection": + op = martinez.intersection; + break; + case "xor": + op = martinez.xor; + break; + case "diff": + op = martinez.diff; + break; + case "diff_ba": + op = (a, b) => martinez.diff(b, a); + break; + } + if (op == null) { + throw `Invalid mode: ${mode}`; + } + return { + op: op, + coordinates: feature.geometry.coordinates, + }; + }); +} + + +const caseDir = path.join(__dirname, 'genericTestCases'); +const testCases = glob.sync(path.join(caseDir, '*.geojson')); +if (testCases.length === 0) { + throw 'No test cases found, this must not happen'; +} + +testCases.forEach((testCaseFile) => { + let testName = 'Generic test case: ' + path.basename(testCaseFile); + tap.test(testName, (t) => { + + const data = load.sync(testCaseFile); + if (data.features.length < 2) { + throw `Test case file must contain at least two features, but ${testCaseFile} doesn't.`; + } + + let p1Geometry = data.features[0].geometry; + let p2Geometry = data.features[1].geometry; + + let p1 = p1Geometry.type === 'Polygon' ? [p1Geometry.coordinates] : p1Geometry.coordinates; + let p2 = p2Geometry.type === 'Polygon' ? [p2Geometry.coordinates] : p2Geometry.coordinates; + + let expectedResults = extractExpectedResults(data.features.slice(2)); + + let featureIndex = 2; + for (const expectedResult of expectedResults) { + const result = expectedResult.op(p1, p2); + t.same(result, expectedResult.coordinates); + + // Update output data for re-generation mode + data.features[featureIndex].geometry.type = 'MultiPolygon'; + data.features[featureIndex].geometry.coordinates = result; + featureIndex += 1; + } + + if (process.env.REGEN) { + fs.writeFileSync(testCaseFile, stringify(data)); + } + + t.end(); + }); + +}); + diff --git a/test/genericTestCases/_new.geojson.template b/test/genericTestCases/_new.geojson.template new file mode 100644 index 0000000..c6b214b --- /dev/null +++ b/test/genericTestCases/_new.geojson.template @@ -0,0 +1,34 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [ + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "intersection" + }, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/collapsed_edges_removed.geojson b/test/genericTestCases/collapsed_edges_removed.geojson new file mode 100644 index 0000000..2722fbd --- /dev/null +++ b/test/genericTestCases/collapsed_edges_removed.geojson @@ -0,0 +1,63 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [ + [ + [355, 139], + [420, 202], + [384, 237], + [353, 205], + [330, 230], + [330, 230], + [291, 197] + ] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [355, 139], + [420, 202], + [384, 237], + [353, 205], + [330, 230], + [330, 230], + [291, 197] + ] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [291, 197], + [330, 230], + [353, 205], + [384, 237], + [420, 202], + [355, 139] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "intersection", + "comment": "This test case is currently weird, because the rings aren't closed, so the operation doesn't make sense." + }, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/disjoint_union_nesting.geojson b/test/genericTestCases/disjoint_union_nesting.geojson new file mode 100644 index 0000000..c6cd27d --- /dev/null +++ b/test/genericTestCases/disjoint_union_nesting.geojson @@ -0,0 +1,100 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [ + [ + [12.91, 6.09], + [12.91, 6.91], + [12.09, 6.91], + [12.09, 6.09], + [12.91, 6.09] + ] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [12.75, 6.25], + [12.75, 6.75], + [11.75, 6.75], + [11.75, 8.25], + [12.75, 8.25], + [12.75, 8.75], + [11.75, 8.75], + [11.75, 9.75], + [11.25, 9.75], + [11.25, 8.75], + [10.25, 8.75], + [10.25, 8.25], + [11.25, 8.25], + [11.25, 6.75], + [10.25, 6.75], + [10.25, 6.25], + [12.75, 6.25] + ], + [[4.75, 2.25], [4.75, 2.75], [4.25, 2.75], [4.25, 2.25], [4.75, 2.25]] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [ + [ + [4.25, 2.25], + [4.75, 2.25], + [4.75, 2.75], + [4.25, 2.75], + [4.25, 2.25] + ] + ] + ] + ], + [ + [ + [10.25, 6.25], + [12.09, 6.25], + [12.09, 6.09], + [12.91, 6.09], + [12.91, 6.91], + [12.09, 6.91], + [12.09, 6.75], + [11.75, 6.75], + [11.75, 8.25], + [12.75, 8.25], + [12.75, 8.75], + [11.75, 8.75], + [11.75, 9.75], + [11.25, 9.75], + [11.25, 8.75], + [10.25, 8.75], + [10.25, 8.25], + [11.25, 8.25], + [11.25, 6.75], + [10.25, 6.75], + [10.25, 6.25] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "union", + "comment": "This case is wrong, because the first result ring has too many levels of array nesting. Related to #47 and #61. May be fixed by #113." + }, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/fatal1.geojson b/test/genericTestCases/fatal1.geojson new file mode 100644 index 0000000..1eee2c7 --- /dev/null +++ b/test/genericTestCases/fatal1.geojson @@ -0,0 +1,100 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [117.659922722, 3.255275783000087], + [117.63331139400017, 3.268215236000103], + [117.62484785200004, 3.283270575000117], + [117.659922722, 3.255275783000087] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [117.6315403, 3.2711246], + [117.631605, 3.2711063], + [117.6315993, 3.2710864], + [117.6321104, 3.2709415], + [117.6320843, 3.2708497], + [117.6314897, 3.2709469], + [117.6315403, 3.2711246] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "intersection"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [117.63171592083741, 3.271053337273843], + [117.63180470386554, 3.2708954059271265], + [117.6320843, 3.2708497], + [117.6321104, 3.2709415], + [117.63171592083741, 3.271053337273843] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "union"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [117.62484785200004, 3.283270575000117], + [117.63171592083741, 3.271053337273843], + [117.6315993, 3.2710864], + [117.631605, 3.2711063], + [117.6315403, 3.2711246], + [117.6314897, 3.2709469], + [117.63180470386554, 3.2708954059271265], + [117.63331139400017, 3.268215236000103], + [117.659922722, 3.255275783000087], + [117.62484785200004, 3.283270575000117] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "diff"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [117.62484785200004, 3.283270575000117], + [117.63171592083741, 3.271053337273843], + [117.6321104, 3.2709415], + [117.6320843, 3.2708497], + [117.63180470386554, 3.2708954059271265], + [117.63331139400017, 3.268215236000103], + [117.659922722, 3.255275783000087], + [117.62484785200004, 3.283270575000117] + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/fatal2.geojson b/test/genericTestCases/fatal2.geojson new file mode 100644 index 0000000..09c5363 --- /dev/null +++ b/test/genericTestCases/fatal2.geojson @@ -0,0 +1,437 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-79.887128, 40.444464], + [-79.880724, 40.442343], + [-79.879353, 40.441889], + [-79.880716, 40.439506], + [-79.881163, 40.438717], + [-79.882656, 40.436087], + [-79.885782, 40.436843], + [-79.886393, 40.439687], + [-79.886548, 40.440502], + [-79.887122, 40.442579], + [-79.887688, 40.444658], + [-79.887128, 40.444464] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-79.88648, 40.44009399906854], + [-79.886476, 40.440069999068506], + [-79.886458, 40.43996299906853], + [-79.886445, 40.43990699906852], + [-79.886406, 40.43974199906857], + [-79.886393, 40.43968699906842], + [-79.88642, 40.43968699906842], + [-79.886501, 40.43968699906842], + [-79.886528, 40.43968799906853], + [-79.886626, 40.43968799906853], + [-79.886882, 40.43968999906852], + [-79.886921, 40.43969299906843], + [-79.886931, 40.43969399906849], + [-79.887015, 40.43972199906852], + [-79.8872429999999, 40.43979699906849], + [-79.88793, 40.440022999068574], + [-79.888159, 40.44009899906841], + [-79.888264, 40.44013299906854], + [-79.888579, 40.440237999068586], + [-79.888684, 40.440272999068426], + [-79.888857, 40.44032999906851], + [-79.889376, 40.44050199906853], + [-79.88955, 40.440559999068554], + [-79.889892, 40.44067299906851], + [-79.89092, 40.44101499906854], + [-79.890921, 40.44101499906854], + [-79.891262, 40.441137999068566], + [-79.891368, 40.44117599906851], + [-79.891437, 40.44120099906849], + [-79.891502, 40.441215999068476], + [-79.891555, 40.44122299906853], + [-79.891702, 40.441229999068575], + [-79.891816, 40.44123699906842], + [-79.891928, 40.441241999068474], + [-79.892213, 40.44125799906857], + [-79.892264, 40.44125599906838], + [-79.892377, 40.44125199906844], + [-79.892543, 40.44124499906835], + [-79.8925749999999, 40.441243999068476], + [-79.893169, 40.441239999068465], + [-79.893368, 40.441238999068446], + [-79.89357, 40.441237999068484], + [-79.894179, 40.44123699906842], + [-79.894272, 40.44123699906842], + [-79.894363, 40.44117499906849], + [-79.894344, 40.4412529990685], + [-79.894336, 40.44128999906837], + [-79.894279, 40.44148399906843], + [-79.894257, 40.44156199906851], + [-79.894242, 40.44160999906841], + [-79.894231, 40.44163799906855], + [-79.894172, 40.44191599906846], + [-79.894169, 40.441928999068494], + [-79.894085, 40.44231599906855], + [-79.894005, 40.442688999068444], + [-79.893999, 40.44271799906857], + [-79.893923, 40.443065999068416], + [-79.893841, 40.44344499906848], + [-79.893782, 40.443722999068385], + [-79.893751, 40.443836999068466], + [-79.893584, 40.44458899906848], + [-79.893578, 40.444658999068416], + [-79.893428, 40.44549099906846], + [-79.893338, 40.44599099906845], + [-79.893242, 40.44640399906853], + [-79.893225, 40.44649399906848], + [-79.893163, 40.44684999906851], + [-79.893021, 40.447475999068395], + [-79.893015, 40.44750399906845], + [-79.892996, 40.4475889990685], + [-79.892802, 40.44851799906848], + [-79.892788, 40.44858799906836], + [-79.892759, 40.44870099906847], + [-79.892742, 40.44876399906836], + [-79.892529, 40.44956799906845], + [-79.892458, 40.44983699906852], + [-79.892452, 40.44985699906839], + [-79.892436, 40.449918999068366], + [-79.892431, 40.44993999906836], + [-79.892429, 40.44997199906848], + [-79.892424, 40.45006999906842], + [-79.892423, 40.45010299906852], + [-79.892423, 40.45017299906844], + [-79.892423, 40.45026599906851], + [-79.892372, 40.45025199906842], + [-79.892038, 40.45017699906838], + [-79.891768, 40.45009799906849], + [-79.891154, 40.449820999068436], + [-79.89107299999988, 40.4497789990684], + [-79.890444, 40.44945899906849], + [-79.889816, 40.44905099906851], + [-79.8892419999999, 40.448540999068435], + [-79.889005, 40.448329999068356], + [-79.888729, 40.448060999068524], + [-79.888547, 40.447843999068475], + [-79.888406, 40.44777299906845], + [-79.888366, 40.44773499906852], + [-79.888318, 40.44771499906848], + [-79.888184, 40.44765899906843], + [-79.887733, 40.44750899906847], + [-79.88638, 40.447058999068375], + [-79.886143, 40.446980999068494], + [-79.88593, 40.44690699906842], + [-79.885974, 40.446827999068454], + [-79.88611, 40.44659399906846], + [-79.886155, 40.44651599906838], + [-79.886199, 40.4464369990684], + [-79.886335, 40.44620099906844], + [-79.886381, 40.446122999068365], + [-79.886472, 40.44596399906852], + [-79.886745, 40.44548899906847], + [-79.886837, 40.44533099906844], + [-79.886934, 40.44516499906851], + [-79.88695099999988, 40.445137999068415], + [-79.887134, 40.444810999068544], + [-79.887158, 40.4447569990685], + [-79.887176, 40.44464599906839], + [-79.887182, 40.44461099906854], + [-79.887128, 40.44446399906846], + [-79.88724, 40.44449899906847], + [-79.887351, 40.44453499906845], + [-79.887472, 40.44457999906844], + [-79.8875759999999, 40.44461799906841], + [-79.887639, 40.44464199906838], + [-79.887688, 40.444657999068475], + [-79.887574, 40.44424199906833], + [-79.887235, 40.442993999068484], + [-79.887122, 40.44257899906844], + [-79.887067, 40.4423799990685], + [-79.88690199999989, 40.44178499906848], + [-79.886848, 40.441586999068434], + [-79.886788, 40.4413689990685], + [-79.88661599999989, 40.440745999068476], + [-79.886608, 40.44071799906848], + [-79.886548, 40.44050199906853], + [-79.88652999999987, 40.44039399906853], + [-79.88648, 40.44009399906854] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "intersection"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-79.887688, 40.444658], + [-79.88768799972165, 40.44465799897759], + [-79.88768795318525, 40.44465798378203], + [-79.887688, 40.444658] + ] + ], + [ + [ + [-79.88768796122203, 40.444657857562895], + [-79.88724301621599, 40.443023510093695], + [-79.887574, 40.44424199906833], + [-79.88768796122203, 40.444657857562895] + ] + ], + [ + [ + [-79.88761078560448, 40.44463125072726], + [-79.8875759999999, 40.44461799906841], + [-79.887472, 40.44457999906844], + [-79.887351, 40.44453499906845], + [-79.88724, 40.44449899906847], + [-79.887128, 40.44446399906846], + [-79.8871280003921, 40.44446400013584], + [-79.88761078560448, 40.44463125072726] + ] + ], + [ + [ + [-79.88711873229528, 40.44256717591859], + [-79.88685922414403, 40.4416281542633], + [-79.88690199999989, 40.44178499906848], + [-79.887067, 40.4423799990685], + [-79.88711873229528, 40.44256717591859] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "union"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-79.894363, 40.44117499906849], + [-79.894272, 40.44123699906842], + [-79.894179, 40.44123699906842], + [-79.89357, 40.441237999068484], + [-79.893368, 40.441238999068446], + [-79.893169, 40.441239999068465], + [-79.8925749999999, 40.441243999068476], + [-79.892543, 40.44124499906835], + [-79.892377, 40.44125199906844], + [-79.892264, 40.44125599906838], + [-79.892213, 40.44125799906857], + [-79.891928, 40.441241999068474], + [-79.891816, 40.44123699906842], + [-79.891702, 40.441229999068575], + [-79.891555, 40.44122299906853], + [-79.891502, 40.441215999068476], + [-79.891437, 40.44120099906849], + [-79.891368, 40.44117599906851], + [-79.891262, 40.441137999068566], + [-79.890921, 40.44101499906854], + [-79.89092, 40.44101499906854], + [-79.889892, 40.44067299906851], + [-79.88955, 40.440559999068554], + [-79.889376, 40.44050199906853], + [-79.888857, 40.44032999906851], + [-79.888684, 40.440272999068426], + [-79.888579, 40.440237999068586], + [-79.888264, 40.44013299906854], + [-79.888159, 40.44009899906841], + [-79.88793, 40.440022999068574], + [-79.8872429999999, 40.43979699906849], + [-79.887015, 40.43972199906852], + [-79.886931, 40.43969399906849], + [-79.886921, 40.43969299906843], + [-79.886882, 40.43968999906852], + [-79.886626, 40.43968799906853], + [-79.886528, 40.43968799906853], + [-79.886501, 40.43968699906842], + [-79.88642, 40.43968699906842], + [-79.886393, 40.43968699906842], + [-79.886406, 40.43974199906857], + [-79.886445, 40.43990699906852], + [-79.886458, 40.43996299906853], + [-79.886476, 40.440069999068506], + [-79.88648, 40.44009399906854], + [-79.88652999999987, 40.44039399906853], + [-79.886548, 40.44050199906853], + [-79.886608, 40.44071799906848], + [-79.88661599999989, 40.440745999068476], + [-79.886788, 40.4413689990685], + [-79.886848, 40.441586999068434], + [-79.88685922414403, 40.4416281542633], + [-79.886548, 40.440502], + [-79.886393, 40.439687], + [-79.885782, 40.436843], + [-79.882656, 40.436087], + [-79.881163, 40.438717], + [-79.880716, 40.439506], + [-79.879353, 40.441889], + [-79.880724, 40.442343], + [-79.887128, 40.444464], + [-79.8871280003921, 40.44446400013584], + [-79.887182, 40.44461099906854], + [-79.887176, 40.44464599906839], + [-79.887158, 40.4447569990685], + [-79.887134, 40.444810999068544], + [-79.88695099999988, 40.445137999068415], + [-79.886934, 40.44516499906851], + [-79.886837, 40.44533099906844], + [-79.886745, 40.44548899906847], + [-79.886472, 40.44596399906852], + [-79.886381, 40.446122999068365], + [-79.886335, 40.44620099906844], + [-79.886199, 40.4464369990684], + [-79.886155, 40.44651599906838], + [-79.88611, 40.44659399906846], + [-79.885974, 40.446827999068454], + [-79.88593, 40.44690699906842], + [-79.886143, 40.446980999068494], + [-79.88638, 40.447058999068375], + [-79.887733, 40.44750899906847], + [-79.888184, 40.44765899906843], + [-79.888318, 40.44771499906848], + [-79.888366, 40.44773499906852], + [-79.888406, 40.44777299906845], + [-79.888547, 40.447843999068475], + [-79.888729, 40.448060999068524], + [-79.889005, 40.448329999068356], + [-79.8892419999999, 40.448540999068435], + [-79.889816, 40.44905099906851], + [-79.890444, 40.44945899906849], + [-79.89107299999988, 40.4497789990684], + [-79.891154, 40.449820999068436], + [-79.891768, 40.45009799906849], + [-79.892038, 40.45017699906838], + [-79.892372, 40.45025199906842], + [-79.892423, 40.45026599906851], + [-79.892423, 40.45017299906844], + [-79.892423, 40.45010299906852], + [-79.892424, 40.45006999906842], + [-79.892429, 40.44997199906848], + [-79.892431, 40.44993999906836], + [-79.892436, 40.449918999068366], + [-79.892452, 40.44985699906839], + [-79.892458, 40.44983699906852], + [-79.892529, 40.44956799906845], + [-79.892742, 40.44876399906836], + [-79.892759, 40.44870099906847], + [-79.892788, 40.44858799906836], + [-79.892802, 40.44851799906848], + [-79.892996, 40.4475889990685], + [-79.893015, 40.44750399906845], + [-79.893021, 40.447475999068395], + [-79.893163, 40.44684999906851], + [-79.893225, 40.44649399906848], + [-79.893242, 40.44640399906853], + [-79.893338, 40.44599099906845], + [-79.893428, 40.44549099906846], + [-79.893578, 40.444658999068416], + [-79.893584, 40.44458899906848], + [-79.893751, 40.443836999068466], + [-79.893782, 40.443722999068385], + [-79.893841, 40.44344499906848], + [-79.893923, 40.443065999068416], + [-79.893999, 40.44271799906857], + [-79.894005, 40.442688999068444], + [-79.894085, 40.44231599906855], + [-79.894169, 40.441928999068494], + [-79.894172, 40.44191599906846], + [-79.894231, 40.44163799906855], + [-79.894242, 40.44160999906841], + [-79.894257, 40.44156199906851], + [-79.894279, 40.44148399906843], + [-79.894336, 40.44128999906837], + [-79.894344, 40.4412529990685], + [-79.894363, 40.44117499906849] + ] + ], + [ + [ + [-79.887688, 40.444657999068475], + [-79.88768796122203, 40.444657857562895], + [-79.88768799972165, 40.44465799897759], + [-79.887688, 40.444657999068475] + ] + ], + [ + [ + [-79.88768795318525, 40.44465798378203], + [-79.88761078560448, 40.44463125072726], + [-79.887639, 40.44464199906838], + [-79.88768795318525, 40.44465798378203] + ] + ], + [ + [ + [-79.88724301621599, 40.443023510093695], + [-79.887235, 40.442993999068484], + [-79.887122, 40.44257899906844], + [-79.88711873229528, 40.44256717591859], + [-79.887122, 40.442579], + [-79.88724301621599, 40.443023510093695] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "diff"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-79.88768799972165, 40.44465799897759], + [-79.88768796122203, 40.444657857562895], + [-79.887574, 40.44424199906833], + [-79.88724301621599, 40.443023510093695], + [-79.887122, 40.442579], + [-79.88711873229528, 40.44256717591859], + [-79.887067, 40.4423799990685], + [-79.88690199999989, 40.44178499906848], + [-79.88685922414403, 40.4416281542633], + [-79.886548, 40.440502], + [-79.886393, 40.439687], + [-79.885782, 40.436843], + [-79.882656, 40.436087], + [-79.881163, 40.438717], + [-79.880716, 40.439506], + [-79.879353, 40.441889], + [-79.880724, 40.442343], + [-79.887128, 40.444464], + [-79.8871280003921, 40.44446400013584], + [-79.887128, 40.44446399906846], + [-79.88724, 40.44449899906847], + [-79.887351, 40.44453499906845], + [-79.887472, 40.44457999906844], + [-79.8875759999999, 40.44461799906841], + [-79.88761078560448, 40.44463125072726], + [-79.88768795318525, 40.44465798378203], + [-79.88768799972165, 40.44465799897759] + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/fatal3.geojson b/test/genericTestCases/fatal3.geojson new file mode 100644 index 0000000..06d49da --- /dev/null +++ b/test/genericTestCases/fatal3.geojson @@ -0,0 +1,109 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [180.60987101280907, 22.943242898435663], + [280.6098710128091, 22.943242898435663], + [280.6098710128091, 62.94324289843566], + [180.60987101280907, 62.94324289843566], + [180.60987101280907, 22.943242898435663] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-5.65625, 110.828125], + [-7.53125, 202.234375], + [366.0625, 202.234375], + [356.6875, 65.828125], + [260.125, 59.265625], + [253.09375, 40.984375], + [189.34375, 19.890625], + [141.0625, 36.765625], + [111.53125, 6.765625], + [73.5625, 36.765625], + [67.46875, 10.984375], + [41.21875, 10.515625], + [36.0625, 42.390625], + [65.59375, 53.171875], + [-5.65625, 110.828125] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "operation": "intersection", + "comment": "This test case currently has a wrong result" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [198.56943964860557, 22.943242898435663], + [253.09375, 40.984375], + [260.125, 59.265625], + [280.6098710128091, 60.657800699899646], + [280.6098710128091, 62.94324289843566] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "operation": "union", + "comment": "This test case currently has a wrong result" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-7.53125, 202.234375], + [-5.65625, 110.828125], + [65.59375, 53.171875], + [36.0625, 42.390625], + [41.21875, 10.515625], + [67.46875, 10.984375], + [73.5625, 36.765625], + [111.53125, 6.765625], + [141.0625, 36.765625], + [180.60987101280907, 22.943242898435663], + [189.34375, 19.890625], + [198.56943964860557, 22.943242898435663], + [180.60987101280907, 22.943242898435663], + [180.60987101280907, 62.94324289843566], + [280.6098710128091, 62.94324289843566], + [356.6875, 65.828125], + [366.0625, 202.234375], + [-7.53125, 202.234375] + ] + ], + [ + [ + [198.56943964860557, 22.943242898435663], + [280.6098710128091, 22.943242898435663], + [280.6098710128091, 60.657800699899646] + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/fatal4.geojson b/test/genericTestCases/fatal4.geojson new file mode 100644 index 0000000..cf757db --- /dev/null +++ b/test/genericTestCases/fatal4.geojson @@ -0,0 +1,105 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [3.846028904999335, 7.51285572161238], + [13.846028904999335, 7.51285572161238], + [13.846028904999335, 11.512855721612379], + [3.846028904999335, 11.512855721612379], + [3.846028904999335, 7.51285572161238] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-0.565625, 11.0828125], + [-0.753125, 20.2234375], + [36.60625, 20.2234375], + [35.66875, 6.5828125], + [26.0125, 5.9265625], + [25.309375, 4.0984375], + [18.934375, 1.9890625], + [14.10625, 3.6765625], + [11.153125, 0.6765625], + [7.35625, 3.6765625], + [6.746875, 1.0984375], + [4.121875, 1.0515625], + [3.60625, 4.2390625], + [6.559375, 5.3171875], + [-0.565625, 11.0828125] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "operation": "union", + "comment": "This test case currently has a wrong result, but will most likely be fixed by #115" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [-0.753125, 20.2234375], + [-0.565625, 11.0828125], + [3.846028904999335, 7.51285572161238], + [6.559375, 5.3171875], + [3.60625, 4.2390625], + [4.121875, 1.0515625], + [6.746875, 1.0984375], + [7.35625, 3.6765625], + [11.153125, 0.6765625], + [14.10625, 3.6765625], + [18.934375, 1.9890625], + [25.309375, 4.0984375], + [26.0125, 5.9265625], + [35.66875, 6.5828125], + [36.60625, 20.2234375], + [-0.753125, 20.2234375] + ] + ], + [ + [ + [3.846028904999335, 7.51285572161238], + [13.846028904999335, 7.51285572161238], + [13.846028904999335, 11.512855721612379], + [3.846028904999335, 7.51285572161238] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": { + "operation": "intersection", + "comment": "This test case currently has a wrong result, but will most likely be fixed by #115" + }, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [13.846028904999335, 7.51285572161238], + [13.846028904999335, 11.512855721612379] + ] + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/filling_rectangle.geojson b/test/genericTestCases/filling_rectangle.geojson new file mode 100644 index 0000000..d8b2bff --- /dev/null +++ b/test/genericTestCases/filling_rectangle.geojson @@ -0,0 +1,32 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [ + [[-2, 2], [2, 2], [2, -2], [-2, -2], [-2, 2]], + [[-1, 1], [1, 1], [1, -1], [-1, -1], [-1, 1]] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [[[-1, 1], [1, 1], [1, -1], [-1, -1], [-1, 1]]], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [[[[-2, -2], [2, -2], [2, 2], [-2, 2], [-2, -2]]]], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/hourglasses.geojson b/test/genericTestCases/hourglasses.geojson new file mode 100644 index 0000000..4471ca9 --- /dev/null +++ b/test/genericTestCases/hourglasses.geojson @@ -0,0 +1,122 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[0, 0], [0, 1], [1, 0], [1, 1], [0, 0]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[0, 0.5], [0, 1.5], [1, 0.5], [1, 1.5], [0, 0.5]]] + } + }, + { + "type": "Feature", + "properties": {"operation": "intersection"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [[[0, 0.5], [0.25, 0.75], [0, 1], [0, 0.5]]], + [[[0.75, 0.75], [1, 0.5], [1, 1], [0.75, 0.75]]] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "union"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [0.5, 0.5], + [0.25, 0.75], + [0.5, 1], + [0, 1.5], + [0, 1], + [0, 0.5], + [0, 0] + ] + ], + [ + [ + [0.5, 0.5], + [1, 0], + [1, 0.5], + [1, 1], + [1, 1.5], + [0.5, 1], + [0.75, 0.75], + [0.5, 0.5] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "xor"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [0, 0], + [0.5, 0.5], + [0.25, 0.75], + [0.5, 1], + [0, 1.5], + [0, 1], + [0.25, 0.75], + [0, 0.5], + [0, 0] + ] + ], + [ + [ + [0.5, 0.5], + [1, 0], + [1, 0.5], + [0.75, 0.75], + [1, 1], + [1, 1.5], + [0.5, 1], + [0.75, 0.75], + [0.5, 0.5] + ] + ] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "diff"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [[[0, 0], [0.5, 0.5], [0.25, 0.75], [0, 0.5], [0, 0]]], + [[[0.5, 0.5], [1, 0], [1, 0.5], [0.75, 0.75], [0.5, 0.5]]] + ] + } + }, + { + "type": "Feature", + "properties": {"operation": "diff_ba"}, + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [[[0, 1], [0.25, 0.75], [0.5, 1], [0, 1.5], [0, 1]]], + [[[0.5, 1], [0.75, 0.75], [1, 1], [1, 1.5], [0.5, 1]]] + ] + } + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/issue103.geojson b/test/genericTestCases/issue103.geojson new file mode 100644 index 0000000..8fb9de7 --- /dev/null +++ b/test/genericTestCases/issue103.geojson @@ -0,0 +1,158 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [ + [ + [314.40495804718677, 245.22995740474045], + [355.3084164255646, 274.62805627384455], + [388.1787335887434, 320.33832954550485], + [388.9124587537205, 320.65353992291637], + [400, 335.9912795978437], + [400, 246.12148820908317], + [374.63976989251296, 232.1889765225989], + [333.1714557280062, 200.59530404401397], + [339.9682813108619, 202.86632587352096], + [352.20189036987824, 165.65101936712378], + [352.1226856869796, 165.67910842756115], + [351.11664245242355, 143.32479268320685], + [358.21104193260544, 135.3909067611561], + [400, 102.7539460309187], + [400, 0], + [371.2197402336615, 2.8421709430404014e-14], + [348.64013551352855, 53.435028392624496], + [344.5955075658226, 53.806406865151274], + [335.14340456541504, 77.83582779964986], + [310.6585569221463, 80.7440852782285], + [301.68587048275344, 132.45449117396356], + [300.5747979723983, 118.7681539616306], + [297.3467313288405, 145.14834613196768], + [272.34144089775623, 145.3051023345713], + [197.10335384609192, 129.83210391441233], + [157.0231603224197, 105.78147219020022], + [120.44771878596228, 109.55893998720018], + [168.9029877884493, 131.3790233720232], + [144.78499570302176, 137.09599949165835], + [89.90107595046035, 118.5515206604366], + [97.05625149415084, 132.96319782327134], + [18.90341962399799, 111.35909458586124], + [18.94383187314372, 116.08488152321168], + [120.9957537807505, 142.53498680412483], + [222.9869248986131, 178.3491004724274], + [244.39124334340312, 180.9975096828225], + [254.38144111881925, 272.10286475523776], + [314.40495804718677, 245.22995740474045] + ] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [244.5557189962528, 185.9229643180382], + [248.5849016468879, 306.58250278991926], + [257.9987920828058, 305.09120506683007], + [254.38144111881925, 272.10286475523776], + [314.40495804718677, 245.22995740474045], + [355.3084164255646, 274.62805627384455], + [292.2355740236037, 186.91740693932564], + [343.1405834727814, 193.2160095427301], + [352.1960877194012, 165.668671346602], + [352.1226856869796, 165.67910842756115], + [351.11664245242355, 143.32479268320685], + [358.21104193260544, 135.3909067611561], + [400, 118.64643487917338], + [400, 75.65538218016279], + [297.3467313288405, 145.14834613196768], + [272.34144089775623, 145.3051023345713], + [197.10335384609192, 129.83210391441233], + [173.31982573883488, 104.09837210383137], + [133.6345063121441, 108.1970243647632], + [168.9029877884493, 131.3790233720232], + [144.78499570302176, 137.09599949165835], + [86.312921823555, 111.32439973633112], + [97.05625149415084, 132.96319782327134], + [18.870187035423584, 107.47289333997468], + [18.89787710655719, 110.71095554199546], + [120.9957537807505, 142.53498680412483], + [244.5557189962528, 185.9229643180382] + ] + ], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [18.870187035423584, 107.47289333997468], + [97.05625149415084, 132.96319782327134], + [89.90107595046035, 118.5515206604366], + [89.90107595046037, 118.5515206604366], + [86.312921823555, 111.32439973633112], + [144.78499570302176, 137.09599949165835], + [168.9029877884493, 131.3790233720232], + [120.44771878596228, 109.55893998720018], + [157.0231603224197, 105.78147219020022], + [157.02316032241973, 105.78147219020023], + [173.31982573883488, 104.09837210383137], + [197.10335384609192, 129.83210391441233], + [272.34144089775623, 145.3051023345713], + [297.3467313288405, 145.14834613196768], + [300.5747979723983, 118.7681539616306], + [301.68587048275344, 132.45449117396356], + [310.6585569221463, 80.7440852782285], + [335.14340456541504, 77.83582779964986], + [344.5955075658226, 53.806406865151274], + [348.64013551352855, 53.435028392624496], + [371.2197402336615, 2.8421709430404014e-14], + [400, 0], + [400, 75.65538218016279], + [400, 102.7539460309187], + [400, 118.64643487917338], + [358.21104193260544, 135.3909067611561], + [351.11664245242355, 143.32479268320685], + [352.1226856869796, 165.67910842756115], + [352.20189036987824, 165.65101936712378], + [352.19608771940113, 165.668671346602], + [352.1960877194012, 165.668671346602], + [343.1405834727814, 193.2160095427301], + [343.1405834727813, 193.2160095427301], + [339.9682813108619, 202.86632587352096], + [333.1714557280062, 200.59530404401397], + [374.63976989251296, 232.1889765225989], + [400, 246.12148820908317], + [400, 335.9912795978437], + [388.9124587537205, 320.65353992291637], + [388.1787335887434, 320.33832954550485], + [355.3084164255646, 274.62805627384455], + [314.40495804718677, 245.22995740474045], + [254.38144111881925, 272.10286475523776], + [257.9987920828058, 305.09120506683007], + [248.5849016468879, 306.58250278991926], + [244.5557189962528, 185.9229643180382], + [222.9869248986131, 178.3491004724274], + [120.9957537807505, 142.53498680412483], + [18.94383187314372, 116.08488152321168], + [18.90341962399799, 111.35909458586124], + [37.232408208905824, 116.42585099314746], + [18.89787710655719, 110.71095554199546], + [18.870187035423584, 107.47289333997468] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/issue76.geojson b/test/genericTestCases/issue76.geojson new file mode 100644 index 0000000..50e0e18 --- /dev/null +++ b/test/genericTestCases/issue76.geojson @@ -0,0 +1,107 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-19.304686742200616, 126.92383121744365], + [-19.304686742200587, -357.48241878255635], + [10.695313257799413, -357.48241878255635], + [10.695313257799384, 126.92383121744365] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [-96.66033269728321, -107.63400219275148], + [13.370917302716792, -107.63400219275148], + [13.370917302716792, -126.63400219275148], + [-96.66033269728321, -126.63400219275148] + ] + ] + } + }, + { + "geometry": { + "coordinates": [ + [ + [ + [-19.3046867422006, -126.63400219275148], + [-19.3046867422006, -107.63400219275148], + [10.695313257799395, -107.63400219275148], + [10.695313257799395, -126.63400219275148], + [-19.3046867422006, -126.63400219275148] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "intersection", + "comment": "This test case is also a bit dubious, because the input polygons aren't closed. For intersection that seems to be okay, ..." + }, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [-96.66033269728321, -126.63400219275148], + [-19.3046867422006, -126.63400219275148], + [-19.304686742200587, -357.48241878255635], + [10.695313257799413, -357.48241878255635], + [10.695313257799395, -126.63400219275148], + [13.370917302716792, -126.63400219275148], + [13.370917302716792, -107.63400219275148], + [10.695313257799395, -107.63400219275148], + [10.695313257799384, 126.92383121744365], + [-19.304686742200616, 126.92383121744365], + [-19.3046867422006, -107.63400219275148] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "union", + "comment": "... but for union it is broken ..." + }, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [-19.304686742200616, 126.92383121744365], + [-19.3046867422006, -107.63400219275148], + [10.695313257799395, -107.63400219275148], + [10.695313257799384, 126.92383121744365], + [10.695313257799413, -357.48241878255635], + [10.695313257799395, -126.63400219275148], + [-19.3046867422006, -126.63400219275148], + [-19.304686742200587, -357.48241878255635] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": { + "operation": "diff", + "comment": "... and for diff as well" + }, + "type": "Feature" + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/overlap_loop.geojson b/test/genericTestCases/overlap_loop.geojson new file mode 100644 index 0000000..a89ad1f --- /dev/null +++ b/test/genericTestCases/overlap_loop.geojson @@ -0,0 +1,83 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [57.8, -37.1], + [57.8, -49.1], + [177.8, -49.1], + [177.8, -37.1], + [57.8, -37.1] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [57.8, -97.1], + [196.4, -97.1], + [196.4, -11.5], + [57.8, -11.5], + [57.8, -97.1] + ] + ] + } + }, + { + "geometry": { + "coordinates": [ + [ + [ + [57.8, -49.1], + [177.8, -49.1], + [177.8, -37.1], + [57.8, -37.1], + [57.8, -49.1] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "intersection"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [57.8, -97.1], + [196.4, -97.1], + [196.4, -11.5], + [57.8, -11.5], + [57.8, -37.1], + [57.8, -49.1], + [57.8, -97.1] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + }, + { + "geometry": {"coordinates": [], "type": "MultiPolygon"}, + "properties": { + "operation": "diff", + "comment": "This test case currently has a wrong result (tests for empty result)." + }, + "type": "Feature" + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/overlap_y.geojson b/test/genericTestCases/overlap_y.geojson new file mode 100644 index 0000000..31b8de0 --- /dev/null +++ b/test/genericTestCases/overlap_y.geojson @@ -0,0 +1,73 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [[-1883, -3], [-1883, -8.5], [-1783, -8.5], [-1783, -3], [-1883, -3]] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [[-1883, -25], [-1783, -25], [-1783, 75], [-1883, 75], [-1883, -25]] + ] + } + }, + { + "geometry": { + "coordinates": [ + [ + [ + [-1883, -8.5], + [-1783, -8.5], + [-1783, -3], + [-1883, -3], + [-1883, -8.5] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "intersection"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [-1883, -25], + [-1783, -25], + [-1783, -8.5], + [-1783, -3], + [-1783, 75], + [-1883, 75], + [-1883, -3], + [-1883, -8.5], + [-1883, -25] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + }, + { + "geometry": {"coordinates": [], "type": "MultiPolygon"}, + "properties": { + "operation": "diff", + "comment": "This test case currently has a wrong result (tests for empty result)." + }, + "type": "Feature" + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/polygon_trapezoid_edge_overlap.geojson b/test/genericTestCases/polygon_trapezoid_edge_overlap.geojson new file mode 100644 index 0000000..26e5434 --- /dev/null +++ b/test/genericTestCases/polygon_trapezoid_edge_overlap.geojson @@ -0,0 +1,66 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[0, 3.5], [0, 0], [21, 0], [21, 3.5], [0, 3.5]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[21, 7], [0, 7], [7, 0], [14, 0], [21, 7]]] + } + }, + { + "geometry": { + "coordinates": [ + [[[3.5, 3.5], [7, 0], [14, 0], [17.5, 3.5], [3.5, 3.5]]] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "intersection"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [0, 0], + [7, 0], + [14, 0], + [21, 0], + [21, 3.5], + [17.5, 3.5], + [21, 7], + [0, 7], + [3.5, 3.5], + [0, 3.5], + [0, 0] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [[[0, 0], [7, 0], [3.5, 3.5], [0, 3.5], [0, 0]]], + [[[14, 0], [21, 0], [21, 3.5], [17.5, 3.5], [14, 0]]] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "diff"}, + "type": "Feature" + } + ] +} \ No newline at end of file diff --git a/test/genericTestCases/tie.geojson b/test/genericTestCases/tie.geojson new file mode 100644 index 0000000..5049238 --- /dev/null +++ b/test/genericTestCases/tie.geojson @@ -0,0 +1,37 @@ +{ + "features": [ + { + "geometry": { + "coordinates": [[[-1, -1], [-1, 1], [0, 0], [-1, -1]]], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [[[0, 0], [1, 1], [1, -1], [0, 0]]], + "type": "Polygon" + }, + "properties": {}, + "type": "Feature" + }, + { + "geometry": {"coordinates": [], "type": "MultiPolygon"}, + "properties": {"operation": "intersection"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [[[-1, -1], [0, 0], [-1, 1], [-1, -1]]], + [[[0, 0], [1, -1], [1, 1], [0, 0]]] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + } + ], + "type": "FeatureCollection" +} \ No newline at end of file diff --git a/test/genericTestCases/touching_boxes.geojson b/test/genericTestCases/touching_boxes.geojson new file mode 100644 index 0000000..c90c5bf --- /dev/null +++ b/test/genericTestCases/touching_boxes.geojson @@ -0,0 +1,58 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[0, 0], [3, 0], [3, 3], [0, 3], [0, 0]]] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [[[3, 1], [4, 1], [4, 2], [3, 2], [3, 1]]] + } + }, + { + "geometry": {"coordinates": [], "type": "MultiPolygon"}, + "properties": {"operation": "intersection"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [ + [ + [0, 0], + [3, 0], + [3, 1], + [4, 1], + [4, 2], + [3, 2], + [3, 3], + [0, 3], + [0, 0] + ] + ] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "union"}, + "type": "Feature" + }, + { + "geometry": { + "coordinates": [ + [[[0, 0], [3, 0], [3, 1], [3, 2], [3, 3], [0, 3], [0, 0]]] + ], + "type": "MultiPolygon" + }, + "properties": {"operation": "diff"}, + "type": "Feature" + } + ] +} \ No newline at end of file From 01990ed5595b8a275710268c56cf195a308dc2d3 Mon Sep 17 00:00:00 2001 From: Rowan Winsemius Date: Mon, 24 Feb 2020 06:06:57 +1100 Subject: [PATCH 2/2] Use original geojson as input (#119) * Use original geojson as input * keep the original leaflet CRS settings as it helps zoom correctly * Fix handling when drawing own features Co-authored-by: Alexander Milevski --- demo/js/index.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/demo/js/index.js b/demo/js/index.js index 1397981..4af1f22 100644 --- a/demo/js/index.js +++ b/demo/js/index.js @@ -2,7 +2,7 @@ import './coordinates'; import './polygoncontrol'; import './booleanopcontrol'; import * as martinez from '../../index'; -//var martinez = require('../../dist/martinez.min'); +// import * as martinez from '../../dist/martinez.min'; let mode = window.location.hash.substring(1); let path = '../test/fixtures/'; @@ -127,13 +127,14 @@ map.addControl(new L.BooleanControl({ })); var drawnItems = window.drawnItems = L.geoJson().addTo(map); - +var rawData = null; function loadData(path) { console.log(path); fetch(path) .then((r) => r.json()) .then((json) => { drawnItems.addData(json); + rawData = json; map.fitBounds(drawnItems.getBounds().pad(0.05), { animate: false }); }); } @@ -141,21 +142,27 @@ function loadData(path) { function clear() { drawnItems.clearLayers(); results.clearLayers(); + rawData = null; } var reader = new jsts.io.GeoJSONReader(); var writer = new jsts.io.GeoJSONWriter(); +function getClippingPoly (layers) { + if (rawData !== null && rawData.features.length > 1) return rawData.features[1]; + return layers[1].toGeoJSON(); +} + function run (op) { var layers = drawnItems.getLayers(); if (layers.length < 2) return; - var subject = layers[0].toGeoJSON(); - var clipping = layers[1].toGeoJSON(); + var subject = rawData !== null ? rawData.features[0] : layers[0].toGeoJSON(); + var clipping = getClippingPoly(layers); //console.log('input', subject, clipping, op); - subject = JSON.parse(JSON.stringify(subject)); - clipping = JSON.parse(JSON.stringify(clipping)); + // subject = JSON.parse(JSON.stringify(subject)); + // clipping = JSON.parse(JSON.stringify(clipping)); var operation; if (op === OPERATIONS.INTERSECTION) { @@ -178,9 +185,8 @@ function run (op) { var result = operation(subject.geometry.coordinates, clipping.geometry.coordinates); console.timeEnd('martinez'); - //if (op === OPERATIONS.UNION) result = result[0]; console.log('result', result); - // console.log(JSON.stringify(result)) + // console.log(JSON.stringify(result)); results.clearLayers(); if (result !== null) { @@ -208,17 +214,11 @@ function run (op) { } res = writer.write(res); console.timeEnd('jsts'); - console.log(res); + // console.log('JSTS result', res); }, 500); } } -//drawnItems.addData(oneInside); -//drawnItems.addData(twoPointedTriangles); -//drawnItems.addData(selfIntersecting); -//drawnItems.addData(holes); -//drawnItems.addData(data); - map.on('editable:created', function(evt) { drawnItems.addLayer(evt.layer); evt.layer.on('click', function(e) {