Skip to content

Commit

Permalink
Merge branch 'master' into fix-overlapping-edges-#35
Browse files Browse the repository at this point in the history
  • Loading branch information
w8r authored Jan 28, 2018
2 parents ef808d5 + 4dd24ed commit 864c33d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/segment_intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,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
4 changes: 2 additions & 2 deletions test/edge_cases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ tap.test('Edge cases', function(main) {
subject.geometry.coordinates,
clipping.geometry.coordinates
);
t.deepEqual(result, [[[[-1883,-8.5],[-1783,-8.5],[-1783,-3],[-1783,-2.999999999999999],[-1883,-3],[-1883,-8.5]]]]);
t.deepEqual(result, [[[[-1883,-8.5],[-1783,-8.5],[-1783,-3],[-1883,-3],[-1883,-8.5]]]]);

t.end();
});
Expand All @@ -151,7 +151,7 @@ tap.test('Edge cases', function(main) {
subject.geometry.coordinates,
clipping.geometry.coordinates
);
t.deepEqual(result, [[[[-1883,-25],[-1783,-25],[-1783,-8.5],[-1783,-3],[-1783,-2.999999999999999],[-1783,75],[-1883,75],[-1883,-3],[-1883,-8.5],[-1883,-25]]]]);
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();
});
Expand Down
3 changes: 3 additions & 0 deletions test/segment_intersection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ tap.test('intersection', function (t) {

t.strictSame(intersection([0, 0], [1, 1], [1, 0], [2, 2]), null, 'null if no intersections');
t.strictSame(intersection([0, 0], [1, 1], [1, 0], [10, 2]), null, 'null if no intersections');
t.strictSame(intersection([2, 2], [3, 3], [0, 6], [2, 4]), null, 'null if no intersections');

t.strictSame(intersection([0, 0], [1, 1], [1, 0], [0, 1]), [[0.5, 0.5]], '1 intersection');
t.strictSame(intersection([0, 0], [1, 1], [0, 1], [0, 0]), [[0, 0]], 'shared point 1');
Expand Down Expand Up @@ -36,5 +37,7 @@ tap.test('intersection', function (t) {
t.strictSame(intersection([0, 0], [1, 1], [0, 0], [1, 1], true), null, 'full overlap, skip touches');
t.strictSame(intersection([1, 1], [0, 0], [0, 0], [1, 1], true), null, 'full overlap, orientation, skip touches');

t.strictSame(intersection([0, 0], [1, 1], [1, 0], [0, 1], true), [[0.5, 0.5]], '1 intersection, skip touches');

t.end();
});

0 comments on commit 864c33d

Please sign in to comment.