15 lines
No EOL
6.1 KiB
JavaScript
15 lines
No EOL
6.1 KiB
JavaScript
/*! geolib.isPointInsideRobust 2.0.21
|
|
* !!EXPERIMENTAL!!
|
|
*
|
|
* Robust version of isPointInside for Geolib.js
|
|
*
|
|
* Based on https://github.com/mikolalysenko/robust-point-in-polygon
|
|
* by Mikola Lysenko, licensed under MIT
|
|
*
|
|
* @author Manuel Bieh
|
|
* @url http://www.manuelbieh.com/
|
|
* @version 2.0.21
|
|
* @license MIT
|
|
*
|
|
*/
|
|
!function(a,b,c){var d=function(a){var b,d=+(Math.pow(2,27)+1),e=5,f=1.1102230246251565e-16,g=(3+16*f)*f,h=(7+56*f)*f,i=function(a,b,c){var e=a*b,f=d*a,g=f-a,h=f-g,i=a-h,j=d*b,k=j-b,l=j-k,m=b-l,n=e-h*l,o=n-i*l,p=o-h*m,q=i*m-p;return c?(c[0]=q,c[1]=e,c):[q,e]},j=function(a,b,c){var d=a+b,e=d-a,f=d-e,g=b-e,h=a-f;return c?(c[0]=h+g,c[1]=d,c):[h+g,d]},k=j,l=function(a,b){var c=0|a.length,d=0|b.length;if(1===c&&1===d)return p(a[0],b[0]);var e,f,g=c+d,h=new Array(g),i=0,j=0,k=0,l=Math.abs,m=a[j],n=l(m),o=b[k],q=l(o);q>n?(f=m,j+=1,c>j&&(m=a[j],n=l(m))):(f=o,k+=1,d>k&&(o=b[k],q=l(o))),c>j&&q>n||k>=d?(e=m,j+=1,c>j&&(m=a[j],n=l(m))):(e=o,k+=1,d>k&&(o=b[k],q=l(o)));for(var r,s,t,u,v,w=e+f,x=w-e,y=f-x,z=y,A=w;c>j&&d>k;)q>n?(e=m,j+=1,c>j&&(m=a[j],n=l(m))):(e=o,k+=1,d>k&&(o=b[k],q=l(o))),f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r;for(;c>j;)e=m,f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r,j+=1,c>j&&(m=a[j]);for(;d>k;)e=o,f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r,k+=1,d>k&&(o=b[k]);return z&&(h[i++]=z),A&&(h[i++]=A),i||(h[i++]=0),h.length=i,h},m=l,n=function(a,b){var c=a.length;if(1===c){var d=i(a[0],b);return d[0]?d:[d[1]]}var e=new Array(2*c),f=[.1,.1],g=[.1,.1],h=0;i(a[0],b,f),f[0]&&(e[h++]=f[0]);for(var j=1;c>j;++j){i(a[j],b,g);var l=f[1];k(l,g[0],f),f[0]&&(e[h++]=f[0]);var m=g[1],n=f[1],o=m+n,p=o-m,q=n-p;f[1]=o,q&&(e[h++]=q)}return f[1]&&(e[h++]=f[1]),0===h&&(e[h++]=0),e.length=h,e},o=n,p=function(a,b){var c=a+b,d=c-a,e=c-d,f=b-d,g=a-e,h=g+f;return h?[h,c]:[c]},q=function(a,b){var c=0|a.length,d=0|b.length;if(1===c&&1===d)return p(a[0],-b[0]);var e,f,g=c+d,h=new Array(g),i=0,j=0,k=0,l=Math.abs,m=a[j],n=l(m),o=-b[k],q=l(o);q>n?(f=m,j+=1,c>j&&(m=a[j],n=l(m))):(f=o,k+=1,d>k&&(o=-b[k],q=l(o))),c>j&&q>n||k>=d?(e=m,j+=1,c>j&&(m=a[j],n=l(m))):(e=o,k+=1,d>k&&(o=-b[k],q=l(o)));for(var r,s,t,u,v,w=e+f,x=w-e,y=f-x,z=y,A=w;c>j&&d>k;)q>n?(e=m,j+=1,c>j&&(m=a[j],n=l(m))):(e=o,k+=1,d>k&&(o=-b[k],q=l(o))),f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r;for(;c>j;)e=m,f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r,j+=1,c>j&&(m=a[j]);for(;d>k;)e=o,f=z,w=e+f,x=w-e,y=f-x,y&&(h[i++]=y),r=A+w,s=r-A,t=r-s,u=w-s,v=A-t,z=v+u,A=r,k+=1,d>k&&(o=-b[k]);return z&&(h[i++]=z),A&&(h[i++]=A),i||(h[i++]=0),h.length=i,h},r=function(a,b){for(var c=new Array(a.length-1),d=1;d<a.length;++d)for(var e=c[d-1]=new Array(a.length-1),f=0,g=0;f<a.length;++f)f!==b&&(e[g++]=a[d][f]);return c},s=function(a){for(var b=new Array(a),c=0;a>c;++c){b[c]=new Array(a);for(var d=0;a>d;++d)b[c][d]=["m",d,"[",a-c-1,"]"].join("")}return b},t=function(a){return 1&a?"-":""},u=function(a){if(1===a.length)return a[0];if(2===a.length)return["sum(",a[0],",",a[1],")"].join("");var b=a.length>>1;return["sum(",u(a.slice(0,b)),",",u(a.slice(b)),")"].join("")},v=function(a){if(2===a.length)return[["sum(prod(",a[0][0],",",a[1][1],"),prod(-",a[0][1],",",a[1][0],"))"].join("")];for(var b=[],c=0;c<a.length;++c)b.push(["scale(",u(v(r(a,c))),",",t(c),a[0][c],")"].join(""));return b},w=function(a){for(var b=[],c=[],d=s(a),e=[],f=0;a>f;++f)0===(1&f)?b.push.apply(b,v(r(d,f))):c.push.apply(c,v(r(d,f))),e.push("m"+f);var g=u(b),h=u(c),j="orientation"+a+"Exact",k=["function ",j,"(",e.join(),"){var p=",g,",n=",h,",d=sub(p,n);return d[d.length-1];};return ",j].join(""),l=new Function("sum","prod","scale","sub",k);return l(m,i,o,q)},x=w(3),y=w(4),z=[function(){return 0},function(){return 0},function(a,b){return b[0]-a[0]},function(a,b,c){var d,e=(a[1]-c[1])*(b[0]-c[0]),f=(a[0]-c[0])*(b[1]-c[1]),h=e-f;if(e>0){if(0>=f)return h;d=e+f}else{if(!(0>e))return h;if(f>=0)return h;d=-(e+f)}var i=g*d;return h>=i||-i>=h?h:x(a,b,c)},function(a,b,c,d){var e=a[0]-d[0],f=b[0]-d[0],g=c[0]-d[0],i=a[1]-d[1],j=b[1]-d[1],k=c[1]-d[1],l=a[2]-d[2],m=b[2]-d[2],n=c[2]-d[2],o=f*k,p=g*j,q=g*i,r=e*k,s=e*j,t=f*i,u=l*(o-p)+m*(q-r)+n*(s-t),v=(Math.abs(o)+Math.abs(p))*Math.abs(l)+(Math.abs(q)+Math.abs(r))*Math.abs(m)+(Math.abs(s)+Math.abs(t))*Math.abs(n),w=h*v;return u>w||-u>w?u:y(a,b,c,d)}],A=function(a){var b=z[a.length];return b||(b=z[a.length]=w(a.length)),b.apply(c,a)},B=function(){for(;z.length<=e;)z.push(w(z.length));for(var a=[],d=["slow"],f=0;e>=f;++f)a.push("a"+f),d.push("o"+f);var g=["function getOrientation(",a.join(),"){switch(arguments.length){case 0:case 1:return 0;"];for(f=2;e>=f;++f)g.push("case ",f,":return o",f,"(",a.slice(0,f).join(),");");g.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation"),d.push(g.join(""));var h=Function.apply(c,d);for(b=h.apply(c,[A].concat(z)),f=0;e>=f;++f)b[f]=z[f]};B();var C=function(c,d){var e=a.longitude(d),f=a.latitude(d),g=c.map(function(b){return[a.longitude(b),a.latitude(b)]});c=g,d=[e,f];for(var h,i,j,k,l,m=c.length,n=1,o=m,p=0,q=m-1;o>p;q=p++){var r=c[p],s=c[q],t=r[1],u=s[1];if(t>u){if(f>u&&t>f){if(h=b(r,s,d),0===h)return 0;n^=h>0|0}else if(f===t&&(i=c[(p+1)%m],j=i[1],j>t)){if(h=b(r,s,d),0===h)return 0;n^=h>0|0}}else if(u>t){if(f>t&&u>f){if(h=b(r,s,d),0===h)return 0;n^=0>h|0}else if(f===t&&(i=c[(p+1)%m],j=i[1],t>j)){if(h=b(r,s,d),0===h)return 0;n^=0>h|0}}else if(f===t){var v=Math.min(r[0],s[0]),w=Math.max(r[0],s[0]);if(0===p){for(;q>0;){var x=(q+m-1)%m;if(l=c[x],l[1]!==f)break;k=l[0],v=Math.min(v,k),w=Math.max(w,k),q=x}if(0===q)return e>=v&&w>=e?0:1;o=q+1}for(var y=c[(q+m-1)%m][1];o>p+1&&(l=c[p+1],l[1]===f);)k=l[0],v=Math.min(v,k),w=Math.max(w,k),p+=1;if(e>=v&&w>=e)return 0;var z=c[(p+1)%m][1];v>e&&f>y!=f>z&&(n^=1)}}return 2*n-1};return{isPointInsideRobust:function(a,b){return C(b,a)},isInside:function(){return this.isPointInsideRobust.apply(this,arguments)}}};"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=function(a){return a.extend(d(a),!0),a}:"function"==typeof define&&define.amd?define(["geolib"],function(a){return a.extend(d(a),!0),a}):b.extend(d(b),!0)}(this,this.geolib); |