2d-polygon-self-intersections
Advanced tools
Comparing version 1.2.1 to 1.2.2
var isect = require('exact-segment-intersect'); | ||
var float = require('robust-estimate-float'); | ||
var hasIsect = require('robust-segment-intersect'); | ||
@@ -35,2 +36,4 @@ module.exports = selfIntersections; | ||
for (var p=0; p<l; p++) { | ||
if (o === p) { continue; } | ||
var s1 = poly[p] | ||
@@ -45,2 +48,6 @@ var e1 = poly[(p+1) % l]; | ||
if (!hasIsect(oc, on, pc, pn)) { | ||
continue; | ||
} | ||
var r = isect(oc, on, pc, pn); | ||
@@ -59,2 +66,6 @@ // since these are homogeneous vectors, if the last component `w` is 0 | ||
if (cmp(r, oc) || cmp(r, on) || cmp(r, pc) || cmp(r, pn)) { | ||
continue; | ||
} | ||
var key = r+''; | ||
@@ -61,0 +72,0 @@ var unique = !seen[key]; |
@@ -8,7 +8,8 @@ { | ||
"exact-segment-intersect": "^1.0.0", | ||
"robust-estimate-float": "^1.0.0" | ||
"robust-estimate-float": "^1.0.0", | ||
"robust-segment-intersect": "^1.0.1" | ||
}, | ||
"name": "2d-polygon-self-intersections", | ||
"description": "This library may not be fast, but it is robust. Robust in the fact that it will find all of the self-intersections in a polygon - minus of course shared endpoints.", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"main": "intersections.js", | ||
@@ -15,0 +16,0 @@ "scripts": { |
43
test.js
@@ -80,1 +80,44 @@ var test = require('tape'); | ||
}); | ||
test('better deduping', function(t) { | ||
var poly = [ | ||
[0, 0], | ||
[20, 0], | ||
[20, 5], | ||
[20, 10], | ||
]; | ||
var r = isects(poly); | ||
t.equal(r.length, 0, 'no self-intersections'); | ||
t.end(); | ||
}); | ||
test('separated intersections', function(t) { | ||
/* | ||
o-----o | ||
| | | ||
o------x-----x------o | ||
| | | | | ||
| | | | | ||
| | | | | ||
o------o o------o | ||
*/ | ||
var poly = [ | ||
[-10, 0], | ||
[10, 0], | ||
[10, 10], | ||
[1, 10], | ||
[1, -1], | ||
[-1, -1], | ||
[-1, 10], | ||
[-10, 1] | ||
]; | ||
var r = isects(poly); | ||
t.equal(r.length, 2, 'two self-intersections'); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9142
211
3
+ Addedrobust-orientation@1.2.1(transitive)
+ Addedrobust-segment-intersect@1.0.1(transitive)
+ Addedrobust-subtract@1.0.0(transitive)