2d-polygon-self-intersections
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -10,8 +10,15 @@ var isect = require('exact-segment-intersect'); | ||
function valid(a) { | ||
if (a[2][0] === 0) { | ||
return false | ||
var pc = [0, 0]; | ||
var pn = [0, 0]; | ||
var oc = [0, 0]; | ||
var on = [0, 0]; | ||
function arrayOrObject(v, ret) { | ||
if (Array.isArray(v)) { | ||
ret[0] = v[0]; | ||
ret[1] = v[1]; | ||
} else { | ||
ret[0] = v.x; | ||
ret[1] = v.y; | ||
} | ||
return true; | ||
} | ||
@@ -24,7 +31,8 @@ | ||
for (var o=0; o<l; o++) { | ||
var oc = poly[o] | ||
var on = poly[(o+1) % l]; | ||
arrayOrObject(poly[o], oc); | ||
arrayOrObject(poly[(o+1) % l], on); | ||
for (var p=0; p<l; p++) { | ||
var pc = poly[p] | ||
var pn = poly[(p+1) % l]; | ||
arrayOrObject(poly[p], pc); | ||
arrayOrObject(poly[(p+1) % l], pn); | ||
if (cmp(pc, oc) || cmp(pc, on) || cmp(pn, oc) || cmp(pn, on)) { | ||
@@ -31,0 +39,0 @@ continue; |
{ | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"tape": "^4.0.0" | ||
@@ -11,3 +12,3 @@ }, | ||
"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.0.0", | ||
"version": "1.1.0", | ||
"main": "intersections.js", | ||
@@ -14,0 +15,0 @@ "scripts": { |
# 2d-polygon-self-intersections | ||
find self-intersections in a 2d polygon | ||
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. | ||
@@ -34,3 +36,3 @@ | ||
* `polygon` - an array of 2 component arrays (i.e. a triangle `[[0, 0], [10, 0], [10, 10]]`) | ||
* `polygon` - an array of 2 component arrays (i.e. a triangle `[[0, 0], [10, 0], [10, 10]]`) or an array of objects: `[{x:0, y:0}, {x:10, y:0}, {x:10, y:10}]` | ||
@@ -37,0 +39,0 @@ __returns__ an empty array if no interesections or an array of 2 component arrays representing the intersection points. |
18
test.js
var test = require('tape'); | ||
var isects = require('./intersections'); | ||
/* | ||
test('no intersections (square)', function(t) { | ||
@@ -36,1 +36,17 @@ | ||
}); | ||
*/ | ||
test('work with vec2', function(t) { | ||
var poly = [ | ||
{ x: 0, y: 0 }, | ||
{ x: 10, y: 0 }, | ||
{ x: 0, y: 10 }, | ||
{ x: 10, y: 10 } | ||
]; | ||
var r = isects(poly); | ||
t.equal(r.length, 1, 'no self-intersections'); | ||
t.deepEqual(r[0], [5, 0], 'isect at (5, 0)') | ||
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
6442
7
134
47
2