@maplat/tin 0.12.0 → 0.13.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,215 +1,215 @@
1
- # Maplat Tin
2
-
3
- A JavaScript library that defines and executes homeomorphic conversion between two plane coordinate systems based on control points.
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
- - **Generate Transformation Definitions:** Create coordinate transformation definitions based on control points and edge constraints
11
- - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
12
- - **Topology Preservation:** Maintains homeomorphic properties during transformation
13
- - **Flexible Configuration:**
14
- - Vertex handling modes (normal/bird's-eye view)
15
- - Topology check modes (strict/auto/loose)
16
- - Y-axis direction control
17
- - **Edge Constraints:** Ability to specify constrained edges for more accurate transformation
18
- - **State Management:** Save and restore transformation definitions
19
-
20
- ## Installation
21
-
22
- ### npm
23
-
24
- ```sh
25
- # Install the main package
26
- npm install @maplat/tin
27
-
28
- # Install required dependency
29
- npm install delaunator
30
- ```
31
-
32
-
33
- ## Development Setup
34
-
35
- This project supports using local dependencies for development. We recommend using `yalc` for managing local package dependencies.
36
-
37
- ### Using yalc for Local Development
38
-
39
- 1. **Install yalc globally:**
40
- ```sh
41
- npm install -g yalc
42
- ```
43
-
44
- 2. **Publish local dependencies:**
45
- ```sh
46
- # In the MaplatTransform directory
47
- cd ../MaplatTransform
48
- yalc publish
49
- ```
50
-
51
- 3. **Link local dependencies in this project:**
52
- ```sh
53
- # In the MaplatTin directory
54
- yalc add @maplat/transform
55
- ```
56
-
57
- 4. **Update local dependencies when changed:**
58
- ```sh
59
- # In the dependency directory (e.g., MaplatTransform)
60
- yalc publish --push
61
- ```
62
-
63
- 5. **Remove local dependencies (to use npm packages):**
64
- ```sh
65
- # In the MaplatTin directory
66
- yalc remove @maplat/transform
67
- npm install
68
- ```
69
-
70
- **Note:** The `.yalc` directory and `yalc.lock` file are ignored by git and will not be committed.
71
-
72
- ### Testing
73
-
74
- The project includes comprehensive unit tests for both the TIN transformation logic and the internal EdgeBound constraint engine.
75
-
76
- **Run all tests:**
77
- ```sh
78
- pnpm test
79
- ```
80
-
81
- **Run specific test suite:**
82
- ```sh
83
- # EdgeBound constraint engine tests
84
- pnpm test tests/edgebound
85
-
86
- # TIN transformation tests
87
- pnpm test tests/tin
88
- ```
89
-
90
- **Test coverage:**
91
- - `tests/edgebound/` - Internal EdgeBound constraint engine tests (455 tests)
92
- - `constrain.test.ts` - Integration tests for constraint operations
93
- - `constrain.unit.test.ts` - Unit tests for constraint methods
94
- - `intersect.test.ts` - Segment intersection detection tests
95
- - `validators.ts` - Test utilities for validating triangulation integrity
96
- - `tests/tin.test.ts` - TIN transformation tests with real map data
97
- - `tests/transform.test.ts` - Coordinate transformation tests
98
-
99
- ### Browser
100
-
101
- When using in the browser, you need to include the peer dependencies:
102
-
103
- ```html
104
- <!-- Required dependencies -->
105
- <script src="https://unpkg.com/delaunator@5.0.0/delaunator.min.js"></script>
106
- <script src="https://unpkg.com/@turf/helpers@7.2.0/dist/turf-helpers.min.js"></script>
107
- <script src="https://unpkg.com/@turf/boolean-point-in-polygon@7.2.0/dist/turf-boolean-point-in-polygon.min.js"></script>
108
- <script src="https://unpkg.com/@turf/centroid@7.2.0/dist/turf-centroid.min.js"></script>
109
- <script src="https://unpkg.com/@turf/convex@7.2.0/dist/turf-convex.min.js"></script>
110
- <script src="https://unpkg.com/@turf/line-intersect@7.2.0/dist/turf-line-intersect.min.js"></script>
111
-
112
- <!-- Maplat Tin (UMD) -->
113
- <script src="https://unpkg.com/@maplat/tin/dist/tin.umd.js"></script>
114
- <script>
115
- // Use the library
116
- const tin = new tin.default({
117
- wh: [500, 500]
118
- });
119
- </script>
120
- ```
121
-
122
- Or using ES modules:
123
-
124
- ```html
125
- <!-- Maplat Tin (ESM) -->
126
- <script type="module">
127
- import Tin from "https://unpkg.com/@maplat/tin/dist/index.js";
128
- // Use the library
129
- const tin = new Tin({
130
- wh: [500, 500]
131
- });
132
- </script>
133
- ```
134
-
135
- ## Basic Usage
136
-
137
- ```javascript
138
- // Create a new instance with basic configuration
139
- const tin = new Tin({
140
- wh: [500, 500], // Width and height of the source plane
141
- yaxisMode: Tin.YAXIS_FOLLOW // Y-axis direction handling
142
- });
143
-
144
- // Set control points: Array of [source, target] coordinates
145
- tin.setPoints([
146
- [[100,100], [200, 200]], // Point 1
147
- [[200,200], [400, 400]], // Point 2
148
- [[150,150], [320, 350]], // Point 3
149
- [[200,100], [420, 220]] // Point 4
150
- ]);
151
-
152
- // Initialize the TIN network
153
- tin.updateTin();
154
-
155
- // Check topology status
156
- if (tin.strict_status === Tin.STATUS_STRICT) {
157
- console.log('Topology OK: Roundtrip transform is guaranteed');
158
- } else if (tin.strict_status === Tin.STATUS_LOOSE) {
159
- console.log('Topology warning: Roundtrip transform is not guaranteed');
160
- }
161
-
162
- // Forward transform: source to target
163
- const transformed = tin.transform([160, 160], false);
164
-
165
- // Backward transform: target to source
166
- const restored = tin.transform(transformed, true);
167
- ```
168
-
169
- ## Configuration
170
-
171
- ### Constructor Options
172
-
173
- | **Option** | **Type** | **Description** | **Default** |
174
- | ------------- | --------------------------- | ------------------------- | ------------- |
175
- | `bounds` | `Position[]` | **Boundary polygon vertices** | `-` |
176
- | `wh` | `number[]` | **Width and height [w, h]** | `-` |
177
- | `vertexMode` | `"plain"|"birdeye"` | **Vertex handling mode** | `"plain"` |
178
- | `strictMode` | `"strict"|"auto"|"loose"` | **Topology check mode** | `"auto"` |
179
- | `yaxisMode` | `"follow"|"invert"` | **Y-axis direction** | `"invert"` |
180
- | `importance` | `number` | **Map importance** | `0` |
181
- | `priority` | `number` | **Map priority** | `0` |
182
-
183
- Either `bounds` or `wh` must be specified.
184
-
185
- ### Methods
186
-
187
- | **Method** | **Description** |
188
- | ---------------------------- | --------------------------------- |
189
- | `setPoints(points)` | **Set control points** |
190
- | `setEdges(edges)` | **Set constrained edges** |
191
- | `updateTin()` | **Initialize/update TIN network** |
192
- | `transform(coords, inverse)` | **Execute coordinate transformation** |
193
- | `getCompiled()` | **Get serializable state** |
194
- | `setCompiled(state)` | **Restore from serialized state** |
195
-
196
- ### Error Handling
197
-
198
- The library may throw errors in the following cases:
199
-
200
- - `"TOO LINEAR1"`,`"TOO LINEAR2"`: Control points are too linear
201
- - `"SOME POINTS OUTSIDE"`: Points outside boundary
202
- - Custom error when attempting backward transformation in a disallowed state
203
-
204
- ## License
205
-
206
- Maplat Limited License 1.1
207
-
208
- Copyright (c) 2024 Code for History
209
-
210
- ## Developers
211
-
212
- - Kohei Otsuka
213
- - Code for History
214
-
215
- We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).
1
+ # Maplat Tin
2
+
3
+ A JavaScript library that defines and executes homeomorphic conversion between two plane coordinate systems based on control points.
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
+ - **Generate Transformation Definitions:** Create coordinate transformation definitions based on control points and edge constraints
11
+ - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
12
+ - **Topology Preservation:** Maintains homeomorphic properties during transformation
13
+ - **Flexible Configuration:**
14
+ - Vertex handling modes (normal/bird's-eye view)
15
+ - Topology check modes (strict/auto/loose)
16
+ - Y-axis direction control
17
+ - **Edge Constraints:** Ability to specify constrained edges for more accurate transformation
18
+ - **State Management:** Save and restore transformation definitions
19
+
20
+ ## Installation
21
+
22
+ ### npm
23
+
24
+ ```sh
25
+ # Install the main package
26
+ npm install @maplat/tin
27
+
28
+ # Install required dependency
29
+ npm install delaunator
30
+ ```
31
+
32
+
33
+ ## Development Setup
34
+
35
+ This project supports using local dependencies for development. We recommend using `yalc` for managing local package dependencies.
36
+
37
+ ### Using yalc for Local Development
38
+
39
+ 1. **Install yalc globally:**
40
+ ```sh
41
+ npm install -g yalc
42
+ ```
43
+
44
+ 2. **Publish local dependencies:**
45
+ ```sh
46
+ # In the MaplatTransform directory
47
+ cd ../MaplatTransform
48
+ yalc publish
49
+ ```
50
+
51
+ 3. **Link local dependencies in this project:**
52
+ ```sh
53
+ # In the MaplatTin directory
54
+ yalc add @maplat/transform
55
+ ```
56
+
57
+ 4. **Update local dependencies when changed:**
58
+ ```sh
59
+ # In the dependency directory (e.g., MaplatTransform)
60
+ yalc publish --push
61
+ ```
62
+
63
+ 5. **Remove local dependencies (to use npm packages):**
64
+ ```sh
65
+ # In the MaplatTin directory
66
+ yalc remove @maplat/transform
67
+ npm install
68
+ ```
69
+
70
+ **Note:** The `.yalc` directory and `yalc.lock` file are ignored by git and will not be committed.
71
+
72
+ ### Testing
73
+
74
+ The project includes comprehensive unit tests for both the TIN transformation logic and the internal EdgeBound constraint engine.
75
+
76
+ **Run all tests:**
77
+ ```sh
78
+ pnpm test
79
+ ```
80
+
81
+ **Run specific test suite:**
82
+ ```sh
83
+ # EdgeBound constraint engine tests
84
+ pnpm test tests/edgebound
85
+
86
+ # TIN transformation tests
87
+ pnpm test tests/tin
88
+ ```
89
+
90
+ **Test coverage:**
91
+ - `tests/edgebound/` - Internal EdgeBound constraint engine tests (455 tests)
92
+ - `constrain.test.ts` - Integration tests for constraint operations
93
+ - `constrain.unit.test.ts` - Unit tests for constraint methods
94
+ - `intersect.test.ts` - Segment intersection detection tests
95
+ - `validators.ts` - Test utilities for validating triangulation integrity
96
+ - `tests/tin.test.ts` - TIN transformation tests with real map data
97
+ - `tests/transform.test.ts` - Coordinate transformation tests
98
+
99
+ ### Browser
100
+
101
+ When using in the browser, you need to include the peer dependencies:
102
+
103
+ ```html
104
+ <!-- Required dependencies -->
105
+ <script src="https://unpkg.com/delaunator@5.0.0/delaunator.min.js"></script>
106
+ <script src="https://unpkg.com/@turf/helpers@7.2.0/dist/turf-helpers.min.js"></script>
107
+ <script src="https://unpkg.com/@turf/boolean-point-in-polygon@7.2.0/dist/turf-boolean-point-in-polygon.min.js"></script>
108
+ <script src="https://unpkg.com/@turf/centroid@7.2.0/dist/turf-centroid.min.js"></script>
109
+ <script src="https://unpkg.com/@turf/convex@7.2.0/dist/turf-convex.min.js"></script>
110
+ <script src="https://unpkg.com/@turf/line-intersect@7.2.0/dist/turf-line-intersect.min.js"></script>
111
+
112
+ <!-- Maplat Tin (UMD) -->
113
+ <script src="https://unpkg.com/@maplat/tin/dist/tin.umd.js"></script>
114
+ <script>
115
+ // Use the library
116
+ const tin = new tin.default({
117
+ wh: [500, 500]
118
+ });
119
+ </script>
120
+ ```
121
+
122
+ Or using ES modules:
123
+
124
+ ```html
125
+ <!-- Maplat Tin (ESM) -->
126
+ <script type="module">
127
+ import Tin from "https://unpkg.com/@maplat/tin/dist/index.js";
128
+ // Use the library
129
+ const tin = new Tin({
130
+ wh: [500, 500]
131
+ });
132
+ </script>
133
+ ```
134
+
135
+ ## Basic Usage
136
+
137
+ ```javascript
138
+ // Create a new instance with basic configuration
139
+ const tin = new Tin({
140
+ wh: [500, 500], // Width and height of the source plane
141
+ yaxisMode: Tin.YAXIS_FOLLOW // Y-axis direction handling
142
+ });
143
+
144
+ // Set control points: Array of [source, target] coordinates
145
+ tin.setPoints([
146
+ [[100,100], [200, 200]], // Point 1
147
+ [[200,200], [400, 400]], // Point 2
148
+ [[150,150], [320, 350]], // Point 3
149
+ [[200,100], [420, 220]] // Point 4
150
+ ]);
151
+
152
+ // Initialize the TIN network
153
+ tin.updateTin();
154
+
155
+ // Check topology status
156
+ if (tin.strict_status === Tin.STATUS_STRICT) {
157
+ console.log('Topology OK: Roundtrip transform is guaranteed');
158
+ } else if (tin.strict_status === Tin.STATUS_LOOSE) {
159
+ console.log('Topology warning: Roundtrip transform is not guaranteed');
160
+ }
161
+
162
+ // Forward transform: source to target
163
+ const transformed = tin.transform([160, 160], false);
164
+
165
+ // Backward transform: target to source
166
+ const restored = tin.transform(transformed, true);
167
+ ```
168
+
169
+ ## Configuration
170
+
171
+ ### Constructor Options
172
+
173
+ | **Option** | **Type** | **Description** | **Default** |
174
+ | ------------- | --------------------------- | ------------------------- | ------------- |
175
+ | `bounds` | `Position[]` | **Boundary polygon vertices** | `-` |
176
+ | `wh` | `number[]` | **Width and height [w, h]** | `-` |
177
+ | `vertexMode` | `"plain"|"birdeye"` | **Vertex handling mode** | `"plain"` |
178
+ | `strictMode` | `"strict"|"auto"|"loose"` | **Topology check mode** | `"auto"` |
179
+ | `yaxisMode` | `"follow"|"invert"` | **Y-axis direction** | `"invert"` |
180
+ | `importance` | `number` | **Map importance** | `0` |
181
+ | `priority` | `number` | **Map priority** | `0` |
182
+
183
+ Either `bounds` or `wh` must be specified.
184
+
185
+ ### Methods
186
+
187
+ | **Method** | **Description** |
188
+ | ---------------------------- | --------------------------------- |
189
+ | `setPoints(points)` | **Set control points** |
190
+ | `setEdges(edges)` | **Set constrained edges** |
191
+ | `updateTin()` | **Initialize/update TIN network** |
192
+ | `transform(coords, inverse)` | **Execute coordinate transformation** |
193
+ | `getCompiled()` | **Get serializable state** |
194
+ | `setCompiled(state)` | **Restore from serialized state** |
195
+
196
+ ### Error Handling
197
+
198
+ The library may throw errors in the following cases:
199
+
200
+ - `"TOO LINEAR1"`,`"TOO LINEAR2"`: Control points are too linear
201
+ - `"SOME POINTS OUTSIDE"`: Points outside boundary
202
+ - Custom error when attempting backward transformation in a disallowed state
203
+
204
+ ## License
205
+
206
+ Maplat Limited License 1.1
207
+
208
+ Copyright (c) 2024 Code for History
209
+
210
+ ## Developers
211
+
212
+ - Kohei Otsuka
213
+ - Code for History
214
+
215
+ We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).