Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for overlapping edges #58

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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();
});