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