@maplat/tin 0.9.4 → 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 +176 -0
- package/README.md +143 -77
- package/dist/constrained-tin.d.ts +29 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.html +42 -0
- 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 -81
- package/src/constrained-tin.ts +79 -0
- package/src/index.ts +41 -0
- package/src/kinks.ts +1035 -0
- package/src/searchutils.ts +67 -0
- package/src/tin.ts +894 -0
- package/src/types/cdt2d.d.ts +4 -0
- package/src/types/constrainautor.d.ts +6 -0
- package/src/types/kinks.d.ts +36 -0
- package/src/types/tin.d.ts +54 -0
- package/src/vertexutils.ts +83 -0
- package/es5/index.js +0 -3
- package/es5/index.js.LICENSE.txt +0 -10
- package/es5/index.js.map +0 -1
- package/lib/booleanPointInPolygon.d.ts +0 -4
- package/lib/booleanPointInPolygon.js +0 -103
- package/lib/booleanPointInPolygon.js.map +0 -1
- package/lib/constrained-tin.d.ts +0 -4
- package/lib/constrained-tin.js +0 -41
- package/lib/constrained-tin.js.map +0 -1
- package/lib/index.d.ts +0 -157
- package/lib/index.js +0 -1472
- package/lib/index.js.map +0 -1
- package/lib/kinks.d.ts +0 -2
- package/lib/kinks.js +0 -669
- package/lib/kinks.js.map +0 -1
package/README.ja.md
ADDED
|
@@ -0,0 +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
|
+
### 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
|
+
|
|
176
|
+
あなたの貢献をお待ちしていますは大歓迎です。
|
package/README.md
CHANGED
|
@@ -1,111 +1,177 @@
|
|
|
1
|
-
# Maplat Tin
|
|
1
|
+
# Maplat Tin
|
|
2
2
|
|
|
3
|
-
JavaScript library
|
|
4
|
-
This is part of [Maplat](https://github.com/
|
|
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
5
|
|
|
6
|
-
|
|
6
|
+
日本語のREADMEは[こちら](./README.ja.md)
|
|
7
|
+
|
|
8
|
+
## Key Features
|
|
7
9
|
|
|
8
|
-
|
|
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
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
## Installation
|
|
11
21
|
|
|
12
|
-
|
|
22
|
+
### npm
|
|
13
23
|
|
|
14
24
|
```sh
|
|
25
|
+
# Install the main package
|
|
15
26
|
npm install @maplat/tin
|
|
27
|
+
|
|
28
|
+
# Install required dependency
|
|
29
|
+
npm install delaunator
|
|
16
30
|
```
|
|
17
31
|
|
|
18
|
-
###
|
|
32
|
+
### JSR (JavaScript Registry)
|
|
19
33
|
|
|
20
|
-
|
|
34
|
+
```sh
|
|
35
|
+
# For Deno
|
|
36
|
+
deno add @maplat/tin
|
|
21
37
|
|
|
22
|
-
|
|
23
|
-
|
|
38
|
+
# For npm/Node.js
|
|
39
|
+
npx jsr add @maplat/tin
|
|
24
40
|
```
|
|
25
41
|
|
|
42
|
+
### Deno
|
|
26
43
|
|
|
27
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
// Using JSR (recommended)
|
|
46
|
+
import Tin from "jsr:@maplat/tin";
|
|
28
47
|
|
|
29
|
-
|
|
30
|
-
|
|
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";
|
|
31
53
|
|
|
32
|
-
|
|
54
|
+
// Use the library
|
|
55
|
+
const tin = new Tin({
|
|
33
56
|
wh: [500, 500],
|
|
34
57
|
yaxisMode: Tin.YAXIS_FOLLOW
|
|
35
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
|
|
36
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
|
|
37
107
|
tin.setPoints([
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
42
112
|
]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.log('
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
console.log(rev);
|
|
60
|
-
//rev => [160, 160]
|
|
61
|
-
|
|
62
|
-
//Solving triangulated irregular network from many points by scrach takes too many time.
|
|
63
|
-
//So, there are object-serialization method to store solved instance.
|
|
64
|
-
|
|
65
|
-
var compiled = tin.getCompiled();
|
|
66
|
-
|
|
67
|
-
var tin2 = new Tin();
|
|
68
|
-
tin2.setCompiled(compiled);
|
|
69
|
-
// Compiled triangulated irregular network was set. no "updateTinAsync" call is need.
|
|
70
|
-
|
|
71
|
-
var ord2 = tin.transform([160, 160], false);
|
|
72
|
-
console.log(ord2);
|
|
73
|
-
var rev2 = tin.transform(ord2, true);
|
|
74
|
-
console.log(rev2);
|
|
75
|
-
//Same results with ord, rev
|
|
76
|
-
}).catch(function(e) {
|
|
77
|
-
if (e == 'TOO LINEAR1' || e == 'TOO LINEAR2') {
|
|
78
|
-
console.log('Given GCP points are too linear, fail to create triangulated irregular network.');
|
|
79
|
-
} else {
|
|
80
|
-
console.log('Something wrong');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
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);
|
|
83
129
|
```
|
|
84
130
|
|
|
85
|
-
##
|
|
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** |
|
|
86
157
|
|
|
87
|
-
###
|
|
88
|
-
Set width and height of the first coordinate system.
|
|
89
|
-
*NOTE: If setWh was called, TIN network is reset. So need to call updateTinAsync() again.*
|
|
158
|
+
### Error Handling
|
|
90
159
|
|
|
91
|
-
|
|
92
|
-
Set *Tin.YAXIS_FOLLOW* if the y coordinate of the first coordinate system is the same as the direction of the y axis of the second coordinate system, and set *Tin.YAXIS_INVERT* if it is in the opposite direction.
|
|
93
|
-
Default value is *Tin.YAXIS_INVERT*.
|
|
160
|
+
The library may throw errors in the following cases:
|
|
94
161
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
98
165
|
|
|
99
|
-
##
|
|
166
|
+
## License
|
|
100
167
|
|
|
101
|
-
|
|
102
|
-
Return value is Promise. Calcurate TIN asynchronously. Before calling *transform*, this method needs to be completed.
|
|
168
|
+
Maplat Limited License 1.1
|
|
103
169
|
|
|
104
|
-
|
|
105
|
-
Convert the coordinates. If the value of *inverse* is false, the direction of conversion is from the first coordinate system to the second one, if it is true, the direction of conversion is reverse direction.
|
|
170
|
+
Copyright (c) 2024 Code for History
|
|
106
171
|
|
|
107
|
-
##
|
|
172
|
+
## Developers
|
|
108
173
|
|
|
109
|
-
|
|
174
|
+
- Kohei Otsuka
|
|
175
|
+
- Code for History
|
|
110
176
|
|
|
111
|
-
|
|
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>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @maplat/tin - TIN (Triangulated Irregular Network) generation library
|
|
3
|
+
*
|
|
4
|
+
* This is the main entry point for the library.
|
|
5
|
+
* Provides TIN generation with constrained edges for map transformation.
|
|
6
|
+
*/
|
|
7
|
+
export { Tin } from "./tin";
|
|
8
|
+
export type { Options } from "./tin";
|
|
9
|
+
export { default as constrainedTin } from "./constrained-tin";
|
|
10
|
+
export { default as findIntersections } from "./kinks";
|
|
11
|
+
export { insertSearchIndex } from "./searchutils";
|
|
12
|
+
export { createPoint, counterPoint, vertexCalc } from "./vertexutils";
|
|
13
|
+
export type { SearchIndex } from "./searchutils";
|
|
14
|
+
export type { IntersectionPoint } from "./types/kinks";
|
|
15
|
+
export type { TriangleProperties } from "./types/tin";
|
|
16
|
+
export type { Compiled, Edge, EdgeSet, EdgeSetLegacy, PointSet, PropertyTriKey, StrictMode, StrictStatus, Tri, Tins, Transform, VertexMode, YaxisMode } from '@maplat/transform';
|
|
17
|
+
export { format_version } from '@maplat/transform';
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="ja">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>MaplatTin Test</title>
|
|
6
|
+
<script src="https://unpkg.com/@turf/turf/turf.min.js"></script>
|
|
7
|
+
<script src="https://unpkg.com/delaunator/delaunator.min.js"></script>
|
|
8
|
+
<script src="https://unpkg.com/@kninnug/constrainautor/lib/Constrainautor.min.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<h1>MaplatTin Test</h1>
|
|
12
|
+
<div id="output"></div>
|
|
13
|
+
<script type="module">
|
|
14
|
+
import Tin from '/src/index.ts';
|
|
15
|
+
|
|
16
|
+
const tin = new Tin({
|
|
17
|
+
bounds: [[100, 50], [150, 150], [150, 200], [60, 190], [50, 100]],
|
|
18
|
+
strictMode: Tin.MODE_STRICT
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
tin.setPoints([
|
|
22
|
+
[[80, 90], [160, -90]],
|
|
23
|
+
[[120, 120], [240, -120]],
|
|
24
|
+
[[100, 140], [200, -140]],
|
|
25
|
+
[[130, 180], [260, -180]],
|
|
26
|
+
[[70, 150], [140, -150]]
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
tin.updateTinAsync().then(() => {
|
|
30
|
+
const output = document.getElementById('output');
|
|
31
|
+
const result1 = tin.transform([140, 150]);
|
|
32
|
+
const result2 = tin.transform(result1, true);
|
|
33
|
+
|
|
34
|
+
output.innerHTML = `
|
|
35
|
+
<h2>Test Results:</h2>
|
|
36
|
+
<p>Forward transform [140, 150] => [${result1.join(', ')}]</p>
|
|
37
|
+
<p>Backward transform [${result1.join(', ')}] => [${result2.join(', ')}]</p>
|
|
38
|
+
`;
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
package/dist/kinks.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Tri, Tins } from '@maplat/transform';
|
|
2
|
+
type BiDirectionKey = "forw" | "bakw";
|
|
3
|
+
type TinsBD = {
|
|
4
|
+
[key in BiDirectionKey]?: Tins;
|
|
5
|
+
};
|
|
6
|
+
type SearchTris = {
|
|
7
|
+
[key in BiDirectionKey]: Tri;
|
|
8
|
+
};
|
|
9
|
+
export type SearchIndex = {
|
|
10
|
+
[key: string]: SearchTris[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 検索インデックスに三角形を追加する
|
|
14
|
+
*
|
|
15
|
+
* @param searchIndex 検索インデックス
|
|
16
|
+
* @param tris 追加する三角形ペア
|
|
17
|
+
* @param tins (オプション)追加先の三角形群
|
|
18
|
+
* @throws キーの不一致エラー
|
|
19
|
+
*/
|
|
20
|
+
declare function insertSearchIndex(searchIndex: SearchIndex, tris: SearchTris, tins?: TinsBD): void;
|
|
21
|
+
export { insertSearchIndex };
|