@maplat/transform 0.2.3 → 0.4.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.
- package/LICENSE +224 -224
- package/README.ja.md +68 -68
- package/README.md +143 -143
- package/dist/index.d.ts +28 -23
- package/dist/maplat_transform.js +515 -444
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +40 -44
- package/src/compiled-state.ts +211 -0
- package/src/edgeutils.ts +47 -47
- package/src/geometry.ts +247 -248
- package/src/index.ts +398 -567
- package/src/triangulation.ts +179 -179
- package/src/types.ts +122 -0
- package/dist/index.html +0 -39
- package/dist/maplat_transform.cjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p,O){typeof exports=="object"&&typeof module<"u"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(p=typeof globalThis<"u"?globalThis:p||self,O(p.maplat_transform={}))})(this,function(p){"use strict";var Ot=Object.defineProperty;var St=(p,O,S)=>O in p?Ot(p,O,{enumerable:!0,configurable:!0,writable:!0,value:S}):p[O]=S;var _=(p,O,S)=>St(p,typeof O!="symbol"?O+"":O,S);const O=11102230246251565e-32,S=134217729,ot=(3+8*O)*O;function D(e,t,n,r,a){let s,c,d,g,l=t[0],y=r[0],o=0,u=0;y>l==y>-l?(s=l,l=t[++o]):(s=y,y=r[++u]);let b=0;if(o<e&&u<n)for(y>l==y>-l?(c=l+s,d=s-(c-l),l=t[++o]):(c=y+s,d=s-(c-y),y=r[++u]),s=c,d!==0&&(a[b++]=d);o<e&&u<n;)y>l==y>-l?(c=s+l,g=c-s,d=s-(c-g)+(l-g),l=t[++o]):(c=s+y,g=c-s,d=s-(c-g)+(y-g),y=r[++u]),s=c,d!==0&&(a[b++]=d);for(;o<e;)c=s+l,g=c-s,d=s-(c-g)+(l-g),l=t[++o],s=c,d!==0&&(a[b++]=d);for(;u<n;)c=s+y,g=c-s,d=s-(c-g)+(y-g),y=r[++u],s=c,d!==0&&(a[b++]=d);return(s!==0||b===0)&&(a[b++]=s),b}function at(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function Y(e){return new Float64Array(e)}const ft=(3+16*O)*O,ct=(2+12*O)*O,ut=(9+64*O)*O*O,X=Y(4),G=Y(8),z=Y(12),J=Y(16),I=Y(4);function ht(e,t,n,r,a,s,c){let d,g,l,y,o,u,b,x,h,f,i,w,v,A,E,m,M,P;const k=e-a,N=n-a,C=t-s,U=r-s;A=k*U,u=S*k,b=u-(u-k),x=k-b,u=S*U,h=u-(u-U),f=U-h,E=x*f-(A-b*h-x*h-b*f),m=C*N,u=S*C,b=u-(u-C),x=C-b,u=S*N,h=u-(u-N),f=N-h,M=x*f-(m-b*h-x*h-b*f),i=E-M,o=E-i,X[0]=E-(i+o)+(o-M),w=A+i,o=w-A,v=A-(w-o)+(i-o),i=v-m,o=v-i,X[1]=v-(i+o)+(o-m),P=w+i,o=P-w,X[2]=w-(P-o)+(i-o),X[3]=P;let B=at(4,X),W=ct*c;if(B>=W||-B>=W||(o=e-k,d=e-(k+o)+(o-a),o=n-N,l=n-(N+o)+(o-a),o=t-C,g=t-(C+o)+(o-s),o=r-U,y=r-(U+o)+(o-s),d===0&&g===0&&l===0&&y===0)||(W=ut*c+ot*Math.abs(B),B+=k*y+U*d-(C*l+N*g),B>=W||-B>=W))return B;A=d*U,u=S*d,b=u-(u-d),x=d-b,u=S*U,h=u-(u-U),f=U-h,E=x*f-(A-b*h-x*h-b*f),m=g*N,u=S*g,b=u-(u-g),x=g-b,u=S*N,h=u-(u-N),f=N-h,M=x*f-(m-b*h-x*h-b*f),i=E-M,o=E-i,I[0]=E-(i+o)+(o-M),w=A+i,o=w-A,v=A-(w-o)+(i-o),i=v-m,o=v-i,I[1]=v-(i+o)+(o-m),P=w+i,o=P-w,I[2]=w-(P-o)+(i-o),I[3]=P;const Mt=D(4,X,4,I,G);A=k*y,u=S*k,b=u-(u-k),x=k-b,u=S*y,h=u-(u-y),f=y-h,E=x*f-(A-b*h-x*h-b*f),m=C*l,u=S*C,b=u-(u-C),x=C-b,u=S*l,h=u-(u-l),f=l-h,M=x*f-(m-b*h-x*h-b*f),i=E-M,o=E-i,I[0]=E-(i+o)+(o-M),w=A+i,o=w-A,v=A-(w-o)+(i-o),i=v-m,o=v-i,I[1]=v-(i+o)+(o-m),P=w+i,o=P-w,I[2]=w-(P-o)+(i-o),I[3]=P;const Et=D(Mt,G,4,I,z);A=d*y,u=S*d,b=u-(u-d),x=d-b,u=S*y,h=u-(u-y),f=y-h,E=x*f-(A-b*h-x*h-b*f),m=g*l,u=S*g,b=u-(u-g),x=g-b,u=S*l,h=u-(u-l),f=l-h,M=x*f-(m-b*h-x*h-b*f),i=E-M,o=E-i,I[0]=E-(i+o)+(o-M),w=A+i,o=w-A,v=A-(w-o)+(i-o),i=v-m,o=v-i,I[1]=v-(i+o)+(o-m),P=w+i,o=P-w,I[2]=w-(P-o)+(i-o),I[3]=P;const Tt=D(Et,z,4,I,J);return J[Tt-1]}function gt(e,t,n,r,a,s){const c=(t-s)*(n-a),d=(e-a)*(r-s),g=c-d,l=Math.abs(c+d);return Math.abs(g)>=ft*l?g:-ht(e,t,n,r,a,s,l)}function dt(e,t){var n,r,a=0,s,c,d,g,l,y,o,u=e[0],b=e[1],x=t.length;for(n=0;n<x;n++){r=0;var h=t[n],f=h.length-1;if(y=h[0],y[0]!==h[f][0]&&y[1]!==h[f][1])throw new Error("First and last coordinates in a ring must be the same");for(c=y[0]-u,d=y[1]-b,r;r<f;r++){if(o=h[r+1],g=o[0]-u,l=o[1]-b,d===0&&l===0){if(g<=0&&c>=0||c<=0&&g>=0)return 0}else if(l>=0&&d<=0||l<=0&&d>=0){if(s=gt(c,g,d,l,0,0),s===0)return 0;(s>0&&l>0&&d<=0||s<0&&l<=0&&d>0)&&a++}y=o,d=l,c=g}}return a%2!==0}function K(e,t,n={}){const r={type:"Feature"};return(n.id===0||n.id)&&(r.id=n.id),n.bbox&&(r.bbox=n.bbox),r.properties=t||{},r.geometry=e,r}function $(e,t,n={}){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 K({type:"Point",coordinates:e},t,n)}function Q(e,t,n={}){for(const a of e){if(a.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(a[a.length-1].length!==a[0].length)throw new Error("First and last Position are not equivalent.");for(let s=0;s<a[a.length-1].length;s++)if(a[a.length-1][s]!==a[0][s])throw new Error("First and last Position are not equivalent.")}return K({type:"Polygon",coordinates:e},t,n)}function F(e,t={}){const n={type:"FeatureCollection"};return t.id&&(n.id=t.id),t.bbox&&(n.bbox=t.bbox),n.features=e,n}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 yt(e){return e.type==="Feature"?e.geometry:e}function bt(e,t,n={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");const r=lt(e),a=yt(t),s=a.type,c=t.bbox;let d=a.coordinates;if(c&&wt(r,c)===!1)return!1;s==="Polygon"&&(d=[d]);let g=!1;for(var l=0;l<d.length;++l){const y=dt(r,d[l]);if(y===0)return!n.ignoreBoundary;y&&(g=!0)}return g}function wt(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}var q=bt;function mt(e){const t=e.features;for(let n=0;n<t.length;n++){const r=t[n];`${r.properties.a.index}`.substring(0,1)==="b"&&`${r.properties.b.index}`.substring(0,1)==="b"?t[n]={geometry:{type:"Polygon",coordinates:[[r.geometry.coordinates[0][2],r.geometry.coordinates[0][0],r.geometry.coordinates[0][1],r.geometry.coordinates[0][2]]]},properties:{a:{geom:r.properties.c.geom,index:r.properties.c.index},b:{geom:r.properties.a.geom,index:r.properties.a.index},c:{geom:r.properties.b.geom,index:r.properties.b.index}},type:"Feature"}:`${r.properties.c.index}`.substring(0,1)==="b"&&`${r.properties.a.index}`.substring(0,1)==="b"&&(t[n]={geometry:{type:"Polygon",coordinates:[[r.geometry.coordinates[0][1],r.geometry.coordinates[0][2],r.geometry.coordinates[0][0],r.geometry.coordinates[0][1]]]},properties:{a:{geom:r.properties.b.geom,index:r.properties.b.index},b:{geom:r.properties.c.geom,index:r.properties.c.index},c:{geom:r.properties.a.geom,index:r.properties.a.index}},type:"Feature"})}return e}function xt(e){const t=["a","b","c","a"].map(s=>e.properties[s].geom),n=e.geometry.coordinates[0],r=e.properties,a={a:{geom:n[0],index:r.a.index},b:{geom:n[1],index:r.b.index},c:{geom:n[2],index:r.c.index}};return Q([t],a)}function _t(e){const t=[0,1,2,0].map(r=>e[r][0][0]),n={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 Q([t],n)}function V(e,t,n,r,a,s=!1,c){const d=e.map(g=>{(!c||c<2.00703)&&(g=tt(g));const l=isFinite(g)?t[g]:g==="c"?r:g==="b0"?a[0]:g==="b1"?a[1]:g==="b2"?a[2]:g==="b3"?a[3]:function(){const y=g.match(/e(\d+)/);if(y){const o=parseInt(y[1]);return n[o]}throw"Bad index value for indexesToTri"}();return s?[[l[1],l[0]],g]:[[l[0],l[1]],g]});return _t(d)}function tt(e){return typeof e=="number"?e:e.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}function et(e,t){return t&&t>=2.00703||Array.isArray(e[0])?e:e.map(n=>[n.illstNodes,n.mercNodes,n.startEnd])}function rt(e,t){for(let n=0;n<t.features.length;n++)if(q(e,t.features[n]))return t.features[n]}function nt(e,t,n){const r=t.geometry.coordinates[0][0],a=t.geometry.coordinates[0][1],s=t.geometry.coordinates[0][2],c=e.geometry.coordinates,d=t.properties.a.geom,g=t.properties.b.geom,l=t.properties.c.geom,y=[a[0]-r[0],a[1]-r[1]],o=[s[0]-r[0],s[1]-r[1]],u=[c[0]-r[0],c[1]-r[1]],b=[g[0]-d[0],g[1]-d[1]],x=[l[0]-d[0],l[1]-d[1]];let h=(o[1]*u[0]-o[0]*u[1])/(y[0]*o[1]-y[1]*o[0]),f=(y[0]*u[1]-y[1]*u[0])/(y[0]*o[1]-y[1]*o[0]);if(n){const i=n[t.properties.a.index],w=n[t.properties.b.index],v=n[t.properties.c.index];let A;if(h<0||f<0||1-h-f<0){const E=h/(h+f),m=f/(h+f);A=h/w/(E/w+m/v),f=f/v/(E/w+m/v)}else A=h/w/(h/w+f/v+(1-h-f)/i),f=f/v/(h/w+f/v+(1-h-f)/i);h=A}return[h*b[0]+f*x[0]+d[0],h*b[1]+f*x[1]+d[1]]}function vt(e,t,n,r){const a=e.geometry.coordinates,s=n.geometry.coordinates,c=Math.atan2(a[0]-s[0],a[1]-s[1]),d=At(c,t[0]);if(d===void 0)throw new Error("Unable to determine vertex index");const g=t[1][d];return nt(e,g.features[0],r)}function st(e,t,n,r,a,s,c,d){let g;if(c&&(g=rt(e,F([c]))),!g){if(n){const l=e.geometry.coordinates,y=n.gridNum,o=n.xOrigin,u=n.yOrigin,b=n.xUnit,x=n.yUnit,h=n.gridCache,f=R(l[0],o,b,y),i=R(l[1],u,x,y),w=h[f]?h[f][i]?h[f][i]:[]:[];t=F(w.map(v=>t.features[v]))}g=rt(e,t)}return d&&d(g),g?nt(e,g,s):vt(e,r,a,s)}function R(e,t,n,r){let a=Math.floor((e-t)/n);return a>=r&&(a=r-1),a}function At(e,t){let n=it(e-t[0]),r=Math.PI*2,a;for(let s=0;s<t.length;s++){const c=(s+1)%t.length,d=it(e-t[c]),g=Math.min(Math.abs(n),Math.abs(d));n*d<=0&&g<r&&(r=g,a=s),n=d}return a}function it(e,t=!1){const n=t?function(r){return!(r>=0&&r<Math.PI*2)}:function(r){return!(r>-1*Math.PI&&r<=Math.PI)};for(;n(e);)e=e+2*Math.PI*(e>0?-1:1);return e}const L=2.00703,T=class T{constructor(){_(this,"points",[]);_(this,"pointsWeightBuffer");_(this,"strict_status");_(this,"vertices_params");_(this,"centroid");_(this,"edgeNodes");_(this,"edges");_(this,"tins");_(this,"kinks");_(this,"yaxisMode",T.YAXIS_INVERT);_(this,"strictMode",T.MODE_AUTO);_(this,"vertexMode",T.VERTEX_PLAIN);_(this,"bounds");_(this,"boundsPolygon");_(this,"wh");_(this,"xy");_(this,"indexedTins");_(this,"stateFull",!1);_(this,"stateTriangle");_(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((r,a)=>{const s=t.weight_buffer[a];return s&&(r[a]=Object.keys(s).reduce((c,d)=>{const g=tt(d);return c[g]=s[d],c},{})),r},{}):t.weight_buffer,t.strict_status?this.strict_status=t.strict_status:t.kinks_points?this.strict_status=T.STATUS_ERROR:t.tins_points.length==2?this.strict_status=T.STATUS_LOOSE:this.strict_status=T.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(r=>{const a=(r+1)%4,s=V(["c",`b${r}`,`b${a}`],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(r=>{const a=(r+1)%4,s=V(["c",`b${r}`,`b${a}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,L);return F([s])}),this.centroid={forw:$(t.centroid_point[0],{target:{geom:t.centroid_point[1],index:"c"}}),bakw:$(t.centroid_point[1],{target:{geom:t.centroid_point[0],index:"c"}})},this.edges=et(t.edges||[]),this.edgeNodes=t.edgeNodes||[];const n=t.tins_points.length==1?0:1;this.tins={forw:F(t.tins_points[0].map(r=>V(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:F(t.tins_points[n].map(r=>V(r,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(r=>$(r)))}),t.yaxisMode?this.yaxisMode=t.yaxisMode:this.yaxisMode=T.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 n=[];for(let r=0;r<this.tins.forw.features.length;r++){const a=this.tins.forw.features[r];["a","b","c"].map((s,c)=>{const d=a.geometry.coordinates[0][c],g=a.properties[s].geom,l=a.properties[s].index;typeof l=="number"&&(n[l]=[d,g])})}this.points=n}}addIndexedTin(){const t=this.tins,n=t.forw,r=t.bakw,a=Math.ceil(Math.sqrt(n.features.length));if(a<3){this.indexedTins=void 0;return}let s=[],c=[];const d=n.features.map(h=>{let f=[];return Z(h)[0].map(i=>{s.length===0?s=[Array.from(i),Array.from(i)]:(i[0]<s[0][0]&&(s[0][0]=i[0]),i[0]>s[1][0]&&(s[1][0]=i[0]),i[1]<s[0][1]&&(s[0][1]=i[1]),i[1]>s[1][1]&&(s[1][1]=i[1])),f.length===0?f=[Array.from(i),Array.from(i)]:(i[0]<f[0][0]&&(f[0][0]=i[0]),i[0]>f[1][0]&&(f[1][0]=i[0]),i[1]<f[0][1]&&(f[0][1]=i[1]),i[1]>f[1][1]&&(f[1][1]=i[1]))}),f}),g=(s[1][0]-s[0][0])/a,l=(s[1][1]-s[0][1])/a,y=d.reduce((h,f,i)=>{const w=R(f[0][0],s[0][0],g,a),v=R(f[1][0],s[0][0],g,a),A=R(f[0][1],s[0][1],l,a),E=R(f[1][1],s[0][1],l,a);for(let m=w;m<=v;m++){h[m]||(h[m]=[]);for(let M=A;M<=E;M++)h[m][M]||(h[m][M]=[]),h[m][M].push(i)}return h},[]),o=r.features.map(h=>{let f=[];return Z(h)[0].map(i=>{c.length===0?c=[Array.from(i),Array.from(i)]:(i[0]<c[0][0]&&(c[0][0]=i[0]),i[0]>c[1][0]&&(c[1][0]=i[0]),i[1]<c[0][1]&&(c[0][1]=i[1]),i[1]>c[1][1]&&(c[1][1]=i[1])),f.length===0?f=[Array.from(i),Array.from(i)]:(i[0]<f[0][0]&&(f[0][0]=i[0]),i[0]>f[1][0]&&(f[1][0]=i[0]),i[1]<f[0][1]&&(f[0][1]=i[1]),i[1]>f[1][1]&&(f[1][1]=i[1]))}),f}),u=(c[1][0]-c[0][0])/a,b=(c[1][1]-c[0][1])/a,x=o.reduce((h,f,i)=>{const w=R(f[0][0],c[0][0],u,a),v=R(f[1][0],c[0][0],u,a),A=R(f[0][1],c[0][1],b,a),E=R(f[1][1],c[0][1],b,a);for(let m=w;m<=v;m++){h[m]||(h[m]=[]);for(let M=A;M<=E;M++)h[m][M]||(h[m][M]=[]),h[m][M].push(i)}return h},[]);this.indexedTins={forw:{gridNum:a,xOrigin:s[0][0],yOrigin:s[0][1],xUnit:g,yUnit:l,gridCache:y},bakw:{gridNum:a,xOrigin:c[0][0],yOrigin:c[0][1],xUnit:u,yUnit:b,gridCache:x}}}transform(t,n,r){if(n&&this.strict_status==T.STATUS_ERROR)throw'Backward transform is not allowed if strict_status == "strict_error"';this.yaxisMode==T.YAXIS_FOLLOW&&n&&(t=[t[0],-1*t[1]]);const a=$(t);if(this.bounds&&!n&&!r&&!q(a,this.boundsPolygon))return!1;const s=n?this.tins.bakw:this.tins.forw,c=n?this.indexedTins.bakw:this.indexedTins.forw,d=n?this.vertices_params.bakw:this.vertices_params.forw,g=n?this.centroid.bakw:this.centroid.forw,l=n?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let y,o;this.stateFull&&(this.stateBackward==n?y=this.stateTriangle:(this.stateBackward=n,this.stateTriangle=void 0),o=b=>{this.stateTriangle=b});let u=st(a,s,c,d,g,l,y,o);if(this.bounds&&n&&!r){const b=$(u);if(!q(b,this.boundsPolygon))return!1}else this.yaxisMode==T.YAXIS_FOLLOW&&!n&&(u=[u[0],-1*u[1]]);return u}};_(T,"VERTEX_PLAIN","plain"),_(T,"VERTEX_BIRDEYE","birdeye"),_(T,"MODE_STRICT","strict"),_(T,"MODE_AUTO","auto"),_(T,"MODE_LOOSE","loose"),_(T,"STATUS_STRICT","strict"),_(T,"STATUS_ERROR","strict_error"),_(T,"STATUS_LOOSE","loose"),_(T,"YAXIS_FOLLOW","follow"),_(T,"YAXIS_INVERT","invert");let j=T;p.Transform=j,p.counterTri=xt,p.format_version=L,p.normalizeEdges=et,p.rotateVerticesTriangle=mt,p.transformArr=st,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(P,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(P=typeof globalThis<"u"?globalThis:P||self,k(P.maplat_transform={}))})(this,(function(P){"use strict";var Xt=Object.defineProperty;var Wt=(P,k,R)=>k in P?Xt(P,k,{enumerable:!0,configurable:!0,writable:!0,value:R}):P[k]=R;var x=(P,k,R)=>Wt(P,typeof k!="symbol"?k+"":k,R);function k(t,e,r={}){const n={type:"Feature"};return(r.id===0||r.id)&&(n.id=r.id),r.bbox&&(n.bbox=r.bbox),n.properties=e||{},n.geometry=t,n}function R(t,e,r={}){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(!J(t[0])||!J(t[1]))throw new Error("coordinates must contain numbers");return k({type:"Point",coordinates:t},e,r)}function G(t,e,r={}){for(const c of t){if(c.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(c[c.length-1].length!==c[0].length)throw new Error("First and last Position are not equivalent.");for(let i=0;i<c[c.length-1].length;i++)if(c[c.length-1][i]!==c[0][i])throw new Error("First and last Position are not equivalent.")}return k({type:"Polygon",coordinates:t},e,r)}function W(t,e={}){const r={type:"FeatureCollection"};return e.id&&(r.id=e.id),e.bbox&&(r.bbox=e.bbox),r.features=t,r}function J(t){return!isNaN(t)&&t!==null&&!Array.isArray(t)}function at(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 K(t){if(Array.isArray(t))return t;if(t.type==="Feature"){if(t.geometry!==null)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}function ct(t){return t.type==="Feature"?t.geometry:t}const F=11102230246251565e-32,S=134217729,ut=(3+8*F)*F;function $(t,e,r,n,c){let i,f,g,h,l=e[0],y=n[0],o=0,u=0;y>l==y>-l?(i=l,l=e[++o]):(i=y,y=n[++u]);let b=0;if(o<t&&u<r)for(y>l==y>-l?(f=l+i,g=i-(f-l),l=e[++o]):(f=y+i,g=i-(f-y),y=n[++u]),i=f,g!==0&&(c[b++]=g);o<t&&u<r;)y>l==y>-l?(f=i+l,h=f-i,g=i-(f-h)+(l-h),l=e[++o]):(f=i+y,h=f-i,g=i-(f-h)+(y-h),y=n[++u]),i=f,g!==0&&(c[b++]=g);for(;o<t;)f=i+l,h=f-i,g=i-(f-h)+(l-h),l=e[++o],i=f,g!==0&&(c[b++]=g);for(;u<r;)f=i+y,h=f-i,g=i-(f-h)+(y-h),y=n[++u],i=f,g!==0&&(c[b++]=g);return(i!==0||b===0)&&(c[b++]=i),b}function ft(t,e){let r=e[0];for(let n=1;n<t;n++)r+=e[n];return r}function Y(t){return new Float64Array(t)}const dt=(3+16*F)*F,ht=(2+12*F)*F,gt=(9+64*F)*F*F,V=Y(4),Q=Y(8),H=Y(12),Z=Y(16),T=Y(4);function lt(t,e,r,n,c,i,f){let g,h,l,y,o,u,b,p,d,a,s,m,v,M,_,w,A,O;const I=t-c,N=r-c,B=e-i,C=n-i;M=I*C,u=S*I,b=u-(u-I),p=I-b,u=S*C,d=u-(u-C),a=C-d,_=p*a-(M-b*d-p*d-b*a),w=B*N,u=S*B,b=u-(u-B),p=B-b,u=S*N,d=u-(u-N),a=N-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,V[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,V[1]=v-(s+o)+(o-w),O=m+s,o=O-m,V[2]=m-(O-o)+(s-o),V[3]=O;let X=ft(4,V),L=ht*f;if(X>=L||-X>=L||(o=t-I,g=t-(I+o)+(o-c),o=r-N,l=r-(N+o)+(o-c),o=e-B,h=e-(B+o)+(o-i),o=n-C,y=n-(C+o)+(o-i),g===0&&h===0&&l===0&&y===0)||(L=gt*f+ut*Math.abs(X),X+=I*y+C*g-(B*l+N*h),X>=L||-X>=L))return X;M=g*C,u=S*g,b=u-(u-g),p=g-b,u=S*C,d=u-(u-C),a=C-d,_=p*a-(M-b*d-p*d-b*a),w=h*N,u=S*h,b=u-(u-h),p=h-b,u=S*N,d=u-(u-N),a=N-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Rt=$(4,V,4,T,Q);M=I*y,u=S*I,b=u-(u-I),p=I-b,u=S*y,d=u-(u-y),a=y-d,_=p*a-(M-b*d-p*d-b*a),w=B*l,u=S*B,b=u-(u-B),p=B-b,u=S*l,d=u-(u-l),a=l-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Ut=$(Rt,Q,4,T,H);M=g*y,u=S*g,b=u-(u-g),p=g-b,u=S*y,d=u-(u-y),a=y-d,_=p*a-(M-b*d-p*d-b*a),w=h*l,u=S*h,b=u-(u-h),p=h-b,u=S*l,d=u-(u-l),a=l-d,A=p*a-(w-b*d-p*d-b*a),s=_-A,o=_-s,T[0]=_-(s+o)+(o-A),m=M+s,o=m-M,v=M-(m-o)+(s-o),s=v-w,o=v-s,T[1]=v-(s+o)+(o-w),O=m+s,o=O-m,T[2]=m-(O-o)+(s-o),T[3]=O;const Ft=$(Ut,H,4,T,Z);return Z[Ft-1]}function yt(t,e,r,n,c,i){const f=(e-i)*(r-c),g=(t-c)*(n-i),h=f-g,l=Math.abs(f+g);return Math.abs(h)>=dt*l?h:-lt(t,e,r,n,c,i,l)}function bt(t,e){var r,n,c=0,i,f,g,h,l,y,o,u=t[0],b=t[1],p=e.length;for(r=0;r<p;r++){n=0;var d=e[r],a=d.length-1;if(y=d[0],y[0]!==d[a][0]&&y[1]!==d[a][1])throw new Error("First and last coordinates in a ring must be the same");for(f=y[0]-u,g=y[1]-b,n;n<a;n++){if(o=d[n+1],h=o[0]-u,l=o[1]-b,g===0&&l===0){if(h<=0&&f>=0||f<=0&&h>=0)return 0}else if(l>=0&&g<=0||l<=0&&g>=0){if(i=yt(f,h,g,l,0,0),i===0)return 0;(i>0&&l>0&&g<=0||i<0&&l<=0&&g>0)&&c++}y=o,g=l,f=h}}return c%2!==0}function D(t,e,r={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const n=at(t),c=ct(e),i=c.type,f=e.bbox;let g=c.coordinates;if(f&&mt(n,f)===!1)return!1;i==="Polygon"&&(g=[g]);let h=!1;for(var l=0;l<g.length;++l){const y=bt(n,g[l]);if(y===0)return!r.ignoreBoundary;y&&(h=!0)}return h}function mt(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}function tt(t,e){for(let r=0;r<e.features.length;r++)if(D(t,e.features[r]))return e.features[r]}function et(t,e,r){const n=e.geometry.coordinates[0][0],c=e.geometry.coordinates[0][1],i=e.geometry.coordinates[0][2],f=t.geometry.coordinates,g=e.properties.a.geom,h=e.properties.b.geom,l=e.properties.c.geom,y=[c[0]-n[0],c[1]-n[1]],o=[i[0]-n[0],i[1]-n[1]],u=[f[0]-n[0],f[1]-n[1]],b=[h[0]-g[0],h[1]-g[1]],p=[l[0]-g[0],l[1]-g[1]];let d=(o[1]*u[0]-o[0]*u[1])/(y[0]*o[1]-y[1]*o[0]),a=(y[0]*u[1]-y[1]*u[0])/(y[0]*o[1]-y[1]*o[0]);if(r){const s=r[e.properties.a.index],m=r[e.properties.b.index],v=r[e.properties.c.index];let M;if(d<0||a<0||1-d-a<0){const _=d/(d+a),w=a/(d+a);M=d/m/(_/m+w/v),a=a/v/(_/m+w/v)}else M=d/m/(d/m+a/v+(1-d-a)/s),a=a/v/(d/m+a/v+(1-d-a)/s);d=M}return[d*b[0]+a*p[0]+g[0],d*b[1]+a*p[1]+g[1]]}function wt(t,e,r,n){const c=t.geometry.coordinates,i=r.geometry.coordinates,f=Math.atan2(c[0]-i[0],c[1]-i[1]),g=xt(f,e[0]);if(g===void 0)throw new Error("Unable to determine vertex index");const h=e[1][g];return et(t,h.features[0],n)}function rt(t,e,r,n,c,i,f,g){let h;if(f&&(h=tt(t,W([f]))),!h){if(r){const l=t.geometry.coordinates,y=r.gridNum,o=r.xOrigin,u=r.yOrigin,b=r.xUnit,p=r.yUnit,d=r.gridCache,a=U(l[0],o,b,y),s=U(l[1],u,p,y),m=d[a]?d[a][s]?d[a][s]:[]:[];e=W(m.map(v=>e.features[v]))}h=tt(t,e)}return g&&g(h),h?et(t,h,i):wt(t,n,c,i)}function U(t,e,r,n){let c=Math.floor((t-e)/r);return c>=n&&(c=n-1),c}function xt(t,e){let r=nt(t-e[0]),n=Math.PI*2,c;for(let i=0;i<e.length;i++){const f=(i+1)%e.length,g=nt(t-e[f]),h=Math.min(Math.abs(r),Math.abs(g));r*g<=0&&h<n&&(n=h,c=i),r=g}return c}function nt(t,e=!1){const r=e?function(n){return!(n>=0&&n<Math.PI*2)}:function(n){return!(n>-1*Math.PI&&n<=Math.PI)};for(;r(t);)t=t+2*Math.PI*(t>0?-1:1);return t}function it(t,e){return e&&e>=2.00703||Array.isArray(t[0])?t:t.map(r=>[r.illstNodes,r.mercNodes,r.startEnd])}function pt(t){const e=t.features;for(let r=0;r<e.length;r++){const n=e[r];`${n.properties.a.index}`.substring(0,1)==="b"&&`${n.properties.b.index}`.substring(0,1)==="b"?e[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1],n.geometry.coordinates[0][2]]]},properties:{a:{geom:n.properties.c.geom,index:n.properties.c.index},b:{geom:n.properties.a.geom,index:n.properties.a.index},c:{geom:n.properties.b.geom,index:n.properties.b.index}},type:"Feature"}:`${n.properties.c.index}`.substring(0,1)==="b"&&`${n.properties.a.index}`.substring(0,1)==="b"&&(e[r]={geometry:{type:"Polygon",coordinates:[[n.geometry.coordinates[0][1],n.geometry.coordinates[0][2],n.geometry.coordinates[0][0],n.geometry.coordinates[0][1]]]},properties:{a:{geom:n.properties.b.geom,index:n.properties.b.index},b:{geom:n.properties.c.geom,index:n.properties.c.index},c:{geom:n.properties.a.geom,index:n.properties.a.index}},type:"Feature"})}return t}function vt(t){const e=["a","b","c","a"].map(i=>t.properties[i].geom),r=t.geometry.coordinates[0],n=t.properties,c={a:{geom:r[0],index:n.a.index},b:{geom:r[1],index:n.b.index},c:{geom:r[2],index:n.c.index}};return G([e],c)}function Mt(t){const e=[0,1,2,0].map(n=>t[n][0][0]),r={a:{geom:t[0][0][1],index:t[0][1]},b:{geom:t[1][0][1],index:t[1][1]},c:{geom:t[2][0][1],index:t[2][1]}};return G([e],r)}function q(t,e,r,n,c,i=!1,f){const g=t.map(h=>{(!f||f<2.00703)&&(h=st(h));const l=isFinite(h)?e[h]:h==="c"?n:h==="b0"?c[0]:h==="b1"?c[1]:h==="b2"?c[2]:h==="b3"?c[3]:(function(){const y=h.match(/e(\d+)/);if(y){const o=parseInt(y[1]);return r[o]}throw"Bad index value for indexesToTri"})();return i?[[l[1],l[0]],h]:[[l[0],l[1]],h]});return Mt(g)}function st(t){return typeof t=="number"?t:t.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/,"$1$2")}const z=2.00703;function At(t){return!!(t.version||!t.tins&&t.points&&t.tins_points)}function _t(t){return{points:t.points,pointsWeightBuffer:Pt(t),strictStatus:St(t),verticesParams:Ot(t),centroid:Tt(t),edges:it(t.edges||[]),edgeNodes:t.edgeNodes||[],tins:kt(t),kinks:It(t.kinks_points),yaxisMode:t.yaxisMode??"invert",strictMode:t.strictMode??"auto",vertexMode:t.vertexMode,bounds:t.bounds,boundsPolygon:t.boundsPolygon,wh:t.wh,xy:t.bounds?t.xy:[0,0]}}function Et(t){const e=Nt(t),r=e.tins;return{compiled:e,tins:r,points:Bt(r),strictStatus:e.strict_status,pointsWeightBuffer:e.weight_buffer,verticesParams:e.vertices_params,centroid:e.centroid,kinks:e.kinks}}function Pt(t){return!t.version||t.version<z?["forw","bakw"].reduce((e,r)=>{const n=t.weight_buffer[r];return n&&(e[r]=Object.keys(n).reduce((c,i)=>{const f=st(i);return c[f]=n[i],c},{})),e},{}):t.weight_buffer}function St(t){return t.strict_status?t.strict_status:t.kinks_points?"strict_error":t.tins_points.length===2?"loose":"strict"}function Ot(t){const e={forw:[t.vertices_params[0]],bakw:[t.vertices_params[1]]};return e.forw[1]=ot(t,!1),e.bakw[1]=ot(t,!0),e}function ot(t,e){return[0,1,2,3].map(r=>{const n=(r+1)%4,c=q(["c",`b${r}`,`b${n}`],t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,e,z);return W([c])})}function Tt(t){return{forw:R(t.centroid_point[0],{target:{geom:t.centroid_point[1],index:"c"}}),bakw:R(t.centroid_point[1],{target:{geom:t.centroid_point[0],index:"c"}})}}function kt(t){const e=t.tins_points.length===1?0:1;return{forw:W(t.tins_points[0].map(r=>q(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:W(t.tins_points[e].map(r=>q(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!0,t.version)))}}function It(t){if(t)return{bakw:W(t.map(e=>R(e)))}}function Nt(t){return JSON.parse(JSON.stringify(t).replace('"cent"','"c"').replace(/"bbox(\d+)"/g,'"b$1"'))}function Bt(t){const e=[],r=t.forw.features;for(let n=0;n<r.length;n++){const c=r[n];["a","b","c"].map((i,f)=>{const g=c.geometry.coordinates[0][f],h=c.properties[i].geom,l=c.properties[i].index;typeof l=="number"&&(e[l]=[g,h])})}return e}const Ct=z,E=class E{constructor(){x(this,"points",[]);x(this,"pointsWeightBuffer");x(this,"strict_status");x(this,"vertices_params");x(this,"centroid");x(this,"edgeNodes");x(this,"edges");x(this,"tins");x(this,"kinks");x(this,"yaxisMode",E.YAXIS_INVERT);x(this,"strictMode",E.MODE_AUTO);x(this,"vertexMode",E.VERTEX_PLAIN);x(this,"bounds");x(this,"boundsPolygon");x(this,"wh");x(this,"xy");x(this,"indexedTins");x(this,"stateFull",!1);x(this,"stateTriangle");x(this,"stateBackward");x(this,"priority");x(this,"importance");x(this,"xyBounds");x(this,"mercBounds")}setCompiled(e){if(At(e)){this.applyModernState(_t(e));return}this.applyLegacyState(Et(e))}applyModernState(e){this.points=e.points,this.pointsWeightBuffer=e.pointsWeightBuffer,this.strict_status=e.strictStatus,this.vertices_params=e.verticesParams,this.centroid=e.centroid,this.edges=e.edges,this.edgeNodes=e.edgeNodes||[],this.tins=e.tins,this.addIndexedTin(),this.kinks=e.kinks,this.yaxisMode=e.yaxisMode??E.YAXIS_INVERT,this.vertexMode=e.vertexMode??E.VERTEX_PLAIN,this.strictMode=e.strictMode??E.MODE_AUTO,e.bounds?(this.bounds=e.bounds,this.boundsPolygon=e.boundsPolygon,this.xy=e.xy,this.wh=e.wh):(this.bounds=void 0,this.boundsPolygon=void 0,this.xy=e.xy??[0,0],e.wh&&(this.wh=e.wh))}applyLegacyState(e){this.tins=e.tins,this.addIndexedTin(),this.strict_status=e.strictStatus,this.pointsWeightBuffer=e.pointsWeightBuffer,this.vertices_params=e.verticesParams,this.centroid=e.centroid,this.kinks=e.kinks,this.points=e.points}addIndexedTin(){const e=this.tins,r=e.forw,n=e.bakw,c=Math.ceil(Math.sqrt(r.features.length));if(c<3){this.indexedTins=void 0;return}let i=[],f=[];const g=r.features.map(d=>{let a=[];return K(d)[0].map(s=>{i.length===0?i=[Array.from(s),Array.from(s)]:(s[0]<i[0][0]&&(i[0][0]=s[0]),s[0]>i[1][0]&&(i[1][0]=s[0]),s[1]<i[0][1]&&(i[0][1]=s[1]),s[1]>i[1][1]&&(i[1][1]=s[1])),a.length===0?a=[Array.from(s),Array.from(s)]:(s[0]<a[0][0]&&(a[0][0]=s[0]),s[0]>a[1][0]&&(a[1][0]=s[0]),s[1]<a[0][1]&&(a[0][1]=s[1]),s[1]>a[1][1]&&(a[1][1]=s[1]))}),a}),h=(i[1][0]-i[0][0])/c,l=(i[1][1]-i[0][1])/c,y=g.reduce((d,a,s)=>{const m=U(a[0][0],i[0][0],h,c),v=U(a[1][0],i[0][0],h,c),M=U(a[0][1],i[0][1],l,c),_=U(a[1][1],i[0][1],l,c);for(let w=m;w<=v;w++){d[w]||(d[w]=[]);for(let A=M;A<=_;A++)d[w][A]||(d[w][A]=[]),d[w][A].push(s)}return d},[]),o=n.features.map(d=>{let a=[];return K(d)[0].map(s=>{f.length===0?f=[Array.from(s),Array.from(s)]:(s[0]<f[0][0]&&(f[0][0]=s[0]),s[0]>f[1][0]&&(f[1][0]=s[0]),s[1]<f[0][1]&&(f[0][1]=s[1]),s[1]>f[1][1]&&(f[1][1]=s[1])),a.length===0?a=[Array.from(s),Array.from(s)]:(s[0]<a[0][0]&&(a[0][0]=s[0]),s[0]>a[1][0]&&(a[1][0]=s[0]),s[1]<a[0][1]&&(a[0][1]=s[1]),s[1]>a[1][1]&&(a[1][1]=s[1]))}),a}),u=(f[1][0]-f[0][0])/c,b=(f[1][1]-f[0][1])/c,p=o.reduce((d,a,s)=>{const m=U(a[0][0],f[0][0],u,c),v=U(a[1][0],f[0][0],u,c),M=U(a[0][1],f[0][1],b,c),_=U(a[1][1],f[0][1],b,c);for(let w=m;w<=v;w++){d[w]||(d[w]=[]);for(let A=M;A<=_;A++)d[w][A]||(d[w][A]=[]),d[w][A].push(s)}return d},[]);this.indexedTins={forw:{gridNum:c,xOrigin:i[0][0],yOrigin:i[0][1],xUnit:h,yUnit:l,gridCache:y},bakw:{gridNum:c,xOrigin:f[0][0],yOrigin:f[0][1],xUnit:u,yUnit:b,gridCache:p}}}transform(e,r,n){if(r&&this.strict_status==E.STATUS_ERROR)throw'Backward transform is not allowed if strict_status == "strict_error"';this.yaxisMode==E.YAXIS_FOLLOW&&r&&(e=[e[0],-1*e[1]]);const c=R(e);if(this.bounds&&!r&&!n&&!D(c,this.boundsPolygon))return!1;const i=r?this.tins.bakw:this.tins.forw,f=r?this.indexedTins.bakw:this.indexedTins.forw,g=r?this.vertices_params.bakw:this.vertices_params.forw,h=r?this.centroid.bakw:this.centroid.forw,l=r?this.pointsWeightBuffer.bakw:this.pointsWeightBuffer.forw;let y,o;this.stateFull&&(this.stateBackward==r?y=this.stateTriangle:(this.stateBackward=r,this.stateTriangle=void 0),o=b=>{this.stateTriangle=b});let u=rt(c,i,f,g,h,l,y,o);if(this.bounds&&r&&!n){const b=R(u);if(!D(b,this.boundsPolygon))return!1}else this.yaxisMode==E.YAXIS_FOLLOW&&!r&&(u=[u[0],-1*u[1]]);return u}};x(E,"VERTEX_PLAIN","plain"),x(E,"VERTEX_BIRDEYE","birdeye"),x(E,"MODE_STRICT","strict"),x(E,"MODE_AUTO","auto"),x(E,"MODE_LOOSE","loose"),x(E,"STATUS_STRICT","strict"),x(E,"STATUS_ERROR","strict_error"),x(E,"STATUS_LOOSE","loose"),x(E,"YAXIS_FOLLOW","follow"),x(E,"YAXIS_INVERT","invert");let j=E;P.Transform=j,P.counterTri=vt,P.format_version=Ct,P.normalizeEdges=it,P.rotateVerticesTriangle=pt,P.transformArr=rt,Object.defineProperty(P,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -4,45 +4,30 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.4.0",
|
|
8
8
|
"description": "A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.",
|
|
9
9
|
"type": "module",
|
|
10
|
-
"
|
|
10
|
+
"engines": {
|
|
11
|
+
"pnpm": ">=9",
|
|
12
|
+
"node": ">=20"
|
|
13
|
+
},
|
|
11
14
|
"module": "./dist/maplat_transform.js",
|
|
12
15
|
"browser": "./dist/maplat_transform.umd.js",
|
|
13
16
|
"types": "./dist/index.d.ts",
|
|
14
17
|
"exports": {
|
|
15
18
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"require": "./dist/maplat_transform.cjs",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
18
20
|
"browser": "./dist/maplat_transform.umd.js",
|
|
19
|
-
"
|
|
21
|
+
"import": "./dist/maplat_transform.js",
|
|
22
|
+
"default": "./dist/maplat_transform.js"
|
|
20
23
|
}
|
|
21
24
|
},
|
|
22
25
|
"files": [
|
|
23
26
|
"dist",
|
|
24
27
|
"src",
|
|
25
|
-
"README.md"
|
|
28
|
+
"README.md",
|
|
29
|
+
"README.ja.md"
|
|
26
30
|
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"dev": "vite",
|
|
29
|
-
"build": "npm run typecheck && cross-env BUILD_MODE=package vite build",
|
|
30
|
-
"typecheck": "tsc --noEmit --allowImportingTsExtensions",
|
|
31
|
-
"deploy": "cp public/*.html ./ && tsc && vite build",
|
|
32
|
-
"test": "vitest run",
|
|
33
|
-
"test:watch": "vitest",
|
|
34
|
-
"coverage": "vitest run --coverage",
|
|
35
|
-
"lint": "eslint src tests",
|
|
36
|
-
"prepublishOnly": "npm run lint && npm run typecheck && npm run test && npm run build",
|
|
37
|
-
"version:bump": "node scripts/bump-version.js",
|
|
38
|
-
"version:sync": "node scripts/sync-version.js",
|
|
39
|
-
"publish:npm": "node scripts/publish-npm.js",
|
|
40
|
-
"publish:npm:dry": "node scripts/publish-npm.js --dry-run",
|
|
41
|
-
"publish:deno": "node scripts/publish-deno.js",
|
|
42
|
-
"publish:deno:dry": "node scripts/publish-deno.js --dry-run",
|
|
43
|
-
"publish:all": "node scripts/publish-all.js",
|
|
44
|
-
"publish:all:dry": "node scripts/publish-all.js --dry-run"
|
|
45
|
-
},
|
|
46
31
|
"repository": {
|
|
47
32
|
"type": "git",
|
|
48
33
|
"url": "git+https://github.com/code4history/MaplatTransform.git"
|
|
@@ -59,29 +44,40 @@
|
|
|
59
44
|
"Maplat",
|
|
60
45
|
"MaplatTransform"
|
|
61
46
|
],
|
|
62
|
-
"peerDependencies": {},
|
|
63
47
|
"devDependencies": {
|
|
64
|
-
"@eslint/js": "^9.
|
|
65
|
-
"@
|
|
66
|
-
"@types/
|
|
67
|
-
"@
|
|
68
|
-
"@typescript-eslint/
|
|
69
|
-
"@typescript-eslint/parser": "^8.18.2",
|
|
48
|
+
"@eslint/js": "^9.39.2",
|
|
49
|
+
"@types/geojson": "^7946.0.16",
|
|
50
|
+
"@types/node": "^24.10.4",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
52
|
+
"@typescript-eslint/parser": "^8.50.1",
|
|
70
53
|
"@vitest/coverage-v8": "^3.2.4",
|
|
71
|
-
"cross-env": "^
|
|
72
|
-
"eslint": "^9.
|
|
73
|
-
"eslint-config-prettier": "^
|
|
54
|
+
"cross-env": "^10.1.0",
|
|
55
|
+
"eslint": "^9.39.2",
|
|
56
|
+
"eslint-config-prettier": "^10.1.8",
|
|
74
57
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
75
|
-
"jsdom": "^
|
|
76
|
-
"prettier": "^3.4
|
|
77
|
-
"typescript": "^5.
|
|
78
|
-
"vite": "^6.
|
|
79
|
-
"vite-plugin-dts": "^4.4
|
|
58
|
+
"jsdom": "^27.4.0",
|
|
59
|
+
"prettier": "^3.7.4",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"vite": "^6.4.1",
|
|
62
|
+
"vite-plugin-dts": "^4.5.4",
|
|
80
63
|
"vitest": "^3.2.4"
|
|
81
64
|
},
|
|
82
65
|
"dependencies": {
|
|
83
|
-
"@turf/
|
|
84
|
-
|
|
85
|
-
|
|
66
|
+
"@turf/turf": "^7.3.1"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"dev": "vite --host",
|
|
70
|
+
"build": "pnpm run typecheck && cross-env BUILD_MODE=package vite build",
|
|
71
|
+
"typecheck": "tsc --noEmit --allowImportingTsExtensions",
|
|
72
|
+
"build:demo": "vite build",
|
|
73
|
+
"deploy": "pnpm run build:demo",
|
|
74
|
+
"test": "vitest run",
|
|
75
|
+
"test:watch": "vitest",
|
|
76
|
+
"coverage": "vitest run --coverage",
|
|
77
|
+
"lint": "eslint src tests",
|
|
78
|
+
"version:bump": "node scripts/bump-version.js",
|
|
79
|
+
"version:sync": "node scripts/sync-version.js",
|
|
80
|
+
"publish:npm": "node scripts/publish-npm.js",
|
|
81
|
+
"publish:npm:dry": "node scripts/publish-npm.js --dry-run"
|
|
86
82
|
}
|
|
87
|
-
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { featureCollection, point } from "@turf/turf";
|
|
2
|
+
import type { Position } from "geojson";
|
|
3
|
+
import { normalizeEdges } from "./edgeutils.ts";
|
|
4
|
+
import { indexesToTri, normalizeNodeKey } from "./triangulation.ts";
|
|
5
|
+
import type { PropertyTriKey } from "./geometry.ts";
|
|
6
|
+
import type {
|
|
7
|
+
BiDirectionKey,
|
|
8
|
+
Compiled,
|
|
9
|
+
CompiledLegacy,
|
|
10
|
+
LegacyStatePayload,
|
|
11
|
+
ModernStatePayload,
|
|
12
|
+
PointSet,
|
|
13
|
+
StrictStatus,
|
|
14
|
+
TinsBD,
|
|
15
|
+
VerticesParamsBD,
|
|
16
|
+
WeightBufferBD
|
|
17
|
+
} from "./types.ts";
|
|
18
|
+
import type { WeightBuffer } from "./geometry.ts";
|
|
19
|
+
|
|
20
|
+
export const FORMAT_VERSION = 2.00703;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for discriminating modern compiled payloads.
|
|
24
|
+
*/
|
|
25
|
+
export function isModernCompiled(
|
|
26
|
+
compiled: Compiled | CompiledLegacy
|
|
27
|
+
): compiled is Compiled {
|
|
28
|
+
return Boolean(
|
|
29
|
+
compiled.version ||
|
|
30
|
+
(!(compiled as CompiledLegacy).tins && compiled.points && compiled.tins_points)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Restore the in-memory state produced by modern compiled payloads.
|
|
36
|
+
*/
|
|
37
|
+
export function restoreModernState(compiled: Compiled): ModernStatePayload {
|
|
38
|
+
return {
|
|
39
|
+
points: compiled.points,
|
|
40
|
+
pointsWeightBuffer: normalizeWeightBuffer(compiled),
|
|
41
|
+
strictStatus: deriveStrictStatus(compiled),
|
|
42
|
+
verticesParams: buildVerticesParams(compiled),
|
|
43
|
+
centroid: buildCentroid(compiled),
|
|
44
|
+
edges: normalizeEdges(compiled.edges || []),
|
|
45
|
+
edgeNodes: compiled.edgeNodes || [],
|
|
46
|
+
tins: buildTins(compiled),
|
|
47
|
+
kinks: buildKinks(compiled.kinks_points),
|
|
48
|
+
yaxisMode: compiled.yaxisMode ?? "invert",
|
|
49
|
+
strictMode: compiled.strictMode ?? "auto",
|
|
50
|
+
vertexMode: compiled.vertexMode,
|
|
51
|
+
bounds: compiled.bounds,
|
|
52
|
+
boundsPolygon: compiled.boundsPolygon,
|
|
53
|
+
wh: compiled.wh,
|
|
54
|
+
xy: compiled.bounds ? compiled.xy : [0, 0]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Restore the in-memory state produced by the legacy payloads.
|
|
60
|
+
*/
|
|
61
|
+
export function restoreLegacyState(
|
|
62
|
+
rawCompiled: CompiledLegacy
|
|
63
|
+
): LegacyStatePayload {
|
|
64
|
+
const normalized = normalizeLegacyStructure(rawCompiled);
|
|
65
|
+
const tins = normalized.tins!;
|
|
66
|
+
return {
|
|
67
|
+
compiled: normalized,
|
|
68
|
+
tins,
|
|
69
|
+
points: rebuildLegacyPoints(tins),
|
|
70
|
+
strictStatus: normalized.strict_status,
|
|
71
|
+
pointsWeightBuffer: normalized.weight_buffer,
|
|
72
|
+
verticesParams: normalized.vertices_params as VerticesParamsBD,
|
|
73
|
+
centroid: normalized.centroid,
|
|
74
|
+
kinks: normalized.kinks
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function normalizeWeightBuffer(compiled: Compiled): WeightBufferBD {
|
|
79
|
+
if (!compiled.version || compiled.version < FORMAT_VERSION) {
|
|
80
|
+
return (["forw", "bakw"] as BiDirectionKey[]).reduce((bd, forb) => {
|
|
81
|
+
const base = compiled.weight_buffer[forb];
|
|
82
|
+
if (base) {
|
|
83
|
+
bd[forb] = Object.keys(base).reduce((buffer, key) => {
|
|
84
|
+
const normKey = normalizeNodeKey(key);
|
|
85
|
+
buffer[normKey] = base[key];
|
|
86
|
+
return buffer;
|
|
87
|
+
}, {} as WeightBuffer);
|
|
88
|
+
}
|
|
89
|
+
return bd;
|
|
90
|
+
}, {} as WeightBufferBD);
|
|
91
|
+
}
|
|
92
|
+
return compiled.weight_buffer;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function deriveStrictStatus(compiled: Compiled): StrictStatus {
|
|
96
|
+
if (compiled.strict_status) return compiled.strict_status;
|
|
97
|
+
if (compiled.kinks_points) return "strict_error";
|
|
98
|
+
if (compiled.tins_points.length === 2) return "loose";
|
|
99
|
+
return "strict";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function buildVerticesParams(compiled: Compiled): VerticesParamsBD {
|
|
103
|
+
const params: VerticesParamsBD = {
|
|
104
|
+
forw: [compiled.vertices_params[0]],
|
|
105
|
+
bakw: [compiled.vertices_params[1]]
|
|
106
|
+
};
|
|
107
|
+
params.forw![1] = buildVertexTins(compiled, false);
|
|
108
|
+
params.bakw![1] = buildVertexTins(compiled, true);
|
|
109
|
+
return params;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function buildVertexTins(compiled: Compiled, bakw: boolean) {
|
|
113
|
+
return [0, 1, 2, 3].map(idx => {
|
|
114
|
+
const idxNxt = (idx + 1) % 4;
|
|
115
|
+
const tri = indexesToTri(
|
|
116
|
+
["c", `b${idx}`, `b${idxNxt}`],
|
|
117
|
+
compiled.points,
|
|
118
|
+
compiled.edgeNodes || [],
|
|
119
|
+
compiled.centroid_point,
|
|
120
|
+
compiled.vertices_points,
|
|
121
|
+
bakw,
|
|
122
|
+
FORMAT_VERSION
|
|
123
|
+
);
|
|
124
|
+
return featureCollection([tri]);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function buildCentroid(compiled: Compiled) {
|
|
129
|
+
return {
|
|
130
|
+
forw: point(compiled.centroid_point[0], {
|
|
131
|
+
target: {
|
|
132
|
+
geom: compiled.centroid_point[1],
|
|
133
|
+
index: "c"
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
bakw: point(compiled.centroid_point[1], {
|
|
137
|
+
target: {
|
|
138
|
+
geom: compiled.centroid_point[0],
|
|
139
|
+
index: "c"
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function buildTins(compiled: Compiled) {
|
|
146
|
+
const bakwIndex = compiled.tins_points.length === 1 ? 0 : 1;
|
|
147
|
+
return {
|
|
148
|
+
forw: featureCollection(
|
|
149
|
+
compiled.tins_points[0].map(idxes =>
|
|
150
|
+
indexesToTri(
|
|
151
|
+
idxes,
|
|
152
|
+
compiled.points,
|
|
153
|
+
compiled.edgeNodes || [],
|
|
154
|
+
compiled.centroid_point,
|
|
155
|
+
compiled.vertices_points,
|
|
156
|
+
false,
|
|
157
|
+
compiled.version
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
),
|
|
161
|
+
bakw: featureCollection(
|
|
162
|
+
compiled.tins_points[bakwIndex].map(idxes =>
|
|
163
|
+
indexesToTri(
|
|
164
|
+
idxes,
|
|
165
|
+
compiled.points,
|
|
166
|
+
compiled.edgeNodes || [],
|
|
167
|
+
compiled.centroid_point,
|
|
168
|
+
compiled.vertices_points,
|
|
169
|
+
true,
|
|
170
|
+
compiled.version
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function buildKinks(kinksPoints?: Position[]) {
|
|
178
|
+
if (!kinksPoints) return undefined;
|
|
179
|
+
return {
|
|
180
|
+
bakw: featureCollection(
|
|
181
|
+
kinksPoints.map((coord: Position) => point(coord))
|
|
182
|
+
)
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function normalizeLegacyStructure(
|
|
187
|
+
compiled: CompiledLegacy
|
|
188
|
+
): CompiledLegacy {
|
|
189
|
+
return JSON.parse(
|
|
190
|
+
JSON.stringify(compiled)
|
|
191
|
+
.replace('"cent"', '"c"')
|
|
192
|
+
.replace(/"bbox(\d+)"/g, '"b$1"')
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function rebuildLegacyPoints(tins: TinsBD): PointSet[] {
|
|
197
|
+
const points: PointSet[] = [];
|
|
198
|
+
const features = tins.forw!.features;
|
|
199
|
+
for (let i = 0; i < features.length; i++) {
|
|
200
|
+
const tri = features[i];
|
|
201
|
+
(["a", "b", "c"] as PropertyTriKey[]).map((key, idx) => {
|
|
202
|
+
const forw = tri.geometry!.coordinates[0][idx];
|
|
203
|
+
const bakw = tri.properties![key].geom;
|
|
204
|
+
const pIdx = tri.properties![key].index;
|
|
205
|
+
if (typeof pIdx === "number") {
|
|
206
|
+
points[pIdx] = [forw, bakw];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return points;
|
|
211
|
+
}
|
package/src/edgeutils.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import type { Position } from "geojson";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* エッジの終点を表す型
|
|
5
|
-
* [始点のインデックス, 終点のインデックス]
|
|
6
|
-
*/
|
|
7
|
-
export type Edge = [number, number];
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* エッジセットの型
|
|
11
|
-
* [始点と終点の間の中間点群(地図座標系),
|
|
12
|
-
* 始点と終点の間の中間点群(変換先座標系),
|
|
13
|
-
* 始点と終点のインデックスペア]
|
|
14
|
-
*/
|
|
15
|
-
export type EdgeSet = [Position[], Position[], Edge];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 古いバージョンのエッジセット型
|
|
19
|
-
* @deprecated 2.00703以降は EdgeSet を使用
|
|
20
|
-
*/
|
|
21
|
-
export type EdgeSetLegacy = {
|
|
22
|
-
illstNodes: Position[];
|
|
23
|
-
mercNodes: Position[];
|
|
24
|
-
startEnd: Edge;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* エッジセットを正規化する
|
|
29
|
-
* 古いバージョンのフォーマットを新しいフォーマットに変換する
|
|
30
|
-
*
|
|
31
|
-
* @param edges エッジセット配列
|
|
32
|
-
* @param version バージョン番号(オプション)
|
|
33
|
-
* @returns 正規化されたエッジセット配列
|
|
34
|
-
*/
|
|
35
|
-
function normalizeEdges(
|
|
36
|
-
edges: EdgeSet[] | EdgeSetLegacy[],
|
|
37
|
-
version?: number
|
|
38
|
-
): EdgeSet[] {
|
|
39
|
-
if ((version && version >= 2.00703) || Array.isArray(edges[0]))
|
|
40
|
-
return edges as EdgeSet[];
|
|
41
|
-
return (edges as EdgeSetLegacy[]).map(edge => [
|
|
42
|
-
edge.illstNodes,
|
|
43
|
-
edge.mercNodes,
|
|
44
|
-
edge.startEnd
|
|
45
|
-
]);
|
|
46
|
-
}
|
|
47
|
-
|
|
1
|
+
import type { Position } from "geojson";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* エッジの終点を表す型
|
|
5
|
+
* [始点のインデックス, 終点のインデックス]
|
|
6
|
+
*/
|
|
7
|
+
export type Edge = [number, number];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* エッジセットの型
|
|
11
|
+
* [始点と終点の間の中間点群(地図座標系),
|
|
12
|
+
* 始点と終点の間の中間点群(変換先座標系),
|
|
13
|
+
* 始点と終点のインデックスペア]
|
|
14
|
+
*/
|
|
15
|
+
export type EdgeSet = [Position[], Position[], Edge];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 古いバージョンのエッジセット型
|
|
19
|
+
* @deprecated 2.00703以降は EdgeSet を使用
|
|
20
|
+
*/
|
|
21
|
+
export type EdgeSetLegacy = {
|
|
22
|
+
illstNodes: Position[];
|
|
23
|
+
mercNodes: Position[];
|
|
24
|
+
startEnd: Edge;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* エッジセットを正規化する
|
|
29
|
+
* 古いバージョンのフォーマットを新しいフォーマットに変換する
|
|
30
|
+
*
|
|
31
|
+
* @param edges エッジセット配列
|
|
32
|
+
* @param version バージョン番号(オプション)
|
|
33
|
+
* @returns 正規化されたエッジセット配列
|
|
34
|
+
*/
|
|
35
|
+
function normalizeEdges(
|
|
36
|
+
edges: EdgeSet[] | EdgeSetLegacy[],
|
|
37
|
+
version?: number
|
|
38
|
+
): EdgeSet[] {
|
|
39
|
+
if ((version && version >= 2.00703) || Array.isArray(edges[0]))
|
|
40
|
+
return edges as EdgeSet[];
|
|
41
|
+
return (edges as EdgeSetLegacy[]).map(edge => [
|
|
42
|
+
edge.illstNodes,
|
|
43
|
+
edge.mercNodes,
|
|
44
|
+
edge.startEnd
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
48
|
export { normalizeEdges };
|