@maplat/transform 0.4.0 → 0.5.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.ja.md CHANGED
@@ -1,69 +1,179 @@
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
+ [![CI](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml/badge.svg)](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml)
4
+
5
+ Maplatで生成された座標変換定義を使用して、2つの平面座標系間で座標変換を実現するJavaScriptライブラリです。
6
+ [Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
7
+
8
+ English README is [here](./README.md).
9
+
10
+ ## 主な機能
11
+
12
+ - **座標変換定義のインポート:** Maplatで生成された座標変換定義をインポートし、変換のための内部構造を構築
13
+ - **V2/V3フォーマット対応:** レガシーV2フォーマット(固定4境界頂点)と新しいV3フォーマット(N境界頂点、より高精度)の両方に対応
14
+ - **双方向座標変換:** 2つの平面間で双方向の座標変換が可能
15
+ - **位相保存:** 変換時の同相性(トポロジー)を維持
16
+ - **複数の座標系サポート:** 通常の直交座標系、Y軸反転座標系、鳥瞰図のような歪んだ座標系など、様々な座標系間の変換に対応
17
+ - **状態管理:** 変換状態の保存と復元をサポート
18
+
19
+ ## 動作要件
20
+
21
+ - **Node.js:** >= 20
22
+ - **pnpm:** >= 9(開発時)
23
+
24
+ ## インストール方法
25
+
26
+ ### pnpm(推奨)
27
+
28
+ ```sh
29
+ pnpm add @maplat/transform
30
+ ```
31
+
32
+ ### npm
33
+
34
+ ```sh
35
+ npm install @maplat/transform
36
+ ```
37
+
38
+ ### ブラウザ
39
+
40
+ ```html
41
+ <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
42
+ ```
43
+
44
+ ## 基本的な使用方法
45
+
46
+ ```javascript
47
+ import { Transform } from '@maplat/transform';
48
+
49
+ // 変換定義データのインポート
50
+ const transform = new Transform();
51
+ transform.setCompiled(compiledData); // Maplatで生成された変換定義を適用
52
+
53
+ // 順方向の変換(ソース座標系 → ターゲット座標系)
54
+ const transformed = transform.transform([100, 100], false);
55
+
56
+ // 逆方向の変換(ターゲット座標系 → ソース座標系)
57
+ const restored = transform.transform(transformed, true);
58
+ ```
59
+
60
+ ### エラーハンドリング
61
+
62
+ このライブラリは以下の場合にエラーをスローする可能性があります:
63
+
64
+ - 厳密モードでの変換エラー時
65
+ - 逆変換が許可されていない状態での逆変換実行時
66
+ - 不正なデータ構造での変換実行時
67
+
68
+ エラーが発生した場合は、変換定義データの修正が必要です。変換定義の修正は[@maplat/tin](https://github.com/code4history/MaplatTin/)を使用したエディタツールで行ってください。
69
+
70
+ ## API リファレンス
71
+
72
+ ### Transform クラス
73
+
74
+ 座標変換を行うメインクラスです。
75
+
76
+ #### コンストラクタ
77
+
78
+ ```javascript
79
+ const transform = new Transform();
80
+ ```
81
+
82
+ #### メソッド
83
+
84
+ ##### `setCompiled(compiled: Compiled | CompiledLegacy): void`
85
+
86
+ Maplatで生成されたコンパイル済み変換定義をインポートして適用します。レガシー形式、V2(4境界頂点)、V3(N境界頂点)を自動的に判別して処理します。
87
+
88
+ - **パラメータ:**
89
+ - `compiled`: コンパイル済み変換定義オブジェクト(V2、V3、またはレガシー形式)
90
+
91
+ ##### `transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false`
92
+
93
+ 座標変換を実行します。
94
+
95
+ - **パラメータ:**
96
+ - `apoint`: 変換する座標 `[x, y]`
97
+ - `backward`: 逆方向の変換を行うか(デフォルト: `false`)
98
+ - `ignoreBounds`: 境界チェックを無視するか(デフォルト: `false`)
99
+ - **戻り値:** 変換後の座標、または境界外の場合は `false`
100
+ - **例外:** `strict_status == "strict_error"` の状態で逆変換を試みた場合にエラーをスロー
101
+
102
+ #### 静的定数
103
+
104
+ **頂点モード:**
105
+ - `Transform.VERTEX_PLAIN`: 標準平面座標系
106
+ - `Transform.VERTEX_BIRDEYE`: 鳥瞰図座標系
107
+
108
+ **厳密モード:**
109
+ - `Transform.MODE_STRICT`: 厳密な変換モード
110
+ - `Transform.MODE_AUTO`: 自動モード選択
111
+ - `Transform.MODE_LOOSE`: 緩い変換モード
112
+
113
+ **厳密ステータス:**
114
+ - `Transform.STATUS_STRICT`: 厳密ステータス
115
+ - `Transform.STATUS_ERROR`: エラーステータス(逆変換不可)
116
+ - `Transform.STATUS_LOOSE`: 緩いステータス
117
+
118
+ **Y軸モード:**
119
+ - `Transform.YAXIS_FOLLOW`: Y軸方向に従う
120
+ - `Transform.YAXIS_INVERT`: Y軸方向を反転
121
+
122
+ ### エクスポートされる型
123
+
124
+ - `PointSet`, `BiDirectionKey`, `WeightBufferBD`, `VertexMode`, `StrictMode`, `StrictStatus`, `YaxisMode`
125
+ - `CentroidBD`, `TinsBD`, `KinksBD`, `VerticesParamsBD`, `IndexedTinsBD`
126
+ - `Compiled`, `CompiledLegacy`
127
+ - `Tins`, `Tri`, `PropertyTriKey`
128
+ - `Edge`, `EdgeSet`, `EdgeSetLegacy`
129
+
130
+ ### エクスポートされるユーティリティ関数
131
+
132
+ - `transformArr`: 低レベルの座標変換関数
133
+ - `rotateVerticesTriangle`: 三角形の頂点を回転
134
+ - `counterTri`: カウンター三角形ユーティリティ
135
+ - `normalizeEdges`: エッジ定義の正規化
136
+
137
+ ### フォーマットバージョン
138
+
139
+ ```javascript
140
+ import { format_version } from '@maplat/transform';
141
+ console.log(format_version); // 現在のフォーマットバージョン
142
+ ```
143
+
144
+ コンパイル済みデータのフォーマットには2つのモダンバージョンがあります:
145
+
146
+ - **V2:** マップのバウンディングボックスから算出した固定4点の境界頂点を使用
147
+ - **V3:** N個(4以上)の境界頂点を使用し、特にマップ端付近の変換精度を向上
148
+
149
+ どちらのフォーマットも `setCompiled()` が自動的に判別して処理します。V3フォーマットのコンパイル済みデータはバージョン3以降の[@maplat/tin](https://github.com/code4history/MaplatTin/)で生成されます。
150
+
151
+ ## ドキュメント
152
+
153
+ 変換処理の内部実装に関する技術的な詳細については、以下を参照してください:
154
+ - [Transform Internals](./docs/transform-internals.ja.md) - Transformクラスの状態復元と座標検索処理に関する実行時メモ
155
+
156
+ ## 開発
157
+
158
+ ### テストの実行
159
+
160
+ ```sh
161
+ pnpm test
162
+ ```
163
+
164
+ ## 注意事項
165
+
166
+ このライブラリは座標変換の実行に特化しており、変換定義自体の生成や編集機能は含まれていません。変換定義の作成や編集が必要な場合は、[@maplat/tin](https://github.com/code4history/MaplatTin/)パッケージをご利用ください。
167
+
168
+ ## ライセンス
169
+
170
+ Maplat Limited License 1.1
171
+
172
+ Copyright (c) 2025 Code for History
173
+
174
+ ### 開発者
175
+
176
+ - Kohei Otsuka
177
+ - Code for History
178
+
69
179
  あなたの貢献をお待ちしています![イシューやプルリクエスト](https://github.com/code4history/MaplatTransform/issues)は大歓迎です。
package/README.md CHANGED
@@ -1,143 +1,179 @@
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).
1
+ # Maplat Transform
2
+
3
+ [![CI](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml/badge.svg)](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml)
4
+
5
+ A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
6
+ This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
7
+
8
+ 日本語のREADMEは[こちら](./README.ja.md)
9
+
10
+ ## Key Features
11
+
12
+ - **Import Transformation Definitions:** Import and build internal structures from transformation definitions generated by Maplat
13
+ - **V2/V3 Format Support:** Compatible with both legacy V2 compiled format (4 fixed boundary vertices) and the new V3 format (N boundary vertices for higher accuracy)
14
+ - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
15
+ - **Topology Preservation:** Maintains homeomorphic properties during transformation
16
+ - **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
17
+ - **State Management:** Save and restore transformation states
18
+
19
+ ## Requirements
20
+
21
+ - **Node.js:** >= 20
22
+ - **pnpm:** >= 9 (for development)
23
+
24
+ ## Installation
25
+
26
+ ### pnpm (Recommended)
27
+
28
+ ```sh
29
+ pnpm add @maplat/transform
30
+ ```
31
+
32
+ ### npm
33
+
34
+ ```sh
35
+ npm install @maplat/transform
36
+ ```
37
+
38
+ ### Browser
39
+
40
+ ```html
41
+ <script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>
42
+ ```
43
+
44
+ ## Basic Usage
45
+
46
+ ```javascript
47
+ import { Transform } from '@maplat/transform';
48
+
49
+ // Import transformation definition
50
+ const transform = new Transform();
51
+ transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
52
+
53
+ // Forward transformation (source → target coordinate system)
54
+ const transformed = transform.transform([100, 100], false);
55
+
56
+ // Backward transformation (target → source coordinate system)
57
+ const restored = transform.transform(transformed, true);
58
+ ```
59
+
60
+ ### Error Handling
61
+
62
+ The library may throw errors in the following cases:
63
+
64
+ - Transformation errors in strict mode
65
+ - Attempting backward transformation when not allowed
66
+ - Invalid data structure during transformation
67
+
68
+ 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.
69
+
70
+ ## API Reference
71
+
72
+ ### Transform Class
73
+
74
+ The main class for coordinate transformation.
75
+
76
+ #### Constructor
77
+
78
+ ```javascript
79
+ const transform = new Transform();
80
+ ```
81
+
82
+ #### Methods
83
+
84
+ ##### `setCompiled(compiled: Compiled | CompiledLegacy): void`
85
+
86
+ Import and apply a compiled transformation definition generated by Maplat. Supports legacy format, V2 (4 boundary vertices), and V3 (N boundary vertices) automatically.
87
+
88
+ - **Parameters:**
89
+ - `compiled`: Compiled transformation definition object (V2, V3, or legacy format)
90
+
91
+ ##### `transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false`
92
+
93
+ Perform coordinate transformation.
94
+
95
+ - **Parameters:**
96
+ - `apoint`: Coordinate to transform `[x, y]`
97
+ - `backward`: Whether to perform backward transformation (default: `false`)
98
+ - `ignoreBounds`: Whether to ignore boundary checks (default: `false`)
99
+ - **Returns:** Transformed coordinate or `false` if out of bounds
100
+ - **Throws:** Error if backward transformation is attempted when `strict_status == "strict_error"`
101
+
102
+ #### Static Constants
103
+
104
+ **Vertex Modes:**
105
+ - `Transform.VERTEX_PLAIN`: Standard plane coordinate system
106
+ - `Transform.VERTEX_BIRDEYE`: Bird's-eye view coordinate system
107
+
108
+ **Strict Modes:**
109
+ - `Transform.MODE_STRICT`: Strict transformation mode
110
+ - `Transform.MODE_AUTO`: Automatic mode selection
111
+ - `Transform.MODE_LOOSE`: Loose transformation mode
112
+
113
+ **Strict Status:**
114
+ - `Transform.STATUS_STRICT`: Strict status
115
+ - `Transform.STATUS_ERROR`: Error status (backward transformation not allowed)
116
+ - `Transform.STATUS_LOOSE`: Loose status
117
+
118
+ **Y-axis Modes:**
119
+ - `Transform.YAXIS_FOLLOW`: Follow Y-axis direction
120
+ - `Transform.YAXIS_INVERT`: Invert Y-axis direction
121
+
122
+ ### Exported Types
123
+
124
+ - `PointSet`, `BiDirectionKey`, `WeightBufferBD`, `VertexMode`, `StrictMode`, `StrictStatus`, `YaxisMode`
125
+ - `CentroidBD`, `TinsBD`, `KinksBD`, `VerticesParamsBD`, `IndexedTinsBD`
126
+ - `Compiled`, `CompiledLegacy`
127
+ - `Tins`, `Tri`, `PropertyTriKey`
128
+ - `Edge`, `EdgeSet`, `EdgeSetLegacy`
129
+
130
+ ### Exported Utility Functions
131
+
132
+ - `transformArr`: Low-level coordinate transformation function
133
+ - `rotateVerticesTriangle`: Rotate vertices of a triangle
134
+ - `counterTri`: Counter triangle utility
135
+ - `normalizeEdges`: Normalize edge definitions
136
+
137
+ ### Format Version
138
+
139
+ ```javascript
140
+ import { format_version } from '@maplat/transform';
141
+ console.log(format_version); // Current format version
142
+ ```
143
+
144
+ The compiled data format has two modern versions:
145
+
146
+ - **V2:** Uses 4 fixed boundary vertices derived from the map bounding box
147
+ - **V3:** Uses N boundary vertices (≥4) for more precise boundary definition, improving transformation accuracy especially near map edges
148
+
149
+ Both formats are handled transparently by `setCompiled()`. V3 compiled data is generated by [@maplat/tin](https://github.com/code4history/MaplatTin/) version 3 or later.
150
+
151
+ ## Documentation
152
+
153
+ For detailed technical information about the transformation internals, see:
154
+ - [Transform Internals](./docs/transform-internals.md) - Runtime notes on how Transform class reconstructs state and performs coordinate lookups
155
+
156
+ ## Development
157
+
158
+ ### Running Tests
159
+
160
+ ```sh
161
+ pnpm test
162
+ ```
163
+
164
+ ## Important Note
165
+
166
+ 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.
167
+
168
+ ## License
169
+
170
+ Maplat Limited License 1.1
171
+
172
+ Copyright (c) 2025 Code for History
173
+
174
+ ### Developers
175
+
176
+ - Kohei Otsuka
177
+ - Code for History
178
+
179
+ We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTransform/issues).
package/dist/index.d.ts CHANGED
@@ -32,7 +32,7 @@ export declare interface Compiled {
32
32
  strictMode?: StrictMode;
33
33
  vertices_params: number[][];
34
34
  vertices_points: PointSet[];
35
- edges: EdgeSet[];
35
+ edges?: EdgeSet[];
36
36
  bounds?: number[][];
37
37
  boundsPolygon?: Feature<Polygon>;
38
38
  wh?: number[];