@maplat/transform 0.1.4 → 0.2.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/README.md +74 -0
- package/dist/index.d.ts +3 -10
- package/dist/index.html +1 -1
- package/dist/maplat_transform.cjs +1 -1
- package/dist/maplat_transform.js +84 -89
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +4 -3
- package/src/edgeutils.ts +1 -1
- package/src/geometry.ts +12 -9
- package/src/index.ts +21 -28
- package/src/triangulation.ts +4 -4
package/README.md
CHANGED
|
@@ -21,6 +21,29 @@ This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
|
|
|
21
21
|
npm install @maplat/transform
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
### JSR (JavaScript Registry)
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
# For Deno
|
|
28
|
+
deno add @maplat/transform
|
|
29
|
+
|
|
30
|
+
# For npm/Node.js
|
|
31
|
+
npx jsr add @maplat/transform
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Deno
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Using JSR (recommended)
|
|
38
|
+
import { Transform } from "jsr:@maplat/transform";
|
|
39
|
+
|
|
40
|
+
// Using deno.json import map
|
|
41
|
+
import { Transform } from "@maplat/transform";
|
|
42
|
+
|
|
43
|
+
// Or directly from npm
|
|
44
|
+
import { Transform } from "npm:@maplat/transform";
|
|
45
|
+
```
|
|
46
|
+
|
|
24
47
|
### Browser
|
|
25
48
|
|
|
26
49
|
```html
|
|
@@ -29,7 +52,11 @@ npm install @maplat/transform
|
|
|
29
52
|
|
|
30
53
|
## Basic Usage
|
|
31
54
|
|
|
55
|
+
### Node.js/npm
|
|
56
|
+
|
|
32
57
|
```javascript
|
|
58
|
+
import { Transform } from '@maplat/transform';
|
|
59
|
+
|
|
33
60
|
// Import transformation definition
|
|
34
61
|
const transform = new Transform();
|
|
35
62
|
transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
|
|
@@ -41,6 +68,24 @@ const transformed = transform.transform([100, 100], false);
|
|
|
41
68
|
const restored = transform.transform(transformed, true);
|
|
42
69
|
```
|
|
43
70
|
|
|
71
|
+
### Deno
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { Transform } from "../src/index.ts";
|
|
75
|
+
|
|
76
|
+
// Load compiled data from file
|
|
77
|
+
const compiledJson = await Deno.readTextFile('./compiled.json');
|
|
78
|
+
const compiledData = JSON.parse(compiledJson);
|
|
79
|
+
|
|
80
|
+
// Create and configure transform
|
|
81
|
+
const transform = new Transform();
|
|
82
|
+
transform.setCompiled(compiledData);
|
|
83
|
+
|
|
84
|
+
// Use the same API as Node.js
|
|
85
|
+
const transformed = transform.transform([100, 100], false);
|
|
86
|
+
const restored = transform.transform(transformed, true);
|
|
87
|
+
```
|
|
88
|
+
|
|
44
89
|
### Error Handling
|
|
45
90
|
|
|
46
91
|
The library may throw errors in the following cases:
|
|
@@ -51,10 +96,39 @@ The library may throw errors in the following cases:
|
|
|
51
96
|
|
|
52
97
|
If errors occur, the transformation definition data needs to be modified. Please use editor tools that incorporate [@maplat/tin](https://github.com/code4history/MaplatTin/) to modify transformation definitions.
|
|
53
98
|
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
### Running Tests
|
|
102
|
+
|
|
103
|
+
#### Node.js
|
|
104
|
+
```sh
|
|
105
|
+
npm test
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### Deno
|
|
109
|
+
```sh
|
|
110
|
+
deno task test
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Running Examples
|
|
114
|
+
|
|
115
|
+
#### Deno
|
|
116
|
+
```sh
|
|
117
|
+
# Run the example
|
|
118
|
+
deno run --allow-read examples/deno-example.ts
|
|
119
|
+
|
|
120
|
+
# Or using deno task
|
|
121
|
+
cd examples && deno run --allow-read deno-example.ts
|
|
122
|
+
```
|
|
123
|
+
|
|
54
124
|
## Important Note
|
|
55
125
|
|
|
56
126
|
This library specializes in executing coordinate transformations and does not include functionality for generating or editing transformation definitions. If you need to create or edit transformation definitions, please use the [@maplat/tin](https://github.com/code4history/MaplatTin/) package.
|
|
57
127
|
|
|
128
|
+
## Deno Support
|
|
129
|
+
|
|
130
|
+
This library fully supports Deno. See the [Deno Usage Guide](./docs/DENO_USAGE.md) for detailed instructions on using MaplatTransform with Deno.
|
|
131
|
+
|
|
58
132
|
## License
|
|
59
133
|
|
|
60
134
|
Maplat Limited License 1.1
|
package/dist/index.d.ts
CHANGED
|
@@ -213,14 +213,7 @@ export declare class Transform {
|
|
|
213
213
|
* 3. TINネットワークの再構築
|
|
214
214
|
* 4. インデックスの作成
|
|
215
215
|
*/
|
|
216
|
-
setCompiled(compiled: Compiled | CompiledLegacy):
|
|
217
|
-
tins: TinsBD | undefined;
|
|
218
|
-
strict_status: StrictStatus | undefined;
|
|
219
|
-
weight_buffer: WeightBufferBD;
|
|
220
|
-
vertices_params: VerticesParamsBD;
|
|
221
|
-
centroid: CentroidBD | undefined;
|
|
222
|
-
kinks: KinksBD | undefined;
|
|
223
|
-
};
|
|
216
|
+
setCompiled(compiled: Compiled | CompiledLegacy): void;
|
|
224
217
|
/**
|
|
225
218
|
* TINネットワークのインデックスを作成します
|
|
226
219
|
*
|
|
@@ -239,7 +232,7 @@ export declare class Transform {
|
|
|
239
232
|
*
|
|
240
233
|
* @throws {Error} 逆方向変換が許可されていない状態での逆変換時
|
|
241
234
|
*/
|
|
242
|
-
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean):
|
|
235
|
+
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false;
|
|
243
236
|
}
|
|
244
237
|
|
|
245
238
|
/**
|
|
@@ -267,7 +260,7 @@ export declare type Tri = Feature<Polygon, PropertiesTri>;
|
|
|
267
260
|
*/
|
|
268
261
|
export declare type VertexMode = "plain" | "birdeye";
|
|
269
262
|
|
|
270
|
-
declare type VerticesParams = [number[],
|
|
263
|
+
declare type VerticesParams = [number[], Tins[]?];
|
|
271
264
|
|
|
272
265
|
export declare type VerticesParamsBD = {
|
|
273
266
|
[key in BiDirectionKey]?: VerticesParams;
|
package/dist/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<h1>MaplatTransform Test</h1>
|
|
9
9
|
<div id="output"></div>
|
|
10
10
|
<script type="module">
|
|
11
|
-
import Tin from '/src/index.ts';
|
|
11
|
+
import { Transform as Tin } from '/src/index.ts';
|
|
12
12
|
|
|
13
13
|
const tin = new Tin({
|
|
14
14
|
bounds: [[100, 50], [150, 150], [150, 200], [60, 190], [50, 100]],
|
|
@@ -1 +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;
|
|
1
|
+
"use strict";var ft=Object.defineProperty;var ct=(e,t,s)=>t in e?ft(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var _=(e,t,s)=>ct(e,typeof t!="symbol"?t+"":t,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=11102230246251565e-32,S=134217729,ut=(3+8*R)*R;function V(e,t,s,r,a){let n,c,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?(c=d+n,l=n-(c-d),d=t[++o]):(c=y+n,l=n-(c-y),y=r[++u]),n=c,l!==0&&(a[b++]=l);o<e&&u<s;)y>d==y>-d?(c=n+d,g=c-n,l=n-(c-g)+(d-g),d=t[++o]):(c=n+y,g=c-n,l=n-(c-g)+(y-g),y=r[++u]),n=c,l!==0&&(a[b++]=l);for(;o<e;)c=n+d,g=c-n,l=n-(c-g)+(d-g),d=t[++o],n=c,l!==0&&(a[b++]=l);for(;u<s;)c=n+y,g=c-n,l=n-(c-g)+(y-g),y=r[++u],n=c,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 $(e){return new Float64Array(e)}const gt=(3+16*R)*R,lt=(2+12*R)*R,dt=(9+64*R)*R*R,F=$(4),G=$(8),j=$(12),z=$(16),P=$(4);function yt(e,t,s,r,a,n,c){let l,g,d,y,o,u,b,x,h,f,i,w,v,A,E,m,M,O;const I=e-a,p=s-a,k=t-n,N=r-n;A=I*N,u=S*I,b=u-(u-I),x=I-b,u=S*N,h=u-(u-N),f=N-h,E=x*f-(A-b*h-x*h-b*f),m=k*p,u=S*k,b=u-(u-k),x=k-b,u=S*p,h=u-(u-p),f=p-h,M=x*f-(m-b*h-x*h-b*f),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 U=ht(4,F),X=lt*c;if(U>=X||-U>=X||(o=e-I,l=e-(I+o)+(o-a),o=s-p,d=s-(p+o)+(o-a),o=t-k,g=t-(k+o)+(o-n),o=r-N,y=r-(N+o)+(o-n),l===0&&g===0&&d===0&&y===0)||(X=dt*c+ut*Math.abs(U),U+=I*y+N*l-(k*d+p*g),U>=X||-U>=X))return U;A=l*N,u=S*l,b=u-(u-l),x=l-b,u=S*N,h=u-(u-N),f=N-h,E=x*f-(A-b*h-x*h-b*f),m=g*p,u=S*g,b=u-(u-g),x=g-b,u=S*p,h=u-(u-p),f=p-h,M=x*f-(m-b*h-x*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),O=w+i,o=O-w,P[2]=w-(O-o)+(i-o),P[3]=O;const it=V(4,F,4,P,G);A=I*y,u=S*I,b=u-(u-I),x=I-b,u=S*y,h=u-(u-y),f=y-h,E=x*f-(A-b*h-x*h-b*f),m=k*d,u=S*k,b=u-(u-k),x=k-b,u=S*d,h=u-(u-d),f=d-h,M=x*f-(m-b*h-x*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),O=w+i,o=O-w,P[2]=w-(O-o)+(i-o),P[3]=O;const ot=V(it,G,4,P,j);A=l*y,u=S*l,b=u-(u-l),x=l-b,u=S*y,h=u-(u-y),f=y-h,E=x*f-(A-b*h-x*h-b*f),m=g*d,u=S*g,b=u-(u-g),x=g-b,u=S*d,h=u-(u-d),f=d-h,M=x*f-(m-b*h-x*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),O=w+i,o=O-w,P[2]=w-(O-o)+(i-o),P[3]=O;const at=V(ot,j,4,P,z);return z[at-1]}function bt(e,t,s,r,a,n){const c=(t-n)*(s-a),l=(e-a)*(r-n),g=c-l,d=Math.abs(c+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,c,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],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,l=y[1]-b,r;r<f;r++){if(o=h[r+1],g=o[0]-u,d=o[1]-b,l===0&&d===0){if(g<=0&&c>=0||c<=0&&g>=0)return 0}else if(d>=0&&l<=0||d<=0&&l>=0){if(n=bt(c,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,c=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,c=t.bbox;let l=a.coordinates;if(c&&vt(r,c)===!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 W(e,t,s,r,a,n=!1,c){const l=e.map(g=>{(!c||c<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],c=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=[c[0]-r[0],c[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]),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*x[0]+l[0],h*b[1]+f*x[1]+l[1]]}function Tt(e,t,s,r){const a=e.geometry.coordinates,n=s.geometry.coordinates,c=Math.atan2(a[0]-n[0],a[1]-n[1]),l=Ot(c,t[0]);if(l===void 0)throw new Error("Unable to determine vertex index");const g=t[1][l];return st(e,g.features[0],r)}function nt(e,t,s,r,a,n,c,l){let g;if(c&&(g=Q(e,B([c]))),!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,f=C(d[0],o,b,y),i=C(d[1],u,x,y),w=h[f]?h[f][i]?h[f][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 c=(n+1)%t.length,l=H(e-t[c]),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((c,l)=>{const g=et(l);return c[g]=n[l],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=W(["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=W(["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=>W(r,t.points,t.edgeNodes||[],t.centroid_point,t.vertices_points,!1,t.version))),bakw:B(t.tins_points[s].map(r=>W(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,c)=>{const l=a.geometry.coordinates[0][c],g=a.properties[n].geom,d=a.properties[n].index;typeof d=="number"&&(s[d]=[l,g])})}this.points=s}}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 l=s.features.map(h=>{let f=[];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])),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,d=(n[1][1]-n[0][1])/a,y=l.reduce((h,f,i)=>{const w=C(f[0][0],n[0][0],g,a),v=C(f[1][0],n[0][0],g,a),A=C(f[0][1],n[0][1],d,a),E=C(f[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 f=[];return K(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=C(f[0][0],c[0][0],u,a),v=C(f[1][0],c[0][0],u,a),A=C(f[0][1],c[0][1],b,a),E=C(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:d,gridCache:y},bakw:{gridNum:a,xOrigin:c[0][0],yOrigin:c[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,c=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,c,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;
|
package/dist/maplat_transform.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
var ot = Object.defineProperty;
|
|
2
2
|
var at = (e, t, s) => t in e ? ot(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
3
3
|
var _ = (e, t, s) => at(e, typeof t != "symbol" ? t + "" : t, s);
|
|
4
|
-
const
|
|
4
|
+
const R = 11102230246251565e-32, I = 134217729, ft = (3 + 8 * R) * R;
|
|
5
5
|
function V(e, t, s, r, a) {
|
|
6
|
-
let n,
|
|
6
|
+
let n, c, d, g, l = t[0], y = r[0], o = 0, u = 0;
|
|
7
7
|
y > l == y > -l ? (n = l, l = t[++o]) : (n = y, y = r[++u]);
|
|
8
8
|
let b = 0;
|
|
9
9
|
if (o < e && u < s)
|
|
10
|
-
for (y > l == y > -l ? (
|
|
11
|
-
y > l == y > -l ? (
|
|
10
|
+
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; )
|
|
11
|
+
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);
|
|
12
12
|
for (; o < e; )
|
|
13
|
-
|
|
13
|
+
c = n + l, g = c - n, d = n - (c - g) + (l - g), l = t[++o], n = c, d !== 0 && (a[b++] = d);
|
|
14
14
|
for (; u < s; )
|
|
15
|
-
|
|
15
|
+
c = n + y, g = c - n, d = n - (c - g) + (y - g), y = r[++u], n = c, d !== 0 && (a[b++] = d);
|
|
16
16
|
return (n !== 0 || b === 0) && (a[b++] = n), b;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function ct(e, t) {
|
|
19
19
|
let s = t[0];
|
|
20
20
|
for (let r = 1; r < e; r++) s += t[r];
|
|
21
21
|
return s;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function $(e) {
|
|
24
24
|
return new Float64Array(e);
|
|
25
25
|
}
|
|
26
|
-
const ut = (3 + 16 *
|
|
27
|
-
function dt(e, t, s, r, a, n,
|
|
28
|
-
let d, g, l, y, o, u, b, x, h,
|
|
29
|
-
const
|
|
30
|
-
v =
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
v = d * N, u =
|
|
34
|
-
const st = V(4, F, 4,
|
|
35
|
-
v =
|
|
36
|
-
const nt = V(st, q, 4,
|
|
37
|
-
v = d * y, u =
|
|
38
|
-
const it = V(nt, L, 4,
|
|
26
|
+
const ut = (3 + 16 * R) * R, ht = (2 + 12 * R) * R, gt = (9 + 64 * R) * R * R, F = $(4), q = $(8), L = $(12), G = $(16), P = $(4);
|
|
27
|
+
function dt(e, t, s, r, a, n, c) {
|
|
28
|
+
let d, g, l, y, o, u, b, x, h, f, i, w, A, v, E, m, M, T;
|
|
29
|
+
const S = e - a, p = s - a, k = t - n, N = r - n;
|
|
30
|
+
v = S * N, u = I * S, b = u - (u - S), x = S - b, u = I * N, h = u - (u - N), f = N - h, E = x * f - (v - b * h - x * h - b * f), m = k * p, u = I * k, b = u - (u - k), x = k - b, u = I * p, h = u - (u - p), f = p - h, M = x * f - (m - b * h - x * h - b * f), 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 U = ct(4, F), X = ht * c;
|
|
32
|
+
if (U >= X || -U >= X || (o = e - S, d = e - (S + o) + (o - a), o = s - p, l = s - (p + o) + (o - a), o = t - k, g = t - (k + o) + (o - n), o = r - N, y = r - (N + o) + (o - n), d === 0 && g === 0 && l === 0 && y === 0) || (X = gt * c + ft * Math.abs(U), U += S * y + N * d - (k * l + p * g), U >= X || -U >= X)) return U;
|
|
33
|
+
v = d * N, u = I * d, b = u - (u - d), x = d - b, u = I * N, h = u - (u - N), f = N - h, E = x * f - (v - b * h - x * h - b * f), m = g * p, u = I * g, b = u - (u - g), x = g - b, u = I * p, h = u - (u - p), f = p - h, M = x * f - (m - b * h - x * h - b * f), 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 = S * y, u = I * S, b = u - (u - S), x = S - b, u = I * y, h = u - (u - y), f = y - h, E = x * f - (v - b * h - x * h - b * f), m = k * l, u = I * k, b = u - (u - k), x = k - b, u = I * l, h = u - (u - l), f = l - h, M = x * f - (m - b * h - x * h - b * f), 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 = I * d, b = u - (u - d), x = d - b, u = I * y, h = u - (u - y), f = y - h, E = x * f - (v - b * h - x * h - b * f), m = g * l, u = I * g, b = u - (u - g), x = g - b, u = I * l, h = u - (u - l), f = l - h, M = x * f - (m - b * h - x * h - b * f), 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
39
|
return G[it - 1];
|
|
40
40
|
}
|
|
41
41
|
function lt(e, t, s, r, a, n) {
|
|
42
|
-
const
|
|
42
|
+
const c = (t - n) * (s - a), d = (e - a) * (r - n), g = c - d, l = Math.abs(c + d);
|
|
43
43
|
return Math.abs(g) >= ut * l ? g : -dt(e, t, s, r, a, n, l);
|
|
44
44
|
}
|
|
45
45
|
function yt(e, t) {
|
|
46
|
-
var s, r, a = 0, n,
|
|
46
|
+
var s, r, a = 0, n, c, d, g, l, y, o, u = e[0], b = e[1], x = t.length;
|
|
47
47
|
for (s = 0; s < x; s++) {
|
|
48
48
|
r = 0;
|
|
49
|
-
var h = t[s],
|
|
50
|
-
if (y = h[0], y[0] !== h[
|
|
49
|
+
var h = t[s], f = h.length - 1;
|
|
50
|
+
if (y = h[0], y[0] !== h[f][0] && y[1] !== h[f][1])
|
|
51
51
|
throw new Error("First and last coordinates in a ring must be the same");
|
|
52
|
-
for (
|
|
52
|
+
for (c = y[0] - u, d = y[1] - b, r; r < f; r++) {
|
|
53
53
|
if (o = h[r + 1], g = o[0] - u, l = o[1] - b, d === 0 && l === 0) {
|
|
54
|
-
if (g <= 0 &&
|
|
54
|
+
if (g <= 0 && c >= 0 || c <= 0 && g >= 0)
|
|
55
55
|
return 0;
|
|
56
56
|
} else if (l >= 0 && d <= 0 || l <= 0 && d >= 0) {
|
|
57
|
-
if (n = lt(
|
|
57
|
+
if (n = lt(c, g, d, l, 0, 0), n === 0)
|
|
58
58
|
return 0;
|
|
59
59
|
(n > 0 && l > 0 && d <= 0 || n < 0 && l <= 0 && d > 0) && a++;
|
|
60
60
|
}
|
|
61
|
-
y = o, d = l,
|
|
61
|
+
y = o, d = l, c = g;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
return a % 2 !== 0;
|
|
@@ -138,9 +138,9 @@ function mt(e, t, s = {}) {
|
|
|
138
138
|
throw new Error("point is required");
|
|
139
139
|
if (!t)
|
|
140
140
|
throw new Error("polygon is required");
|
|
141
|
-
const r = bt(e), a = wt(t), n = a.type,
|
|
141
|
+
const r = bt(e), a = wt(t), n = a.type, c = t.bbox;
|
|
142
142
|
let d = a.coordinates;
|
|
143
|
-
if (
|
|
143
|
+
if (c && xt(r, c) === !1)
|
|
144
144
|
return !1;
|
|
145
145
|
n === "Polygon" && (d = [d]);
|
|
146
146
|
let g = !1;
|
|
@@ -217,7 +217,7 @@ function Tt(e) {
|
|
|
217
217
|
}
|
|
218
218
|
return e;
|
|
219
219
|
}
|
|
220
|
-
function
|
|
220
|
+
function It(e) {
|
|
221
221
|
const t = ["a", "b", "c", "a"].map(
|
|
222
222
|
(n) => e.properties[n].geom
|
|
223
223
|
), s = e.geometry.coordinates[0], r = e.properties, a = {
|
|
@@ -235,10 +235,10 @@ function _t(e) {
|
|
|
235
235
|
};
|
|
236
236
|
return tt([t], s);
|
|
237
237
|
}
|
|
238
|
-
function
|
|
238
|
+
function W(e, t, s, r, a, n = !1, c) {
|
|
239
239
|
const d = e.map(
|
|
240
240
|
(g) => {
|
|
241
|
-
(!
|
|
241
|
+
(!c || c < 2.00703) && (g = et(g));
|
|
242
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
243
|
const y = g.match(/e(\d+)/);
|
|
244
244
|
if (y) {
|
|
@@ -268,32 +268,35 @@ function z(e, t) {
|
|
|
268
268
|
return t.features[s];
|
|
269
269
|
}
|
|
270
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],
|
|
272
|
-
let h = (o[1] * u[0] - o[0] * u[1]) / (y[0] * o[1] - y[1] * o[0]),
|
|
271
|
+
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]], 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]), f = (y[0] * u[1] - y[1] * u[0]) / (y[0] * o[1] - y[1] * o[0]);
|
|
273
273
|
if (s) {
|
|
274
274
|
const i = s[t.properties.a.index], w = s[t.properties.b.index], A = s[t.properties.c.index];
|
|
275
275
|
let v;
|
|
276
|
-
if (h < 0 ||
|
|
277
|
-
const E = h / (h +
|
|
278
|
-
v = h / w / (E / w + m / A),
|
|
276
|
+
if (h < 0 || f < 0 || 1 - h - f < 0) {
|
|
277
|
+
const E = h / (h + f), m = f / (h + f);
|
|
278
|
+
v = h / w / (E / w + m / A), f = f / A / (E / w + m / A);
|
|
279
279
|
} else
|
|
280
|
-
v = h / w / (h / w +
|
|
280
|
+
v = h / w / (h / w + f / A + (1 - h - f) / i), f = f / A / (h / w + f / A + (1 - h - f) / i);
|
|
281
281
|
h = v;
|
|
282
282
|
}
|
|
283
283
|
return [
|
|
284
|
-
h * b[0] +
|
|
285
|
-
h * b[1] +
|
|
284
|
+
h * b[0] + f * x[0] + d[0],
|
|
285
|
+
h * b[1] + f * x[1] + d[1]
|
|
286
286
|
];
|
|
287
287
|
}
|
|
288
288
|
function vt(e, t, s, r) {
|
|
289
|
-
const a = e.geometry.coordinates, n = s.geometry.coordinates,
|
|
289
|
+
const a = e.geometry.coordinates, n = s.geometry.coordinates, c = Math.atan2(a[0] - n[0], a[1] - n[1]), d = Et(c, t[0]);
|
|
290
|
+
if (d === void 0)
|
|
291
|
+
throw new Error("Unable to determine vertex index");
|
|
292
|
+
const g = t[1][d];
|
|
290
293
|
return rt(e, g.features[0], r);
|
|
291
294
|
}
|
|
292
|
-
function Mt(e, t, s, r, a, n,
|
|
295
|
+
function Mt(e, t, s, r, a, n, c, d) {
|
|
293
296
|
let g;
|
|
294
|
-
if (
|
|
297
|
+
if (c && (g = z(e, B([c]))), !g) {
|
|
295
298
|
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,
|
|
299
|
+
const l = e.geometry.coordinates, y = s.gridNum, o = s.xOrigin, u = s.yOrigin, b = s.xUnit, x = s.yUnit, h = s.gridCache, f = C(l[0], o, b, y), i = C(l[1], u, x, y), w = h[f] ? h[f][i] ? h[f][i] : [] : [];
|
|
297
300
|
t = B(w.map((A) => t.features[A]));
|
|
298
301
|
}
|
|
299
302
|
g = z(e, t);
|
|
@@ -307,7 +310,7 @@ function C(e, t, s, r) {
|
|
|
307
310
|
function Et(e, t) {
|
|
308
311
|
let s = K(e - t[0]), r = Math.PI * 2, a;
|
|
309
312
|
for (let n = 0; n < t.length; n++) {
|
|
310
|
-
const
|
|
313
|
+
const c = (n + 1) % t.length, d = K(e - t[c]), g = Math.min(Math.abs(s), Math.abs(d));
|
|
311
314
|
s * d <= 0 && g < r && (r = g, a = n), s = d;
|
|
312
315
|
}
|
|
313
316
|
return a;
|
|
@@ -361,15 +364,15 @@ const Q = 2.00703, O = class O {
|
|
|
361
364
|
if (t.version || !t.tins && t.points && t.tins_points) {
|
|
362
365
|
this.points = t.points, this.pointsWeightBuffer = !t.version || t.version < 2.00703 ? ["forw", "bakw"].reduce((r, a) => {
|
|
363
366
|
const n = t.weight_buffer[a];
|
|
364
|
-
return n && (r[a] = Object.keys(n).reduce((
|
|
367
|
+
return n && (r[a] = Object.keys(n).reduce((c, d) => {
|
|
365
368
|
const g = et(d);
|
|
366
|
-
return
|
|
369
|
+
return c[g] = n[d], c;
|
|
367
370
|
}, {})), r;
|
|
368
371
|
}, {}) : 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
372
|
forw: [t.vertices_params[0]],
|
|
370
373
|
bakw: [t.vertices_params[1]]
|
|
371
374
|
}, this.vertices_params.forw[1] = [0, 1, 2, 3].map((r) => {
|
|
372
|
-
const a = (r + 1) % 4, n =
|
|
375
|
+
const a = (r + 1) % 4, n = W(
|
|
373
376
|
["c", `b${r}`, `b${a}`],
|
|
374
377
|
t.points,
|
|
375
378
|
t.edgeNodes || [],
|
|
@@ -380,7 +383,7 @@ const Q = 2.00703, O = class O {
|
|
|
380
383
|
);
|
|
381
384
|
return B([n]);
|
|
382
385
|
}), this.vertices_params.bakw[1] = [0, 1, 2, 3].map((r) => {
|
|
383
|
-
const a = (r + 1) % 4, n =
|
|
386
|
+
const a = (r + 1) % 4, n = W(
|
|
384
387
|
["c", `b${r}`, `b${a}`],
|
|
385
388
|
t.points,
|
|
386
389
|
t.edgeNodes || [],
|
|
@@ -408,7 +411,7 @@ const Q = 2.00703, O = class O {
|
|
|
408
411
|
this.tins = {
|
|
409
412
|
forw: B(
|
|
410
413
|
t.tins_points[0].map(
|
|
411
|
-
(r) =>
|
|
414
|
+
(r) => W(
|
|
412
415
|
r,
|
|
413
416
|
t.points,
|
|
414
417
|
t.edgeNodes || [],
|
|
@@ -421,7 +424,7 @@ const Q = 2.00703, O = class O {
|
|
|
421
424
|
),
|
|
422
425
|
bakw: B(
|
|
423
426
|
t.tins_points[s].map(
|
|
424
|
-
(r) =>
|
|
427
|
+
(r) => W(
|
|
425
428
|
r,
|
|
426
429
|
t.points,
|
|
427
430
|
t.edgeNodes || [],
|
|
@@ -444,21 +447,13 @@ const Q = 2.00703, O = class O {
|
|
|
444
447
|
const s = [];
|
|
445
448
|
for (let r = 0; r < this.tins.forw.features.length; r++) {
|
|
446
449
|
const a = this.tins.forw.features[r];
|
|
447
|
-
["a", "b", "c"].map((n,
|
|
448
|
-
const d = a.geometry.coordinates[0][
|
|
449
|
-
s[l] = [d, g];
|
|
450
|
+
["a", "b", "c"].map((n, c) => {
|
|
451
|
+
const d = a.geometry.coordinates[0][c], g = a.properties[n].geom, l = a.properties[n].index;
|
|
452
|
+
typeof l == "number" && (s[l] = [d, g]);
|
|
450
453
|
});
|
|
451
454
|
}
|
|
452
455
|
this.points = s;
|
|
453
456
|
}
|
|
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
457
|
}
|
|
463
458
|
/**
|
|
464
459
|
* TINネットワークのインデックスを作成します
|
|
@@ -473,31 +468,31 @@ const Q = 2.00703, O = class O {
|
|
|
473
468
|
this.indexedTins = void 0;
|
|
474
469
|
return;
|
|
475
470
|
}
|
|
476
|
-
let n = [],
|
|
471
|
+
let n = [], c = [];
|
|
477
472
|
const d = s.features.map((h) => {
|
|
478
|
-
let
|
|
473
|
+
let f = [];
|
|
479
474
|
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])),
|
|
481
|
-
}),
|
|
475
|
+
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]));
|
|
476
|
+
}), f;
|
|
482
477
|
}), g = (n[1][0] - n[0][0]) / a, l = (n[1][1] - n[0][1]) / a, y = d.reduce(
|
|
483
|
-
(h,
|
|
478
|
+
(h, f, i) => {
|
|
484
479
|
const w = C(
|
|
485
|
-
|
|
480
|
+
f[0][0],
|
|
486
481
|
n[0][0],
|
|
487
482
|
g,
|
|
488
483
|
a
|
|
489
484
|
), A = C(
|
|
490
|
-
|
|
485
|
+
f[1][0],
|
|
491
486
|
n[0][0],
|
|
492
487
|
g,
|
|
493
488
|
a
|
|
494
489
|
), v = C(
|
|
495
|
-
|
|
490
|
+
f[0][1],
|
|
496
491
|
n[0][1],
|
|
497
492
|
l,
|
|
498
493
|
a
|
|
499
494
|
), E = C(
|
|
500
|
-
|
|
495
|
+
f[1][1],
|
|
501
496
|
n[0][1],
|
|
502
497
|
l,
|
|
503
498
|
a
|
|
@@ -511,30 +506,30 @@ const Q = 2.00703, O = class O {
|
|
|
511
506
|
},
|
|
512
507
|
[]
|
|
513
508
|
), o = r.features.map((h) => {
|
|
514
|
-
let
|
|
509
|
+
let f = [];
|
|
515
510
|
return J(h)[0].map((i) => {
|
|
516
|
-
|
|
517
|
-
}),
|
|
518
|
-
}), u = (
|
|
519
|
-
(h,
|
|
511
|
+
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]));
|
|
512
|
+
}), f;
|
|
513
|
+
}), u = (c[1][0] - c[0][0]) / a, b = (c[1][1] - c[0][1]) / a, x = o.reduce(
|
|
514
|
+
(h, f, i) => {
|
|
520
515
|
const w = C(
|
|
521
|
-
c[0][0],
|
|
522
516
|
f[0][0],
|
|
517
|
+
c[0][0],
|
|
523
518
|
u,
|
|
524
519
|
a
|
|
525
520
|
), A = C(
|
|
526
|
-
|
|
527
|
-
|
|
521
|
+
f[1][0],
|
|
522
|
+
c[0][0],
|
|
528
523
|
u,
|
|
529
524
|
a
|
|
530
525
|
), v = C(
|
|
531
|
-
c[0][1],
|
|
532
526
|
f[0][1],
|
|
527
|
+
c[0][1],
|
|
533
528
|
b,
|
|
534
529
|
a
|
|
535
530
|
), E = C(
|
|
536
|
-
|
|
537
|
-
|
|
531
|
+
f[1][1],
|
|
532
|
+
c[0][1],
|
|
538
533
|
b,
|
|
539
534
|
a
|
|
540
535
|
);
|
|
@@ -558,8 +553,8 @@ const Q = 2.00703, O = class O {
|
|
|
558
553
|
},
|
|
559
554
|
bakw: {
|
|
560
555
|
gridNum: a,
|
|
561
|
-
xOrigin:
|
|
562
|
-
yOrigin:
|
|
556
|
+
xOrigin: c[0][0],
|
|
557
|
+
yOrigin: c[0][1],
|
|
563
558
|
xUnit: u,
|
|
564
559
|
yUnit: b,
|
|
565
560
|
gridCache: x
|
|
@@ -583,7 +578,7 @@ const Q = 2.00703, O = class O {
|
|
|
583
578
|
const a = Y(t);
|
|
584
579
|
if (this.bounds && !s && !r && !D(a, this.boundsPolygon))
|
|
585
580
|
return !1;
|
|
586
|
-
const n = s ? this.tins.bakw : this.tins.forw,
|
|
581
|
+
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;
|
|
587
582
|
let y, o;
|
|
588
583
|
this.stateFull && (this.stateBackward == s ? y = this.stateTriangle : (this.stateBackward = s, this.stateTriangle = void 0), o = (b) => {
|
|
589
584
|
this.stateTriangle = b;
|
|
@@ -591,7 +586,7 @@ const Q = 2.00703, O = class O {
|
|
|
591
586
|
let u = Mt(
|
|
592
587
|
a,
|
|
593
588
|
n,
|
|
594
|
-
|
|
589
|
+
c,
|
|
595
590
|
d,
|
|
596
591
|
g,
|
|
597
592
|
l,
|
|
@@ -613,7 +608,7 @@ _(O, "VERTEX_PLAIN", "plain"), _(O, "VERTEX_BIRDEYE", "birdeye"), _(O, "MODE_STR
|
|
|
613
608
|
let H = O;
|
|
614
609
|
export {
|
|
615
610
|
H as Transform,
|
|
616
|
-
|
|
611
|
+
It as counterTri,
|
|
617
612
|
Q as format_version,
|
|
618
613
|
At as normalizeEdges,
|
|
619
614
|
Tt as rotateVerticesTriangle,
|
|
@@ -1 +1 @@
|
|
|
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"})});
|
|
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"})});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.2.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
|
"main": "./dist/maplat_transform.cjs",
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
],
|
|
27
27
|
"scripts": {
|
|
28
28
|
"dev": "vite",
|
|
29
|
-
"build": "
|
|
29
|
+
"build": "npm run typecheck && cross-env BUILD_MODE=package vite build",
|
|
30
|
+
"typecheck": "tsc --noEmit --allowImportingTsExtensions",
|
|
30
31
|
"deploy": "cp public/*.html ./ && tsc && vite build",
|
|
31
32
|
"test": "vitest run",
|
|
32
33
|
"test:watch": "vitest",
|
|
33
34
|
"coverage": "vitest run --coverage",
|
|
34
35
|
"lint": "eslint src tests",
|
|
35
|
-
"
|
|
36
|
+
"prepublishOnly": "npm run build"
|
|
36
37
|
},
|
|
37
38
|
"repository": {
|
|
38
39
|
"type": "git",
|
package/src/edgeutils.ts
CHANGED
package/src/geometry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
2
2
|
import { featureCollection } from "@turf/helpers";
|
|
3
|
-
import { Feature, FeatureCollection, Polygon, Point, Position } from "geojson";
|
|
3
|
+
import type { Feature, FeatureCollection, Polygon, Point, Position } from "geojson";
|
|
4
4
|
//import { Tri, Tins, IndexedTins, WeightBuffer, VerticesParams } from "./index";
|
|
5
5
|
type PropertyTri = { geom: Position; index: number | string };
|
|
6
6
|
export type PropertyTriKey = "a" | "b" | "c";
|
|
@@ -8,7 +8,7 @@ type PropertiesTri = { [key in PropertyTriKey]: PropertyTri };
|
|
|
8
8
|
export type Tri = Feature<Polygon, PropertiesTri>;
|
|
9
9
|
export type Tins = FeatureCollection<Polygon, PropertiesTri>;
|
|
10
10
|
export type WeightBuffer = { [index: string]: number };
|
|
11
|
-
export type VerticesParams = [number[],
|
|
11
|
+
export type VerticesParams = [number[], Tins[]?];
|
|
12
12
|
export interface IndexedTins {
|
|
13
13
|
gridNum: number;
|
|
14
14
|
xOrigin: number;
|
|
@@ -40,7 +40,7 @@ function hit(point: Feature<Point>, tins: Tins): Tri | undefined {
|
|
|
40
40
|
* @param weightBuffer 重み付けバッファ(オプション)
|
|
41
41
|
* @returns 変換後の座標
|
|
42
42
|
*/
|
|
43
|
-
function transformTinArr(of:
|
|
43
|
+
function transformTinArr(of: Feature<Point>, tri: Tri, weightBuffer: WeightBuffer | undefined) {
|
|
44
44
|
const a = tri.geometry.coordinates[0][0];
|
|
45
45
|
const b = tri.geometry.coordinates[0][1];
|
|
46
46
|
const c = tri.geometry.coordinates[0][2];
|
|
@@ -97,7 +97,10 @@ function useVerticesArr(
|
|
|
97
97
|
const centCoord = centroid.geometry!.coordinates;
|
|
98
98
|
const radian = Math.atan2(coord[0] - centCoord[0], coord[1] - centCoord[1]);
|
|
99
99
|
const index = decideUseVertex(radian, verticesParams[0]);
|
|
100
|
-
|
|
100
|
+
if (index === undefined) {
|
|
101
|
+
throw new Error("Unable to determine vertex index");
|
|
102
|
+
}
|
|
103
|
+
const tin = verticesParams[1]![index];
|
|
101
104
|
return transformTinArr(o, tin.features[0], weightBuffer);
|
|
102
105
|
}
|
|
103
106
|
|
|
@@ -145,7 +148,7 @@ function transformArr(
|
|
|
145
148
|
? gridCache[normX][normY]
|
|
146
149
|
: []
|
|
147
150
|
: [];
|
|
148
|
-
tins = featureCollection(tinsKey.map((key:
|
|
151
|
+
tins = featureCollection(tinsKey.map((key: number) => tins.features[key]));
|
|
149
152
|
}
|
|
150
153
|
tin = hit(point, tins);
|
|
151
154
|
}
|
|
@@ -189,7 +192,7 @@ function unitCalc(
|
|
|
189
192
|
* const index = decideUseVertex(0.5, [0, Math.PI/2, Math.PI, Math.PI*3/2]);
|
|
190
193
|
* // returns 0 (最初の頂点が最も近い)
|
|
191
194
|
*/
|
|
192
|
-
function decideUseVertex(radian:
|
|
195
|
+
function decideUseVertex(radian: number, radianList: number[]): number | undefined {
|
|
193
196
|
// 最初の頂点との角度差を正規化
|
|
194
197
|
let idel = normalizeRadian(radian - radianList[0]);
|
|
195
198
|
let minTheta = Math.PI * 2; // 最小角度差の初期値
|
|
@@ -226,13 +229,13 @@ function decideUseVertex(radian: any, radianList: any) {
|
|
|
226
229
|
* // [0, 2π)の範囲に正規化
|
|
227
230
|
* normalizeRadian(3 * Math.PI, true); // returns π
|
|
228
231
|
*/
|
|
229
|
-
function normalizeRadian(target:
|
|
232
|
+
function normalizeRadian(target: number, noNegative = false): number {
|
|
230
233
|
// 正規化の範囲を決定する関数
|
|
231
234
|
const rangeFunc = noNegative
|
|
232
|
-
? function (val:
|
|
235
|
+
? function (val: number) {
|
|
233
236
|
return !(val >= 0 && val < Math.PI * 2); // [0, 2π)の範囲外
|
|
234
237
|
}
|
|
235
|
-
: function (val:
|
|
238
|
+
: function (val: number) {
|
|
236
239
|
return !(val > -1 * Math.PI && val <= Math.PI); // (-π, π]の範囲外
|
|
237
240
|
};
|
|
238
241
|
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
2
2
|
import { featureCollection, point } from "@turf/helpers";
|
|
3
3
|
import { getCoords } from "@turf/invariant";
|
|
4
|
-
import { indexesToTri, normalizeNodeKey } from "./triangulation";
|
|
5
|
-
import { Feature, Polygon, Position, Point, FeatureCollection } from "geojson";
|
|
6
|
-
import { normalizeEdges } from "./edgeutils";
|
|
4
|
+
import { indexesToTri, normalizeNodeKey } from "./triangulation.ts";
|
|
5
|
+
import type { Feature, Polygon, Position, Point, FeatureCollection } from "geojson";
|
|
6
|
+
import { normalizeEdges } from "./edgeutils.ts";
|
|
7
7
|
import type {
|
|
8
8
|
WeightBuffer, Tins, VerticesParams, PropertyTriKey,
|
|
9
9
|
IndexedTins, Tri
|
|
10
|
-
} from "./geometry";
|
|
11
|
-
import { unitCalc, transformArr } from "./geometry";
|
|
12
|
-
import type { EdgeSet, EdgeSetLegacy } from "./edgeutils";
|
|
13
|
-
export type { Tins, Tri, PropertyTriKey } from './geometry';
|
|
14
|
-
export { transformArr } from './geometry';
|
|
15
|
-
export { rotateVerticesTriangle, counterTri } from './triangulation';
|
|
16
|
-
export type { Edge, EdgeSet, EdgeSetLegacy } from './edgeutils';
|
|
17
|
-
export { normalizeEdges } from './edgeutils';
|
|
10
|
+
} from "./geometry.ts";
|
|
11
|
+
import { unitCalc, transformArr } from "./geometry.ts";
|
|
12
|
+
import type { EdgeSet, EdgeSetLegacy } from "./edgeutils.ts";
|
|
13
|
+
export type { Tins, Tri, PropertyTriKey } from './geometry.ts';
|
|
14
|
+
export { transformArr } from './geometry.ts';
|
|
15
|
+
export { rotateVerticesTriangle, counterTri } from './triangulation.ts';
|
|
16
|
+
export type { Edge, EdgeSet, EdgeSetLegacy } from './edgeutils.ts';
|
|
17
|
+
export { normalizeEdges } from './edgeutils.ts';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* 座標ペアの型定義。[ソース座標, ターゲット座標] の形式
|
|
@@ -164,10 +164,10 @@ export class Transform {
|
|
|
164
164
|
* 3. TINネットワークの再構築
|
|
165
165
|
* 4. インデックスの作成
|
|
166
166
|
*/
|
|
167
|
-
setCompiled(compiled: Compiled | CompiledLegacy) {
|
|
167
|
+
setCompiled(compiled: Compiled | CompiledLegacy): void {
|
|
168
168
|
if (
|
|
169
169
|
compiled.version ||
|
|
170
|
-
(!(compiled as
|
|
170
|
+
(!(compiled as CompiledLegacy).tins && compiled.points && compiled.tins_points)
|
|
171
171
|
) {
|
|
172
172
|
// 新コンパイルロジック
|
|
173
173
|
// pointsはそのままpoints
|
|
@@ -250,7 +250,7 @@ export class Transform {
|
|
|
250
250
|
const bakwI = compiled.tins_points.length == 1 ? 0 : 1;
|
|
251
251
|
this.tins = {
|
|
252
252
|
forw: featureCollection(
|
|
253
|
-
compiled.tins_points[0].map((idxes:
|
|
253
|
+
compiled.tins_points[0].map((idxes: (number | string)[]) =>
|
|
254
254
|
indexesToTri(
|
|
255
255
|
idxes,
|
|
256
256
|
compiled.points,
|
|
@@ -263,7 +263,7 @@ export class Transform {
|
|
|
263
263
|
)
|
|
264
264
|
),
|
|
265
265
|
bakw: featureCollection(
|
|
266
|
-
compiled.tins_points[bakwI].map((idxes:
|
|
266
|
+
compiled.tins_points[bakwI].map((idxes: (number | string)[]) =>
|
|
267
267
|
indexesToTri(
|
|
268
268
|
idxes,
|
|
269
269
|
compiled.points,
|
|
@@ -324,27 +324,20 @@ export class Transform {
|
|
|
324
324
|
this.vertices_params = compiled.vertices_params as VerticesParamsBD;
|
|
325
325
|
this.centroid = (compiled as CompiledLegacy).centroid;
|
|
326
326
|
this.kinks = (compiled as CompiledLegacy).kinks;
|
|
327
|
-
const points:
|
|
327
|
+
const points: PointSet[] = [];
|
|
328
328
|
for (let i = 0; i < this.tins!.forw!.features.length; i++) {
|
|
329
329
|
const tri = this.tins!.forw!.features[i];
|
|
330
330
|
(["a", "b", "c"] as PropertyTriKey[]).map((key, idx) => {
|
|
331
331
|
const forw = tri.geometry!.coordinates[0][idx];
|
|
332
332
|
const bakw = tri.properties![key].geom;
|
|
333
333
|
const pIdx = tri.properties![key].index;
|
|
334
|
-
|
|
334
|
+
if (typeof pIdx === 'number') {
|
|
335
|
+
points[pIdx] = [forw, bakw];
|
|
336
|
+
}
|
|
335
337
|
});
|
|
336
338
|
}
|
|
337
339
|
this.points = points;
|
|
338
340
|
}
|
|
339
|
-
// 翻訳したオブジェクトを返す
|
|
340
|
-
return {
|
|
341
|
-
tins: this.tins,
|
|
342
|
-
strict_status: this.strict_status,
|
|
343
|
-
weight_buffer: this.pointsWeightBuffer,
|
|
344
|
-
vertices_params: this.vertices_params,
|
|
345
|
-
centroid: this.centroid,
|
|
346
|
-
kinks: this.kinks
|
|
347
|
-
};
|
|
348
341
|
}
|
|
349
342
|
|
|
350
343
|
/**
|
|
@@ -451,7 +444,7 @@ export class Transform {
|
|
|
451
444
|
const bakwXUnit = (bakwBound[1][0] - bakwBound[0][0]) / gridNum;
|
|
452
445
|
const bakwYUnit = (bakwBound[1][1] - bakwBound[0][1]) / gridNum;
|
|
453
446
|
const bakwGridCache = bakwEachBound.reduce(
|
|
454
|
-
(prev:
|
|
447
|
+
(prev: number[][][], bound: Position[], index: number) => {
|
|
455
448
|
const normXMin = unitCalc(
|
|
456
449
|
bound[0][0],
|
|
457
450
|
bakwBound[0][0],
|
|
@@ -517,7 +510,7 @@ export class Transform {
|
|
|
517
510
|
*
|
|
518
511
|
* @throws {Error} 逆方向変換が許可されていない状態での逆変換時
|
|
519
512
|
*/
|
|
520
|
-
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean) {
|
|
513
|
+
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false {
|
|
521
514
|
if (backward && this.strict_status == Transform.STATUS_ERROR)
|
|
522
515
|
throw 'Backward transform is not allowed if strict_status == "strict_error"';
|
|
523
516
|
// if (!this.tins) this.updateTin();
|
package/src/triangulation.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { polygon } from "@turf/helpers";
|
|
2
|
-
import { Position } from "geojson";
|
|
3
|
-
import { PropertyTriKey, Tri, Tins } from "./geometry";
|
|
2
|
+
import type { Position } from "geojson";
|
|
3
|
+
import { PropertyTriKey, Tri, Tins } from "./geometry.ts";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 三角形の頂点の順序を修正する
|
|
@@ -8,7 +8,7 @@ import { PropertyTriKey, Tri, Tins } from "./geometry";
|
|
|
8
8
|
* @param tins 三角形群
|
|
9
9
|
* @returns 頂点順序が修正された三角形群
|
|
10
10
|
*/
|
|
11
|
-
function rotateVerticesTriangle(tins: Tins) {
|
|
11
|
+
function rotateVerticesTriangle(tins: Tins): Tins {
|
|
12
12
|
const features = tins.features;
|
|
13
13
|
for (let i = 0; i < features.length; i++) {
|
|
14
14
|
const feature = features[i];
|
|
@@ -138,7 +138,7 @@ function indexesToTri(
|
|
|
138
138
|
const points_: [Position[], string | number][] = indexes.map(
|
|
139
139
|
(index: number | string) => {
|
|
140
140
|
if (!version || version < 2.00703) index = normalizeNodeKey(index);
|
|
141
|
-
const point_base = isFinite(index as
|
|
141
|
+
const point_base = isFinite(index as number)
|
|
142
142
|
? points[index as number]
|
|
143
143
|
: index === "c"
|
|
144
144
|
? cent
|