@maplat/tin 0.11.0 → 0.11.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 +175 -120
- package/README.md +176 -121
- package/dist/constrained-tin.d.ts +29 -0
- package/dist/index.d.ts +17 -196
- package/dist/kinks.d.ts +8 -0
- package/dist/searchutils.d.ts +21 -0
- package/dist/tin.cjs +3 -0
- package/dist/tin.d.ts +100 -0
- package/dist/tin.js +2090 -0
- package/dist/tin.umd.js +3 -0
- package/dist/vertexutils.d.ts +24 -0
- package/package.json +97 -87
- package/src/constrained-tin.ts +9 -8
- package/src/index.ts +37 -930
- package/src/kinks.ts +6 -4
- package/src/tin.ts +894 -0
- package/src/types/kinks.d.ts +36 -0
- package/src/types/tin.d.ts +54 -0
- package/src/vertexutils.ts +20 -18
- package/dist/maplat_tin.cjs +0 -3
- package/dist/maplat_tin.js +0 -3291
- package/dist/maplat_tin.umd.js +0 -3
package/README.ja.md
CHANGED
|
@@ -1,121 +1,176 @@
|
|
|
1
|
-
# Maplat Tin
|
|
2
|
-
|
|
3
|
-
2つの平面座標系間で制御点に基づく同相変換を定義・実行するJavaScriptライブラリです。
|
|
4
|
-
[Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
|
|
5
|
-
|
|
6
|
-
English README is [here](./README.md).
|
|
7
|
-
|
|
8
|
-
## 主な機能
|
|
9
|
-
|
|
10
|
-
- **座標変換定義の生成:** 制御点とエッジ制約に基づいて座標変換定義を生成
|
|
11
|
-
- **双方向座標変換:** 2つの平面間で双方向の座標変換が可能
|
|
12
|
-
- **位相保存:** 変換時の同相性(トポロジー)を維持
|
|
13
|
-
- **柔軟な設定:**
|
|
14
|
-
- 通常/鳥瞰図モードの頂点処理
|
|
15
|
-
- 厳密/自動/緩和モードのトポロジーチェック
|
|
16
|
-
- Y軸の向きの制御
|
|
17
|
-
- **エッジ制約:** より正確な変換のための制約付きエッジの指定が可能
|
|
18
|
-
- **状態管理:** 変換定義の保存と復元をサポート
|
|
19
|
-
|
|
20
|
-
## インストール方法
|
|
21
|
-
|
|
22
|
-
### npm
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
# メインパッケージのインストール
|
|
26
|
-
npm install @maplat/tin
|
|
27
|
-
|
|
28
|
-
# 必要な依存パッケージのインストール
|
|
29
|
-
npm install delaunator
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
###
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
tin.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
1
|
+
# Maplat Tin
|
|
2
|
+
|
|
3
|
+
2つの平面座標系間で制御点に基づく同相変換を定義・実行するJavaScriptライブラリです。
|
|
4
|
+
[Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
|
|
5
|
+
|
|
6
|
+
English README is [here](./README.md).
|
|
7
|
+
|
|
8
|
+
## 主な機能
|
|
9
|
+
|
|
10
|
+
- **座標変換定義の生成:** 制御点とエッジ制約に基づいて座標変換定義を生成
|
|
11
|
+
- **双方向座標変換:** 2つの平面間で双方向の座標変換が可能
|
|
12
|
+
- **位相保存:** 変換時の同相性(トポロジー)を維持
|
|
13
|
+
- **柔軟な設定:**
|
|
14
|
+
- 通常/鳥瞰図モードの頂点処理
|
|
15
|
+
- 厳密/自動/緩和モードのトポロジーチェック
|
|
16
|
+
- Y軸の向きの制御
|
|
17
|
+
- **エッジ制約:** より正確な変換のための制約付きエッジの指定が可能
|
|
18
|
+
- **状態管理:** 変換定義の保存と復元をサポート
|
|
19
|
+
|
|
20
|
+
## インストール方法
|
|
21
|
+
|
|
22
|
+
### npm
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
# メインパッケージのインストール
|
|
26
|
+
npm install @maplat/tin
|
|
27
|
+
|
|
28
|
+
# 必要な依存パッケージのインストール
|
|
29
|
+
npm install delaunator
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### JSR (JavaScript Registry)
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
# Deno向け
|
|
36
|
+
deno add @maplat/tin
|
|
37
|
+
|
|
38
|
+
# npm/Node.js向け
|
|
39
|
+
npx jsr add @maplat/tin
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Deno
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// JSR経由(推奨)
|
|
46
|
+
import Tin from "jsr:@maplat/tin";
|
|
47
|
+
|
|
48
|
+
// deno.jsonのimport mapを使用
|
|
49
|
+
import Tin from "@maplat/tin";
|
|
50
|
+
|
|
51
|
+
// またはnpmから直接
|
|
52
|
+
import Tin from "npm:@maplat/tin@0.11.1";
|
|
53
|
+
|
|
54
|
+
// ライブラリを使用
|
|
55
|
+
const tin = new Tin({
|
|
56
|
+
wh: [500, 500],
|
|
57
|
+
yaxisMode: Tin.YAXIS_FOLLOW
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### ブラウザ
|
|
62
|
+
|
|
63
|
+
ブラウザで使用する場合、ピア依存関係を含める必要があります:
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<!-- 必要な依存関係 -->
|
|
67
|
+
<script src="https://unpkg.com/delaunator@5.0.0/delaunator.min.js"></script>
|
|
68
|
+
<script src="https://unpkg.com/@turf/helpers@7.2.0/dist/turf-helpers.min.js"></script>
|
|
69
|
+
<script src="https://unpkg.com/@turf/boolean-point-in-polygon@7.2.0/dist/turf-boolean-point-in-polygon.min.js"></script>
|
|
70
|
+
<script src="https://unpkg.com/@turf/centroid@7.2.0/dist/turf-centroid.min.js"></script>
|
|
71
|
+
<script src="https://unpkg.com/@turf/convex@7.2.0/dist/turf-convex.min.js"></script>
|
|
72
|
+
<script src="https://unpkg.com/@turf/line-intersect@7.2.0/dist/turf-line-intersect.min.js"></script>
|
|
73
|
+
|
|
74
|
+
<!-- Maplat Tin (UMD) -->
|
|
75
|
+
<script src="https://unpkg.com/@maplat/tin/dist/tin.umd.js"></script>
|
|
76
|
+
<script>
|
|
77
|
+
// ライブラリを使用
|
|
78
|
+
const tin = new tin.default({
|
|
79
|
+
wh: [500, 500]
|
|
80
|
+
});
|
|
81
|
+
</script>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
またはESモジュールとして使用する場合:
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<!-- Maplat Tin (ESモジュール) -->
|
|
88
|
+
<script type="module">
|
|
89
|
+
import Tin from "https://unpkg.com/@maplat/tin/dist/index.js";
|
|
90
|
+
// ライブラリを使用
|
|
91
|
+
const tin = new Tin({
|
|
92
|
+
wh: [500, 500]
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 基本的な使用方法
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// 基本設定でインスタンスを作成
|
|
101
|
+
const tin = new Tin({
|
|
102
|
+
wh: [500, 500], // ソース座標系の幅と高さ
|
|
103
|
+
yaxisMode: Tin.YAXIS_FOLLOW // Y軸の向きの設定
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 制御点の設定: [ソース座標, ターゲット座標] の配列
|
|
107
|
+
tin.setPoints([
|
|
108
|
+
[[100,100], [200, 200]], // 点1
|
|
109
|
+
[[200,200], [400, 400]], // 点2
|
|
110
|
+
[[150,150], [320, 350]], // 点3
|
|
111
|
+
[[200,100], [420, 220]] // 点4
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
// TINネットワークの初期化
|
|
115
|
+
tin.updateTin();
|
|
116
|
+
|
|
117
|
+
// トポロジーの状態確認
|
|
118
|
+
if (tin.strict_status === Tin.STATUS_STRICT) {
|
|
119
|
+
console.log('トポロジーOK: 往復変換が保証されます');
|
|
120
|
+
} else if (tin.strict_status === Tin.STATUS_LOOSE) {
|
|
121
|
+
console.log('トポロジー警告: 往復変換が保証されません');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 順方向の変換(ソース → ターゲット)
|
|
125
|
+
const transformed = tin.transform([160, 160], false);
|
|
126
|
+
|
|
127
|
+
// 逆方向の変換(ターゲット → ソース)
|
|
128
|
+
const restored = tin.transform(transformed, true);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 設定オプション
|
|
132
|
+
|
|
133
|
+
### コンストラクタオプション
|
|
134
|
+
| **オプション** | **型** | **説明** | **デフォルト** |
|
|
135
|
+
| ------------- | --------------------------- | ------------------------- | ------------- |
|
|
136
|
+
| `bounds` | `Position[]` | **境界多角形の頂点** | `-` |
|
|
137
|
+
| `wh` | `number[]` | **幅と高さ [w, h]** | `-` |
|
|
138
|
+
| `vertexMode` | `"plain"|"birdeye"` | **頂点処理モード** | `"plain"` |
|
|
139
|
+
| `strictMode` | `"strict"|"auto"|"loose"` | **トポロジーチェックモード** | `"auto"` |
|
|
140
|
+
| `yaxisMode` | `"follow"|"invert"` | **Y軸の向き** | `"invert"` |
|
|
141
|
+
| `importance` | `number` | **地図の重要度** | `0` |
|
|
142
|
+
| `priority` | `number` | **地図の優先度** | `0` |
|
|
143
|
+
|
|
144
|
+
`bounds`または`wh`のいずれかを指定する必要があります。
|
|
145
|
+
|
|
146
|
+
### メソッド
|
|
147
|
+
|
|
148
|
+
| **メソッド** | **説明** |
|
|
149
|
+
| ---------------------------- | --------------------------------- |
|
|
150
|
+
| `setPoints(points)` | **制御点の設定** |
|
|
151
|
+
| `setEdges(edges)` | **制約付きエッジの設定** |
|
|
152
|
+
| `updateTin()` | **TINネットワークの初期化/更新** |
|
|
153
|
+
| `transform(coords, inverse)` | **座標変換の実行** |
|
|
154
|
+
| `getCompiled()` | **シリアライズ可能な状態の取得** |
|
|
155
|
+
| `setCompiled(state)` | **シリアライズされた状態からの復元** |
|
|
156
|
+
|
|
157
|
+
### エラーハンドリング
|
|
158
|
+
|
|
159
|
+
このライブラリは以下の場合にエラーをスローします:
|
|
160
|
+
|
|
161
|
+
- `"TOO LINEAR1"`,`"TOO LINEAR2"`: 制御点が直線状に並びすぎている
|
|
162
|
+
- `"SOME POINTS OUTSIDE"`: 点が境界外にある
|
|
163
|
+
- 逆変換が許可されていない状態での逆変換実行時
|
|
164
|
+
|
|
165
|
+
## ライセンス
|
|
166
|
+
|
|
167
|
+
Maplat Limited License 1.1
|
|
168
|
+
|
|
169
|
+
Copyright (c) 2024 Code for History
|
|
170
|
+
|
|
171
|
+
## 開発者
|
|
172
|
+
|
|
173
|
+
- Kohei Otsuka
|
|
174
|
+
- Code for History
|
|
175
|
+
|
|
121
176
|
あなたの貢献をお待ちしていますは大歓迎です。
|
package/README.md
CHANGED
|
@@ -1,122 +1,177 @@
|
|
|
1
|
-
# Maplat Tin
|
|
2
|
-
|
|
3
|
-
A JavaScript library that defines and executes homeomorphic conversion between two plane coordinate systems based on control points.
|
|
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
|
-
- **Generate Transformation Definitions:** Create coordinate transformation definitions based on control points and edge constraints
|
|
11
|
-
- **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
|
|
12
|
-
- **Topology Preservation:** Maintains homeomorphic properties during transformation
|
|
13
|
-
- **Flexible Configuration:**
|
|
14
|
-
- Vertex handling modes (normal/bird's-eye view)
|
|
15
|
-
- Topology check modes (strict/auto/loose)
|
|
16
|
-
- Y-axis direction control
|
|
17
|
-
- **Edge Constraints:** Ability to specify constrained edges for more accurate transformation
|
|
18
|
-
- **State Management:** Save and restore transformation definitions
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
### npm
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
# Install the main package
|
|
26
|
-
npm install @maplat/tin
|
|
27
|
-
|
|
28
|
-
# Install required dependency
|
|
29
|
-
npm install delaunator
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
###
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
tin.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
1
|
+
# Maplat Tin
|
|
2
|
+
|
|
3
|
+
A JavaScript library that defines and executes homeomorphic conversion between two plane coordinate systems based on control points.
|
|
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
|
+
- **Generate Transformation Definitions:** Create coordinate transformation definitions based on control points and edge constraints
|
|
11
|
+
- **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
|
|
12
|
+
- **Topology Preservation:** Maintains homeomorphic properties during transformation
|
|
13
|
+
- **Flexible Configuration:**
|
|
14
|
+
- Vertex handling modes (normal/bird's-eye view)
|
|
15
|
+
- Topology check modes (strict/auto/loose)
|
|
16
|
+
- Y-axis direction control
|
|
17
|
+
- **Edge Constraints:** Ability to specify constrained edges for more accurate transformation
|
|
18
|
+
- **State Management:** Save and restore transformation definitions
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### npm
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
# Install the main package
|
|
26
|
+
npm install @maplat/tin
|
|
27
|
+
|
|
28
|
+
# Install required dependency
|
|
29
|
+
npm install delaunator
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### JSR (JavaScript Registry)
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
# For Deno
|
|
36
|
+
deno add @maplat/tin
|
|
37
|
+
|
|
38
|
+
# For npm/Node.js
|
|
39
|
+
npx jsr add @maplat/tin
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Deno
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// Using JSR (recommended)
|
|
46
|
+
import Tin from "jsr:@maplat/tin";
|
|
47
|
+
|
|
48
|
+
// Using deno.json import map
|
|
49
|
+
import Tin from "@maplat/tin";
|
|
50
|
+
|
|
51
|
+
// Or directly from npm
|
|
52
|
+
import Tin from "npm:@maplat/tin@0.11.1";
|
|
53
|
+
|
|
54
|
+
// Use the library
|
|
55
|
+
const tin = new Tin({
|
|
56
|
+
wh: [500, 500],
|
|
57
|
+
yaxisMode: Tin.YAXIS_FOLLOW
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Browser
|
|
62
|
+
|
|
63
|
+
When using in the browser, you need to include the peer dependencies:
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<!-- Required dependencies -->
|
|
67
|
+
<script src="https://unpkg.com/delaunator@5.0.0/delaunator.min.js"></script>
|
|
68
|
+
<script src="https://unpkg.com/@turf/helpers@7.2.0/dist/turf-helpers.min.js"></script>
|
|
69
|
+
<script src="https://unpkg.com/@turf/boolean-point-in-polygon@7.2.0/dist/turf-boolean-point-in-polygon.min.js"></script>
|
|
70
|
+
<script src="https://unpkg.com/@turf/centroid@7.2.0/dist/turf-centroid.min.js"></script>
|
|
71
|
+
<script src="https://unpkg.com/@turf/convex@7.2.0/dist/turf-convex.min.js"></script>
|
|
72
|
+
<script src="https://unpkg.com/@turf/line-intersect@7.2.0/dist/turf-line-intersect.min.js"></script>
|
|
73
|
+
|
|
74
|
+
<!-- Maplat Tin (UMD) -->
|
|
75
|
+
<script src="https://unpkg.com/@maplat/tin/dist/tin.umd.js"></script>
|
|
76
|
+
<script>
|
|
77
|
+
// Use the library
|
|
78
|
+
const tin = new tin.default({
|
|
79
|
+
wh: [500, 500]
|
|
80
|
+
});
|
|
81
|
+
</script>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Or using ES modules:
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<!-- Maplat Tin (ESM) -->
|
|
88
|
+
<script type="module">
|
|
89
|
+
import Tin from "https://unpkg.com/@maplat/tin/dist/index.js";
|
|
90
|
+
// Use the library
|
|
91
|
+
const tin = new Tin({
|
|
92
|
+
wh: [500, 500]
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Basic Usage
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// Create a new instance with basic configuration
|
|
101
|
+
const tin = new Tin({
|
|
102
|
+
wh: [500, 500], // Width and height of the source plane
|
|
103
|
+
yaxisMode: Tin.YAXIS_FOLLOW // Y-axis direction handling
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Set control points: Array of [source, target] coordinates
|
|
107
|
+
tin.setPoints([
|
|
108
|
+
[[100,100], [200, 200]], // Point 1
|
|
109
|
+
[[200,200], [400, 400]], // Point 2
|
|
110
|
+
[[150,150], [320, 350]], // Point 3
|
|
111
|
+
[[200,100], [420, 220]] // Point 4
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
// Initialize the TIN network
|
|
115
|
+
tin.updateTin();
|
|
116
|
+
|
|
117
|
+
// Check topology status
|
|
118
|
+
if (tin.strict_status === Tin.STATUS_STRICT) {
|
|
119
|
+
console.log('Topology OK: Roundtrip transform is guaranteed');
|
|
120
|
+
} else if (tin.strict_status === Tin.STATUS_LOOSE) {
|
|
121
|
+
console.log('Topology warning: Roundtrip transform is not guaranteed');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Forward transform: source to target
|
|
125
|
+
const transformed = tin.transform([160, 160], false);
|
|
126
|
+
|
|
127
|
+
// Backward transform: target to source
|
|
128
|
+
const restored = tin.transform(transformed, true);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Configuration
|
|
132
|
+
|
|
133
|
+
### Constructor Options
|
|
134
|
+
|
|
135
|
+
| **Option** | **Type** | **Description** | **Default** |
|
|
136
|
+
| ------------- | --------------------------- | ------------------------- | ------------- |
|
|
137
|
+
| `bounds` | `Position[]` | **Boundary polygon vertices** | `-` |
|
|
138
|
+
| `wh` | `number[]` | **Width and height [w, h]** | `-` |
|
|
139
|
+
| `vertexMode` | `"plain"|"birdeye"` | **Vertex handling mode** | `"plain"` |
|
|
140
|
+
| `strictMode` | `"strict"|"auto"|"loose"` | **Topology check mode** | `"auto"` |
|
|
141
|
+
| `yaxisMode` | `"follow"|"invert"` | **Y-axis direction** | `"invert"` |
|
|
142
|
+
| `importance` | `number` | **Map importance** | `0` |
|
|
143
|
+
| `priority` | `number` | **Map priority** | `0` |
|
|
144
|
+
|
|
145
|
+
Either `bounds` or `wh` must be specified.
|
|
146
|
+
|
|
147
|
+
### Methods
|
|
148
|
+
|
|
149
|
+
| **Method** | **Description** |
|
|
150
|
+
| ---------------------------- | --------------------------------- |
|
|
151
|
+
| `setPoints(points)` | **Set control points** |
|
|
152
|
+
| `setEdges(edges)` | **Set constrained edges** |
|
|
153
|
+
| `updateTin()` | **Initialize/update TIN network** |
|
|
154
|
+
| `transform(coords, inverse)` | **Execute coordinate transformation** |
|
|
155
|
+
| `getCompiled()` | **Get serializable state** |
|
|
156
|
+
| `setCompiled(state)` | **Restore from serialized state** |
|
|
157
|
+
|
|
158
|
+
### Error Handling
|
|
159
|
+
|
|
160
|
+
The library may throw errors in the following cases:
|
|
161
|
+
|
|
162
|
+
- `"TOO LINEAR1"`,`"TOO LINEAR2"`: Control points are too linear
|
|
163
|
+
- `"SOME POINTS OUTSIDE"`: Points outside boundary
|
|
164
|
+
- Custom error when attempting backward transformation in a disallowed state
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Maplat Limited License 1.1
|
|
169
|
+
|
|
170
|
+
Copyright (c) 2024 Code for History
|
|
171
|
+
|
|
172
|
+
## Developers
|
|
173
|
+
|
|
174
|
+
- Kohei Otsuka
|
|
175
|
+
- Code for History
|
|
176
|
+
|
|
122
177
|
We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { FeatureCollection, Point, Polygon } from 'geojson';
|
|
2
|
+
import { Edge } from '@maplat/transform';
|
|
3
|
+
/**
|
|
4
|
+
* 制約付きTIN(Triangulated Irregular Network)を生成します
|
|
5
|
+
*
|
|
6
|
+
* 点群から三角形分割を行い、指定されたエッジ(制約線)を
|
|
7
|
+
* 必ず三角形の辺として含むように調整します。
|
|
8
|
+
*
|
|
9
|
+
* @param points - 点群を含むFeatureCollection
|
|
10
|
+
* 各Featureは座標を持つPointである必要があります
|
|
11
|
+
* @param edges - 制約として扱うエッジの配列
|
|
12
|
+
* 各エッジは2つの頂点インデックスの組として指定
|
|
13
|
+
* @param z - 生成される三角形のプロパティに含める項目の名前
|
|
14
|
+
* (例: "target")
|
|
15
|
+
*
|
|
16
|
+
* @returns 三角形のFeatureCollectionを返します
|
|
17
|
+
* 各三角形は以下の情報を持ちます:
|
|
18
|
+
* - geometry: 三角形の座標
|
|
19
|
+
* - properties: 頂点に関連付けられた情報(a, b, cプロパティ)
|
|
20
|
+
*
|
|
21
|
+
* @throws {Error} pointsがFeatureCollectionでない場合
|
|
22
|
+
* @throws {Error} edgesが配列でない場合
|
|
23
|
+
*
|
|
24
|
+
* 処理の流れ:
|
|
25
|
+
* 1. Delaunay三角分割を実行
|
|
26
|
+
* 2. 制約エッジに基づいて三角分割を調整
|
|
27
|
+
* 3. 結果をGeoJSON形式に変換
|
|
28
|
+
*/
|
|
29
|
+
export default function (points: FeatureCollection<Point>, edges: Edge[], z: string): FeatureCollection<Polygon>;
|