Skip to content

Commit

Permalink
Merge pull request #1 from mfogel/fix-overlapping-edges-#35
Browse files Browse the repository at this point in the history
Fix overlapping edges w8r#35
  • Loading branch information
grassick authored Feb 6, 2018
2 parents 7db3374 + 258f3d4 commit f38e9ee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
25 changes: 22 additions & 3 deletions dist/martinez.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @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';

/**
Expand Down Expand Up @@ -733,6 +742,8 @@ AVLTree.prototype.toString = function toString (printNode) {

Object.defineProperties( AVLTree.prototype, prototypeAccessors );

AVLTree.default = AVLTree;

return AVLTree;

})));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/subdivide_segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/edge_cases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,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();
});

0 comments on commit f38e9ee

Please sign in to comment.