@maplat/transform 0.4.1 → 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.md CHANGED
@@ -1,171 +1,179 @@
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).
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[];