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