@maplat/transform 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";var it=Object.defineProperty;var ot=(r,t,e)=>t in r?it(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var A=(r,t,e)=>ot(r,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=11102230246251565e-32,k=134217729,at=(3+8*B)*B;function $(r,t,e,o,f){let s,c,g,l,y=t[0],w=o[0],i=0,u=0;w>y==w>-y?(s=y,y=t[++i]):(s=w,w=o[++u]);let d=0;if(i<r&&u<e)for(w>y==w>-y?(c=y+s,g=s-(c-y),y=t[++i]):(c=w+s,g=s-(c-w),w=o[++u]),s=c,g!==0&&(f[d++]=g);i<r&&u<e;)w>y==w>-y?(c=s+y,l=c-s,g=s-(c-l)+(y-l),y=t[++i]):(c=s+w,l=c-s,g=s-(c-l)+(w-l),w=o[++u]),s=c,g!==0&&(f[d++]=g);for(;i<r;)c=s+y,l=c-s,g=s-(c-l)+(y-l),y=t[++i],s=c,g!==0&&(f[d++]=g);for(;u<e;)c=s+w,l=c-s,g=s-(c-l)+(w-l),w=o[++u],s=c,g!==0&&(f[d++]=g);return(s!==0||d===0)&&(f[d++]=s),d}function ft(r,t){let e=t[0];for(let o=1;o<r;o++)e+=t[o];return e}function D(r){return new Float64Array(r)}const ct=(3+16*B)*B,ut=(2+12*B)*B,ht=(9+64*B)*B*B,X=D(4),j=D(8),J=D(12),z=D(16),S=D(4);function lt(r,t,e,o,f,s,c){let g,l,y,w,i,u,d,v,h,a,n,b,M,x,E,_,m,T;const I=r-f,P=e-f,N=t-s,C=o-s;x=I*C,u=k*I,d=u-(u-I),v=I-d,u=k*C,h=u-(u-C),a=C-h,E=v*a-(x-d*h-v*h-d*a),_=N*P,u=k*N,d=u-(u-N),v=N-d,u=k*P,h=u-(u-P),a=P-h,m=v*a-(_-d*h-v*h-d*a),n=E-m,i=E-n,X[0]=E-(n+i)+(i-m),b=x+n,i=b-x,M=x-(b-i)+(n-i),n=M-_,i=M-n,X[1]=M-(n+i)+(i-_),T=b+n,i=T-b,X[2]=b-(T-i)+(n-i),X[3]=T;let U=ft(4,X),Y=ut*c;if(U>=Y||-U>=Y||(i=r-I,g=r-(I+i)+(i-f),i=e-P,y=e-(P+i)+(i-f),i=t-N,l=t-(N+i)+(i-s),i=o-C,w=o-(C+i)+(i-s),g===0&&l===0&&y===0&&w===0)||(Y=ht*c+at*Math.abs(U),U+=I*w+C*g-(N*y+P*l),U>=Y||-U>=Y))return U;x=g*C,u=k*g,d=u-(u-g),v=g-d,u=k*C,h=u-(u-C),a=C-h,E=v*a-(x-d*h-v*h-d*a),_=l*P,u=k*l,d=u-(u-l),v=l-d,u=k*P,h=u-(u-P),a=P-h,m=v*a-(_-d*h-v*h-d*a),n=E-m,i=E-n,S[0]=E-(n+i)+(i-m),b=x+n,i=b-x,M=x-(b-i)+(n-i),n=M-_,i=M-n,S[1]=M-(n+i)+(i-_),T=b+n,i=T-b,S[2]=b-(T-i)+(n-i),S[3]=T;const et=$(4,X,4,S,j);x=I*w,u=k*I,d=u-(u-I),v=I-d,u=k*w,h=u-(u-w),a=w-h,E=v*a-(x-d*h-v*h-d*a),_=N*y,u=k*N,d=u-(u-N),v=N-d,u=k*y,h=u-(u-y),a=y-h,m=v*a-(_-d*h-v*h-d*a),n=E-m,i=E-n,S[0]=E-(n+i)+(i-m),b=x+n,i=b-x,M=x-(b-i)+(n-i),n=M-_,i=M-n,S[1]=M-(n+i)+(i-_),T=b+n,i=T-b,S[2]=b-(T-i)+(n-i),S[3]=T;const st=$(et,j,4,S,J);x=g*w,u=k*g,d=u-(u-g),v=g-d,u=k*w,h=u-(u-w),a=w-h,E=v*a-(x-d*h-v*h-d*a),_=l*y,u=k*l,d=u-(u-l),v=l-d,u=k*y,h=u-(u-y),a=y-h,m=v*a-(_-d*h-v*h-d*a),n=E-m,i=E-n,S[0]=E-(n+i)+(i-m),b=x+n,i=b-x,M=x-(b-i)+(n-i),n=M-_,i=M-n,S[1]=M-(n+i)+(i-_),T=b+n,i=T-b,S[2]=b-(T-i)+(n-i),S[3]=T;const nt=$(st,J,4,S,z);return z[nt-1]}function gt(r,t,e,o,f,s){const c=(t-s)*(e-f),g=(r-f)*(o-s),l=c-g,y=Math.abs(c+g);return Math.abs(l)>=ct*y?l:-lt(r,t,e,o,f,s,y)}function yt(r,t){var e,o,f=0,s,c,g,l,y,w,i,u=r[0],d=r[1],v=t.length;for(e=0;e<v;e++){o=0;var h=t[e],a=h.length-1;if(w=h[0],w[0]!==h[a][0]&&w[1]!==h[a][1])throw new Error("First and last coordinates in a ring must be the same");for(c=w[0]-u,g=w[1]-d,o;o<a;o++){if(i=h[o+1],l=i[0]-u,y=i[1]-d,g===0&&y===0){if(l<=0&&c>=0||c<=0&&l>=0)return 0}else if(y>=0&&g<=0||y<=0&&g>=0){if(s=gt(c,l,g,y,0,0),s===0)return 0;(s>0&&y>0&&g<=0||s<0&&y<=0&&g>0)&&f++}w=i,g=y,c=l}}return f%2!==0}function p(r,t,e={}){const o={type:"Feature"};return(e.id===0||e.id)&&(o.id=e.id),e.bbox&&(o.bbox=e.bbox),o.properties=t||{},o.geometry=r,o}function W(r,t,e={}){if(!r)throw new Error("coordinates is required");if(!Array.isArray(r))throw new Error("coordinates must be an Array");if(r.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!K(r[0])||!K(r[1]))throw new Error("coordinates must contain numbers");return p({type:"Point",coordinates:r},t,e)}function wt(r,t,e={}){for(const f of r){if(f.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(f[f.length-1].length!==f[0].length)throw new Error("First and last Position are not equivalent.");for(let s=0;s<f[f.length-1].length;s++)if(f[f.length-1][s]!==f[0][s])throw new Error("First and last Position are not equivalent.")}return p({type:"Polygon",coordinates:r},t,e)}function F(r,t={}){const e={type:"FeatureCollection"};return t.id&&(e.id=t.id),t.bbox&&(e.bbox=t.bbox),e.features=r,e}function K(r){return!isNaN(r)&&r!==null&&!Array.isArray(r)}function dt(r){if(!r)throw new Error("coord is required");if(!Array.isArray(r)){if(r.type==="Feature"&&r.geometry!==null&&r.geometry.type==="Point")return[...r.geometry.coordinates];if(r.type==="Point")return[...r.coordinates]}if(Array.isArray(r)&&r.length>=2&&!Array.isArray(r[0])&&!Array.isArray(r[1]))return[...r];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Q(r){if(Array.isArray(r))return r;if(r.type==="Feature"){if(r.geometry!==null)return r.geometry.coordinates}else if(r.coordinates)return r.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function bt(r){return r.type==="Feature"?r.geometry:r}function _t(r,t,e={}){if(!r)throw new Error("point is required");if(!t)throw new Error("polygon is required");const o=dt(r),f=bt(t),s=f.type,c=t.bbox;let g=f.coordinates;if(c&&vt(o,c)===!1)return!1;s==="Polygon"&&(g=[g]);let l=!1;for(var y=0;y<g.length;++y){const w=yt(o,g[y]);if(w===0)return!e.ignoreBoundary;w&&(l=!0)}return l}function vt(r,t){return t[0]<=r[0]&&t[1]<=r[1]&&t[2]>=r[0]&&t[3]>=r[1]}var q=_t;function At(r){const t=[0,1,2,0].map(o=>r[o][0][0]),e={a:{geom:r[0][0][1],index:r[0][1]},b:{geom:r[1][0][1],index:r[1][1]},c:{geom:r[2][0][1],index:r[2][1]}};return wt([t],e)}function V(r,t,e,o,f,s=!1,c){const g=r.map(l=>{(!c||c<2.00703)&&(l=tt(l));const y=isFinite(l)?t[l]:l==="c"?o:l==="b0"?f[0]:l==="b1"?f[1]:l==="b2"?f[2]:l==="b3"?f[3]:function(){const w=l.match(/e(\d+)/);if(w){const i=parseInt(w[1]);return e[i]}throw"Bad index value for indexesToTri"}();return s?[[y[1],y[0]],l]:[[y[0],y[1]],l]});return At(g)}function tt(r){return typeof r=="number"?r:r.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function Mt(r,t){return Array.isArray(r[0])?r:r.map(e=>[e.illstNodes,e.mercNodes,e.startEnd])}function H(r,t){for(let e=0;e<t.features.length;e++)if(q(r,t.features[e]))return t.features[e]}function rt(r,t,e){const o=t.geometry.coordinates[0][0],f=t.geometry.coordinates[0][1],s=t.geometry.coordinates[0][2],c=r.geometry.coordinates,g=t.properties.a.geom,l=t.properties.b.geom,y=t.properties.c.geom,w=[f[0]-o[0],f[1]-o[1]],i=[s[0]-o[0],s[1]-o[1]],u=[c[0]-o[0],c[1]-o[1]],d=[l[0]-g[0],l[1]-g[1]],v=[y[0]-g[0],y[1]-g[1]];let h=(i[1]*u[0]-i[0]*u[1])/(w[0]*i[1]-w[1]*i[0]),a=(w[0]*u[1]-w[1]*u[0])/(w[0]*i[1]-w[1]*i[0]);if(e){const n=e[t.properties.a.index],b=e[t.properties.b.index],M=e[t.properties.c.index];let x;if(h<0||a<0||1-h-a<0){const E=h/(h+a),_=a/(h+a);x=h/b/(E/b+_/M),a=a/M/(E/b+_/M)}else x=h/b/(h/b+a/M+(1-h-a)/n),a=a/M/(h/b+a/M+(1-h-a)/n);h=x}return[h*d[0]+a*v[0]+g[0],h*d[1]+a*v[1]+g[1]]}function xt(r,t,e,o){const f=r.geometry.coordinates,s=e.geometry.coordinates,c=Math.atan2(f[0]-s[0],f[1]-s[1]),g=Et(c,t[0]),l=t[1][g];return rt(r,l.features[0],o)}function mt(r,t,e,o,f,s,c,g){let l;if(c&&(l=H(r,F([c]))),!l){if(e){const y=r.geometry.coordinates,w=e.gridNum,i=e.xOrigin,u=e.yOrigin,d=e.xUnit,v=e.yUnit,h=e.gridCache,a=R(y[0],i,d,w),n=R(y[1],u,v,w),b=h[a]?h[a][n]?h[a][n]:[]:[];t=F(b.map(M=>t.features[M]))}l=H(r,t)}return g&&g(l),l?rt(r,l,s):xt(r,o,f,s)}function R(r,t,e,o){let f=Math.floor((r-t)/e);return f>=o&&(f=o-1),f}function Et(r,t){let e=Z(r-t[0]),o=Math.PI*2,f;for(let s=0;s<t.length;s++){const c=(s+1)%t.length,g=Z(r-t[c]),l=Math.min(Math.abs(e),Math.abs(g));e*g<=0&&l<o&&(o=l,f=s),e=g}return f}function Z(r,t=!1){const e=t?function(o){return!(o>=0&&o<Math.PI*2)}:function(o){return!(o>-1*Math.PI&&o<=Math.PI)};for(;e(r);)r=r+2*Math.PI*(r>0?-1:1);return r}const L=2.00703,O=class O{constructor(){A(this,"points",[]);A(this,"pointsWeightBuffer");A(this,"strict_status");A(this,"vertices_params");A(this,"centroid");A(this,"edgeNodes");A(this,"edges");A(this,"tins");A(this,"kinks");A(this,"yaxisMode",O.YAXIS_INVERT);A(this,"strictMode",O.MODE_AUTO);A(this,"vertexMode",O.VERTEX_PLAIN);A(this,"bounds");A(this,"boundsPolygon");A(this,"wh");A(this,"xy");A(this,"indexedTins");A(this,"stateFull",!1);A(this,"stateTriangle");A(this,"stateBackward")}setCompiled(t){if(t.version||!t.tins&&t.points&&t.tins_points){this.points=t.points,this.pointsWeightBuffer=!t.version||t.version<2.00703?["forw","bakw"].reduce((o,f)=>{const s=t.weight_buffer[f];return s&&(o[f]=Object.keys(s).reduce((c,g)=>{const l=tt(g);return c[l]=s[g],c},{})),o},{}):t.weight_buffer,t.strict_status?this.strict_status=t.strict_status:t.kinks_points?this.strict_status=O.STATUS_ERROR:t.tins_points.length==2?this.strict_status=O.STATUS_LOOSE:this.strict_status=O.STATUS_STRICT,this.vertices_params={forw:[t.vertices_params[0]],bakw:[t.vertices_params[1]]},this.vertices_params.forw[1]=[0,1,2,3].map(o=>{const f=(o+1)%4,s=V(["c",`b${o}`,`b${f}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,L);return F([s])}),this.vertices_params.bakw[1]=[0,1,2,3].map(o=>{const f=(o+1)%4,s=V(["c",`b${o}`,`b${f}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,L);return F([s])}),this.centroid={forw:W(t.centroid_point[0],{target:{geom:t.centroid_point[1],index:"c"}}),bakw:W(t.centroid_point[1],{target:{geom:t.centroid_point[0],index:"c"}})},this.edges=Mt(t.edges||[]),this.edgeNodes=t.edgeNodes||[];const e=t.tins_points.length==1?0:1;this.tins={forw:F(t.tins_points[0].map(o=>V(o,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:F(t.tins_points[e].map(o=>V(o,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,t.version)))},this.addIndexedTin(),t.kinks_points&&(this.kinks={bakw:F(t.kinks_points.map(o=>W(o)))}),t.yaxisMode?this.yaxisMode=t.yaxisMode:this.yaxisMode=O.YAXIS_INVERT,t.vertexMode&&(this.vertexMode=t.vertexMode),t.strictMode&&(this.strictMode=t.strictMode),t.bounds?(this.bounds=t.bounds,this.boundsPolygon=t.boundsPolygon,this.xy=t.xy,this.wh=t.wh):(this.xy=[0,0],t.wh&&(this.wh=t.wh),this.bounds=void 0,this.boundsPolygon=void 0)}else{t=JSON.parse(JSON.stringify(t).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"')),this.tins=t.tins,this.addIndexedTin(),this.strict_status=t.strict_status,this.pointsWeightBuffer=t.weight_buffer,this.vertices_params=t.vertices_params,this.centroid=t.centroid,this.kinks=t.kinks;const e=[];for(let o=0;o<this.tins.forw.features.length;o++){const f=this.tins.forw.features[o];["a","b","c"].map((s,c)=>{const g=f.geometry.coordinates[0][c],l=f.properties[s].geom,y=f.properties[s].index;e[y]=[g,l]})}this.points=e}return{tins:this.tins,strict_status:this.strict_status,weight_buffer:this.pointsWeightBuffer,vertices_params:this.vertices_params,centroid:this.centroid,kinks:this.kinks}}addIndexedTin(){const t=this.tins,e=t.forw,o=t.bakw,f=Math.ceil(Math.sqrt(e.features.length));if(f<3){this.indexedTins=void 0;return}let s=[],c=[];const g=e.features.map(h=>{let a=[];return Q(h)[0].map(n=>{s.length===0?s=[Array.from(n),Array.from(n)]:(n[0]<s[0][0]&&(s[0][0]=n[0]),n[0]>s[1][0]&&(s[1][0]=n[0]),n[1]<s[0][1]&&(s[0][1]=n[1]),n[1]>s[1][1]&&(s[1][1]=n[1])),a.length===0?a=[Array.from(n),Array.from(n)]:(n[0]<a[0][0]&&(a[0][0]=n[0]),n[0]>a[1][0]&&(a[1][0]=n[0]),n[1]<a[0][1]&&(a[0][1]=n[1]),n[1]>a[1][1]&&(a[1][1]=n[1]))}),a}),l=(s[1][0]-s[0][0])/f,y=(s[1][1]-s[0][1])/f,w=g.reduce((h,a,n)=>{const b=R(a[0][0],s[0][0],l,f),M=R(a[1][0],s[0][0],l,f),x=R(a[0][1],s[0][1],y,f),E=R(a[1][1],s[0][1],y,f);for(let _=b;_<=M;_++){h[_]||(h[_]=[]);for(let m=x;m<=E;m++)h[_][m]||(h[_][m]=[]),h[_][m].push(n)}return h},[]),i=o.features.map(h=>{let a=[];return Q(h)[0].map(n=>{c.length===0?c=[Array.from(n),Array.from(n)]:(n[0]<c[0][0]&&(c[0][0]=n[0]),n[0]>c[1][0]&&(c[1][0]=n[0]),n[1]<c[0][1]&&(c[0][1]=n[1]),n[1]>c[1][1]&&(c[1][1]=n[1])),a.length===0?a=[Array.from(n),Array.from(n)]:(n[0]<a[0][0]&&(a[0][0]=n[0]),n[0]>a[1][0]&&(a[1][0]=n[0]),n[1]<a[0][1]&&(a[0][1]=n[1]),n[1]>a[1][1]&&(a[1][1]=n[1]))}),a}),u=(c[1][0]-c[0][0])/f,d=(c[1][1]-c[0][1])/f,v=i.reduce((h,a,n)=>{const b=R(a[0][0],c[0][0],u,f),M=R(a[1][0],c[0][0],u,f),x=R(a[0][1],c[0][1],d,f),E=R(a[1][1],c[0][1],d,f);for(let _=b;_<=M;_++){h[_]||(h[_]=[]);for(let m=x;m<=E;m++)h[_][m]||(h[_][m]=[]),h[_][m].push(n)}return h},[]);this.indexedTins={forw:{gridNum:f,xOrigin:s[0][0],yOrigin:s[0][1],xUnit:l,yUnit:y,gridCache:w},bakw:{gridNum:f,xOrigin:c[0][0],yOrigin:c[0][1],xUnit:u,yUnit:d,gridCache:v}}}transform(t,e,o){if(e&&this.strict_status==O.STATUS_ERROR)throw'Backward transform is not allowed if strict_status == "strict_error"';this.yaxisMode==O.YAXIS_FOLLOW&&e&&(t=[t[0],-1*t[1]]);const f=W(t);if(this.bounds&&!e&&!o&&!q(f,this.boundsPolygon))return!1;const s=e?this.tins.bakw:this.tins.forw,c=e?this.indexedTins.bakw:this.indexedTins.forw,g=e?this.vertices_params.bakw:this.vertices_params.forw,l=e?this.centroid.bakw:this.centroid.forw,y=e?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let w,i;this.stateFull&&(this.stateBackward==e?w=this.stateTriangle:(this.stateBackward=e,this.stateTriangle=void 0),i=d=>{this.stateTriangle=d});let u=mt(f,s,c,g,l,y,w,i);if(this.bounds&&e&&!o){const d=W(u);if(!q(d,this.boundsPolygon))return!1}else this.yaxisMode==O.YAXIS_FOLLOW&&!e&&(u=[u[0],-1*u[1]]);return u}};A(O,"VERTEX_PLAIN","plain"),A(O,"VERTEX_BIRDEYE","birdeye"),A(O,"MODE_STRICT","strict"),A(O,"MODE_AUTO","auto"),A(O,"MODE_LOOSE","loose"),A(O,"STATUS_STRICT","strict"),A(O,"STATUS_ERROR","strict_error"),A(O,"STATUS_LOOSE","loose"),A(O,"YAXIS_FOLLOW","follow"),A(O,"YAXIS_INVERT","invert");let G=O;exports.Transform=G;exports.format_version=L;
@@ -0,0 +1,545 @@
1
+ var it = Object.defineProperty;
2
+ var ot = (r, t, e) => t in r ? it(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var A = (r, t, e) => ot(r, typeof t != "symbol" ? t + "" : t, e);
4
+ const B = 11102230246251565e-32, T = 134217729, at = (3 + 8 * B) * B;
5
+ function $(r, t, e, o, f) {
6
+ let s, c, g, l, y = t[0], w = o[0], i = 0, u = 0;
7
+ w > y == w > -y ? (s = y, y = t[++i]) : (s = w, w = o[++u]);
8
+ let d = 0;
9
+ if (i < r && u < e)
10
+ for (w > y == w > -y ? (c = y + s, g = s - (c - y), y = t[++i]) : (c = w + s, g = s - (c - w), w = o[++u]), s = c, g !== 0 && (f[d++] = g); i < r && u < e; )
11
+ w > y == w > -y ? (c = s + y, l = c - s, g = s - (c - l) + (y - l), y = t[++i]) : (c = s + w, l = c - s, g = s - (c - l) + (w - l), w = o[++u]), s = c, g !== 0 && (f[d++] = g);
12
+ for (; i < r; )
13
+ c = s + y, l = c - s, g = s - (c - l) + (y - l), y = t[++i], s = c, g !== 0 && (f[d++] = g);
14
+ for (; u < e; )
15
+ c = s + w, l = c - s, g = s - (c - l) + (w - l), w = o[++u], s = c, g !== 0 && (f[d++] = g);
16
+ return (s !== 0 || d === 0) && (f[d++] = s), d;
17
+ }
18
+ function ft(r, t) {
19
+ let e = t[0];
20
+ for (let o = 1; o < r; o++) e += t[o];
21
+ return e;
22
+ }
23
+ function D(r) {
24
+ return new Float64Array(r);
25
+ }
26
+ const ct = (3 + 16 * B) * B, ut = (2 + 12 * B) * B, ht = (9 + 64 * B) * B * B, X = D(4), L = D(8), G = D(12), j = D(16), I = D(4);
27
+ function lt(r, t, e, o, f, s, c) {
28
+ let g, l, y, w, i, u, d, v, h, a, n, b, x, M, m, _, E, k;
29
+ const S = r - f, P = e - f, N = t - s, C = o - s;
30
+ M = S * C, u = T * S, d = u - (u - S), v = S - d, u = T * C, h = u - (u - C), a = C - h, m = v * a - (M - d * h - v * h - d * a), _ = N * P, u = T * N, d = u - (u - N), v = N - d, u = T * P, h = u - (u - P), a = P - h, E = v * a - (_ - d * h - v * h - d * a), n = m - E, i = m - n, X[0] = m - (n + i) + (i - E), b = M + n, i = b - M, x = M - (b - i) + (n - i), n = x - _, i = x - n, X[1] = x - (n + i) + (i - _), k = b + n, i = k - b, X[2] = b - (k - i) + (n - i), X[3] = k;
31
+ let U = ft(4, X), Y = ut * c;
32
+ if (U >= Y || -U >= Y || (i = r - S, g = r - (S + i) + (i - f), i = e - P, y = e - (P + i) + (i - f), i = t - N, l = t - (N + i) + (i - s), i = o - C, w = o - (C + i) + (i - s), g === 0 && l === 0 && y === 0 && w === 0) || (Y = ht * c + at * Math.abs(U), U += S * w + C * g - (N * y + P * l), U >= Y || -U >= Y)) return U;
33
+ M = g * C, u = T * g, d = u - (u - g), v = g - d, u = T * C, h = u - (u - C), a = C - h, m = v * a - (M - d * h - v * h - d * a), _ = l * P, u = T * l, d = u - (u - l), v = l - d, u = T * P, h = u - (u - P), a = P - h, E = v * a - (_ - d * h - v * h - d * a), n = m - E, i = m - n, I[0] = m - (n + i) + (i - E), b = M + n, i = b - M, x = M - (b - i) + (n - i), n = x - _, i = x - n, I[1] = x - (n + i) + (i - _), k = b + n, i = k - b, I[2] = b - (k - i) + (n - i), I[3] = k;
34
+ const et = $(4, X, 4, I, L);
35
+ M = S * w, u = T * S, d = u - (u - S), v = S - d, u = T * w, h = u - (u - w), a = w - h, m = v * a - (M - d * h - v * h - d * a), _ = N * y, u = T * N, d = u - (u - N), v = N - d, u = T * y, h = u - (u - y), a = y - h, E = v * a - (_ - d * h - v * h - d * a), n = m - E, i = m - n, I[0] = m - (n + i) + (i - E), b = M + n, i = b - M, x = M - (b - i) + (n - i), n = x - _, i = x - n, I[1] = x - (n + i) + (i - _), k = b + n, i = k - b, I[2] = b - (k - i) + (n - i), I[3] = k;
36
+ const st = $(et, L, 4, I, G);
37
+ M = g * w, u = T * g, d = u - (u - g), v = g - d, u = T * w, h = u - (u - w), a = w - h, m = v * a - (M - d * h - v * h - d * a), _ = l * y, u = T * l, d = u - (u - l), v = l - d, u = T * y, h = u - (u - y), a = y - h, E = v * a - (_ - d * h - v * h - d * a), n = m - E, i = m - n, I[0] = m - (n + i) + (i - E), b = M + n, i = b - M, x = M - (b - i) + (n - i), n = x - _, i = x - n, I[1] = x - (n + i) + (i - _), k = b + n, i = k - b, I[2] = b - (k - i) + (n - i), I[3] = k;
38
+ const nt = $(st, G, 4, I, j);
39
+ return j[nt - 1];
40
+ }
41
+ function gt(r, t, e, o, f, s) {
42
+ const c = (t - s) * (e - f), g = (r - f) * (o - s), l = c - g, y = Math.abs(c + g);
43
+ return Math.abs(l) >= ct * y ? l : -lt(r, t, e, o, f, s, y);
44
+ }
45
+ function yt(r, t) {
46
+ var e, o, f = 0, s, c, g, l, y, w, i, u = r[0], d = r[1], v = t.length;
47
+ for (e = 0; e < v; e++) {
48
+ o = 0;
49
+ var h = t[e], a = h.length - 1;
50
+ if (w = h[0], w[0] !== h[a][0] && w[1] !== h[a][1])
51
+ throw new Error("First and last coordinates in a ring must be the same");
52
+ for (c = w[0] - u, g = w[1] - d, o; o < a; o++) {
53
+ if (i = h[o + 1], l = i[0] - u, y = i[1] - d, g === 0 && y === 0) {
54
+ if (l <= 0 && c >= 0 || c <= 0 && l >= 0)
55
+ return 0;
56
+ } else if (y >= 0 && g <= 0 || y <= 0 && g >= 0) {
57
+ if (s = gt(c, l, g, y, 0, 0), s === 0)
58
+ return 0;
59
+ (s > 0 && y > 0 && g <= 0 || s < 0 && y <= 0 && g > 0) && f++;
60
+ }
61
+ w = i, g = y, c = l;
62
+ }
63
+ }
64
+ return f % 2 !== 0;
65
+ }
66
+ function p(r, t, e = {}) {
67
+ const o = { type: "Feature" };
68
+ return (e.id === 0 || e.id) && (o.id = e.id), e.bbox && (o.bbox = e.bbox), o.properties = t || {}, o.geometry = r, o;
69
+ }
70
+ function W(r, t, e = {}) {
71
+ if (!r)
72
+ throw new Error("coordinates is required");
73
+ if (!Array.isArray(r))
74
+ throw new Error("coordinates must be an Array");
75
+ if (r.length < 2)
76
+ throw new Error("coordinates must be at least 2 numbers long");
77
+ if (!J(r[0]) || !J(r[1]))
78
+ throw new Error("coordinates must contain numbers");
79
+ return p({
80
+ type: "Point",
81
+ coordinates: r
82
+ }, t, e);
83
+ }
84
+ function wt(r, t, e = {}) {
85
+ for (const f of r) {
86
+ if (f.length < 4)
87
+ throw new Error(
88
+ "Each LinearRing of a Polygon must have 4 or more Positions."
89
+ );
90
+ if (f[f.length - 1].length !== f[0].length)
91
+ throw new Error("First and last Position are not equivalent.");
92
+ for (let s = 0; s < f[f.length - 1].length; s++)
93
+ if (f[f.length - 1][s] !== f[0][s])
94
+ throw new Error("First and last Position are not equivalent.");
95
+ }
96
+ return p({
97
+ type: "Polygon",
98
+ coordinates: r
99
+ }, t, e);
100
+ }
101
+ function F(r, t = {}) {
102
+ const e = { type: "FeatureCollection" };
103
+ return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = r, e;
104
+ }
105
+ function J(r) {
106
+ return !isNaN(r) && r !== null && !Array.isArray(r);
107
+ }
108
+ function dt(r) {
109
+ if (!r)
110
+ throw new Error("coord is required");
111
+ if (!Array.isArray(r)) {
112
+ if (r.type === "Feature" && r.geometry !== null && r.geometry.type === "Point")
113
+ return [...r.geometry.coordinates];
114
+ if (r.type === "Point")
115
+ return [...r.coordinates];
116
+ }
117
+ if (Array.isArray(r) && r.length >= 2 && !Array.isArray(r[0]) && !Array.isArray(r[1]))
118
+ return [...r];
119
+ throw new Error("coord must be GeoJSON Point or an Array of numbers");
120
+ }
121
+ function z(r) {
122
+ if (Array.isArray(r))
123
+ return r;
124
+ if (r.type === "Feature") {
125
+ if (r.geometry !== null)
126
+ return r.geometry.coordinates;
127
+ } else if (r.coordinates)
128
+ return r.coordinates;
129
+ throw new Error(
130
+ "coords must be GeoJSON Feature, Geometry Object or an Array"
131
+ );
132
+ }
133
+ function bt(r) {
134
+ return r.type === "Feature" ? r.geometry : r;
135
+ }
136
+ function _t(r, t, e = {}) {
137
+ if (!r)
138
+ throw new Error("point is required");
139
+ if (!t)
140
+ throw new Error("polygon is required");
141
+ const o = dt(r), f = bt(t), s = f.type, c = t.bbox;
142
+ let g = f.coordinates;
143
+ if (c && vt(o, c) === !1)
144
+ return !1;
145
+ s === "Polygon" && (g = [g]);
146
+ let l = !1;
147
+ for (var y = 0; y < g.length; ++y) {
148
+ const w = yt(o, g[y]);
149
+ if (w === 0) return !e.ignoreBoundary;
150
+ w && (l = !0);
151
+ }
152
+ return l;
153
+ }
154
+ function vt(r, t) {
155
+ return t[0] <= r[0] && t[1] <= r[1] && t[2] >= r[0] && t[3] >= r[1];
156
+ }
157
+ var q = _t;
158
+ function At(r) {
159
+ const t = [0, 1, 2, 0].map((o) => r[o][0][0]), e = {
160
+ a: { geom: r[0][0][1], index: r[0][1] },
161
+ b: { geom: r[1][0][1], index: r[1][1] },
162
+ c: { geom: r[2][0][1], index: r[2][1] }
163
+ };
164
+ return wt([t], e);
165
+ }
166
+ function V(r, t, e, o, f, s = !1, c) {
167
+ const g = r.map(
168
+ (l) => {
169
+ (!c || c < 2.00703) && (l = tt(l));
170
+ const y = isFinite(l) ? t[l] : l === "c" ? o : l === "b0" ? f[0] : l === "b1" ? f[1] : l === "b2" ? f[2] : l === "b3" ? f[3] : function() {
171
+ const w = l.match(/e(\d+)/);
172
+ if (w) {
173
+ const i = parseInt(w[1]);
174
+ return e[i];
175
+ }
176
+ throw "Bad index value for indexesToTri";
177
+ }();
178
+ return s ? [[y[1], y[0]], l] : [[y[0], y[1]], l];
179
+ }
180
+ );
181
+ return At(g);
182
+ }
183
+ function tt(r) {
184
+ return typeof r == "number" ? r : r.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2");
185
+ }
186
+ function xt(r, t) {
187
+ return Array.isArray(r[0]) ? r : r.map((e) => [
188
+ e.illstNodes,
189
+ e.mercNodes,
190
+ e.startEnd
191
+ ]);
192
+ }
193
+ function K(r, t) {
194
+ for (let e = 0; e < t.features.length; e++)
195
+ if (q(r, t.features[e]))
196
+ return t.features[e];
197
+ }
198
+ function rt(r, t, e) {
199
+ const o = t.geometry.coordinates[0][0], f = t.geometry.coordinates[0][1], s = t.geometry.coordinates[0][2], c = r.geometry.coordinates, g = t.properties.a.geom, l = t.properties.b.geom, y = t.properties.c.geom, w = [f[0] - o[0], f[1] - o[1]], i = [s[0] - o[0], s[1] - o[1]], u = [c[0] - o[0], c[1] - o[1]], d = [l[0] - g[0], l[1] - g[1]], v = [y[0] - g[0], y[1] - g[1]];
200
+ let h = (i[1] * u[0] - i[0] * u[1]) / (w[0] * i[1] - w[1] * i[0]), a = (w[0] * u[1] - w[1] * u[0]) / (w[0] * i[1] - w[1] * i[0]);
201
+ if (e) {
202
+ const n = e[t.properties.a.index], b = e[t.properties.b.index], x = e[t.properties.c.index];
203
+ let M;
204
+ if (h < 0 || a < 0 || 1 - h - a < 0) {
205
+ const m = h / (h + a), _ = a / (h + a);
206
+ M = h / b / (m / b + _ / x), a = a / x / (m / b + _ / x);
207
+ } else
208
+ M = h / b / (h / b + a / x + (1 - h - a) / n), a = a / x / (h / b + a / x + (1 - h - a) / n);
209
+ h = M;
210
+ }
211
+ return [
212
+ h * d[0] + a * v[0] + g[0],
213
+ h * d[1] + a * v[1] + g[1]
214
+ ];
215
+ }
216
+ function Mt(r, t, e, o) {
217
+ const f = r.geometry.coordinates, s = e.geometry.coordinates, c = Math.atan2(f[0] - s[0], f[1] - s[1]), g = mt(c, t[0]), l = t[1][g];
218
+ return rt(r, l.features[0], o);
219
+ }
220
+ function Et(r, t, e, o, f, s, c, g) {
221
+ let l;
222
+ if (c && (l = K(r, F([c]))), !l) {
223
+ if (e) {
224
+ const y = r.geometry.coordinates, w = e.gridNum, i = e.xOrigin, u = e.yOrigin, d = e.xUnit, v = e.yUnit, h = e.gridCache, a = R(y[0], i, d, w), n = R(y[1], u, v, w), b = h[a] ? h[a][n] ? h[a][n] : [] : [];
225
+ t = F(b.map((x) => t.features[x]));
226
+ }
227
+ l = K(r, t);
228
+ }
229
+ return g && g(l), l ? rt(r, l, s) : Mt(r, o, f, s);
230
+ }
231
+ function R(r, t, e, o) {
232
+ let f = Math.floor((r - t) / e);
233
+ return f >= o && (f = o - 1), f;
234
+ }
235
+ function mt(r, t) {
236
+ let e = Q(r - t[0]), o = Math.PI * 2, f;
237
+ for (let s = 0; s < t.length; s++) {
238
+ const c = (s + 1) % t.length, g = Q(r - t[c]), l = Math.min(Math.abs(e), Math.abs(g));
239
+ e * g <= 0 && l < o && (o = l, f = s), e = g;
240
+ }
241
+ return f;
242
+ }
243
+ function Q(r, t = !1) {
244
+ const e = t ? function(o) {
245
+ return !(o >= 0 && o < Math.PI * 2);
246
+ } : function(o) {
247
+ return !(o > -1 * Math.PI && o <= Math.PI);
248
+ };
249
+ for (; e(r); )
250
+ r = r + 2 * Math.PI * (r > 0 ? -1 : 1);
251
+ return r;
252
+ }
253
+ const H = 2.00703, O = class O {
254
+ constructor() {
255
+ A(this, "points", []);
256
+ A(this, "pointsWeightBuffer");
257
+ A(this, "strict_status");
258
+ A(this, "vertices_params");
259
+ A(this, "centroid");
260
+ A(this, "edgeNodes");
261
+ A(this, "edges");
262
+ A(this, "tins");
263
+ A(this, "kinks");
264
+ A(this, "yaxisMode", O.YAXIS_INVERT);
265
+ A(this, "strictMode", O.MODE_AUTO);
266
+ A(this, "vertexMode", O.VERTEX_PLAIN);
267
+ A(this, "bounds");
268
+ A(this, "boundsPolygon");
269
+ A(this, "wh");
270
+ A(this, "xy");
271
+ A(this, "indexedTins");
272
+ A(this, "stateFull", !1);
273
+ A(this, "stateTriangle");
274
+ A(this, "stateBackward");
275
+ }
276
+ /**
277
+ * コンパイルされた設定を適用します
278
+ *
279
+ * @param compiled - コンパイルされた設定オブジェクト
280
+ * @returns 変換に必要な主要なオブジェクトのセット
281
+ *
282
+ * 以下の処理を行います:
283
+ * 1. バージョンに応じた設定の解釈
284
+ * 2. 各種パラメータの復元
285
+ * 3. TINネットワークの再構築
286
+ * 4. インデックスの作成
287
+ */
288
+ setCompiled(t) {
289
+ if (t.version || !t.tins && t.points && t.tins_points) {
290
+ this.points = t.points, this.pointsWeightBuffer = !t.version || t.version < 2.00703 ? ["forw", "bakw"].reduce((o, f) => {
291
+ const s = t.weight_buffer[f];
292
+ return s && (o[f] = Object.keys(s).reduce((c, g) => {
293
+ const l = tt(g);
294
+ return c[l] = s[g], c;
295
+ }, {})), o;
296
+ }, {}) : t.weight_buffer, t.strict_status ? this.strict_status = t.strict_status : t.kinks_points ? this.strict_status = O.STATUS_ERROR : t.tins_points.length == 2 ? this.strict_status = O.STATUS_LOOSE : this.strict_status = O.STATUS_STRICT, this.vertices_params = {
297
+ forw: [t.vertices_params[0]],
298
+ bakw: [t.vertices_params[1]]
299
+ }, this.vertices_params.forw[1] = [0, 1, 2, 3].map((o) => {
300
+ const f = (o + 1) % 4, s = V(
301
+ ["c", `b${o}`, `b${f}`],
302
+ t.points,
303
+ t.edgeNodes || [],
304
+ t.centroid_point,
305
+ t.vertices_points,
306
+ !1,
307
+ H
308
+ );
309
+ return F([s]);
310
+ }), this.vertices_params.bakw[1] = [0, 1, 2, 3].map((o) => {
311
+ const f = (o + 1) % 4, s = V(
312
+ ["c", `b${o}`, `b${f}`],
313
+ t.points,
314
+ t.edgeNodes || [],
315
+ t.centroid_point,
316
+ t.vertices_points,
317
+ !0,
318
+ H
319
+ );
320
+ return F([s]);
321
+ }), this.centroid = {
322
+ forw: W(t.centroid_point[0], {
323
+ target: {
324
+ geom: t.centroid_point[1],
325
+ index: "c"
326
+ }
327
+ }),
328
+ bakw: W(t.centroid_point[1], {
329
+ target: {
330
+ geom: t.centroid_point[0],
331
+ index: "c"
332
+ }
333
+ })
334
+ }, this.edges = xt(t.edges || []), this.edgeNodes = t.edgeNodes || [];
335
+ const e = t.tins_points.length == 1 ? 0 : 1;
336
+ this.tins = {
337
+ forw: F(
338
+ t.tins_points[0].map(
339
+ (o) => V(
340
+ o,
341
+ t.points,
342
+ t.edgeNodes || [],
343
+ t.centroid_point,
344
+ t.vertices_points,
345
+ !1,
346
+ t.version
347
+ )
348
+ )
349
+ ),
350
+ bakw: F(
351
+ t.tins_points[e].map(
352
+ (o) => V(
353
+ o,
354
+ t.points,
355
+ t.edgeNodes || [],
356
+ t.centroid_point,
357
+ t.vertices_points,
358
+ !0,
359
+ t.version
360
+ )
361
+ )
362
+ )
363
+ }, this.addIndexedTin(), t.kinks_points && (this.kinks = {
364
+ bakw: F(
365
+ t.kinks_points.map((o) => W(o))
366
+ )
367
+ }), t.yaxisMode ? this.yaxisMode = t.yaxisMode : this.yaxisMode = O.YAXIS_INVERT, t.vertexMode && (this.vertexMode = t.vertexMode), t.strictMode && (this.strictMode = t.strictMode), t.bounds ? (this.bounds = t.bounds, this.boundsPolygon = t.boundsPolygon, this.xy = t.xy, this.wh = t.wh) : (this.xy = [0, 0], t.wh && (this.wh = t.wh), this.bounds = void 0, this.boundsPolygon = void 0);
368
+ } else {
369
+ t = JSON.parse(
370
+ JSON.stringify(t).replace('"cent"', '"c"').replace(/"bbox(\d+)"/g, '"b$1"')
371
+ ), this.tins = t.tins, this.addIndexedTin(), this.strict_status = t.strict_status, this.pointsWeightBuffer = t.weight_buffer, this.vertices_params = t.vertices_params, this.centroid = t.centroid, this.kinks = t.kinks;
372
+ const e = [];
373
+ for (let o = 0; o < this.tins.forw.features.length; o++) {
374
+ const f = this.tins.forw.features[o];
375
+ ["a", "b", "c"].map((s, c) => {
376
+ const g = f.geometry.coordinates[0][c], l = f.properties[s].geom, y = f.properties[s].index;
377
+ e[y] = [g, l];
378
+ });
379
+ }
380
+ this.points = e;
381
+ }
382
+ return {
383
+ tins: this.tins,
384
+ strict_status: this.strict_status,
385
+ weight_buffer: this.pointsWeightBuffer,
386
+ vertices_params: this.vertices_params,
387
+ centroid: this.centroid,
388
+ kinks: this.kinks
389
+ };
390
+ }
391
+ /**
392
+ * TINネットワークのインデックスを作成します
393
+ *
394
+ * インデックスは変換処理を高速化するために使用されます。
395
+ * グリッド形式のインデックスを作成し、各グリッドに
396
+ * 含まれる三角形を記録します。
397
+ */
398
+ addIndexedTin() {
399
+ const t = this.tins, e = t.forw, o = t.bakw, f = Math.ceil(Math.sqrt(e.features.length));
400
+ if (f < 3) {
401
+ this.indexedTins = void 0;
402
+ return;
403
+ }
404
+ let s = [], c = [];
405
+ const g = e.features.map((h) => {
406
+ let a = [];
407
+ return z(h)[0].map((n) => {
408
+ s.length === 0 ? s = [Array.from(n), Array.from(n)] : (n[0] < s[0][0] && (s[0][0] = n[0]), n[0] > s[1][0] && (s[1][0] = n[0]), n[1] < s[0][1] && (s[0][1] = n[1]), n[1] > s[1][1] && (s[1][1] = n[1])), a.length === 0 ? a = [Array.from(n), Array.from(n)] : (n[0] < a[0][0] && (a[0][0] = n[0]), n[0] > a[1][0] && (a[1][0] = n[0]), n[1] < a[0][1] && (a[0][1] = n[1]), n[1] > a[1][1] && (a[1][1] = n[1]));
409
+ }), a;
410
+ }), l = (s[1][0] - s[0][0]) / f, y = (s[1][1] - s[0][1]) / f, w = g.reduce(
411
+ (h, a, n) => {
412
+ const b = R(
413
+ a[0][0],
414
+ s[0][0],
415
+ l,
416
+ f
417
+ ), x = R(
418
+ a[1][0],
419
+ s[0][0],
420
+ l,
421
+ f
422
+ ), M = R(
423
+ a[0][1],
424
+ s[0][1],
425
+ y,
426
+ f
427
+ ), m = R(
428
+ a[1][1],
429
+ s[0][1],
430
+ y,
431
+ f
432
+ );
433
+ for (let _ = b; _ <= x; _++) {
434
+ h[_] || (h[_] = []);
435
+ for (let E = M; E <= m; E++)
436
+ h[_][E] || (h[_][E] = []), h[_][E].push(n);
437
+ }
438
+ return h;
439
+ },
440
+ []
441
+ ), i = o.features.map((h) => {
442
+ let a = [];
443
+ return z(h)[0].map((n) => {
444
+ c.length === 0 ? c = [Array.from(n), Array.from(n)] : (n[0] < c[0][0] && (c[0][0] = n[0]), n[0] > c[1][0] && (c[1][0] = n[0]), n[1] < c[0][1] && (c[0][1] = n[1]), n[1] > c[1][1] && (c[1][1] = n[1])), a.length === 0 ? a = [Array.from(n), Array.from(n)] : (n[0] < a[0][0] && (a[0][0] = n[0]), n[0] > a[1][0] && (a[1][0] = n[0]), n[1] < a[0][1] && (a[0][1] = n[1]), n[1] > a[1][1] && (a[1][1] = n[1]));
445
+ }), a;
446
+ }), u = (c[1][0] - c[0][0]) / f, d = (c[1][1] - c[0][1]) / f, v = i.reduce(
447
+ (h, a, n) => {
448
+ const b = R(
449
+ a[0][0],
450
+ c[0][0],
451
+ u,
452
+ f
453
+ ), x = R(
454
+ a[1][0],
455
+ c[0][0],
456
+ u,
457
+ f
458
+ ), M = R(
459
+ a[0][1],
460
+ c[0][1],
461
+ d,
462
+ f
463
+ ), m = R(
464
+ a[1][1],
465
+ c[0][1],
466
+ d,
467
+ f
468
+ );
469
+ for (let _ = b; _ <= x; _++) {
470
+ h[_] || (h[_] = []);
471
+ for (let E = M; E <= m; E++)
472
+ h[_][E] || (h[_][E] = []), h[_][E].push(n);
473
+ }
474
+ return h;
475
+ },
476
+ []
477
+ );
478
+ this.indexedTins = {
479
+ forw: {
480
+ gridNum: f,
481
+ xOrigin: s[0][0],
482
+ yOrigin: s[0][1],
483
+ xUnit: l,
484
+ yUnit: y,
485
+ gridCache: w
486
+ },
487
+ bakw: {
488
+ gridNum: f,
489
+ xOrigin: c[0][0],
490
+ yOrigin: c[0][1],
491
+ xUnit: u,
492
+ yUnit: d,
493
+ gridCache: v
494
+ }
495
+ };
496
+ }
497
+ /**
498
+ * 座標変換を実行します
499
+ *
500
+ * @param apoint - 変換する座標
501
+ * @param backward - 逆方向の変換かどうか
502
+ * @param ignoreBounds - 境界チェックを無視するかどうか
503
+ * @returns 変換後の座標、または境界外の場合はfalse
504
+ *
505
+ * @throws {Error} 逆方向変換が許可されていない状態での逆変換時
506
+ */
507
+ transform(t, e, o) {
508
+ if (e && this.strict_status == O.STATUS_ERROR)
509
+ throw 'Backward transform is not allowed if strict_status == "strict_error"';
510
+ this.yaxisMode == O.YAXIS_FOLLOW && e && (t = [t[0], -1 * t[1]]);
511
+ const f = W(t);
512
+ if (this.bounds && !e && !o && !q(f, this.boundsPolygon))
513
+ return !1;
514
+ const s = e ? this.tins.bakw : this.tins.forw, c = e ? this.indexedTins.bakw : this.indexedTins.forw, g = e ? this.vertices_params.bakw : this.vertices_params.forw, l = e ? this.centroid.bakw : this.centroid.forw, y = e ? this.pointsWeightBuffer.bakw : this.pointsWeightBuffer.forw;
515
+ let w, i;
516
+ this.stateFull && (this.stateBackward == e ? w = this.stateTriangle : (this.stateBackward = e, this.stateTriangle = void 0), i = (d) => {
517
+ this.stateTriangle = d;
518
+ });
519
+ let u = Et(
520
+ f,
521
+ s,
522
+ c,
523
+ g,
524
+ l,
525
+ y,
526
+ w,
527
+ i
528
+ );
529
+ if (this.bounds && e && !o) {
530
+ const d = W(u);
531
+ if (!q(d, this.boundsPolygon)) return !1;
532
+ } else this.yaxisMode == O.YAXIS_FOLLOW && !e && (u = [u[0], -1 * u[1]]);
533
+ return u;
534
+ }
535
+ };
536
+ /**
537
+ * 各種モードの定数定義
538
+ * すべてreadonlyで、型安全性を確保
539
+ */
540
+ A(O, "VERTEX_PLAIN", "plain"), A(O, "VERTEX_BIRDEYE", "birdeye"), A(O, "MODE_STRICT", "strict"), A(O, "MODE_AUTO", "auto"), A(O, "MODE_LOOSE", "loose"), A(O, "STATUS_STRICT", "strict"), A(O, "STATUS_ERROR", "strict_error"), A(O, "STATUS_LOOSE", "loose"), A(O, "YAXIS_FOLLOW", "follow"), A(O, "YAXIS_INVERT", "invert");
541
+ let Z = O;
542
+ export {
543
+ Z as Transform,
544
+ H as format_version
545
+ };
@@ -0,0 +1 @@
1
+ (function(P,T){typeof exports=="object"&&typeof module<"u"?T(exports):typeof define=="function"&&define.amd?define(["exports"],T):(P=typeof globalThis<"u"?globalThis:P||self,T(P.maplat_transform={}))})(this,function(P){"use strict";var Et=Object.defineProperty;var Ot=(P,T,k)=>T in P?Et(P,T,{enumerable:!0,configurable:!0,writable:!0,value:k}):P[T]=k;var A=(P,T,k)=>Ot(P,typeof T!="symbol"?T+"":T,k);const T=11102230246251565e-32,k=134217729,st=(3+8*T)*T;function q(e,t,s,o,f){let r,u,g,l,y=t[0],d=o[0],i=0,c=0;d>y==d>-y?(r=y,y=t[++i]):(r=d,d=o[++c]);let w=0;if(i<e&&c<s)for(d>y==d>-y?(u=y+r,g=r-(u-y),y=t[++i]):(u=d+r,g=r-(u-d),d=o[++c]),r=u,g!==0&&(f[w++]=g);i<e&&c<s;)d>y==d>-y?(u=r+y,l=u-r,g=r-(u-l)+(y-l),y=t[++i]):(u=r+d,l=u-r,g=r-(u-l)+(d-l),d=o[++c]),r=u,g!==0&&(f[w++]=g);for(;i<e;)u=r+y,l=u-r,g=r-(u-l)+(y-l),y=t[++i],r=u,g!==0&&(f[w++]=g);for(;c<s;)u=r+d,l=u-r,g=r-(u-l)+(d-l),d=o[++c],r=u,g!==0&&(f[w++]=g);return(r!==0||w===0)&&(f[w++]=r),w}function nt(e,t){let s=t[0];for(let o=1;o<e;o++)s+=t[o];return s}function W(e){return new Float64Array(e)}const it=(3+16*T)*T,ot=(2+12*T)*T,at=(9+64*T)*T*T,Y=W(4),J=W(8),z=W(12),K=W(16),I=W(4);function ft(e,t,s,o,f,r,u){let g,l,y,d,i,c,w,v,h,a,n,b,m,M,E,_,x,S;const N=e-f,C=s-f,R=t-r,U=o-r;M=N*U,c=k*N,w=c-(c-N),v=N-w,c=k*U,h=c-(c-U),a=U-h,E=v*a-(M-w*h-v*h-w*a),_=R*C,c=k*R,w=c-(c-R),v=R-w,c=k*C,h=c-(c-C),a=C-h,x=v*a-(_-w*h-v*h-w*a),n=E-x,i=E-n,Y[0]=E-(n+i)+(i-x),b=M+n,i=b-M,m=M-(b-i)+(n-i),n=m-_,i=m-n,Y[1]=m-(n+i)+(i-_),S=b+n,i=S-b,Y[2]=b-(S-i)+(n-i),Y[3]=S;let F=nt(4,Y),V=ot*u;if(F>=V||-F>=V||(i=e-N,g=e-(N+i)+(i-f),i=s-C,y=s-(C+i)+(i-f),i=t-R,l=t-(R+i)+(i-r),i=o-U,d=o-(U+i)+(i-r),g===0&&l===0&&y===0&&d===0)||(V=at*u+st*Math.abs(F),F+=N*d+U*g-(R*y+C*l),F>=V||-F>=V))return F;M=g*U,c=k*g,w=c-(c-g),v=g-w,c=k*U,h=c-(c-U),a=U-h,E=v*a-(M-w*h-v*h-w*a),_=l*C,c=k*l,w=c-(c-l),v=l-w,c=k*C,h=c-(c-C),a=C-h,x=v*a-(_-w*h-v*h-w*a),n=E-x,i=E-n,I[0]=E-(n+i)+(i-x),b=M+n,i=b-M,m=M-(b-i)+(n-i),n=m-_,i=m-n,I[1]=m-(n+i)+(i-_),S=b+n,i=S-b,I[2]=b-(S-i)+(n-i),I[3]=S;const mt=q(4,Y,4,I,J);M=N*d,c=k*N,w=c-(c-N),v=N-w,c=k*d,h=c-(c-d),a=d-h,E=v*a-(M-w*h-v*h-w*a),_=R*y,c=k*R,w=c-(c-R),v=R-w,c=k*y,h=c-(c-y),a=y-h,x=v*a-(_-w*h-v*h-w*a),n=E-x,i=E-n,I[0]=E-(n+i)+(i-x),b=M+n,i=b-M,m=M-(b-i)+(n-i),n=m-_,i=m-n,I[1]=m-(n+i)+(i-_),S=b+n,i=S-b,I[2]=b-(S-i)+(n-i),I[3]=S;const Mt=q(mt,J,4,I,z);M=g*d,c=k*g,w=c-(c-g),v=g-w,c=k*d,h=c-(c-d),a=d-h,E=v*a-(M-w*h-v*h-w*a),_=l*y,c=k*l,w=c-(c-l),v=l-w,c=k*y,h=c-(c-y),a=y-h,x=v*a-(_-w*h-v*h-w*a),n=E-x,i=E-n,I[0]=E-(n+i)+(i-x),b=M+n,i=b-M,m=M-(b-i)+(n-i),n=m-_,i=m-n,I[1]=m-(n+i)+(i-_),S=b+n,i=S-b,I[2]=b-(S-i)+(n-i),I[3]=S;const xt=q(Mt,z,4,I,K);return K[xt-1]}function ut(e,t,s,o,f,r){const u=(t-r)*(s-f),g=(e-f)*(o-r),l=u-g,y=Math.abs(u+g);return Math.abs(l)>=it*y?l:-ft(e,t,s,o,f,r,y)}function ct(e,t){var s,o,f=0,r,u,g,l,y,d,i,c=e[0],w=e[1],v=t.length;for(s=0;s<v;s++){o=0;var h=t[s],a=h.length-1;if(d=h[0],d[0]!==h[a][0]&&d[1]!==h[a][1])throw new Error("First and last coordinates in a ring must be the same");for(u=d[0]-c,g=d[1]-w,o;o<a;o++){if(i=h[o+1],l=i[0]-c,y=i[1]-w,g===0&&y===0){if(l<=0&&u>=0||u<=0&&l>=0)return 0}else if(y>=0&&g<=0||y<=0&&g>=0){if(r=ut(u,l,g,y,0,0),r===0)return 0;(r>0&&y>0&&g<=0||r<0&&y<=0&&g>0)&&f++}d=i,g=y,u=l}}return f%2!==0}function Q(e,t,s={}){const o={type:"Feature"};return(s.id===0||s.id)&&(o.id=s.id),s.bbox&&(o.bbox=s.bbox),o.properties=t||{},o.geometry=e,o}function D(e,t,s={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!H(e[0])||!H(e[1]))throw new Error("coordinates must contain numbers");return Q({type:"Point",coordinates:e},t,s)}function ht(e,t,s={}){for(const f of e){if(f.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(f[f.length-1].length!==f[0].length)throw new Error("First and last Position are not equivalent.");for(let r=0;r<f[f.length-1].length;r++)if(f[f.length-1][r]!==f[0][r])throw new Error("First and last Position are not equivalent.")}return Q({type:"Polygon",coordinates:e},t,s)}function X(e,t={}){const s={type:"FeatureCollection"};return t.id&&(s.id=t.id),t.bbox&&(s.bbox=t.bbox),s.features=e,s}function H(e){return!isNaN(e)&&e!==null&&!Array.isArray(e)}function lt(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if(e.type==="Feature"&&e.geometry!==null&&e.geometry.type==="Point")return[...e.geometry.coordinates];if(e.type==="Point")return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function Z(e){if(Array.isArray(e))return e;if(e.type==="Feature"){if(e.geometry!==null)return e.geometry.coordinates}else if(e.coordinates)return e.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function gt(e){return e.type==="Feature"?e.geometry:e}function yt(e,t,s={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const o=lt(e),f=gt(t),r=f.type,u=t.bbox;let g=f.coordinates;if(u&&dt(o,u)===!1)return!1;r==="Polygon"&&(g=[g]);let l=!1;for(var y=0;y<g.length;++y){const d=ct(o,g[y]);if(d===0)return!s.ignoreBoundary;d&&(l=!0)}return l}function dt(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}var L=yt;function wt(e){const t=[0,1,2,0].map(o=>e[o][0][0]),s={a:{geom:e[0][0][1],index:e[0][1]},b:{geom:e[1][0][1],index:e[1][1]},c:{geom:e[2][0][1],index:e[2][1]}};return ht([t],s)}function $(e,t,s,o,f,r=!1,u){const g=e.map(l=>{(!u||u<2.00703)&&(l=p(l));const y=isFinite(l)?t[l]:l==="c"?o:l==="b0"?f[0]:l==="b1"?f[1]:l==="b2"?f[2]:l==="b3"?f[3]:function(){const d=l.match(/e(\d+)/);if(d){const i=parseInt(d[1]);return s[i]}throw"Bad index value for indexesToTri"}();return r?[[y[1],y[0]],l]:[[y[0],y[1]],l]});return wt(g)}function p(e){return typeof e=="number"?e:e.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function bt(e,t){return Array.isArray(e[0])?e:e.map(s=>[s.illstNodes,s.mercNodes,s.startEnd])}function tt(e,t){for(let s=0;s<t.features.length;s++)if(L(e,t.features[s]))return t.features[s]}function et(e,t,s){const o=t.geometry.coordinates[0][0],f=t.geometry.coordinates[0][1],r=t.geometry.coordinates[0][2],u=e.geometry.coordinates,g=t.properties.a.geom,l=t.properties.b.geom,y=t.properties.c.geom,d=[f[0]-o[0],f[1]-o[1]],i=[r[0]-o[0],r[1]-o[1]],c=[u[0]-o[0],u[1]-o[1]],w=[l[0]-g[0],l[1]-g[1]],v=[y[0]-g[0],y[1]-g[1]];let h=(i[1]*c[0]-i[0]*c[1])/(d[0]*i[1]-d[1]*i[0]),a=(d[0]*c[1]-d[1]*c[0])/(d[0]*i[1]-d[1]*i[0]);if(s){const n=s[t.properties.a.index],b=s[t.properties.b.index],m=s[t.properties.c.index];let M;if(h<0||a<0||1-h-a<0){const E=h/(h+a),_=a/(h+a);M=h/b/(E/b+_/m),a=a/m/(E/b+_/m)}else M=h/b/(h/b+a/m+(1-h-a)/n),a=a/m/(h/b+a/m+(1-h-a)/n);h=M}return[h*w[0]+a*v[0]+g[0],h*w[1]+a*v[1]+g[1]]}function _t(e,t,s,o){const f=e.geometry.coordinates,r=s.geometry.coordinates,u=Math.atan2(f[0]-r[0],f[1]-r[1]),g=At(u,t[0]),l=t[1][g];return et(e,l.features[0],o)}function vt(e,t,s,o,f,r,u,g){let l;if(u&&(l=tt(e,X([u]))),!l){if(s){const y=e.geometry.coordinates,d=s.gridNum,i=s.xOrigin,c=s.yOrigin,w=s.xUnit,v=s.yUnit,h=s.gridCache,a=B(y[0],i,w,d),n=B(y[1],c,v,d),b=h[a]?h[a][n]?h[a][n]:[]:[];t=X(b.map(m=>t.features[m]))}l=tt(e,t)}return g&&g(l),l?et(e,l,r):_t(e,o,f,r)}function B(e,t,s,o){let f=Math.floor((e-t)/s);return f>=o&&(f=o-1),f}function At(e,t){let s=rt(e-t[0]),o=Math.PI*2,f;for(let r=0;r<t.length;r++){const u=(r+1)%t.length,g=rt(e-t[u]),l=Math.min(Math.abs(s),Math.abs(g));s*g<=0&&l<o&&(o=l,f=r),s=g}return f}function rt(e,t=!1){const s=t?function(o){return!(o>=0&&o<Math.PI*2)}:function(o){return!(o>-1*Math.PI&&o<=Math.PI)};for(;s(e);)e=e+2*Math.PI*(e>0?-1:1);return e}const j=2.00703,O=class O{constructor(){A(this,"points",[]);A(this,"pointsWeightBuffer");A(this,"strict_status");A(this,"vertices_params");A(this,"centroid");A(this,"edgeNodes");A(this,"edges");A(this,"tins");A(this,"kinks");A(this,"yaxisMode",O.YAXIS_INVERT);A(this,"strictMode",O.MODE_AUTO);A(this,"vertexMode",O.VERTEX_PLAIN);A(this,"bounds");A(this,"boundsPolygon");A(this,"wh");A(this,"xy");A(this,"indexedTins");A(this,"stateFull",!1);A(this,"stateTriangle");A(this,"stateBackward")}setCompiled(t){if(t.version||!t.tins&&t.points&&t.tins_points){this.points=t.points,this.pointsWeightBuffer=!t.version||t.version<2.00703?["forw","bakw"].reduce((o,f)=>{const r=t.weight_buffer[f];return r&&(o[f]=Object.keys(r).reduce((u,g)=>{const l=p(g);return u[l]=r[g],u},{})),o},{}):t.weight_buffer,t.strict_status?this.strict_status=t.strict_status:t.kinks_points?this.strict_status=O.STATUS_ERROR:t.tins_points.length==2?this.strict_status=O.STATUS_LOOSE:this.strict_status=O.STATUS_STRICT,this.vertices_params={forw:[t.vertices_params[0]],bakw:[t.vertices_params[1]]},this.vertices_params.forw[1]=[0,1,2,3].map(o=>{const f=(o+1)%4,r=$(["c",`b${o}`,`b${f}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,j);return X([r])}),this.vertices_params.bakw[1]=[0,1,2,3].map(o=>{const f=(o+1)%4,r=$(["c",`b${o}`,`b${f}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,j);return X([r])}),this.centroid={forw:D(t.centroid_point[0],{target:{geom:t.centroid_point[1],index:"c"}}),bakw:D(t.centroid_point[1],{target:{geom:t.centroid_point[0],index:"c"}})},this.edges=bt(t.edges||[]),this.edgeNodes=t.edgeNodes||[];const s=t.tins_points.length==1?0:1;this.tins={forw:X(t.tins_points[0].map(o=>$(o,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:X(t.tins_points[s].map(o=>$(o,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,t.version)))},this.addIndexedTin(),t.kinks_points&&(this.kinks={bakw:X(t.kinks_points.map(o=>D(o)))}),t.yaxisMode?this.yaxisMode=t.yaxisMode:this.yaxisMode=O.YAXIS_INVERT,t.vertexMode&&(this.vertexMode=t.vertexMode),t.strictMode&&(this.strictMode=t.strictMode),t.bounds?(this.bounds=t.bounds,this.boundsPolygon=t.boundsPolygon,this.xy=t.xy,this.wh=t.wh):(this.xy=[0,0],t.wh&&(this.wh=t.wh),this.bounds=void 0,this.boundsPolygon=void 0)}else{t=JSON.parse(JSON.stringify(t).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"')),this.tins=t.tins,this.addIndexedTin(),this.strict_status=t.strict_status,this.pointsWeightBuffer=t.weight_buffer,this.vertices_params=t.vertices_params,this.centroid=t.centroid,this.kinks=t.kinks;const s=[];for(let o=0;o<this.tins.forw.features.length;o++){const f=this.tins.forw.features[o];["a","b","c"].map((r,u)=>{const g=f.geometry.coordinates[0][u],l=f.properties[r].geom,y=f.properties[r].index;s[y]=[g,l]})}this.points=s}return{tins:this.tins,strict_status:this.strict_status,weight_buffer:this.pointsWeightBuffer,vertices_params:this.vertices_params,centroid:this.centroid,kinks:this.kinks}}addIndexedTin(){const t=this.tins,s=t.forw,o=t.bakw,f=Math.ceil(Math.sqrt(s.features.length));if(f<3){this.indexedTins=void 0;return}let r=[],u=[];const g=s.features.map(h=>{let a=[];return Z(h)[0].map(n=>{r.length===0?r=[Array.from(n),Array.from(n)]:(n[0]<r[0][0]&&(r[0][0]=n[0]),n[0]>r[1][0]&&(r[1][0]=n[0]),n[1]<r[0][1]&&(r[0][1]=n[1]),n[1]>r[1][1]&&(r[1][1]=n[1])),a.length===0?a=[Array.from(n),Array.from(n)]:(n[0]<a[0][0]&&(a[0][0]=n[0]),n[0]>a[1][0]&&(a[1][0]=n[0]),n[1]<a[0][1]&&(a[0][1]=n[1]),n[1]>a[1][1]&&(a[1][1]=n[1]))}),a}),l=(r[1][0]-r[0][0])/f,y=(r[1][1]-r[0][1])/f,d=g.reduce((h,a,n)=>{const b=B(a[0][0],r[0][0],l,f),m=B(a[1][0],r[0][0],l,f),M=B(a[0][1],r[0][1],y,f),E=B(a[1][1],r[0][1],y,f);for(let _=b;_<=m;_++){h[_]||(h[_]=[]);for(let x=M;x<=E;x++)h[_][x]||(h[_][x]=[]),h[_][x].push(n)}return h},[]),i=o.features.map(h=>{let a=[];return Z(h)[0].map(n=>{u.length===0?u=[Array.from(n),Array.from(n)]:(n[0]<u[0][0]&&(u[0][0]=n[0]),n[0]>u[1][0]&&(u[1][0]=n[0]),n[1]<u[0][1]&&(u[0][1]=n[1]),n[1]>u[1][1]&&(u[1][1]=n[1])),a.length===0?a=[Array.from(n),Array.from(n)]:(n[0]<a[0][0]&&(a[0][0]=n[0]),n[0]>a[1][0]&&(a[1][0]=n[0]),n[1]<a[0][1]&&(a[0][1]=n[1]),n[1]>a[1][1]&&(a[1][1]=n[1]))}),a}),c=(u[1][0]-u[0][0])/f,w=(u[1][1]-u[0][1])/f,v=i.reduce((h,a,n)=>{const b=B(a[0][0],u[0][0],c,f),m=B(a[1][0],u[0][0],c,f),M=B(a[0][1],u[0][1],w,f),E=B(a[1][1],u[0][1],w,f);for(let _=b;_<=m;_++){h[_]||(h[_]=[]);for(let x=M;x<=E;x++)h[_][x]||(h[_][x]=[]),h[_][x].push(n)}return h},[]);this.indexedTins={forw:{gridNum:f,xOrigin:r[0][0],yOrigin:r[0][1],xUnit:l,yUnit:y,gridCache:d},bakw:{gridNum:f,xOrigin:u[0][0],yOrigin:u[0][1],xUnit:c,yUnit:w,gridCache:v}}}transform(t,s,o){if(s&&this.strict_status==O.STATUS_ERROR)throw'Backward transform is not allowed if strict_status == "strict_error"';this.yaxisMode==O.YAXIS_FOLLOW&&s&&(t=[t[0],-1*t[1]]);const f=D(t);if(this.bounds&&!s&&!o&&!L(f,this.boundsPolygon))return!1;const r=s?this.tins.bakw:this.tins.forw,u=s?this.indexedTins.bakw:this.indexedTins.forw,g=s?this.vertices_params.bakw:this.vertices_params.forw,l=s?this.centroid.bakw:this.centroid.forw,y=s?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let d,i;this.stateFull&&(this.stateBackward==s?d=this.stateTriangle:(this.stateBackward=s,this.stateTriangle=void 0),i=w=>{this.stateTriangle=w});let c=vt(f,r,u,g,l,y,d,i);if(this.bounds&&s&&!o){const w=D(c);if(!L(w,this.boundsPolygon))return!1}else this.yaxisMode==O.YAXIS_FOLLOW&&!s&&(c=[c[0],-1*c[1]]);return c}};A(O,"VERTEX_PLAIN","plain"),A(O,"VERTEX_BIRDEYE","birdeye"),A(O,"MODE_STRICT","strict"),A(O,"MODE_AUTO","auto"),A(O,"MODE_LOOSE","loose"),A(O,"STATUS_STRICT","strict"),A(O,"STATUS_ERROR","strict_error"),A(O,"STATUS_LOOSE","loose"),A(O,"YAXIS_FOLLOW","follow"),A(O,"YAXIS_INVERT","invert");let G=O;P.Transform=G,P.format_version=j,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})});