From ef808d555132bb74afd4848cbb74b335298060f6 Mon Sep 17 00:00:00 2001 From: Mike Fogel Date: Sat, 27 Jan 2018 12:59:46 -0300 Subject: [PATCH 1/2] Fix for overlapping edges https://github.com/w8r/martinez/issues/35 --- src/subdivide_segments.js | 2 +- test/edge_cases.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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(); }); From 258f3d4b97a8649d6893864c9b8b19529727b22e Mon Sep 17 00:00:00 2001 From: Mike Fogel Date: Mon, 29 Jan 2018 18:05:01 -0300 Subject: [PATCH 2/2] Update dist/martinez.js --- dist/martinez.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/dist/martinez.js b/dist/martinez.js index fa84ab3..03fbc48 100644 --- a/dist/martinez.js +++ b/dist/martinez.js @@ -14,10 +14,19 @@ boolean.default = boolean; module.exports = boolean; },{"./src/index":12}],2:[function(require,module,exports){ +/** + * avl v1.4.1 + * Fast AVL tree for Node and browser + * + * @author Alexander Milevski + * @license MIT + * @preserve + */ + (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - (global.avl = factory()); + (global.AVLTree = factory()); }(this, (function () { 'use strict'; /** @@ -733,6 +742,8 @@ AVLTree.prototype.toString = function toString (printNode) { Object.defineProperties( AVLTree.prototype, prototypeAccessors ); +AVLTree.default = AVLTree; + return AVLTree; }))); @@ -1649,7 +1660,15 @@ module.exports = function (a1, a2, b1, b2, noEndpointTouch) { // not on line segment b return null; } - return noEndpointTouch ? null : [toPoint(a1, s, va)]; + if (s === 0 || s === 1) { + // on an endpoint of line segment a + return noEndpointTouch ? null : [toPoint(a1, s, va)]; + } + if (t === 0 || t === 1) { + // on an endpoint of line segment b + return noEndpointTouch ? null : [toPoint(b1, t, vb)]; + } + return [toPoint(a1, s, va)]; } // If we've reached this point, then the lines are either parallel or the @@ -1757,7 +1776,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); } }