Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

2d-polygon-self-intersections

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2d-polygon-self-intersections - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

13

intersections.js

@@ -25,3 +25,3 @@ var isect = require('exact-segment-intersect');

function selfIntersections(poly) {
function selfIntersections(poly, filterFn) {
var seen = {};

@@ -55,4 +55,13 @@ var l = poly.length;

var key = r+'';
if (!seen[key]) {
var unique = !seen[key];
if (unique) {
seen[key] = true;
}
var collect = unique;
if (filterFn) {
collect = filterFn(r, oc, on, pc, pn, unique);
}
if (collect) {
isects.push(r);

@@ -59,0 +68,0 @@ }

2

package.json

@@ -12,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.1.2",
"version": "1.2.0",
"main": "intersections.js",

@@ -15,0 +15,0 @@ "scripts": {

@@ -34,5 +34,13 @@ # 2d-polygon-self-intersections

__isects__(`polygon`)
__isects__(`polygon`[, `filterFn`])
* `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}]`
* `filterFn` - a filter function called whenever an intersection is found: `filterFn`(`isect`, `start0`, `end0`, `start1`, `end1`, `unique`)
* `isect` - current intersection (e.g. `[5, 5]`) - mutations in this array get collected
* `start0` - start of the first segment (e.g `[0, 5]`)
* `end0` - start of the first segment (e.g `[10, 5]`)
* `start1` - start of the first segment (e.g `[5, 0]`)
* `end1` - start of the first segment (e.g `[5, 10]`)
* `unique` - boolean representing whether or not this intersection point has been seen before
* __return__ `true` to collect and `false` to discard

@@ -43,3 +51,3 @@ __returns__ an empty array if no interesections or an array of 2 component arrays representing the intersection points.

Also note that there are 2 intersections per crossing, this library will only report one. All intersections will be unique.
Also note that there are 2 intersections per crossing, this library by default will only report one - all intersections will be unique. This behavior can be changed with the `filterFn`.

@@ -46,0 +54,0 @@ ## license

@@ -14,4 +14,3 @@ var test = require('tape');

var r = isects(poly);
var r = isects(poly, t.fail);
t.equal(r.length, 0, 'no self-intersections');

@@ -31,3 +30,9 @@

var r = isects(poly);
var calls = 0;
var r = isects(poly, function(isect, s0, e0, s1, e1, unique) {
calls++;
return unique;
});
t.equal(calls, 2, 'visitor called twice')
t.equal(r.length, 1, 'no self-intersections');

@@ -38,3 +43,24 @@ t.deepEqual(r[0], [5, 5], 'isect at (5, 0)')

test('interesection visitor', function(t) {
var poly = [
[0, 0],
[10, 0],
[0, 10],
[10, 10],
];
var calls = 0;
var r = isects(poly, function(isect, start0, end0, start1, end1, unique) {
calls++;
return true;
});
t.equal(calls, 2, 'visitor called twice')
t.equal(r.length, 2, 'no self-intersections');
t.deepEqual(r[0], [5, 5], 'isect at (5, 0)')
t.deepEqual(r[1], [5, 5], 'isect at (5, 0)')
t.end();
});
test('work with vec2', function(t) {

@@ -41,0 +67,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc