diff --git a/src/subdivide_segments.js b/src/subdivide_segments.js index e1480c7..5529f0d 100644 --- a/src/subdivide_segments.js +++ b/src/subdivide_segments.js @@ -43,7 +43,7 @@ module.exports = function subdivide(eventQueue, subject, clipping, sbbox, cbbox, if (next) { if (possibleIntersection(event, next.key, eventQueue) === 2) { computeFields(event, prevEvent, operation); - computeFields(event, next.key, operation); + computeFields(next.key, event, operation); } } diff --git a/test/edge_cases.test.js b/test/edge_cases.test.js index cfc783b..7b50ecf 100644 --- a/test/edge_cases.test.js +++ b/test/edge_cases.test.js @@ -243,5 +243,17 @@ tap.test('Edge cases', function(main) { t.end(); }); + main.test('overlapping edges difference', function (t) { // issue #35 + const p1 = [ [ [0,0], [3,0], [3,3], [0,3], [0,0] ] ] + const p2 = [ [ [1,0], [2,0], [2,4], [1,4], [1,0] ] ] + + var result = martinez.diff(p1, p2) + t.deepEqual(result, [ + [[[0, 0], [1, 0], [1, 3], [0, 3], [0, 0]]], + [[[2, 0], [3, 0], [3, 3], [2, 3], [2, 0]]] + ]) + t.end() + }) + main.end(); });