@maplat/transform 0.1.5 → 0.2.1

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.ja.md CHANGED
@@ -1,69 +1,69 @@
1
- # Maplat Transform
2
-
3
- Maplatで生成された座標変換定義を使用して、2つの平面座標系間で座標変換を実現するJavaScriptライブラリです。
4
- [Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
5
-
6
- English README is [here](./README.md).
7
-
8
- ## 主な機能
9
-
10
- - **座標変換定義のインポート:** Maplatで生成された座標変換定義をインポートし、変換のための内部構造を構築
11
- - **双方向座標変換:** 2つの平面間で双方向の座標変換が可能
12
- - **位相保存:** 変換時の同相性(トポロジー)を維持
13
- - **複数の座標系サポート:** 通常の直交座標系、Y軸反転座標系、鳥瞰図のような歪んだ座標系など、様々な座標系間の変換に対応
14
- - **状態管理:** 変換状態の保存と復元をサポート
15
-
16
- ## インストール方法
17
-
18
- ### npm
19
-
20
- ```sh
21
- npm install @maplat/transform
22
- ```
23
-
24
- ### ブラウザ
25
-
26
- ```html
27
- <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
28
- ```
29
-
30
- ## 基本的な使用方法
31
-
32
- ```javascript
33
- // 変換定義データのインポート
34
- const transform = new Transform();
35
- transform.setCompiled(compiledData); // Maplatで生成された変換定義を適用
36
-
37
- // 順方向の変換(ソース座標系 → ターゲット座標系)
38
- const transformed = transform.transform([100, 100], false);
39
-
40
- // 逆方向の変換(ターゲット座標系 → ソース座標系)
41
- const restored = transform.transform(transformed, true);
42
- ```
43
-
44
- ### エラーハンドリング
45
-
46
- このライブラリは以下の場合にエラーをスローする可能性があります:
47
-
48
- - 厳密モードでの変換エラー時
49
- - 逆変換が許可されていない状態での逆変換実行時
50
- - 不正なデータ構造での変換実行時
51
-
52
- エラーが発生した場合は、変換定義データの修正が必要です。変換定義の修正は[@maplat/tin](https://github.com/code4history/MaplatTin/)を使用したエディタツールで行ってください。
53
-
54
- ## 注意事項
55
-
56
- このライブラリは座標変換の実行に特化しており、変換定義自体の生成や編集機能は含まれていません。変換定義の作成や編集が必要な場合は、[@maplat/tin](https://github.com/code4history/MaplatTin/)パッケージをご利用ください。
57
-
58
- ## ライセンス
59
-
60
- Maplat Limited License 1.1
61
-
62
- Copyright (c) 2024 Code for History
63
-
64
- ### 開発者
65
-
66
- - Kohei Otsuka
67
- - Code for History
68
-
1
+ # Maplat Transform
2
+
3
+ Maplatで生成された座標変換定義を使用して、2つの平面座標系間で座標変換を実現するJavaScriptライブラリです。
4
+ [Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
5
+
6
+ English README is [here](./README.md).
7
+
8
+ ## 主な機能
9
+
10
+ - **座標変換定義のインポート:** Maplatで生成された座標変換定義をインポートし、変換のための内部構造を構築
11
+ - **双方向座標変換:** 2つの平面間で双方向の座標変換が可能
12
+ - **位相保存:** 変換時の同相性(トポロジー)を維持
13
+ - **複数の座標系サポート:** 通常の直交座標系、Y軸反転座標系、鳥瞰図のような歪んだ座標系など、様々な座標系間の変換に対応
14
+ - **状態管理:** 変換状態の保存と復元をサポート
15
+
16
+ ## インストール方法
17
+
18
+ ### npm
19
+
20
+ ```sh
21
+ npm install @maplat/transform
22
+ ```
23
+
24
+ ### ブラウザ
25
+
26
+ ```html
27
+ <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
28
+ ```
29
+
30
+ ## 基本的な使用方法
31
+
32
+ ```javascript
33
+ // 変換定義データのインポート
34
+ const transform = new Transform();
35
+ transform.setCompiled(compiledData); // Maplatで生成された変換定義を適用
36
+
37
+ // 順方向の変換(ソース座標系 → ターゲット座標系)
38
+ const transformed = transform.transform([100, 100], false);
39
+
40
+ // 逆方向の変換(ターゲット座標系 → ソース座標系)
41
+ const restored = transform.transform(transformed, true);
42
+ ```
43
+
44
+ ### エラーハンドリング
45
+
46
+ このライブラリは以下の場合にエラーをスローする可能性があります:
47
+
48
+ - 厳密モードでの変換エラー時
49
+ - 逆変換が許可されていない状態での逆変換実行時
50
+ - 不正なデータ構造での変換実行時
51
+
52
+ エラーが発生した場合は、変換定義データの修正が必要です。変換定義の修正は[@maplat/tin](https://github.com/code4history/MaplatTin/)を使用したエディタツールで行ってください。
53
+
54
+ ## 注意事項
55
+
56
+ このライブラリは座標変換の実行に特化しており、変換定義自体の生成や編集機能は含まれていません。変換定義の作成や編集が必要な場合は、[@maplat/tin](https://github.com/code4history/MaplatTin/)パッケージをご利用ください。
57
+
58
+ ## ライセンス
59
+
60
+ Maplat Limited License 1.1
61
+
62
+ Copyright (c) 2024 Code for History
63
+
64
+ ### 開発者
65
+
66
+ - Kohei Otsuka
67
+ - Code for History
68
+
69
69
  あなたの貢献をお待ちしています![イシューやプルリクエスト](https://github.com/code4history/MaplatTransform/issues)は大歓迎です。
package/README.md CHANGED
@@ -1,69 +1,143 @@
1
- # Maplat Transform
2
-
3
- A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
4
- This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
5
-
6
- 日本語のREADMEは[こちら](./README.ja.md)
7
-
8
- ## Key Features
9
-
10
- - **Import Transformation Definitions:** Import and build internal structures from transformation definitions generated by Maplat
11
- - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
12
- - **Topology Preservation:** Maintains homeomorphic properties during transformation
13
- - **Multiple Coordinate System Support:** Handles transformations between various coordinate systems including standard orthogonal coordinates, Y-axis inverted coordinates, and distorted coordinates like bird's-eye views
14
- - **State Management:** Save and restore transformation states
15
-
16
- ## Installation
17
-
18
- ### npm
19
-
20
- ```sh
21
- npm install @maplat/transform
22
- ```
23
-
24
- ### Browser
25
-
26
- ```html
27
- <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
28
- ```
29
-
30
- ## Basic Usage
31
-
32
- ```javascript
33
- // Import transformation definition
34
- const transform = new Transform();
35
- transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
36
-
37
- // Forward transformation (source → target coordinate system)
38
- const transformed = transform.transform([100, 100], false);
39
-
40
- // Backward transformation (target → source coordinate system)
41
- const restored = transform.transform(transformed, true);
42
- ```
43
-
44
- ### Error Handling
45
-
46
- The library may throw errors in the following cases:
47
-
48
- - Transformation errors in strict mode
49
- - Attempting backward transformation when not allowed
50
- - Invalid data structure during transformation
51
-
52
- 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
-
54
- ## Important Note
55
-
56
- 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
-
58
- ## License
59
-
60
- Maplat Limited License 1.1
61
-
62
- Copyright (c) 2024 Code for History
63
-
64
- ### Developers
65
-
66
- - Kohei Otsuka
67
- - Code for History
68
-
69
- We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTransform/issues).
1
+ # Maplat Transform
2
+
3
+ A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
4
+ This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
5
+
6
+ 日本語のREADMEは[こちら](./README.ja.md)
7
+
8
+ ## Key Features
9
+
10
+ - **Import Transformation Definitions:** Import and build internal structures from transformation definitions generated by Maplat
11
+ - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
12
+ - **Topology Preservation:** Maintains homeomorphic properties during transformation
13
+ - **Multiple Coordinate System Support:** Handles transformations between various coordinate systems including standard orthogonal coordinates, Y-axis inverted coordinates, and distorted coordinates like bird's-eye views
14
+ - **State Management:** Save and restore transformation states
15
+
16
+ ## Installation
17
+
18
+ ### npm
19
+
20
+ ```sh
21
+ npm install @maplat/transform
22
+ ```
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
+
47
+ ### Browser
48
+
49
+ ```html
50
+ <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
51
+ ```
52
+
53
+ ## Basic Usage
54
+
55
+ ### Node.js/npm
56
+
57
+ ```javascript
58
+ import { Transform } from '@maplat/transform';
59
+
60
+ // Import transformation definition
61
+ const transform = new Transform();
62
+ transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
63
+
64
+ // Forward transformation (source → target coordinate system)
65
+ const transformed = transform.transform([100, 100], false);
66
+
67
+ // Backward transformation (target → source coordinate system)
68
+ const restored = transform.transform(transformed, true);
69
+ ```
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
+
89
+ ### Error Handling
90
+
91
+ The library may throw errors in the following cases:
92
+
93
+ - Transformation errors in strict mode
94
+ - Attempting backward transformation when not allowed
95
+ - Invalid data structure during transformation
96
+
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.
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
+
124
+ ## Important Note
125
+
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.
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
+
132
+ ## License
133
+
134
+ Maplat Limited License 1.1
135
+
136
+ Copyright (c) 2024 Code for History
137
+
138
+ ### Developers
139
+
140
+ - Kohei Otsuka
141
+ - Code for History
142
+
143
+ We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTransform/issues).
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): false | Position;
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[], FeatureCollection<Polygon>[]?];
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;