point-in-polygon-hao
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -0,1 +1,4 @@ | ||
# 1.2.1 | ||
- update packaging | ||
# 1.2.0 | ||
@@ -2,0 +5,0 @@ - Use robust-predicates library for some calcs |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('robust-predicates')) : | ||
typeof define === 'function' && define.amd ? define(['robust-predicates'], factory) : | ||
(global = global || self, global.pointInPolygon = factory(global.robustPredicates)); | ||
}(this, (function (robustPredicates) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.pointInPolygon = factory()); | ||
})(this, (function () { 'use strict'; | ||
var epsilon = 1.1102230246251565e-16; | ||
var splitter = 134217729; | ||
var resulterrbound = (3 + 8 * epsilon) * epsilon; | ||
// fast_expansion_sum_zeroelim routine from oritinal code | ||
function sum(elen, e, flen, f, h) { | ||
var Q, Qnew, hh, bvirt; | ||
var enow = e[0]; | ||
var fnow = f[0]; | ||
var eindex = 0; | ||
var findex = 0; | ||
if ((fnow > enow) === (fnow > -enow)) { | ||
Q = enow; | ||
enow = e[++eindex]; | ||
} else { | ||
Q = fnow; | ||
fnow = f[++findex]; | ||
} | ||
var hindex = 0; | ||
if (eindex < elen && findex < flen) { | ||
if ((fnow > enow) === (fnow > -enow)) { | ||
Qnew = enow + Q; | ||
hh = Q - (Qnew - enow); | ||
enow = e[++eindex]; | ||
} else { | ||
Qnew = fnow + Q; | ||
hh = Q - (Qnew - fnow); | ||
fnow = f[++findex]; | ||
} | ||
Q = Qnew; | ||
if (hh !== 0) { | ||
h[hindex++] = hh; | ||
} | ||
while (eindex < elen && findex < flen) { | ||
if ((fnow > enow) === (fnow > -enow)) { | ||
Qnew = Q + enow; | ||
bvirt = Qnew - Q; | ||
hh = Q - (Qnew - bvirt) + (enow - bvirt); | ||
enow = e[++eindex]; | ||
} else { | ||
Qnew = Q + fnow; | ||
bvirt = Qnew - Q; | ||
hh = Q - (Qnew - bvirt) + (fnow - bvirt); | ||
fnow = f[++findex]; | ||
} | ||
Q = Qnew; | ||
if (hh !== 0) { | ||
h[hindex++] = hh; | ||
} | ||
} | ||
} | ||
while (eindex < elen) { | ||
Qnew = Q + enow; | ||
bvirt = Qnew - Q; | ||
hh = Q - (Qnew - bvirt) + (enow - bvirt); | ||
enow = e[++eindex]; | ||
Q = Qnew; | ||
if (hh !== 0) { | ||
h[hindex++] = hh; | ||
} | ||
} | ||
while (findex < flen) { | ||
Qnew = Q + fnow; | ||
bvirt = Qnew - Q; | ||
hh = Q - (Qnew - bvirt) + (fnow - bvirt); | ||
fnow = f[++findex]; | ||
Q = Qnew; | ||
if (hh !== 0) { | ||
h[hindex++] = hh; | ||
} | ||
} | ||
if (Q !== 0 || hindex === 0) { | ||
h[hindex++] = Q; | ||
} | ||
return hindex; | ||
} | ||
function estimate(elen, e) { | ||
var Q = e[0]; | ||
for (var i = 1; i < elen; i++) { Q += e[i]; } | ||
return Q; | ||
} | ||
function vec(n) { | ||
return new Float64Array(n); | ||
} | ||
var ccwerrboundA = (3 + 16 * epsilon) * epsilon; | ||
var ccwerrboundB = (2 + 12 * epsilon) * epsilon; | ||
var ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon; | ||
var B = vec(4); | ||
var C1 = vec(8); | ||
var C2 = vec(12); | ||
var D = vec(16); | ||
var u = vec(4); | ||
function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) { | ||
var acxtail, acytail, bcxtail, bcytail; | ||
var bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3; | ||
var acx = ax - cx; | ||
var bcx = bx - cx; | ||
var acy = ay - cy; | ||
var bcy = by - cy; | ||
s1 = acx * bcy; | ||
c = splitter * acx; | ||
ahi = c - (c - acx); | ||
alo = acx - ahi; | ||
c = splitter * bcy; | ||
bhi = c - (c - bcy); | ||
blo = bcy - bhi; | ||
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); | ||
t1 = acy * bcx; | ||
c = splitter * acy; | ||
ahi = c - (c - acy); | ||
alo = acy - ahi; | ||
c = splitter * bcx; | ||
bhi = c - (c - bcx); | ||
blo = bcx - bhi; | ||
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); | ||
_i = s0 - t0; | ||
bvirt = s0 - _i; | ||
B[0] = s0 - (_i + bvirt) + (bvirt - t0); | ||
_j = s1 + _i; | ||
bvirt = _j - s1; | ||
_0 = s1 - (_j - bvirt) + (_i - bvirt); | ||
_i = _0 - t1; | ||
bvirt = _0 - _i; | ||
B[1] = _0 - (_i + bvirt) + (bvirt - t1); | ||
u3 = _j + _i; | ||
bvirt = u3 - _j; | ||
B[2] = _j - (u3 - bvirt) + (_i - bvirt); | ||
B[3] = u3; | ||
var det = estimate(4, B); | ||
var errbound = ccwerrboundB * detsum; | ||
if (det >= errbound || -det >= errbound) { | ||
return det; | ||
} | ||
bvirt = ax - acx; | ||
acxtail = ax - (acx + bvirt) + (bvirt - cx); | ||
bvirt = bx - bcx; | ||
bcxtail = bx - (bcx + bvirt) + (bvirt - cx); | ||
bvirt = ay - acy; | ||
acytail = ay - (acy + bvirt) + (bvirt - cy); | ||
bvirt = by - bcy; | ||
bcytail = by - (bcy + bvirt) + (bvirt - cy); | ||
if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) { | ||
return det; | ||
} | ||
errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det); | ||
det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail); | ||
if (det >= errbound || -det >= errbound) { return det; } | ||
s1 = acxtail * bcy; | ||
c = splitter * acxtail; | ||
ahi = c - (c - acxtail); | ||
alo = acxtail - ahi; | ||
c = splitter * bcy; | ||
bhi = c - (c - bcy); | ||
blo = bcy - bhi; | ||
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); | ||
t1 = acytail * bcx; | ||
c = splitter * acytail; | ||
ahi = c - (c - acytail); | ||
alo = acytail - ahi; | ||
c = splitter * bcx; | ||
bhi = c - (c - bcx); | ||
blo = bcx - bhi; | ||
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); | ||
_i = s0 - t0; | ||
bvirt = s0 - _i; | ||
u[0] = s0 - (_i + bvirt) + (bvirt - t0); | ||
_j = s1 + _i; | ||
bvirt = _j - s1; | ||
_0 = s1 - (_j - bvirt) + (_i - bvirt); | ||
_i = _0 - t1; | ||
bvirt = _0 - _i; | ||
u[1] = _0 - (_i + bvirt) + (bvirt - t1); | ||
u3 = _j + _i; | ||
bvirt = u3 - _j; | ||
u[2] = _j - (u3 - bvirt) + (_i - bvirt); | ||
u[3] = u3; | ||
var C1len = sum(4, B, 4, u, C1); | ||
s1 = acx * bcytail; | ||
c = splitter * acx; | ||
ahi = c - (c - acx); | ||
alo = acx - ahi; | ||
c = splitter * bcytail; | ||
bhi = c - (c - bcytail); | ||
blo = bcytail - bhi; | ||
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); | ||
t1 = acy * bcxtail; | ||
c = splitter * acy; | ||
ahi = c - (c - acy); | ||
alo = acy - ahi; | ||
c = splitter * bcxtail; | ||
bhi = c - (c - bcxtail); | ||
blo = bcxtail - bhi; | ||
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); | ||
_i = s0 - t0; | ||
bvirt = s0 - _i; | ||
u[0] = s0 - (_i + bvirt) + (bvirt - t0); | ||
_j = s1 + _i; | ||
bvirt = _j - s1; | ||
_0 = s1 - (_j - bvirt) + (_i - bvirt); | ||
_i = _0 - t1; | ||
bvirt = _0 - _i; | ||
u[1] = _0 - (_i + bvirt) + (bvirt - t1); | ||
u3 = _j + _i; | ||
bvirt = u3 - _j; | ||
u[2] = _j - (u3 - bvirt) + (_i - bvirt); | ||
u[3] = u3; | ||
var C2len = sum(C1len, C1, 4, u, C2); | ||
s1 = acxtail * bcytail; | ||
c = splitter * acxtail; | ||
ahi = c - (c - acxtail); | ||
alo = acxtail - ahi; | ||
c = splitter * bcytail; | ||
bhi = c - (c - bcytail); | ||
blo = bcytail - bhi; | ||
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo); | ||
t1 = acytail * bcxtail; | ||
c = splitter * acytail; | ||
ahi = c - (c - acytail); | ||
alo = acytail - ahi; | ||
c = splitter * bcxtail; | ||
bhi = c - (c - bcxtail); | ||
blo = bcxtail - bhi; | ||
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo); | ||
_i = s0 - t0; | ||
bvirt = s0 - _i; | ||
u[0] = s0 - (_i + bvirt) + (bvirt - t0); | ||
_j = s1 + _i; | ||
bvirt = _j - s1; | ||
_0 = s1 - (_j - bvirt) + (_i - bvirt); | ||
_i = _0 - t1; | ||
bvirt = _0 - _i; | ||
u[1] = _0 - (_i + bvirt) + (bvirt - t1); | ||
u3 = _j + _i; | ||
bvirt = u3 - _j; | ||
u[2] = _j - (u3 - bvirt) + (_i - bvirt); | ||
u[3] = u3; | ||
var Dlen = sum(C2len, C2, 4, u, D); | ||
return D[Dlen - 1]; | ||
} | ||
function orient2d(ax, ay, bx, by, cx, cy) { | ||
var detleft = (ay - cy) * (bx - cx); | ||
var detright = (ax - cx) * (by - cy); | ||
var det = detleft - detright; | ||
var detsum = Math.abs(detleft + detright); | ||
if (Math.abs(det) >= ccwerrboundA * detsum) { return det; } | ||
return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum); | ||
} | ||
function pointInPolygon(p, polygon) { | ||
@@ -46,3 +312,3 @@ var i; | ||
} else if ((v2 >= 0 && v1 < 0) || (v2 < 0 && v1 >= 0)) { | ||
f = robustPredicates.orient2d(u1, u2, v1, v2, 0, 0); | ||
f = orient2d(u1, u2, v1, v2, 0, 0); | ||
if (f === 0) { return 0 } | ||
@@ -63,2 +329,2 @@ if ((f > 0 && v2 > 0 && v1 <= 0) || (f < 0 && v2 <= 0 && v1 > 0)) { k++; } | ||
}))); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("robust-predicates")):"function"==typeof define&&define.amd?define(["robust-predicates"],t):(e=e||self).pointInPolygon=t(e.robustPredicates)}(this,function(e){"use strict";return function(t,r){var n,i,o,f,s,u,d,a,c,l=0,p=t[0],b=t[1],h=r.length;for(n=0;n<h;n++){i=0;var m=r[n],g=m.length-1;if((a=m[0])[0]!==m[g][0]&&a[1]!==m[g][1])throw new Error("First and last coordinates in a ring must be the same");for(f=a[0]-p,s=a[1]-b;i<g;i++){if(u=(c=m[i+1])[0]-p,d=c[1]-b,0===s&&0===d){if(u<=0&&f>=0||f<=0&&u>=0)return 0}else if(d>=0&&s<0||d<0&&s>=0){if(0===(o=e.orient2d(f,u,s,d,0,0)))return 0;(o>0&&d>0&&s<=0||o<0&&d<=0&&s>0)&&l++}a=c,s=d,f=u}}return l%2!=0}}); | ||
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r="undefined"!=typeof globalThis?globalThis:r||self).pointInPolygon=n()}(this,(function(){"use strict";var r=11102230246251565e-32,n=134217729,e=(3+8*r)*r;function t(r,n,e,t,f){var o,i,a,u,s=n[0],l=t[0],v=0,c=0;l>s==l>-s?(o=s,s=n[++v]):(o=l,l=t[++c]);var d=0;if(v<r&&c<e)for(l>s==l>-s?(a=o-((i=s+o)-s),s=n[++v]):(a=o-((i=l+o)-l),l=t[++c]),o=i,0!==a&&(f[d++]=a);v<r&&c<e;)l>s==l>-s?(a=o-((i=o+s)-(u=i-o))+(s-u),s=n[++v]):(a=o-((i=o+l)-(u=i-o))+(l-u),l=t[++c]),o=i,0!==a&&(f[d++]=a);for(;v<r;)a=o-((i=o+s)-(u=i-o))+(s-u),s=n[++v],o=i,0!==a&&(f[d++]=a);for(;c<e;)a=o-((i=o+l)-(u=i-o))+(l-u),l=t[++c],o=i,0!==a&&(f[d++]=a);return 0===o&&0!==d||(f[d++]=o),d}function f(r){return new Float64Array(r)}var o=f(4),i=f(8),a=f(12),u=f(16),s=f(4);function l(r,f,l,v,c,d){var h=(f-d)*(l-c),b=(r-c)*(v-d),p=h-b,g=Math.abs(h+b);return Math.abs(p)>=33306690738754716e-32*g?p:-function(r,f,l,v,c,d,h){var b,p,g,y,m,w,M,x,F,T,j,A,E,I,P,k,q,z,B=r-c,C=l-c,D=f-d,G=v-d;m=(P=(x=B-(M=(w=n*B)-(w-B)))*(T=G-(F=(w=n*G)-(w-G)))-((I=B*G)-M*F-x*F-M*T))-(j=P-(q=(x=D-(M=(w=n*D)-(w-D)))*(T=C-(F=(w=n*C)-(w-C)))-((k=D*C)-M*F-x*F-M*T))),o[0]=P-(j+m)+(m-q),m=(E=I-((A=I+j)-(m=A-I))+(j-m))-(j=E-k),o[1]=E-(j+m)+(m-k),m=(z=A+j)-A,o[2]=A-(z-m)+(j-m),o[3]=z;var H=function(r,n){for(var e=n[0],t=1;t<r;t++)e+=n[t];return e}(4,o),J=22204460492503146e-32*h;if(H>=J||-H>=J)return H;if(b=r-(B+(m=r-B))+(m-c),g=l-(C+(m=l-C))+(m-c),p=f-(D+(m=f-D))+(m-d),y=v-(G+(m=v-G))+(m-d),0===b&&0===p&&0===g&&0===y)return H;if(J=11093356479670487e-47*h+e*Math.abs(H),(H+=B*y+G*b-(D*g+C*p))>=J||-H>=J)return H;m=(P=(x=b-(M=(w=n*b)-(w-b)))*(T=G-(F=(w=n*G)-(w-G)))-((I=b*G)-M*F-x*F-M*T))-(j=P-(q=(x=p-(M=(w=n*p)-(w-p)))*(T=C-(F=(w=n*C)-(w-C)))-((k=p*C)-M*F-x*F-M*T))),s[0]=P-(j+m)+(m-q),m=(E=I-((A=I+j)-(m=A-I))+(j-m))-(j=E-k),s[1]=E-(j+m)+(m-k),m=(z=A+j)-A,s[2]=A-(z-m)+(j-m),s[3]=z;var K=t(4,o,4,s,i);m=(P=(x=B-(M=(w=n*B)-(w-B)))*(T=y-(F=(w=n*y)-(w-y)))-((I=B*y)-M*F-x*F-M*T))-(j=P-(q=(x=D-(M=(w=n*D)-(w-D)))*(T=g-(F=(w=n*g)-(w-g)))-((k=D*g)-M*F-x*F-M*T))),s[0]=P-(j+m)+(m-q),m=(E=I-((A=I+j)-(m=A-I))+(j-m))-(j=E-k),s[1]=E-(j+m)+(m-k),m=(z=A+j)-A,s[2]=A-(z-m)+(j-m),s[3]=z;var L=t(K,i,4,s,a);m=(P=(x=b-(M=(w=n*b)-(w-b)))*(T=y-(F=(w=n*y)-(w-y)))-((I=b*y)-M*F-x*F-M*T))-(j=P-(q=(x=p-(M=(w=n*p)-(w-p)))*(T=g-(F=(w=n*g)-(w-g)))-((k=p*g)-M*F-x*F-M*T))),s[0]=P-(j+m)+(m-q),m=(E=I-((A=I+j)-(m=A-I))+(j-m))-(j=E-k),s[1]=E-(j+m)+(m-k),m=(z=A+j)-A,s[2]=A-(z-m)+(j-m),s[3]=z;var N=t(L,a,4,s,u);return u[N-1]}(r,f,l,v,c,d,g)}return function(r,n){var e,t,f,o,i,a,u,s,v,c=0,d=r[0],h=r[1],b=n.length;for(e=0;e<b;e++){t=0;var p=n[e],g=p.length-1;if((s=p[0])[0]!==p[g][0]&&s[1]!==p[g][1])throw new Error("First and last coordinates in a ring must be the same");for(o=s[0]-d,i=s[1]-h;t<g;t++){if(a=(v=p[t+1])[0]-d,u=v[1]-h,0===i&&0===u){if(a<=0&&o>=0||o<=0&&a>=0)return 0}else if(u>=0&&i<0||u<0&&i>=0){if(0===(f=l(o,a,i,u,0,0)))return 0;(f>0&&u>0&&i<=0||f<0&&u<=0&&i>0)&&c++}s=v,i=u,o=a}}return c%2!=0}})); |
{ | ||
"name": "point-in-polygon-hao", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"type": "module", | ||
"description": "A point in polygon based on the paper Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons", | ||
"main": "dist/pointInPolygon.mjs", | ||
"module": "dist/pointInPolygon.mjs", | ||
"main": "dist/pointInPolygon.cjs.js", | ||
"module": "dist/pointInPolygon.esm.js", | ||
"unpkg": "dist/pointInPolygon.min.js", | ||
@@ -20,3 +20,6 @@ "jsdelivr": "dist/pointInPolygon.min.js", | ||
"devDependencies": { | ||
"@rollup/plugin-buble": "^0.21.3", | ||
"@rollup/plugin-buble": "^1.0.3", | ||
"@rollup/plugin-commonjs": "^28.0.1", | ||
"@rollup/plugin-node-resolve": "^15.3.0", | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"benchmark": "^2.1.4", | ||
@@ -29,4 +32,3 @@ "eslint": "^5.15.3", | ||
"robust-point-in-polygon": "^1.0.3", | ||
"rollup": "^1.7.0", | ||
"rollup-plugin-terser": "^4.0.4", | ||
"rollup": "^4.28.0", | ||
"vitest": "^2.1.6" | ||
@@ -33,0 +35,0 @@ }, |
@@ -1,3 +0,5 @@ | ||
import {terser} from 'rollup-plugin-terser' | ||
import terser from '@rollup/plugin-terser' | ||
import buble from '@rollup/plugin-buble' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import resolve from '@rollup/plugin-node-resolve' | ||
@@ -16,5 +18,6 @@ const output = (file, plugins, format) => ({ | ||
export default [ | ||
output('./dist/pointInPolygon.mjs', [buble()], 'es'), | ||
output('./dist/pointInPolygon.js', [buble()], 'umd'), | ||
output('./dist/pointInPolygon.min.js', [buble(), terser()], 'umd') | ||
output('./dist/pointInPolygon.esm.js', [buble()], 'esm'), | ||
output('./dist/pointInPolygon.cjs.js', [buble()], 'cjs'), | ||
output('./dist/pointInPolygon.js', [commonjs(), resolve(), buble()], 'umd'), | ||
output('./dist/pointInPolygon.min.js', [commonjs(), resolve(), buble(), terser()], 'umd') | ||
] |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
23780
13
476
0
13
1