Stage 1 of the GIS Analytical Tools concept — client-side spatial analysis: - src/analysis/overlay.js: vector overlays (intersect / clip / difference / union-dissolve) on Turf.js, reprojecting to WGS84 and merging attributes (intersect keeps both layers', clip keeps only A's). - src/analysis/zonal.js: vector-in-vector zonal statistics — count / sum / mean / min / max / total area per zone, with centroid-in-zone (default) or any-overlap membership. - Bounding-box pre-filtering in both: only genuinely overlapping pairs reach the expensive geometry test. 43 zones x 25,004 parcels now completes in ~106 ms; previously it was refused as too large. - src/analysis-modal.js + markup: Analysis panel with "Apply to" scoping — whole layer, current map view, selected features, or the catch of a drawn Circle/Area. Reached from a new "Analyse" dock button. - MapView.addCOGLayer() for Cloud-Optimized GeoTIFF display (WebGLTile + GeoTIFF source, imported lazily); listVectorLayers(); getSelectedFeatures(). - Circle/Area analysis popup: one "Export" button (PDF folded into the export modal as a fourth format, field-rename table hidden for it) plus an "Analyse" button that opens the panel pre-scoped to the intersecting features. - vite.config.js: code-split turf, geotiff and pako so the eager bundle is unchanged (~283 kB). Giving pako its own chunk also fixes a circular chunk between jspdf and geotiff, which share it via fast-png. Drawing-tool fixes carried in the same working tree: - Delete/Backspace key deletes the selection via the EditBar's Delete interaction (same undoable block as the button). - Multi-select: shift-click toggles, Ctrl/Cmd-drag box-selects; helper layers (vertex overlay, GPS) excluded. - Undo: split/merge/divide wrapped in undo blocks so one press reverses the whole operation; vertex-overlay churn no longer pollutes the undo stack; sources are re-scanned and the stack cleared when edit mode is entered, so deletes on sub-grouped layers are undoable. NOTE: the undo behaviour is not yet confirmed on-device. - ol-ext TouchCursor gated to touch-only devices, so hybrid touchscreen laptops keep the normal cursor. Service worker v12 -> v13. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
3 lines
56 KiB
JavaScript
3 lines
56 KiB
JavaScript
var Qe=63710088e-1;function ue(t,e,n={}){const i={type:"Feature"};return(n.id===0||n.id)&&(i.id=n.id),n.bbox&&(i.bbox=n.bbox),i.properties=e||{},i.geometry=t,i}function gt(t,e,n={}){if(!t)throw new Error("coordinates is required");if(!Array.isArray(t))throw new Error("coordinates must be an Array");if(t.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Je(t[0])||!Je(t[1]))throw new Error("coordinates must contain numbers");return ue({type:"Point",coordinates:t},e,n)}function Ye(t,e,n={}){for(const r of t){if(r.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(r[r.length-1].length!==r[0].length)throw new Error("First and last Position are not equivalent.");for(let l=0;l<r[r.length-1].length;l++)if(r[r.length-1][l]!==r[0][l])throw new Error("First and last Position are not equivalent.")}return ue({type:"Polygon",coordinates:t},e,n)}function bt(t,e,n={}){if(t.length<2)throw new Error("coordinates must be an array of two or more positions");return ue({type:"LineString",coordinates:t},e,n)}function ze(t,e={}){const n={type:"FeatureCollection"};return e.id&&(n.id=e.id),e.bbox&&(n.bbox=e.bbox),n.features=t,n}function Lt(t,e,n={}){return ue({type:"MultiLineString",coordinates:t},e,n)}function We(t,e,n={}){return ue({type:"MultiPolygon",coordinates:t},e,n)}function Je(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function yt(t,e,n){if(t!==null)for(var i,r,l,h,f,g,c,S=0,m=0,P,T=t.type,O=T==="FeatureCollection",M=T==="Feature",N=O?t.features.length:1,_=0;_<N;_++){c=O?t.features[_].geometry:M?t.geometry:t,P=c?c.type==="GeometryCollection":!1,f=P?c.geometries.length:1;for(var b=0;b<f;b++){var B=0,G=0;if(h=P?c.geometries[b]:c,h!==null){g=h.coordinates;var q=h.type;switch(S=q==="Polygon"||q==="MultiPolygon"?1:0,q){case null:break;case"Point":if(e(g,m,_,B,G)===!1)return!1;m++,B++;break;case"LineString":case"MultiPoint":for(i=0;i<g.length;i++){if(e(g[i],m,_,B,G)===!1)return!1;m++,q==="MultiPoint"&&B++}q==="LineString"&&B++;break;case"Polygon":case"MultiLineString":for(i=0;i<g.length;i++){for(r=0;r<g[i].length-S;r++){if(e(g[i][r],m,_,B,G)===!1)return!1;m++}q==="MultiLineString"&&B++,q==="Polygon"&&G++}q==="Polygon"&&B++;break;case"MultiPolygon":for(i=0;i<g.length;i++){for(G=0,r=0;r<g[i].length;r++){for(l=0;l<g[i][r].length-S;l++){if(e(g[i][r][l],m,_,B,G)===!1)return!1;m++}G++}B++}break;case"GeometryCollection":for(i=0;i<h.geometries.length;i++)if(yt(h.geometries[i],e)===!1)return!1;break;default:throw new Error("Unknown Geometry Type")}}}}}function Ee(t,e){var n,i,r,l,h,f,g,c,S,m,P=0,T=t.type==="FeatureCollection",O=t.type==="Feature",M=T?t.features.length:1;for(n=0;n<M;n++){for(f=T?t.features[n].geometry:O?t.geometry:t,c=T?t.features[n].properties:O?t.properties:{},S=T?t.features[n].bbox:O?t.bbox:void 0,m=T?t.features[n].id:O?t.id:void 0,g=f?f.type==="GeometryCollection":!1,h=g?f.geometries.length:1,r=0;r<h;r++){if(l=g?f.geometries[r]:f,l===null){if(e(null,P,c,S,m)===!1)return!1;continue}switch(l.type){case"Point":case"LineString":case"MultiPoint":case"Polygon":case"MultiLineString":case"MultiPolygon":{if(e(l,P,c,S,m)===!1)return!1;break}case"GeometryCollection":{for(i=0;i<l.geometries.length;i++)if(e(l.geometries[i],P,c,S,m)===!1)return!1;break}default:throw new Error("Unknown Geometry Type")}}P++}}function Tt(t,e,n){var i=n;return Ee(t,function(r,l,h,f,g){i=e(i,r,l,h,f,g)}),i}function _e(t,e){Ee(t,function(n,i,r,l,h){var f=n===null?null:n.type;switch(f){case null:case"Point":case"LineString":case"Polygon":return e(ue(n,r,{bbox:l,id:h}),i,0)===!1?!1:void 0}var g;switch(f){case"MultiPoint":g="Point";break;case"MultiLineString":g="LineString";break;case"MultiPolygon":g="Polygon";break}for(var c=0;c<n.coordinates.length;c++){var S=n.coordinates[c],m={type:g,coordinates:S};if(e(ue(m,r),i,c)===!1)return!1}})}var Mt=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Ge=Math.ceil,ee=Math.floor,Q="[BigNumber Error] ",je=Q+"Number primitive has more than 15 significant digits: ",ne=1e14,C=14,qe=9007199254740991,Fe=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],he=1e7,K=1e9;function dt(t){var e,n,i,r=b.prototype={constructor:b,toString:null,valueOf:null},l=new b(1),h=20,f=4,g=-7,c=21,S=-1e7,m=1e7,P=!1,T=1,O=0,M={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},N="0123456789abcdefghijklmnopqrstuvwxyz",_=!0;function b(s,o){var u,w,a,y,v,p,d,E,x=this;if(!(x instanceof b))return new b(s,o);if(o==null){if(s&&s._isBigNumber===!0){x.s=s.s,!s.c||s.e>m?x.c=x.e=null:s.e<S?x.c=[x.e=0]:(x.e=s.e,x.c=s.c.slice());return}if((p=typeof s=="number")&&s*0==0){if(x.s=1/s<0?(s=-s,-1):1,s===~~s){for(y=0,v=s;v>=10;v/=10,y++);y>m?x.c=x.e=null:(x.e=y,x.c=[s]);return}E=String(s)}else{if(!Mt.test(E=String(s)))return i(x,E,p);x.s=E.charCodeAt(0)==45?(E=E.slice(1),-1):1}(y=E.indexOf("."))>-1&&(E=E.replace(".","")),(v=E.search(/e/i))>0?(y<0&&(y=v),y+=+E.slice(v+1),E=E.substring(0,v)):y<0&&(y=E.length)}else{if(U(o,2,N.length,"Base"),o==10&&_)return x=new b(s),F(x,h+x.e+1,f);if(E=String(s),p=typeof s=="number"){if(s*0!=0)return i(x,E,p,o);if(x.s=1/s<0?(E=E.slice(1),-1):1,b.DEBUG&&E.replace(/^0\.0*|\./,"").length>15)throw Error(je+s)}else x.s=E.charCodeAt(0)===45?(E=E.slice(1),-1):1;for(u=N.slice(0,o),y=v=0,d=E.length;v<d;v++)if(u.indexOf(w=E.charAt(v))<0){if(w=="."){if(v>y){y=d;continue}}else if(!a&&(E==E.toUpperCase()&&(E=E.toLowerCase())||E==E.toLowerCase()&&(E=E.toUpperCase()))){a=!0,v=-1,y=0;continue}return i(x,String(s),p,o)}p=!1,E=n(E,o,10,x.s),(y=E.indexOf("."))>-1?E=E.replace(".",""):y=E.length}for(v=0;E.charCodeAt(v)===48;v++);for(d=E.length;E.charCodeAt(--d)===48;);if(E=E.slice(v,++d)){if(d-=v,p&&b.DEBUG&&d>15&&(s>qe||s!==ee(s)))throw Error(je+x.s*s);if((y=y-v-1)>m)x.c=x.e=null;else if(y<S)x.c=[x.e=0];else{if(x.e=y,x.c=[],v=(y+1)%C,y<0&&(v+=C),v<d){for(v&&x.c.push(+E.slice(0,v)),d-=C;v<d;)x.c.push(+E.slice(v,v+=C));v=C-(E=E.slice(v)).length}else v-=d;for(;v--;E+="0");x.c.push(+E)}}else x.c=[x.e=0]}b.clone=dt,b.ROUND_UP=0,b.ROUND_DOWN=1,b.ROUND_CEIL=2,b.ROUND_FLOOR=3,b.ROUND_HALF_UP=4,b.ROUND_HALF_DOWN=5,b.ROUND_HALF_EVEN=6,b.ROUND_HALF_CEIL=7,b.ROUND_HALF_FLOOR=8,b.EUCLID=9,b.config=b.set=function(s){var o,u;if(s!=null)if(typeof s=="object"){if(s.hasOwnProperty(o="DECIMAL_PLACES")&&(u=s[o],U(u,0,K,o),h=u),s.hasOwnProperty(o="ROUNDING_MODE")&&(u=s[o],U(u,0,8,o),f=u),s.hasOwnProperty(o="EXPONENTIAL_AT")&&(u=s[o],u&&u.pop?(U(u[0],-K,0,o),U(u[1],0,K,o),g=u[0],c=u[1]):(U(u,-K,K,o),g=-(c=u<0?-u:u))),s.hasOwnProperty(o="RANGE"))if(u=s[o],u&&u.pop)U(u[0],-K,-1,o),U(u[1],1,K,o),S=u[0],m=u[1];else if(U(u,-K,K,o),u)S=-(m=u<0?-u:u);else throw Error(Q+o+" cannot be zero: "+u);if(s.hasOwnProperty(o="CRYPTO"))if(u=s[o],u===!!u)if(u)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))P=u;else throw P=!u,Error(Q+"crypto unavailable");else P=u;else throw Error(Q+o+" not true or false: "+u);if(s.hasOwnProperty(o="MODULO_MODE")&&(u=s[o],U(u,0,9,o),T=u),s.hasOwnProperty(o="POW_PRECISION")&&(u=s[o],U(u,0,K,o),O=u),s.hasOwnProperty(o="FORMAT"))if(u=s[o],typeof u=="object")M=u;else throw Error(Q+o+" not an object: "+u);if(s.hasOwnProperty(o="ALPHABET"))if(u=s[o],typeof u=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(u))_=u.slice(0,10)=="0123456789",N=u;else throw Error(Q+o+" invalid: "+u)}else throw Error(Q+"Object expected: "+s);return{DECIMAL_PLACES:h,ROUNDING_MODE:f,EXPONENTIAL_AT:[g,c],RANGE:[S,m],CRYPTO:P,MODULO_MODE:T,POW_PRECISION:O,FORMAT:M,ALPHABET:N}},b.isBigNumber=function(s){if(!s||s._isBigNumber!==!0)return!1;if(!b.DEBUG)return!0;var o,u,w=s.c,a=s.e,y=s.s;e:if({}.toString.call(w)=="[object Array]"){if((y===1||y===-1)&&a>=-K&&a<=K&&a===ee(a)){if(w[0]===0){if(a===0&&w.length===1)return!0;break e}if(o=(a+1)%C,o<1&&(o+=C),String(w[0]).length==o){for(o=0;o<w.length;o++)if(u=w[o],u<0||u>=ne||u!==ee(u))break e;if(u!==0)return!0}}}else if(w===null&&a===null&&(y===null||y===1||y===-1))return!0;throw Error(Q+"Invalid BigNumber: "+s)},b.maximum=b.max=function(){return G(arguments,-1)},b.minimum=b.min=function(){return G(arguments,1)},b.random=(function(){var s=9007199254740992,o=Math.random()*s&2097151?function(){return ee(Math.random()*s)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(u){var w,a,y,v,p,d=0,E=[],x=new b(l);if(u==null?u=h:U(u,0,K),v=Ge(u/C),P)if(crypto.getRandomValues){for(w=crypto.getRandomValues(new Uint32Array(v*=2));d<v;)p=w[d]*131072+(w[d+1]>>>11),p>=9e15?(a=crypto.getRandomValues(new Uint32Array(2)),w[d]=a[0],w[d+1]=a[1]):(E.push(p%1e14),d+=2);d=v/2}else if(crypto.randomBytes){for(w=crypto.randomBytes(v*=7);d<v;)p=(w[d]&31)*281474976710656+w[d+1]*1099511627776+w[d+2]*4294967296+w[d+3]*16777216+(w[d+4]<<16)+(w[d+5]<<8)+w[d+6],p>=9e15?crypto.randomBytes(7).copy(w,d):(E.push(p%1e14),d+=7);d=v/7}else throw P=!1,Error(Q+"crypto unavailable");if(!P)for(;d<v;)p=o(),p<9e15&&(E[d++]=p%1e14);for(v=E[--d],u%=C,v&&u&&(p=Fe[C-u],E[d]=ee(v/p)*p);E[d]===0;E.pop(),d--);if(d<0)E=[y=0];else{for(y=-1;E[0]===0;E.splice(0,1),y-=C);for(d=1,p=E[0];p>=10;p/=10,d++);d<C&&(y-=C-d)}return x.e=y,x.c=E,x}})(),b.sum=function(){for(var s=1,o=arguments,u=new b(o[0]);s<o.length;)u=u.plus(o[s++]);return u},n=(function(){var s="0123456789";function o(u,w,a,y){for(var v,p=[0],d,E=0,x=u.length;E<x;){for(d=p.length;d--;p[d]*=w);for(p[0]+=y.indexOf(u.charAt(E++)),v=0;v<p.length;v++)p[v]>a-1&&(p[v+1]==null&&(p[v+1]=0),p[v+1]+=p[v]/a|0,p[v]%=a)}return p.reverse()}return function(u,w,a,y,v){var p,d,E,x,L,R,A,k,$=u.indexOf("."),X=h,I=f;for($>=0&&(x=O,O=0,u=u.replace(".",""),k=new b(w),R=k.pow(u.length-$),O=x,k.c=o(oe(j(R.c),R.e,"0"),10,a,s),k.e=k.c.length),A=o(u,w,a,v?(p=N,s):(p=s,N)),E=x=A.length;A[--x]==0;A.pop());if(!A[0])return p.charAt(0);if($<0?--E:(R.c=A,R.e=E,R.s=y,R=e(R,k,X,I,a),A=R.c,L=R.r,E=R.e),d=E+X+1,$=A[d],x=a/2,L=L||d<0||A[d+1]!=null,L=I<4?($!=null||L)&&(I==0||I==(R.s<0?3:2)):$>x||$==x&&(I==4||L||I==6&&A[d-1]&1||I==(R.s<0?8:7)),d<1||!A[0])u=L?oe(p.charAt(1),-X,p.charAt(0)):p.charAt(0);else{if(A.length=d,L)for(--a;++A[--d]>a;)A[d]=0,d||(++E,A=[1].concat(A));for(x=A.length;!A[--x];);for($=0,u="";$<=x;u+=p.charAt(A[$++]));u=oe(u,E,p.charAt(0))}return u}})(),e=(function(){function s(w,a,y){var v,p,d,E,x=0,L=w.length,R=a%he,A=a/he|0;for(w=w.slice();L--;)d=w[L]%he,E=w[L]/he|0,v=A*d+E*R,p=R*d+v%he*he+x,x=(p/y|0)+(v/he|0)+A*E,w[L]=p%y;return x&&(w=[x].concat(w)),w}function o(w,a,y,v){var p,d;if(y!=v)d=y>v?1:-1;else for(p=d=0;p<y;p++)if(w[p]!=a[p]){d=w[p]>a[p]?1:-1;break}return d}function u(w,a,y,v){for(var p=0;y--;)w[y]-=p,p=w[y]<a[y]?1:0,w[y]=p*v+w[y]-a[y];for(;!w[0]&&w.length>1;w.splice(0,1));}return function(w,a,y,v,p){var d,E,x,L,R,A,k,$,X,I,D,H,Se,ke,Be,ie,ge,J=w.s==a.s?1:-1,W=w.c,V=a.c;if(!W||!W[0]||!V||!V[0])return new b(!w.s||!a.s||(W?V&&W[0]==V[0]:!V)?NaN:W&&W[0]==0||!V?J*0:J/0);for($=new b(J),X=$.c=[],E=w.e-a.e,J=y+E+1,p||(p=ne,E=te(w.e/C)-te(a.e/C),J=J/C|0),x=0;V[x]==(W[x]||0);x++);if(V[x]>(W[x]||0)&&E--,J<0)X.push(1),L=!0;else{for(ke=W.length,ie=V.length,x=0,J+=2,R=ee(p/(V[0]+1)),R>1&&(V=s(V,R,p),W=s(W,R,p),ie=V.length,ke=W.length),Se=ie,I=W.slice(0,ie),D=I.length;D<ie;I[D++]=0);ge=V.slice(),ge=[0].concat(ge),Be=V[0],V[1]>=p/2&&Be++;do{if(R=0,d=o(V,I,ie,D),d<0){if(H=I[0],ie!=D&&(H=H*p+(I[1]||0)),R=ee(H/Be),R>1)for(R>=p&&(R=p-1),A=s(V,R,p),k=A.length,D=I.length;o(A,I,k,D)==1;)R--,u(A,ie<k?ge:V,k,p),k=A.length,d=1;else R==0&&(d=R=1),A=V.slice(),k=A.length;if(k<D&&(A=[0].concat(A)),u(I,A,D,p),D=I.length,d==-1)for(;o(V,I,ie,D)<1;)R++,u(I,ie<D?ge:V,D,p),D=I.length}else d===0&&(R++,I=[0]);X[x++]=R,I[0]?I[D++]=W[Se]||0:(I=[W[Se]],D=1)}while((Se++<ke||I[0]!=null)&&J--);L=I[0]!=null,X[0]||X.splice(0,1)}if(p==ne){for(x=1,J=X[0];J>=10;J/=10,x++);F($,y+($.e=x+E*C-1)+1,v,L)}else $.e=E,$.r=+L;return $}})();function B(s,o,u,w){var a,y,v,p,d;if(u==null?u=f:U(u,0,8),!s.c)return s.toString();if(a=s.c[0],v=s.e,o==null)d=j(s.c),d=w==1||w==2&&(v<=g||v>=c)?be(d,v):oe(d,v,"0");else if(s=F(new b(s),o,u),y=s.e,d=j(s.c),p=d.length,w==1||w==2&&(o<=y||y<=g)){for(;p<o;d+="0",p++);d=be(d,y)}else if(o-=v+(w===2&&y>v),d=oe(d,y,"0"),y+1>p){if(--o>0)for(d+=".";o--;d+="0");}else if(o+=y-p,o>0)for(y+1==p&&(d+=".");o--;d+="0");return s.s<0&&a?"-"+d:d}function G(s,o){for(var u,w,a=1,y=new b(s[0]);a<s.length;a++)w=new b(s[a]),(!w.s||(u=ce(y,w))===o||u===0&&y.s===o)&&(y=w);return y}function q(s,o,u){for(var w=1,a=o.length;!o[--a];o.pop());for(a=o[0];a>=10;a/=10,w++);return(u=w+u*C-1)>m?s.c=s.e=null:u<S?s.c=[s.e=0]:(s.e=u,s.c=o),s}i=(function(){var s=/^(-?)0([xbo])(?=\w[\w.]*$)/i,o=/^([^.]+)\.$/,u=/^\.([^.]+)$/,w=/^-?(Infinity|NaN)$/,a=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(y,v,p,d){var E,x=p?v:v.replace(a,"");if(w.test(x))y.s=isNaN(x)?null:x<0?-1:1;else{if(!p&&(x=x.replace(s,function(L,R,A){return E=(A=A.toLowerCase())=="x"?16:A=="b"?2:8,!d||d==E?R:L}),d&&(E=d,x=x.replace(o,"$1").replace(u,"0.$1")),v!=x))return new b(x,E);if(b.DEBUG)throw Error(Q+"Not a"+(d?" base "+d:"")+" number: "+v);y.s=null}y.c=y.e=null}})();function F(s,o,u,w){var a,y,v,p,d,E,x,L=s.c,R=Fe;if(L){e:{for(a=1,p=L[0];p>=10;p/=10,a++);if(y=o-a,y<0)y+=C,v=o,d=L[E=0],x=ee(d/R[a-v-1]%10);else if(E=Ge((y+1)/C),E>=L.length)if(w){for(;L.length<=E;L.push(0));d=x=0,a=1,y%=C,v=y-C+1}else break e;else{for(d=p=L[E],a=1;p>=10;p/=10,a++);y%=C,v=y-C+a,x=v<0?0:ee(d/R[a-v-1]%10)}if(w=w||o<0||L[E+1]!=null||(v<0?d:d%R[a-v-1]),w=u<4?(x||w)&&(u==0||u==(s.s<0?3:2)):x>5||x==5&&(u==4||w||u==6&&(y>0?v>0?d/R[a-v]:0:L[E-1])%10&1||u==(s.s<0?8:7)),o<1||!L[0])return L.length=0,w?(o-=s.e+1,L[0]=R[(C-o%C)%C],s.e=-o||0):L[0]=s.e=0,s;if(y==0?(L.length=E,p=1,E--):(L.length=E+1,p=R[C-y],L[E]=v>0?ee(d/R[a-v]%R[v])*p:0),w)for(;;)if(E==0){for(y=1,v=L[0];v>=10;v/=10,y++);for(v=L[0]+=p,p=1;v>=10;v/=10,p++);y!=p&&(s.e++,L[0]==ne&&(L[0]=1));break}else{if(L[E]+=p,L[E]!=ne)break;L[E--]=0,p=1}for(y=L.length;L[--y]===0;L.pop());}s.e>m?s.c=s.e=null:s.e<S&&(s.c=[s.e=0])}return s}function z(s){var o,u=s.e;return u===null?s.toString():(o=j(s.c),o=u<=g||u>=c?be(o,u):oe(o,u,"0"),s.s<0?"-"+o:o)}return r.absoluteValue=r.abs=function(){var s=new b(this);return s.s<0&&(s.s=1),s},r.comparedTo=function(s,o){return ce(this,new b(s,o))},r.decimalPlaces=r.dp=function(s,o){var u,w,a,y=this;if(s!=null)return U(s,0,K),o==null?o=f:U(o,0,8),F(new b(y),s+y.e+1,o);if(!(u=y.c))return null;if(w=((a=u.length-1)-te(this.e/C))*C,a=u[a])for(;a%10==0;a/=10,w--);return w<0&&(w=0),w},r.dividedBy=r.div=function(s,o){return e(this,new b(s,o),h,f)},r.dividedToIntegerBy=r.idiv=function(s,o){return e(this,new b(s,o),0,1)},r.exponentiatedBy=r.pow=function(s,o){var u,w,a,y,v,p,d,E,x,L=this;if(s=new b(s),s.c&&!s.isInteger())throw Error(Q+"Exponent not an integer: "+z(s));if(o!=null&&(o=new b(o)),p=s.e>14,!L.c||!L.c[0]||L.c[0]==1&&!L.e&&L.c.length==1||!s.c||!s.c[0])return x=new b(Math.pow(+z(L),p?s.s*(2-Pe(s)):+z(s))),o?x.mod(o):x;if(d=s.s<0,o){if(o.c?!o.c[0]:!o.s)return new b(NaN);w=!d&&L.isInteger()&&o.isInteger(),w&&(L=L.mod(o))}else{if(s.e>9&&(L.e>0||L.e<-1||(L.e==0?L.c[0]>1||p&&L.c[1]>=24e7:L.c[0]<8e13||p&&L.c[0]<=9999975e7)))return y=L.s<0&&Pe(s)?-0:0,L.e>-1&&(y=1/y),new b(d?1/y:y);O&&(y=Ge(O/C+2))}for(p?(u=new b(.5),d&&(s.s=1),E=Pe(s)):(a=Math.abs(+z(s)),E=a%2),x=new b(l);;){if(E){if(x=x.times(L),!x.c)break;y?x.c.length>y&&(x.c.length=y):w&&(x=x.mod(o))}if(a){if(a=ee(a/2),a===0)break;E=a%2}else if(s=s.times(u),F(s,s.e+1,1),s.e>14)E=Pe(s);else{if(a=+z(s),a===0)break;E=a%2}L=L.times(L),y?L.c&&L.c.length>y&&(L.c.length=y):w&&(L=L.mod(o))}return w?x:(d&&(x=l.div(x)),o?x.mod(o):y?F(x,O,f,v):x)},r.integerValue=function(s){var o=new b(this);return s==null?s=f:U(s,0,8),F(o,o.e+1,s)},r.isEqualTo=r.eq=function(s,o){return ce(this,new b(s,o))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(s,o){return ce(this,new b(s,o))>0},r.isGreaterThanOrEqualTo=r.gte=function(s,o){return(o=ce(this,new b(s,o)))===1||o===0},r.isInteger=function(){return!!this.c&&te(this.e/C)>this.c.length-2},r.isLessThan=r.lt=function(s,o){return ce(this,new b(s,o))<0},r.isLessThanOrEqualTo=r.lte=function(s,o){return(o=ce(this,new b(s,o)))===-1||o===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(s,o){var u,w,a,y,v=this,p=v.s;if(s=new b(s,o),o=s.s,!p||!o)return new b(NaN);if(p!=o)return s.s=-o,v.plus(s);var d=v.e/C,E=s.e/C,x=v.c,L=s.c;if(!d||!E){if(!x||!L)return x?(s.s=-o,s):new b(L?v:NaN);if(!x[0]||!L[0])return L[0]?(s.s=-o,s):new b(x[0]?v:f==3?-0:0)}if(d=te(d),E=te(E),x=x.slice(),p=d-E){for((y=p<0)?(p=-p,a=x):(E=d,a=L),a.reverse(),o=p;o--;a.push(0));a.reverse()}else for(w=(y=(p=x.length)<(o=L.length))?p:o,p=o=0;o<w;o++)if(x[o]!=L[o]){y=x[o]<L[o];break}if(y&&(a=x,x=L,L=a,s.s=-s.s),o=(w=L.length)-(u=x.length),o>0)for(;o--;x[u++]=0);for(o=ne-1;w>p;){if(x[--w]<L[w]){for(u=w;u&&!x[--u];x[u]=o);--x[u],x[w]+=ne}x[w]-=L[w]}for(;x[0]==0;x.splice(0,1),--E);return x[0]?q(s,x,E):(s.s=f==3?-1:1,s.c=[s.e=0],s)},r.modulo=r.mod=function(s,o){var u,w,a=this;return s=new b(s,o),!a.c||!s.s||s.c&&!s.c[0]?new b(NaN):!s.c||a.c&&!a.c[0]?new b(a):(T==9?(w=s.s,s.s=1,u=e(a,s,0,3),s.s=w,u.s*=w):u=e(a,s,0,T),s=a.minus(u.times(s)),!s.c[0]&&T==1&&(s.s=a.s),s)},r.multipliedBy=r.times=function(s,o){var u,w,a,y,v,p,d,E,x,L,R,A,k,$,X,I=this,D=I.c,H=(s=new b(s,o)).c;if(!D||!H||!D[0]||!H[0])return!I.s||!s.s||D&&!D[0]&&!H||H&&!H[0]&&!D?s.c=s.e=s.s=null:(s.s*=I.s,!D||!H?s.c=s.e=null:(s.c=[0],s.e=0)),s;for(w=te(I.e/C)+te(s.e/C),s.s*=I.s,d=D.length,L=H.length,d<L&&(k=D,D=H,H=k,a=d,d=L,L=a),a=d+L,k=[];a--;k.push(0));for($=ne,X=he,a=L;--a>=0;){for(u=0,R=H[a]%X,A=H[a]/X|0,v=d,y=a+v;y>a;)E=D[--v]%X,x=D[v]/X|0,p=A*E+x*R,E=R*E+p%X*X+k[y]+u,u=(E/$|0)+(p/X|0)+A*x,k[y--]=E%$;k[y]=u}return u?++w:k.splice(0,1),q(s,k,w)},r.negated=function(){var s=new b(this);return s.s=-s.s||null,s},r.plus=function(s,o){var u,w=this,a=w.s;if(s=new b(s,o),o=s.s,!a||!o)return new b(NaN);if(a!=o)return s.s=-o,w.minus(s);var y=w.e/C,v=s.e/C,p=w.c,d=s.c;if(!y||!v){if(!p||!d)return new b(a/0);if(!p[0]||!d[0])return d[0]?s:new b(p[0]?w:a*0)}if(y=te(y),v=te(v),p=p.slice(),a=y-v){for(a>0?(v=y,u=d):(a=-a,u=p),u.reverse();a--;u.push(0));u.reverse()}for(a=p.length,o=d.length,a-o<0&&(u=d,d=p,p=u,o=a),a=0;o;)a=(p[--o]=p[o]+d[o]+a)/ne|0,p[o]=ne===p[o]?0:p[o]%ne;return a&&(p=[a].concat(p),++v),q(s,p,v)},r.precision=r.sd=function(s,o){var u,w,a,y=this;if(s!=null&&s!==!!s)return U(s,1,K),o==null?o=f:U(o,0,8),F(new b(y),s,o);if(!(u=y.c))return null;if(a=u.length-1,w=a*C+1,a=u[a]){for(;a%10==0;a/=10,w--);for(a=u[0];a>=10;a/=10,w++);}return s&&y.e+1>w&&(w=y.e+1),w},r.shiftedBy=function(s){return U(s,-qe,qe),this.times("1e"+s)},r.squareRoot=r.sqrt=function(){var s,o,u,w,a,y=this,v=y.c,p=y.s,d=y.e,E=h+4,x=new b("0.5");if(p!==1||!v||!v[0])return new b(!p||p<0&&(!v||v[0])?NaN:v?y:1/0);if(p=Math.sqrt(+z(y)),p==0||p==1/0?(o=j(v),(o.length+d)%2==0&&(o+="0"),p=Math.sqrt(+o),d=te((d+1)/2)-(d<0||d%2),p==1/0?o="5e"+d:(o=p.toExponential(),o=o.slice(0,o.indexOf("e")+1)+d),u=new b(o)):u=new b(p+""),u.c[0]){for(d=u.e,p=d+E,p<3&&(p=0);;)if(a=u,u=x.times(a.plus(e(y,a,E,1))),j(a.c).slice(0,p)===(o=j(u.c)).slice(0,p))if(u.e<d&&--p,o=o.slice(p-3,p+1),o=="9999"||!w&&o=="4999"){if(!w&&(F(a,a.e+h+2,0),a.times(a).eq(y))){u=a;break}E+=4,p+=4,w=1}else{(!+o||!+o.slice(1)&&o.charAt(0)=="5")&&(F(u,u.e+h+2,1),s=!u.times(u).eq(y));break}}return F(u,u.e+h+1,f,s)},r.toExponential=function(s,o){return s!=null&&(U(s,0,K),s++),B(this,s,o,1)},r.toFixed=function(s,o){return s!=null&&(U(s,0,K),s=s+this.e+1),B(this,s,o)},r.toFormat=function(s,o,u){var w,a=this;if(u==null)s!=null&&o&&typeof o=="object"?(u=o,o=null):s&&typeof s=="object"?(u=s,s=o=null):u=M;else if(typeof u!="object")throw Error(Q+"Argument not an object: "+u);if(w=a.toFixed(s,o),a.c){var y,v=w.split("."),p=+u.groupSize,d=+u.secondaryGroupSize,E=u.groupSeparator||"",x=v[0],L=v[1],R=a.s<0,A=R?x.slice(1):x,k=A.length;if(d&&(y=p,p=d,d=y,k-=y),p>0&&k>0){for(y=k%p||p,x=A.substr(0,y);y<k;y+=p)x+=E+A.substr(y,p);d>0&&(x+=E+A.slice(y)),R&&(x="-"+x)}w=L?x+(u.decimalSeparator||"")+((d=+u.fractionGroupSize)?L.replace(new RegExp("\\d{"+d+"}\\B","g"),"$&"+(u.fractionGroupSeparator||"")):L):x}return(u.prefix||"")+w+(u.suffix||"")},r.toFraction=function(s){var o,u,w,a,y,v,p,d,E,x,L,R,A=this,k=A.c;if(s!=null&&(p=new b(s),!p.isInteger()&&(p.c||p.s!==1)||p.lt(l)))throw Error(Q+"Argument "+(p.isInteger()?"out of range: ":"not an integer: ")+z(p));if(!k)return new b(A);for(o=new b(l),E=u=new b(l),w=d=new b(l),R=j(k),y=o.e=R.length-A.e-1,o.c[0]=Fe[(v=y%C)<0?C+v:v],s=!s||p.comparedTo(o)>0?y>0?o:E:p,v=m,m=1/0,p=new b(R),d.c[0]=0;x=e(p,o,0,1),a=u.plus(x.times(w)),a.comparedTo(s)!=1;)u=w,w=a,E=d.plus(x.times(a=E)),d=a,o=p.minus(x.times(a=o)),p=a;return a=e(s.minus(u),w,0,1),d=d.plus(a.times(E)),u=u.plus(a.times(w)),d.s=E.s=A.s,y=y*2,L=e(E,w,y,f).minus(A).abs().comparedTo(e(d,u,y,f).minus(A).abs())<1?[E,w]:[d,u],m=v,L},r.toNumber=function(){return+z(this)},r.toPrecision=function(s,o){return s!=null&&U(s,1,K),B(this,s,o,2)},r.toString=function(s){var o,u=this,w=u.s,a=u.e;return a===null?w?(o="Infinity",w<0&&(o="-"+o)):o="NaN":(s==null?o=a<=g||a>=c?be(j(u.c),a):oe(j(u.c),a,"0"):s===10&&_?(u=F(new b(u),h+a+1,f),o=oe(j(u.c),u.e,"0")):(U(s,2,N.length,"Base"),o=n(oe(j(u.c),a,"0"),10,s,w,!0)),w<0&&u.c[0]&&(o="-"+o)),o},r.valueOf=r.toJSON=function(){return z(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,t!=null&&b.set(t),b}function te(t){var e=t|0;return t>0||t===e?e:e-1}function j(t){for(var e,n,i=1,r=t.length,l=t[0]+"";i<r;){for(e=t[i++]+"",n=C-e.length;n--;e="0"+e);l+=e}for(r=l.length;l.charCodeAt(--r)===48;);return l.slice(0,r+1||1)}function ce(t,e){var n,i,r=t.c,l=e.c,h=t.s,f=e.s,g=t.e,c=e.e;if(!h||!f)return null;if(n=r&&!r[0],i=l&&!l[0],n||i)return n?i?0:-f:h;if(h!=f)return h;if(n=h<0,i=g==c,!r||!l)return i?0:!r^n?1:-1;if(!i)return g>c^n?1:-1;for(f=(g=r.length)<(c=l.length)?g:c,h=0;h<f;h++)if(r[h]!=l[h])return r[h]>l[h]^n?1:-1;return g==c?0:g>c^n?1:-1}function U(t,e,n,i){if(t<e||t>n||t!==ee(t))throw Error(Q+(i||"Argument")+(typeof t=="number"?t<e||t>n?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function Pe(t){var e=t.c.length-1;return te(t.e/C)==e&&t.c[e]%2!=0}function be(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function oe(t,e,n){var i,r;if(e<0){for(r=n+".";++e;r+=n);t=r+t}else if(i=t.length,++e>i){for(r=n,e-=i;--e;r+=n);t+=r}else e<i&&(t=t.slice(0,e)+"."+t.slice(e));return t}var se=dt(),Rt=class{key;left=null;right=null;constructor(t){this.key=t}},ye=class extends Rt{constructor(t){super(t)}},At=class{size=0;modificationCount=0;splayCount=0;splay(t){const e=this.root;if(e==null)return this.compare(t,t),-1;let n=null,i=null,r=null,l=null,h=e;const f=this.compare;let g;for(;;)if(g=f(h.key,t),g>0){let c=h.left;if(c==null||(g=f(c.key,t),g>0&&(h.left=c.right,c.right=h,h=c,c=h.left,c==null)))break;n==null?i=h:n.left=h,n=h,h=c}else if(g<0){let c=h.right;if(c==null||(g=f(c.key,t),g<0&&(h.right=c.left,c.left=h,h=c,c=h.right,c==null)))break;r==null?l=h:r.right=h,r=h,h=c}else break;return r!=null&&(r.right=h.left,h.left=l),n!=null&&(n.left=h.right,h.right=i),this.root!==h&&(this.root=h,this.splayCount++),g}splayMin(t){let e=t,n=e.left;for(;n!=null;){const i=n;e.left=i.right,i.right=e,e=i,n=e.left}return e}splayMax(t){let e=t,n=e.right;for(;n!=null;){const i=n;e.right=i.left,i.left=e,e=i,n=e.right}return e}_delete(t){if(this.root==null||this.splay(t)!=0)return null;let n=this.root;const i=n,r=n.left;if(this.size--,r==null)this.root=n.right;else{const l=n.right;n=this.splayMax(r),n.right=l,this.root=n}return this.modificationCount++,i}addNewRoot(t,e){this.size++,this.modificationCount++;const n=this.root;if(n==null){this.root=t;return}e<0?(t.left=n,t.right=n.right,n.right=null):(t.right=n,t.left=n.left,n.left=null),this.root=t}_first(){const t=this.root;return t==null?null:(this.root=this.splayMin(t),this.root)}_last(){const t=this.root;return t==null?null:(this.root=this.splayMax(t),this.root)}clear(){this.root=null,this.size=0,this.modificationCount++}has(t){return this.validKey(t)&&this.splay(t)==0}defaultCompare(){return(t,e)=>t<e?-1:t>e?1:0}wrap(){return{getRoot:()=>this.root,setRoot:t=>{this.root=t},getSize:()=>this.size,getModificationCount:()=>this.modificationCount,getSplayCount:()=>this.splayCount,setSplayCount:t=>{this.splayCount=t},splay:t=>this.splay(t),has:t=>this.has(t)}}},Oe=class we extends At{root=null;compare;validKey;constructor(e,n){super(),this.compare=e??this.defaultCompare(),this.validKey=n??(i=>i!=null&&i!=null)}delete(e){return this.validKey(e)?this._delete(e)!=null:!1}deleteAll(e){for(const n of e)this.delete(n)}forEach(e){const n=this[Symbol.iterator]();let i;for(;i=n.next(),!i.done;)e(i.value,i.value,this)}add(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new ye(e),n),this}addAndReturn(e){const n=this.splay(e);return n!=0&&this.addNewRoot(new ye(e),n),this.root.key}addAll(e){for(const n of e)this.add(n)}isEmpty(){return this.root==null}isNotEmpty(){return this.root!=null}single(){if(this.size==0)throw"Bad state: No element";if(this.size>1)throw"Bad state: Too many element";return this.root.key}first(){if(this.size==0)throw"Bad state: No element";return this._first().key}last(){if(this.size==0)throw"Bad state: No element";return this._last().key}lastBefore(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)<0)return this.root.key;let i=this.root.left;if(i==null)return null;let r=i.right;for(;r!=null;)i=r,r=i.right;return i.key}firstAfter(e){if(e==null)throw"Invalid arguments(s)";if(this.root==null)return null;if(this.splay(e)>0)return this.root.key;let i=this.root.right;if(i==null)return null;let r=i.left;for(;r!=null;)i=r,r=i.left;return i.key}retainAll(e){const n=new we(this.compare,this.validKey),i=this.modificationCount;for(const r of e){if(i!=this.modificationCount)throw"Concurrent modification during iteration.";this.validKey(r)&&this.splay(r)==0&&n.add(this.root.key)}n.size!=this.size&&(this.root=n.root,this.size=n.size,this.modificationCount++)}lookup(e){return!this.validKey(e)||this.splay(e)!=0?null:this.root.key}intersection(e){const n=new we(this.compare,this.validKey);for(const i of this)e.has(i)&&n.add(i);return n}difference(e){const n=new we(this.compare,this.validKey);for(const i of this)e.has(i)||n.add(i);return n}union(e){const n=this.clone();return n.addAll(e),n}clone(){const e=new we(this.compare,this.validKey);return e.size=this.size,e.root=this.copyNode(this.root),e}copyNode(e){if(e==null)return null;function n(r,l){let h,f;do{if(h=r.left,f=r.right,h!=null){const g=new ye(h.key);l.left=g,n(h,g)}if(f!=null){const g=new ye(f.key);l.right=g,r=f,l=g}}while(f!=null)}const i=new ye(e.key);return n(e,i),i}toSet(){return this.clone()}entries(){return new Ot(this.wrap())}keys(){return this[Symbol.iterator]()}values(){return this[Symbol.iterator]()}[Symbol.iterator](){return new _t(this.wrap())}[Symbol.toStringTag]="[object Set]"},wt=class{tree;path=new Array;modificationCount=null;splayCount;constructor(t){this.tree=t,this.splayCount=t.getSplayCount()}[Symbol.iterator](){return this}next(){return this.moveNext()?{done:!1,value:this.current()}:{done:!0,value:null}}current(){if(!this.path.length)return null;const t=this.path[this.path.length-1];return this.getValue(t)}rebuildPath(t){this.path.splice(0,this.path.length),this.tree.splay(t),this.path.push(this.tree.getRoot()),this.splayCount=this.tree.getSplayCount()}findLeftMostDescendent(t){for(;t!=null;)this.path.push(t),t=t.left}moveNext(){if(this.modificationCount!=this.tree.getModificationCount()){if(this.modificationCount==null){this.modificationCount=this.tree.getModificationCount();let n=this.tree.getRoot();for(;n!=null;)this.path.push(n),n=n.left;return this.path.length>0}throw"Concurrent modification during iteration."}if(!this.path.length)return!1;this.splayCount!=this.tree.getSplayCount()&&this.rebuildPath(this.path[this.path.length-1].key);let t=this.path[this.path.length-1],e=t.right;if(e!=null){for(;e!=null;)this.path.push(e),e=e.left;return!0}for(this.path.pop();this.path.length&&this.path[this.path.length-1].right===t;)t=this.path.pop();return this.path.length>0}},_t=class extends wt{getValue(t){return t.key}},Ot=class extends wt{getValue(t){return[t.key,t.key]}},xt=t=>()=>t,$e=t=>{const e=t?(n,i)=>i.minus(n).abs().isLessThanOrEqualTo(t):xt(!1);return(n,i)=>e(n,i)?0:n.comparedTo(i)};function Nt(t){const e=t?(n,i,r,l,h)=>n.exponentiatedBy(2).isLessThanOrEqualTo(l.minus(i).exponentiatedBy(2).plus(h.minus(r).exponentiatedBy(2)).times(t)):xt(!1);return(n,i,r)=>{const l=n.x,h=n.y,f=r.x,g=r.y,c=h.minus(g).times(i.x.minus(f)).minus(l.minus(f).times(i.y.minus(g)));return e(c,l,h,f,g)?0:c.comparedTo(0)}}var Ct=t=>t,It=t=>{if(t){const e=new Oe($e(t)),n=new Oe($e(t)),i=(l,h)=>h.addAndReturn(l),r=l=>({x:i(l.x,e),y:i(l.y,n)});return r({x:new se(0),y:new se(0)}),r}return Ct},Ve=t=>({set:e=>{fe=Ve(e)},reset:()=>Ve(t),compare:$e(t),snap:It(t),orient:Nt(t)}),fe=Ve(),de=(t,e)=>t.ll.x.isLessThanOrEqualTo(e.x)&&e.x.isLessThanOrEqualTo(t.ur.x)&&t.ll.y.isLessThanOrEqualTo(e.y)&&e.y.isLessThanOrEqualTo(t.ur.y),Xe=(t,e)=>{if(e.ur.x.isLessThan(t.ll.x)||t.ur.x.isLessThan(e.ll.x)||e.ur.y.isLessThan(t.ll.y)||t.ur.y.isLessThan(e.ll.y))return null;const n=t.ll.x.isLessThan(e.ll.x)?e.ll.x:t.ll.x,i=t.ur.x.isLessThan(e.ur.x)?t.ur.x:e.ur.x,r=t.ll.y.isLessThan(e.ll.y)?e.ll.y:t.ll.y,l=t.ur.y.isLessThan(e.ur.y)?t.ur.y:e.ur.y;return{ll:{x:n,y:r},ur:{x:i,y:l}}},Re=(t,e)=>t.x.times(e.y).minus(t.y.times(e.x)),mt=(t,e)=>t.x.times(e.x).plus(t.y.times(e.y)),Ne=t=>mt(t,t).sqrt(),kt=(t,e,n)=>{const i={x:e.x.minus(t.x),y:e.y.minus(t.y)},r={x:n.x.minus(t.x),y:n.y.minus(t.y)};return Re(r,i).div(Ne(r)).div(Ne(i))},Bt=(t,e,n)=>{const i={x:e.x.minus(t.x),y:e.y.minus(t.y)},r={x:n.x.minus(t.x),y:n.y.minus(t.y)};return mt(r,i).div(Ne(r)).div(Ne(i))},et=(t,e,n)=>e.y.isZero()?null:{x:t.x.plus(e.x.div(e.y).times(n.minus(t.y))),y:n},tt=(t,e,n)=>e.x.isZero()?null:{x:n,y:t.y.plus(e.y.div(e.x).times(n.minus(t.x)))},Gt=(t,e,n,i)=>{if(e.x.isZero())return tt(n,i,t.x);if(i.x.isZero())return tt(t,e,n.x);if(e.y.isZero())return et(n,i,t.y);if(i.y.isZero())return et(t,e,n.y);const r=Re(e,i);if(r.isZero())return null;const l={x:n.x.minus(t.x),y:n.y.minus(t.y)},h=Re(l,e).div(r),f=Re(l,i).div(r),g=t.x.plus(f.times(e.x)),c=n.x.plus(h.times(i.x)),S=t.y.plus(f.times(e.y)),m=n.y.plus(h.times(i.y)),P=g.plus(c).div(2),T=S.plus(m).div(2);return{x:P,y:T}},re=class Et{point;isLeft;segment;otherSE;consumedBy;static compare(e,n){const i=Et.comparePoints(e.point,n.point);return i!==0?i:(e.point!==n.point&&e.link(n),e.isLeft!==n.isLeft?e.isLeft?1:-1:Ce.compare(e.segment,n.segment))}static comparePoints(e,n){return e.x.isLessThan(n.x)?-1:e.x.isGreaterThan(n.x)?1:e.y.isLessThan(n.y)?-1:e.y.isGreaterThan(n.y)?1:0}constructor(e,n){e.events===void 0?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=n}link(e){if(e.point===this.point)throw new Error("Tried to link already linked events");const n=e.point.events;for(let i=0,r=n.length;i<r;i++){const l=n[i];this.point.events.push(l),l.point=this.point}this.checkForConsuming()}checkForConsuming(){const e=this.point.events.length;for(let n=0;n<e;n++){const i=this.point.events[n];if(i.segment.consumedBy===void 0)for(let r=n+1;r<e;r++){const l=this.point.events[r];l.consumedBy===void 0&&i.otherSE.point.events===l.otherSE.point.events&&i.segment.consume(l.segment)}}}getAvailableLinkedEvents(){const e=[];for(let n=0,i=this.point.events.length;n<i;n++){const r=this.point.events[n];r!==this&&!r.segment.ringOut&&r.segment.isInResult()&&e.push(r)}return e}getLeftmostComparator(e){const n=new Map,i=r=>{const l=r.otherSE;n.set(r,{sine:kt(this.point,e.point,l.point),cosine:Bt(this.point,e.point,l.point)})};return(r,l)=>{n.has(r)||i(r),n.has(l)||i(l);const{sine:h,cosine:f}=n.get(r),{sine:g,cosine:c}=n.get(l);return h.isGreaterThanOrEqualTo(0)&&g.isGreaterThanOrEqualTo(0)?f.isLessThan(c)?1:f.isGreaterThan(c)?-1:0:h.isLessThan(0)&&g.isLessThan(0)?f.isLessThan(c)?-1:f.isGreaterThan(c)?1:0:g.isLessThan(h)?-1:g.isGreaterThan(h)?1:0}}},qt=class Ke{events;poly;_isExteriorRing;_enclosingRing;static factory(e){const n=[];for(let i=0,r=e.length;i<r;i++){const l=e[i];if(!l.isInResult()||l.ringOut)continue;let h=null,f=l.leftSE,g=l.rightSE;const c=[f],S=f.point,m=[];for(;h=f,f=g,c.push(f),f.point!==S;)for(;;){const P=f.getAvailableLinkedEvents();if(P.length===0){const M=c[0].point,N=c[c.length-1].point;throw new Error(`Unable to complete output ring starting at [${M.x}, ${M.y}]. Last matching segment found ends at [${N.x}, ${N.y}].`)}if(P.length===1){g=P[0].otherSE;break}let T=null;for(let M=0,N=m.length;M<N;M++)if(m[M].point===f.point){T=M;break}if(T!==null){const M=m.splice(T)[0],N=c.splice(M.index);N.unshift(N[0].otherSE),n.push(new Ke(N.reverse()));continue}m.push({index:c.length,point:f.point});const O=f.getLeftmostComparator(h);g=P.sort(O)[0].otherSE;break}n.push(new Ke(c))}return n}constructor(e){this.events=e;for(let n=0,i=e.length;n<i;n++)e[n].segment.ringOut=this;this.poly=null}getGeom(){let e=this.events[0].point;const n=[e];for(let c=1,S=this.events.length-1;c<S;c++){const m=this.events[c].point,P=this.events[c+1].point;fe.orient(m,e,P)!==0&&(n.push(m),e=m)}if(n.length===1)return null;const i=n[0],r=n[1];fe.orient(i,e,r)===0&&n.shift(),n.push(n[0]);const l=this.isExteriorRing()?1:-1,h=this.isExteriorRing()?0:n.length-1,f=this.isExteriorRing()?n.length:-1,g=[];for(let c=h;c!=f;c+=l)g.push([n[c].x.toNumber(),n[c].y.toNumber()]);return g}isExteriorRing(){if(this._isExteriorRing===void 0){const e=this.enclosingRing();this._isExteriorRing=e?!e.isExteriorRing():!0}return this._isExteriorRing}enclosingRing(){return this._enclosingRing===void 0&&(this._enclosingRing=this._calcEnclosingRing()),this._enclosingRing}_calcEnclosingRing(){let e=this.events[0];for(let r=1,l=this.events.length;r<l;r++){const h=this.events[r];re.compare(e,h)>0&&(e=h)}let n=e.segment.prevInResult(),i=n?n.prevInResult():null;for(;;){if(!n)return null;if(!i)return n.ringOut;if(i.ringOut!==n.ringOut)return i.ringOut?.enclosingRing()!==n.ringOut?n.ringOut:n.ringOut?.enclosingRing();n=i.prevInResult(),i=n?n.prevInResult():null}}},nt=class{exteriorRing;interiorRings;constructor(t){this.exteriorRing=t,t.poly=this,this.interiorRings=[]}addInterior(t){this.interiorRings.push(t),t.poly=this}getGeom(){const t=this.exteriorRing.getGeom();if(t===null)return null;const e=[t];for(let n=0,i=this.interiorRings.length;n<i;n++){const r=this.interiorRings[n].getGeom();r!==null&&e.push(r)}return e}},Ft=class{rings;polys;constructor(t){this.rings=t,this.polys=this._composePolys(t)}getGeom(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const i=this.polys[e].getGeom();i!==null&&t.push(i)}return t}_composePolys(t){const e=[];for(let n=0,i=t.length;n<i;n++){const r=t[n];if(!r.poly)if(r.isExteriorRing())e.push(new nt(r));else{const l=r.enclosingRing();l?.poly||e.push(new nt(l)),l?.poly?.addInterior(r)}}return e}},Dt=class{queue;tree;segments;constructor(t,e=Ce.compare){this.queue=t,this.tree=new Oe(e),this.segments=[]}process(t){const e=t.segment,n=[];if(t.consumedBy)return t.isLeft?this.queue.delete(t.otherSE):this.tree.delete(e),n;t.isLeft&&this.tree.add(e);let i=e,r=e;do i=this.tree.lastBefore(i);while(i!=null&&i.consumedBy!=null);do r=this.tree.firstAfter(r);while(r!=null&&r.consumedBy!=null);if(t.isLeft){let l=null;if(i){const f=i.getIntersection(e);if(f!==null&&(e.isAnEndpoint(f)||(l=f),!i.isAnEndpoint(f))){const g=this._splitSafely(i,f);for(let c=0,S=g.length;c<S;c++)n.push(g[c])}}let h=null;if(r){const f=r.getIntersection(e);if(f!==null&&(e.isAnEndpoint(f)||(h=f),!r.isAnEndpoint(f))){const g=this._splitSafely(r,f);for(let c=0,S=g.length;c<S;c++)n.push(g[c])}}if(l!==null||h!==null){let f=null;l===null?f=h:h===null?f=l:f=re.comparePoints(l,h)<=0?l:h,this.queue.delete(e.rightSE),n.push(e.rightSE);const g=e.split(f);for(let c=0,S=g.length;c<S;c++)n.push(g[c])}n.length>0?(this.tree.delete(e),n.push(t)):(this.segments.push(e),e.prev=i)}else{if(i&&r){const l=i.getIntersection(r);if(l!==null){if(!i.isAnEndpoint(l)){const h=this._splitSafely(i,l);for(let f=0,g=h.length;f<g;f++)n.push(h[f])}if(!r.isAnEndpoint(l)){const h=this._splitSafely(r,l);for(let f=0,g=h.length;f<g;f++)n.push(h[f])}}}this.tree.delete(e)}return n}_splitSafely(t,e){this.tree.delete(t);const n=t.rightSE;this.queue.delete(n);const i=t.split(e);return i.push(n),t.consumedBy===void 0&&this.tree.add(t),i}},Ut=class{type;numMultiPolys;run(t,e,n){xe.type=t;const i=[new rt(e,!0)];for(let c=0,S=n.length;c<S;c++)i.push(new rt(n[c],!1));if(xe.numMultiPolys=i.length,xe.type==="difference"){const c=i[0];let S=1;for(;S<i.length;)Xe(i[S].bbox,c.bbox)!==null?S++:i.splice(S,1)}if(xe.type==="intersection")for(let c=0,S=i.length;c<S;c++){const m=i[c];for(let P=c+1,T=i.length;P<T;P++)if(Xe(m.bbox,i[P].bbox)===null)return[]}const r=new Oe(re.compare);for(let c=0,S=i.length;c<S;c++){const m=i[c].getSweepEvents();for(let P=0,T=m.length;P<T;P++)r.add(m[P])}const l=new Dt(r);let h=null;for(r.size!=0&&(h=r.first(),r.delete(h));h;){const c=l.process(h);for(let S=0,m=c.length;S<m;S++){const P=c[S];P.consumedBy===void 0&&r.add(P)}r.size!=0?(h=r.first(),r.delete(h)):h=null}fe.reset();const f=qt.factory(l.segments);return new Ft(f).getGeom()}},xe=new Ut,me=xe,zt=0,Ce=class Ae{id;leftSE;rightSE;rings;windings;ringOut;consumedBy;prev;_prevInResult;_beforeState;_afterState;_isInResult;static compare(e,n){const i=e.leftSE.point.x,r=n.leftSE.point.x,l=e.rightSE.point.x,h=n.rightSE.point.x;if(h.isLessThan(i))return 1;if(l.isLessThan(r))return-1;const f=e.leftSE.point.y,g=n.leftSE.point.y,c=e.rightSE.point.y,S=n.rightSE.point.y;if(i.isLessThan(r)){if(g.isLessThan(f)&&g.isLessThan(c))return 1;if(g.isGreaterThan(f)&&g.isGreaterThan(c))return-1;const m=e.comparePoint(n.leftSE.point);if(m<0)return 1;if(m>0)return-1;const P=n.comparePoint(e.rightSE.point);return P!==0?P:-1}if(i.isGreaterThan(r)){if(f.isLessThan(g)&&f.isLessThan(S))return-1;if(f.isGreaterThan(g)&&f.isGreaterThan(S))return 1;const m=n.comparePoint(e.leftSE.point);if(m!==0)return m;const P=e.comparePoint(n.rightSE.point);return P<0?1:P>0?-1:1}if(f.isLessThan(g))return-1;if(f.isGreaterThan(g))return 1;if(l.isLessThan(h)){const m=n.comparePoint(e.rightSE.point);if(m!==0)return m}if(l.isGreaterThan(h)){const m=e.comparePoint(n.rightSE.point);if(m<0)return 1;if(m>0)return-1}if(!l.eq(h)){const m=c.minus(f),P=l.minus(i),T=S.minus(g),O=h.minus(r);if(m.isGreaterThan(P)&&T.isLessThan(O))return 1;if(m.isLessThan(P)&&T.isGreaterThan(O))return-1}return l.isGreaterThan(h)?1:l.isLessThan(h)||c.isLessThan(S)?-1:c.isGreaterThan(S)?1:e.id<n.id?-1:e.id>n.id?1:0}constructor(e,n,i,r){this.id=++zt,this.leftSE=e,e.segment=this,e.otherSE=n,this.rightSE=n,n.segment=this,n.otherSE=e,this.rings=i,this.windings=r}static fromRing(e,n,i){let r,l,h;const f=re.comparePoints(e,n);if(f<0)r=e,l=n,h=1;else if(f>0)r=n,l=e,h=-1;else throw new Error(`Tried to create degenerate segment at [${e.x}, ${e.y}]`);const g=new re(r,!0),c=new re(l,!1);return new Ae(g,c,[i],[h])}replaceRightSE(e){this.rightSE=e,this.rightSE.segment=this,this.rightSE.otherSE=this.leftSE,this.leftSE.otherSE=this.rightSE}bbox(){const e=this.leftSE.point.y,n=this.rightSE.point.y;return{ll:{x:this.leftSE.point.x,y:e.isLessThan(n)?e:n},ur:{x:this.rightSE.point.x,y:e.isGreaterThan(n)?e:n}}}vector(){return{x:this.rightSE.point.x.minus(this.leftSE.point.x),y:this.rightSE.point.y.minus(this.leftSE.point.y)}}isAnEndpoint(e){return e.x.eq(this.leftSE.point.x)&&e.y.eq(this.leftSE.point.y)||e.x.eq(this.rightSE.point.x)&&e.y.eq(this.rightSE.point.y)}comparePoint(e){return fe.orient(this.leftSE.point,e,this.rightSE.point)}getIntersection(e){const n=this.bbox(),i=e.bbox(),r=Xe(n,i);if(r===null)return null;const l=this.leftSE.point,h=this.rightSE.point,f=e.leftSE.point,g=e.rightSE.point,c=de(n,f)&&this.comparePoint(f)===0,S=de(i,l)&&e.comparePoint(l)===0,m=de(n,g)&&this.comparePoint(g)===0,P=de(i,h)&&e.comparePoint(h)===0;if(S&&c)return P&&!m?h:!P&&m?g:null;if(S)return m&&l.x.eq(g.x)&&l.y.eq(g.y)?null:l;if(c)return P&&h.x.eq(f.x)&&h.y.eq(f.y)?null:f;if(P&&m)return null;if(P)return h;if(m)return g;const T=Gt(l,this.vector(),f,e.vector());return T===null||!de(r,T)?null:fe.snap(T)}split(e){const n=[],i=e.events!==void 0,r=new re(e,!0),l=new re(e,!1),h=this.rightSE;this.replaceRightSE(l),n.push(l),n.push(r);const f=new Ae(r,h,this.rings.slice(),this.windings.slice());return re.comparePoints(f.leftSE.point,f.rightSE.point)>0&&f.swapEvents(),re.comparePoints(this.leftSE.point,this.rightSE.point)>0&&this.swapEvents(),i&&(r.checkForConsuming(),l.checkForConsuming()),n}swapEvents(){const e=this.rightSE;this.rightSE=this.leftSE,this.leftSE=e,this.leftSE.isLeft=!0,this.rightSE.isLeft=!1;for(let n=0,i=this.windings.length;n<i;n++)this.windings[n]*=-1}consume(e){let n=this,i=e;for(;n.consumedBy;)n=n.consumedBy;for(;i.consumedBy;)i=i.consumedBy;const r=Ae.compare(n,i);if(r!==0){if(r>0){const l=n;n=i,i=l}if(n.prev===i){const l=n;n=i,i=l}for(let l=0,h=i.rings.length;l<h;l++){const f=i.rings[l],g=i.windings[l],c=n.rings.indexOf(f);c===-1?(n.rings.push(f),n.windings.push(g)):n.windings[c]+=g}i.rings=null,i.windings=null,i.consumedBy=n,i.leftSE.consumedBy=n.leftSE,i.rightSE.consumedBy=n.rightSE}}prevInResult(){return this._prevInResult!==void 0?this._prevInResult:(this.prev?this.prev.isInResult()?this._prevInResult=this.prev:this._prevInResult=this.prev.prevInResult():this._prevInResult=null,this._prevInResult)}beforeState(){if(this._beforeState!==void 0)return this._beforeState;if(!this.prev)this._beforeState={rings:[],windings:[],multiPolys:[]};else{const e=this.prev.consumedBy||this.prev;this._beforeState=e.afterState()}return this._beforeState}afterState(){if(this._afterState!==void 0)return this._afterState;const e=this.beforeState();this._afterState={rings:e.rings.slice(0),windings:e.windings.slice(0),multiPolys:[]};const n=this._afterState.rings,i=this._afterState.windings,r=this._afterState.multiPolys;for(let f=0,g=this.rings.length;f<g;f++){const c=this.rings[f],S=this.windings[f],m=n.indexOf(c);m===-1?(n.push(c),i.push(S)):i[m]+=S}const l=[],h=[];for(let f=0,g=n.length;f<g;f++){if(i[f]===0)continue;const c=n[f],S=c.poly;if(h.indexOf(S)===-1)if(c.isExterior)l.push(S);else{h.indexOf(S)===-1&&h.push(S);const m=l.indexOf(c.poly);m!==-1&&l.splice(m,1)}}for(let f=0,g=l.length;f<g;f++){const c=l[f].multiPoly;r.indexOf(c)===-1&&r.push(c)}return this._afterState}isInResult(){if(this.consumedBy)return!1;if(this._isInResult!==void 0)return this._isInResult;const e=this.beforeState().multiPolys,n=this.afterState().multiPolys;switch(me.type){case"union":{const i=e.length===0,r=n.length===0;this._isInResult=i!==r;break}case"intersection":{let i,r;e.length<n.length?(i=e.length,r=n.length):(i=n.length,r=e.length),this._isInResult=r===me.numMultiPolys&&i<r;break}case"xor":{const i=Math.abs(e.length-n.length);this._isInResult=i%2===1;break}case"difference":{const i=r=>r.length===1&&r[0].isSubject;this._isInResult=i(e)!==i(n);break}}return this._isInResult}},it=class{poly;isExterior;segments;bbox;constructor(t,e,n){if(!Array.isArray(t)||t.length===0)throw new Error("Input geometry is not a valid Polygon or MultiPolygon");if(this.poly=e,this.isExterior=n,this.segments=[],typeof t[0][0]!="number"||typeof t[0][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const i=fe.snap({x:new se(t[0][0]),y:new se(t[0][1])});this.bbox={ll:{x:i.x,y:i.y},ur:{x:i.x,y:i.y}};let r=i;for(let l=1,h=t.length;l<h;l++){if(typeof t[l][0]!="number"||typeof t[l][1]!="number")throw new Error("Input geometry is not a valid Polygon or MultiPolygon");const f=fe.snap({x:new se(t[l][0]),y:new se(t[l][1])});f.x.eq(r.x)&&f.y.eq(r.y)||(this.segments.push(Ce.fromRing(r,f,this)),f.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=f.x),f.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=f.y),f.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=f.x),f.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=f.y),r=f)}(!i.x.eq(r.x)||!i.y.eq(r.y))&&this.segments.push(Ce.fromRing(r,i,this))}getSweepEvents(){const t=[];for(let e=0,n=this.segments.length;e<n;e++){const i=this.segments[e];t.push(i.leftSE),t.push(i.rightSE)}return t}},$t=class{multiPoly;exteriorRing;interiorRings;bbox;constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");this.exteriorRing=new it(t[0],this,!0),this.bbox={ll:{x:this.exteriorRing.bbox.ll.x,y:this.exteriorRing.bbox.ll.y},ur:{x:this.exteriorRing.bbox.ur.x,y:this.exteriorRing.bbox.ur.y}},this.interiorRings=[];for(let n=1,i=t.length;n<i;n++){const r=new it(t[n],this,!1);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.interiorRings.push(r)}this.multiPoly=e}getSweepEvents(){const t=this.exteriorRing.getSweepEvents();for(let e=0,n=this.interiorRings.length;e<n;e++){const i=this.interiorRings[e].getSweepEvents();for(let r=0,l=i.length;r<l;r++)t.push(i[r])}return t}},rt=class{isSubject;polys;bbox;constructor(t,e){if(!Array.isArray(t))throw new Error("Input geometry is not a valid Polygon or MultiPolygon");try{typeof t[0][0][0]=="number"&&(t=[t])}catch{}this.polys=[],this.bbox={ll:{x:new se(Number.POSITIVE_INFINITY),y:new se(Number.POSITIVE_INFINITY)},ur:{x:new se(Number.NEGATIVE_INFINITY),y:new se(Number.NEGATIVE_INFINITY)}};for(let n=0,i=t.length;n<i;n++){const r=new $t(t[n],this);r.bbox.ll.x.isLessThan(this.bbox.ll.x)&&(this.bbox.ll.x=r.bbox.ll.x),r.bbox.ll.y.isLessThan(this.bbox.ll.y)&&(this.bbox.ll.y=r.bbox.ll.y),r.bbox.ur.x.isGreaterThan(this.bbox.ur.x)&&(this.bbox.ur.x=r.bbox.ur.x),r.bbox.ur.y.isGreaterThan(this.bbox.ur.y)&&(this.bbox.ur.y=r.bbox.ur.y),this.polys.push(r)}this.isSubject=e}getSweepEvents(){const t=[];for(let e=0,n=this.polys.length;e<n;e++){const i=this.polys[e].getSweepEvents();for(let r=0,l=i.length;r<l;r++)t.push(i[r])}return t}},Vt=(t,...e)=>me.run("union",t,e),Xt=(t,...e)=>me.run("intersection",t,e),Kt=(t,...e)=>me.run("difference",t,e);fe.set;function Ht(t,e={}){const n=[];if(Ee(t,r=>{n.push(r.coordinates)}),n.length<2)throw new Error("Must specify at least 2 geometries");const i=Xt(n[0],...n.slice(1));return i.length===0?null:i.length===1?Ye(i[0],e.properties):We(i,e.properties)}var Rn=Ht;function Yt(t,e={}){const n=[];if(Ee(t,r=>{n.push(r.coordinates)}),n.length<2)throw new Error("Must have at least 2 geometries");const i=Vt(n[0],...n.slice(1));return i.length===0?null:i.length===1?Ye(i[0],e.properties):We(i,e.properties)}var An=Yt;function Wt(t){const e=[];if(Ee(t,r=>{e.push(r.coordinates)}),e.length<2)throw new Error("Must have at least two features");const n=t.features[0].properties||{},i=Kt(e[0],...e.slice(1));return i.length===0?null:i.length===1?Ye(i[0],n):We(i,n)}var _n=Wt;const le=11102230246251565e-32,Y=134217729,Zt=(3+8*le)*le;function De(t,e,n,i,r){let l,h,f,g,c=e[0],S=i[0],m=0,P=0;S>c==S>-c?(l=c,c=e[++m]):(l=S,S=i[++P]);let T=0;if(m<t&&P<n)for(S>c==S>-c?(h=c+l,f=l-(h-c),c=e[++m]):(h=S+l,f=l-(h-S),S=i[++P]),l=h,f!==0&&(r[T++]=f);m<t&&P<n;)S>c==S>-c?(h=l+c,g=h-l,f=l-(h-g)+(c-g),c=e[++m]):(h=l+S,g=h-l,f=l-(h-g)+(S-g),S=i[++P]),l=h,f!==0&&(r[T++]=f);for(;m<t;)h=l+c,g=h-l,f=l-(h-g)+(c-g),c=e[++m],l=h,f!==0&&(r[T++]=f);for(;P<n;)h=l+S,g=h-l,f=l-(h-g)+(S-g),S=i[++P],l=h,f!==0&&(r[T++]=f);return(l!==0||T===0)&&(r[T++]=l),T}function Qt(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}function ve(t){return new Float64Array(t)}const Jt=(3+16*le)*le,jt=(2+12*le)*le,en=(9+64*le)*le*le,ae=ve(4),st=ve(8),ot=ve(12),lt=ve(16),Z=ve(4);function tn(t,e,n,i,r,l,h){let f,g,c,S,m,P,T,O,M,N,_,b,B,G,q,F,z,s;const o=t-r,u=n-r,w=e-l,a=i-l;G=o*a,P=Y*o,T=P-(P-o),O=o-T,P=Y*a,M=P-(P-a),N=a-M,q=O*N-(G-T*M-O*M-T*N),F=w*u,P=Y*w,T=P-(P-w),O=w-T,P=Y*u,M=P-(P-u),N=u-M,z=O*N-(F-T*M-O*M-T*N),_=q-z,m=q-_,ae[0]=q-(_+m)+(m-z),b=G+_,m=b-G,B=G-(b-m)+(_-m),_=B-F,m=B-_,ae[1]=B-(_+m)+(m-F),s=b+_,m=s-b,ae[2]=b-(s-m)+(_-m),ae[3]=s;let y=Qt(4,ae),v=jt*h;if(y>=v||-y>=v||(m=t-o,f=t-(o+m)+(m-r),m=n-u,c=n-(u+m)+(m-r),m=e-w,g=e-(w+m)+(m-l),m=i-a,S=i-(a+m)+(m-l),f===0&&g===0&&c===0&&S===0)||(v=en*h+Zt*Math.abs(y),y+=o*S+a*f-(w*c+u*g),y>=v||-y>=v))return y;G=f*a,P=Y*f,T=P-(P-f),O=f-T,P=Y*a,M=P-(P-a),N=a-M,q=O*N-(G-T*M-O*M-T*N),F=g*u,P=Y*g,T=P-(P-g),O=g-T,P=Y*u,M=P-(P-u),N=u-M,z=O*N-(F-T*M-O*M-T*N),_=q-z,m=q-_,Z[0]=q-(_+m)+(m-z),b=G+_,m=b-G,B=G-(b-m)+(_-m),_=B-F,m=B-_,Z[1]=B-(_+m)+(m-F),s=b+_,m=s-b,Z[2]=b-(s-m)+(_-m),Z[3]=s;const p=De(4,ae,4,Z,st);G=o*S,P=Y*o,T=P-(P-o),O=o-T,P=Y*S,M=P-(P-S),N=S-M,q=O*N-(G-T*M-O*M-T*N),F=w*c,P=Y*w,T=P-(P-w),O=w-T,P=Y*c,M=P-(P-c),N=c-M,z=O*N-(F-T*M-O*M-T*N),_=q-z,m=q-_,Z[0]=q-(_+m)+(m-z),b=G+_,m=b-G,B=G-(b-m)+(_-m),_=B-F,m=B-_,Z[1]=B-(_+m)+(m-F),s=b+_,m=s-b,Z[2]=b-(s-m)+(_-m),Z[3]=s;const d=De(p,st,4,Z,ot);G=f*S,P=Y*f,T=P-(P-f),O=f-T,P=Y*S,M=P-(P-S),N=S-M,q=O*N-(G-T*M-O*M-T*N),F=g*c,P=Y*g,T=P-(P-g),O=g-T,P=Y*c,M=P-(P-c),N=c-M,z=O*N-(F-T*M-O*M-T*N),_=q-z,m=q-_,Z[0]=q-(_+m)+(m-z),b=G+_,m=b-G,B=G-(b-m)+(_-m),_=B-F,m=B-_,Z[1]=B-(_+m)+(m-F),s=b+_,m=s-b,Z[2]=b-(s-m)+(_-m),Z[3]=s;const E=De(d,ot,4,Z,lt);return lt[E-1]}function nn(t,e,n,i,r,l){const h=(e-l)*(n-r),f=(t-r)*(i-l),g=h-f,c=Math.abs(h+f);return Math.abs(g)>=Jt*c?g:-tn(t,e,n,i,r,l,c)}function rn(t,e){var n,i,r=0,l,h,f,g,c,S,m,P=t[0],T=t[1],O=e.length;for(n=0;n<O;n++){i=0;var M=e[n],N=M.length-1;if(S=M[0],S[0]!==M[N][0]&&S[1]!==M[N][1])throw new Error("First and last coordinates in a ring must be the same");for(h=S[0]-P,f=S[1]-T,i;i<N;i++){if(m=M[i+1],g=m[0]-P,c=m[1]-T,f===0&&c===0){if(g<=0&&h>=0||h<=0&&g>=0)return 0}else if(c>=0&&f<=0||c<=0&&f>=0){if(l=nn(h,g,f,c,0,0),l===0)return 0;(l>0&&c>0&&f<=0||l<0&&c<=0&&f>0)&&r++}S=m,f=c,h=g}}return r%2!==0}function sn(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if(t.type==="Feature"&&t.geometry!==null&&t.geometry.type==="Point")return[...t.geometry.coordinates];if(t.type==="Point")return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Ie(t){return t.type==="Feature"?t.geometry:t}function pe(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const i=sn(t),r=Ie(e),l=r.type,h=e.bbox;let f=r.coordinates;if(h&&on(i,h)===!1)return!1;l==="Polygon"&&(f=[f]);let g=!1;for(var c=0;c<f.length;++c){const S=rn(i,f[c]);if(S===0)return!n.ignoreBoundary;S&&(g=!0)}return g}function on(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}var On=pe;class vt{constructor(e=[],n=ln){if(this.data=e,this.length=this.data.length,this.compare=n,this.length>0)for(let i=(this.length>>1)-1;i>=0;i--)this._down(i)}push(e){this.data.push(e),this.length++,this._up(this.length-1)}pop(){if(this.length===0)return;const e=this.data[0],n=this.data.pop();return this.length--,this.length>0&&(this.data[0]=n,this._down(0)),e}peek(){return this.data[0]}_up(e){const{data:n,compare:i}=this,r=n[e];for(;e>0;){const l=e-1>>1,h=n[l];if(i(r,h)>=0)break;n[e]=h,e=l}n[e]=r}_down(e){const{data:n,compare:i}=this,r=this.length>>1,l=n[e];for(;e<r;){let h=(e<<1)+1,f=n[h];const g=h+1;if(g<this.length&&i(n[g],f)<0&&(h=g,f=n[g]),i(f,l)>=0)break;n[e]=f,e=h}n[e]=l}}function ln(t,e){return t<e?-1:t>e?1:0}function St(t,e){return t.p.x>e.p.x?1:t.p.x<e.p.x?-1:t.p.y!==e.p.y?t.p.y>e.p.y?1:-1:1}function un(t,e){return t.rightSweepEvent.p.x>e.rightSweepEvent.p.x?1:t.rightSweepEvent.p.x<e.rightSweepEvent.p.x?-1:t.rightSweepEvent.p.y!==e.rightSweepEvent.p.y?t.rightSweepEvent.p.y<e.rightSweepEvent.p.y?1:-1:1}class ut{constructor(e,n,i,r){this.p={x:e[0],y:e[1]},this.featureId=n,this.ringId=i,this.eventId=r,this.otherEvent=null,this.isLeftEndpoint=null}isSamePoint(e){return this.p.x===e.p.x&&this.p.y===e.p.y}}function fn(t,e){if(t.type==="FeatureCollection"){const n=t.features;for(let i=0;i<n.length;i++)ft(n[i],e)}else ft(t,e)}let Le=0,Te=0,Me=0;function ft(t,e){const n=t.type==="Feature"?t.geometry:t;let i=n.coordinates;(n.type==="Polygon"||n.type==="MultiLineString")&&(i=[i]),n.type==="LineString"&&(i=[[i]]);for(let r=0;r<i.length;r++)for(let l=0;l<i[r].length;l++){let h=i[r][l][0],f=null;Te=Te+1;for(let g=0;g<i[r][l].length-1;g++){f=i[r][l][g+1];const c=new ut(h,Le,Te,Me),S=new ut(f,Le,Te,Me+1);c.otherEvent=S,S.otherEvent=c,St(c,S)>0?(S.isLeftEndpoint=!0,c.isLeftEndpoint=!1):(c.isLeftEndpoint=!0,S.isLeftEndpoint=!1),e.push(c),e.push(S),h=f,Me=Me+1}}Le=Le+1}class hn{constructor(e){this.leftSweepEvent=e,this.rightSweepEvent=e.otherEvent}}function cn(t,e){if(t===null||e===null||t.leftSweepEvent.ringId===e.leftSweepEvent.ringId&&(t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.leftSweepEvent)||t.rightSweepEvent.isSamePoint(e.rightSweepEvent)||t.leftSweepEvent.isSamePoint(e.leftSweepEvent)||t.leftSweepEvent.isSamePoint(e.rightSweepEvent)))return!1;const n=t.leftSweepEvent.p.x,i=t.leftSweepEvent.p.y,r=t.rightSweepEvent.p.x,l=t.rightSweepEvent.p.y,h=e.leftSweepEvent.p.x,f=e.leftSweepEvent.p.y,g=e.rightSweepEvent.p.x,c=e.rightSweepEvent.p.y,S=(c-f)*(r-n)-(g-h)*(l-i),m=(g-h)*(i-f)-(c-f)*(n-h),P=(r-n)*(i-f)-(l-i)*(n-h);if(S===0)return!1;const T=m/S,O=P/S;if(T>=0&&T<=1&&O>=0&&O<=1){const M=n+T*(r-n),N=i+T*(l-i);return[M,N]}return!1}function an(t,e){e=e||!1;const n=[],i=new vt([],un);for(;t.length;){const r=t.pop();if(r.isLeftEndpoint){const l=new hn(r);for(let h=0;h<i.data.length;h++){const f=i.data[h];if(e&&f.leftSweepEvent.featureId===r.featureId)continue;const g=cn(l,f);g!==!1&&n.push(g)}i.push(l)}else r.isLeftEndpoint===!1&&i.pop()}return n}function pn(t,e){const n=new vt([],St);return fn(t,n),an(n,e)}var gn=pn;function Ze(t,e,n={}){const{removeDuplicates:i=!0,ignoreSelfIntersections:r=!0}=n;let l=[];t.type==="FeatureCollection"?l=l.concat(t.features):t.type==="Feature"?l.push(t):(t.type==="LineString"||t.type==="Polygon"||t.type==="MultiLineString"||t.type==="MultiPolygon")&&l.push(ue(t)),e.type==="FeatureCollection"?l=l.concat(e.features):e.type==="Feature"?l.push(e):(e.type==="LineString"||e.type==="Polygon"||e.type==="MultiLineString"||e.type==="MultiPolygon")&&l.push(ue(e));const h=gn(ze(l),r);let f=[];if(i){const g={};h.forEach(c=>{const S=c.join(",");g[S]||(g[S]=!0,f.push(c))})}else f=h;return ze(f.map(g=>gt(g)))}function He(t,e={}){const n=Ie(t);switch(!e.properties&&t.type==="Feature"&&(e.properties=t.properties),n.type){case"Polygon":return yn(n,e);case"MultiPolygon":return dn(n,e);default:throw new Error("invalid poly")}}function yn(t,e={}){const i=Ie(t).coordinates,r=e.properties?e.properties:t.type==="Feature"?t.properties:{};return Pt(i,r)}function dn(t,e={}){const i=Ie(t).coordinates,r=e.properties?e.properties:t.type==="Feature"?t.properties:{},l=[];return i.forEach(h=>{l.push(Pt(h,r))}),ze(l)}function Pt(t,e){return t.length>1?Lt(t,e):bt(t[0],e)}function wn(t,e,{ignoreSelfIntersections:n=!0}={ignoreSelfIntersections:!0}){let i=!0;return _e(t,r=>{_e(e,l=>{if(i===!1)return!1;i=xn(r.geometry,l.geometry,n)})}),i}function xn(t,e,n){switch(t.type){case"Point":switch(e.type){case"Point":return!Sn(t.coordinates,e.coordinates);case"LineString":return!ht(e,t);case"Polygon":return!pe(t,e)}break;case"LineString":switch(e.type){case"Point":return!ht(t,e);case"LineString":return!mn(t,e,n);case"Polygon":return!ct(e,t,n)}break;case"Polygon":switch(e.type){case"Point":return!pe(e,t);case"LineString":return!ct(t,e,n);case"Polygon":return!En(e,t,n)}}return!1}function ht(t,e){for(let n=0;n<t.coordinates.length-1;n++)if(vn(t.coordinates[n],t.coordinates[n+1],e.coordinates))return!0;return!1}function mn(t,e,n){return Ze(t,e,{ignoreSelfIntersections:n}).features.length>0}function ct(t,e,n){for(const r of e.coordinates)if(pe(r,t))return!0;return Ze(e,He(t),{ignoreSelfIntersections:n}).features.length>0}function En(t,e,n){for(const r of t.coordinates[0])if(pe(r,e))return!0;for(const r of e.coordinates[0])if(pe(r,t))return!0;return Ze(He(t),He(e),{ignoreSelfIntersections:n}).features.length>0}function vn(t,e,n){const i=n[0]-t[0],r=n[1]-t[1],l=e[0]-t[0],h=e[1]-t[1];return i*h-r*l!==0?!1:Math.abs(l)>=Math.abs(h)?l>0?t[0]<=n[0]&&n[0]<=e[0]:e[0]<=n[0]&&n[0]<=t[0]:h>0?t[1]<=n[1]&&n[1]<=e[1]:e[1]<=n[1]&&n[1]<=t[1]}function Sn(t,e){return t[0]===e[0]&&t[1]===e[1]}function Pn(t,e,{ignoreSelfIntersections:n=!0}={}){let i=!1;return _e(t,r=>{_e(e,l=>{if(i===!0)return!0;i=!wn(r.geometry,l.geometry,{ignoreSelfIntersections:n})})}),i}var Nn=Pn;function bn(t,e={}){let n=0,i=0,r=0;return yt(t,function(l){n+=l[0],i+=l[1],r++}),gt([n/r,i/r],e.properties)}var Cn=bn;function Ln(t){return Tt(t,(e,n)=>e+Tn(n),0)}function Tn(t){let e=0,n;switch(t.type){case"Polygon":return at(t.coordinates);case"MultiPolygon":for(n=0;n<t.coordinates.length;n++)e+=at(t.coordinates[n]);return e;case"Point":case"MultiPoint":case"LineString":case"MultiLineString":return 0}return 0}function at(t){let e=0;if(t&&t.length>0){e+=Math.abs(pt(t[0]));for(let n=1;n<t.length;n++)e-=Math.abs(pt(t[n]))}return e}var Mn=Qe*Qe/2,Ue=Math.PI/180;function pt(t){const e=t.length-1;if(e<=2)return 0;let n=0,i=0;for(;i<e;){const r=t[i],l=t[i+1===e?0:i+1],h=t[i+2>=e?(i+2)%e:i+2],f=r[0]*Ue,g=l[1]*Ue,c=h[0]*Ue;n+=(c-f)*Math.sin(g),i++}return n*Mn}var In=Ln;export{_n as a,Rn as b,Cn as c,On as d,Nn as e,ze as f,In as g,An as i};
|
||
//# sourceMappingURL=turf-B-0GbNlN.js.map
|