@maplat/transform 0.4.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.
Files changed (3) hide show
  1. package/README.ja.md +103 -1
  2. package/README.md +89 -61
  3. package/package.json +1 -1
package/README.ja.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Maplat Transform
2
2
 
3
+ [![CI](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml/badge.svg)](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml)
4
+
3
5
  Maplatで生成された座標変換定義を使用して、2つの平面座標系間で座標変換を実現するJavaScriptライブラリです。
4
6
  [Maplat](https://github.com/code4history/Maplat/)プロジェクトの一部として開発されています。
5
7
 
@@ -13,8 +15,19 @@ English README is [here](./README.md).
13
15
  - **複数の座標系サポート:** 通常の直交座標系、Y軸反転座標系、鳥瞰図のような歪んだ座標系など、様々な座標系間の変換に対応
14
16
  - **状態管理:** 変換状態の保存と復元をサポート
15
17
 
18
+ ## 動作要件
19
+
20
+ - **Node.js:** >= 20
21
+ - **pnpm:** >= 9(開発時)
22
+
16
23
  ## インストール方法
17
24
 
25
+ ### pnpm(推奨)
26
+
27
+ ```sh
28
+ pnpm add @maplat/transform
29
+ ```
30
+
18
31
  ### npm
19
32
 
20
33
  ```sh
@@ -30,6 +43,8 @@ npm install @maplat/transform
30
43
  ## 基本的な使用方法
31
44
 
32
45
  ```javascript
46
+ import { Transform } from '@maplat/transform';
47
+
33
48
  // 変換定義データのインポート
34
49
  const transform = new Transform();
35
50
  transform.setCompiled(compiledData); // Maplatで生成された変換定義を適用
@@ -51,6 +66,93 @@ const restored = transform.transform(transformed, true);
51
66
 
52
67
  エラーが発生した場合は、変換定義データの修正が必要です。変換定義の修正は[@maplat/tin](https://github.com/code4history/MaplatTin/)を使用したエディタツールで行ってください。
53
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
+
54
156
  ## 注意事項
55
157
 
56
158
  このライブラリは座標変換の実行に特化しており、変換定義自体の生成や編集機能は含まれていません。変換定義の作成や編集が必要な場合は、[@maplat/tin](https://github.com/code4history/MaplatTin/)パッケージをご利用ください。
@@ -59,7 +161,7 @@ const restored = transform.transform(transformed, true);
59
161
 
60
162
  Maplat Limited License 1.1
61
163
 
62
- Copyright (c) 2024 Code for History
164
+ Copyright (c) 2025 Code for History
63
165
 
64
166
  ### 開発者
65
167
 
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Maplat Transform
2
2
 
3
+ [![CI](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml/badge.svg)](https://github.com/code4history/MaplatTransform/actions/workflows/test.yml)
4
+
3
5
  A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.
4
6
  This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
5
7
 
@@ -13,35 +15,23 @@ This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
13
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
14
16
  - **State Management:** Save and restore transformation states
15
17
 
16
- ## Installation
18
+ ## Requirements
17
19
 
18
- ### npm
20
+ - **Node.js:** >= 20
21
+ - **pnpm:** >= 9 (for development)
19
22
 
20
- ```sh
21
- npm install @maplat/transform
22
- ```
23
+ ## Installation
23
24
 
24
- ### JSR (JavaScript Registry)
25
+ ### pnpm (Recommended)
25
26
 
26
27
  ```sh
27
- # For Deno
28
- deno add @maplat/transform
29
-
30
- # For npm/Node.js
31
- npx jsr add @maplat/transform
28
+ pnpm add @maplat/transform
32
29
  ```
33
30
 
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";
31
+ ### npm
42
32
 
43
- // Or directly from npm
44
- import { Transform } from "npm:@maplat/transform";
33
+ ```sh
34
+ npm install @maplat/transform
45
35
  ```
46
36
 
47
37
  ### Browser
@@ -52,8 +42,6 @@ import { Transform } from "npm:@maplat/transform";
52
42
 
53
43
  ## Basic Usage
54
44
 
55
- ### Node.js/npm
56
-
57
45
  ```javascript
58
46
  import { Transform } from '@maplat/transform';
59
47
 
@@ -68,24 +56,6 @@ const transformed = transform.transform([100, 100], false);
68
56
  const restored = transform.transform(transformed, true);
69
57
  ```
70
58
 
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
59
  ### Error Handling
90
60
 
91
61
  The library may throw errors in the following cases:
@@ -96,44 +66,102 @@ The library may throw errors in the following cases:
96
66
 
97
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.
98
68
 
99
- ## Development
69
+ ## API Reference
100
70
 
101
- ### Running Tests
71
+ ### Transform Class
102
72
 
103
- #### Node.js
104
- ```sh
105
- npm test
73
+ The main class for coordinate transformation.
74
+
75
+ #### Constructor
76
+
77
+ ```javascript
78
+ const transform = new Transform();
106
79
  ```
107
80
 
108
- #### Deno
109
- ```sh
110
- deno task test
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
111
141
  ```
112
142
 
113
- ### Running Examples
143
+ ## Documentation
114
144
 
115
- #### Deno
116
- ```sh
117
- # Run the example
118
- deno run --allow-read examples/deno-example.ts
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
119
147
 
120
- # Or using deno task
121
- cd examples && deno run --allow-read deno-example.ts
148
+ ## Development
149
+
150
+ ### Running Tests
151
+
152
+ ```sh
153
+ pnpm test
122
154
  ```
123
155
 
124
156
  ## Important Note
125
157
 
126
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.
127
159
 
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
160
  ## License
133
161
 
134
162
  Maplat Limited License 1.1
135
163
 
136
- Copyright (c) 2024 Code for History
164
+ Copyright (c) 2025 Code for History
137
165
 
138
166
  ### Developers
139
167
 
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.4.0",
7
+ "version": "0.4.1",
8
8
  "description": "A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat.",
9
9
  "type": "module",
10
10
  "engines": {