point-in-polygon-hao
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -27,2 +27,7 @@ (function (global, factory) { | ||
const contour = polygon[i]; | ||
// This helps to ensure that points on the left edges pass... | ||
// Not 100% sure if it's legit | ||
contour.push(contour[1]); | ||
currentP = contour[0]; | ||
@@ -68,2 +73,3 @@ v1 = currentP[0] - x; | ||
} | ||
} | ||
@@ -70,0 +76,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).pointInPolygon=n()}(this,function(){"use strict";return function(e,n){let f=0,t=0,i=0,r=0,o=0,l=0,u=0,s=0,c=null,d=null;const p=e[0],y=e[1],g=n.length;for(;f<g;f++){t=0;const g=n[f].length-1,h=n[f];for(l=(c=h[0])[0]-p,o=c[1]-y;t<g;t++)if(s=(d=h[t+1])[1]-y,l<0&&s<0||l>0&&s>0)l=s,o=(c=d)[0]-p;else{if(u=d[0]-e[0],s>0&&l<=0){if((r=o*s-u*l)>0)i+=1;else if(0===r)return 0}else if(l>0&&s<=0){if((r=o*s-u*l)<0)i+=1;else if(0===r)return 0}else if(0===s&&l<0){if(0==(r=o*s-u*l))return 0}else if(0===l&&s<0){if(0==(r=o*s-u*l))return 0}else if(0===l&&0===s){if(u<=0&&o>=0)return 0;if(o<=0&&u>=0)return 0}c=d,l=s,o=u}}return i%2!=0}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).pointInPolygon=n()}(this,function(){"use strict";return function(e,n){let f=0,t=0,i=0,r=0,o=0,u=0,l=0,s=0,c=null,d=null;const p=e[0],h=e[1],y=n.length;for(;f<y;f++){t=0;const y=n[f].length-1,g=n[f];for(g.push(g[1]),u=(c=g[0])[0]-p,o=c[1]-h;t<y;t++)if(s=(d=g[t+1])[1]-h,u<0&&s<0||u>0&&s>0)u=s,o=(c=d)[0]-p;else{if(l=d[0]-e[0],s>0&&u<=0){if((r=o*s-l*u)>0)i+=1;else if(0===r)return 0}else if(u>0&&s<=0){if((r=o*s-l*u)<0)i+=1;else if(0===r)return 0}else if(0===s&&u<0){if(0==(r=o*s-l*u))return 0}else if(0===u&&s<0){if(0==(r=o*s-l*u))return 0}else if(0===u&&0===s){if(l<=0&&o>=0)return 0;if(o<=0&&l>=0)return 0}c=d,u=s,o=l}}return i%2!=0}}); |
{ | ||
"name": "point-in-polygon-hao", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A point in polygon based on the paper Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons", | ||
@@ -22,2 +22,3 @@ "main": "dist/pointInPolygon.js", | ||
"esm": "^3.2.20", | ||
"jsts": "^2.0.3", | ||
"load-json-file": "^5.2.0", | ||
@@ -24,0 +25,0 @@ "point-in-polygon": "^1.0.1", |
@@ -8,12 +8,16 @@ Based on the paper [Optimal Reliable Point-in-Polygon Test and | ||
### Usage | ||
Install via `npm install point-in-polygon-hao` | ||
```` | ||
const inside = require('point-in-polygon-hao') | ||
const polygon = [ [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ], [ 2, 1 ], [ 1, 1 ] ] ]; | ||
inside([ 1.5, 1.5 ], polygon) | ||
// when inside returns true | ||
// returns true | ||
inside([ 4.9, 1.2 ], polygon) | ||
// when outside returns false | ||
// returns false | ||
inside([1, 2], polygon) | ||
// when on edge returns 0 | ||
// returns 0 to indicate on edge | ||
```` | ||
@@ -23,4 +27,4 @@ | ||
### Comparisons | ||
Some rough comparisons to similar libraries although | ||
`point-in-polygon` & `robust-point-in-polygon` do not support polygons with holes. So while `point-in-polygon` is slightly faster in most cases it supports fewer use cases. | ||
Some rough comparisons to similar libraries. | ||
While `point-in-polygon` is slightly faster in most cases it does not support polygons with holes or degenerate polygons. | ||
@@ -33,3 +37,5 @@ ```` | ||
robust-point-in-polygon x 18,344,949 ops/sec ±1.69% (83 runs sampled) | ||
```` | ||
```` | ||
// For a point in a much larger geometry (700+ vertices) | ||
@@ -36,0 +42,0 @@ point-in-poly-hao x 449,670 ops/sec ±0.80% (90 runs sampled) |
@@ -21,2 +21,7 @@ export default function pointInPolygon(p, polygon) { | ||
const contour = polygon[i] | ||
// This helps to ensure that points on the left edges pass... | ||
// Not 100% sure if it's legit | ||
contour.push(contour[1]) | ||
currentP = contour[0] | ||
@@ -62,2 +67,3 @@ v1 = currentP[0] - x | ||
} | ||
} | ||
@@ -64,0 +70,0 @@ |
Sorry, the diff of this file is not supported yet
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
44
8233
12
7
144