@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/LICENSE +224 -224
- package/README.ja.md +178 -170
- package/README.md +179 -171
- package/dist/index.d.ts +1 -1
- package/dist/maplat_transform.js +130 -135
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +1 -1
- package/src/compiled-state.ts +213 -211
- package/src/edgeutils.ts +47 -47
- package/src/geometry.ts +240 -247
- package/src/index.ts +400 -398
- package/src/triangulation.ts +170 -179
- package/src/types.ts +122 -122
package/README.md
CHANGED
|
@@ -1,171 +1,179 @@
|
|
|
1
|
-
# Maplat Transform
|
|
2
|
-
|
|
3
|
-
[](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
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- **
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
transform
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
- `
|
|
97
|
-
- `
|
|
98
|
-
-
|
|
99
|
-
- **
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
- `Transform.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
- `Transform.
|
|
110
|
-
- `Transform.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
- `Transform.
|
|
115
|
-
- `Transform.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
- `Transform.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
- `
|
|
125
|
-
- `
|
|
126
|
-
- `
|
|
127
|
-
- `
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
134
|
-
- `
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
##
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
1
|
+
# Maplat Transform
|
|
2
|
+
|
|
3
|
+
[](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