@maplat/tin 0.14.0 → 0.14.2

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,221 +1,231 @@
1
- # Maplat Tin
1
+ <!-- SECTION 1: Header (logo, badges, title) -->
2
+ <h1 align="center">MaplatTin</h1>
2
3
 
3
- [![CI](https://github.com/code4history/MaplatTin/actions/workflows/ci.yml/badge.svg)](https://github.com/code4history/MaplatTin/actions/workflows/ci.yml)
4
+ <p align="center">
5
+ <a href="https://github.com/code4history/MaplatTin/actions/workflows/ci.yml"><img src="https://github.com/code4history/MaplatTin/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
6
+ <a href="https://www.npmjs.com/package/@maplat/tin"><img src="https://img.shields.io/npm/v/@maplat/tin" alt="npm version" /></a>
7
+ <a href="LICENSE"><img src="https://img.shields.io/npm/l/@maplat/tin" alt="License" /></a>
8
+ </p>
4
9
 
5
- A JavaScript library that defines and executes homeomorphic conversion between two plane coordinate systems based on control points.
6
- This is part of the [Maplat](https://github.com/code4history/Maplat/) project.
10
+ <!-- SECTION 2: Elevator Pitch -->
11
+ ## About MaplatTin
7
12
 
8
- 日本語のREADMEは[こちら](./README.ja.md)
13
+ MaplatTin is a JavaScript library that defines and executes homeomorphic
14
+ conversion between two plane coordinate systems based on control points. It
15
+ guarantees a nonlinear but topology-preserving (homeomorphic) bidirectional
16
+ mapping, which is the core property that lets the
17
+ [Maplat](https://github.com/code4history/Maplat) viewer overlay historical
18
+ maps on accurate modern maps **without distorting the original images**.
9
19
 
10
- ## Key Features
20
+ MaplatTin is open-source under the Apache License 2.0 (from version 0.14.2).
11
21
 
12
- - **Generate Transformation Definitions:** Create coordinate transformation definitions based on control points and edge constraints
13
- - **Bidirectional Coordinate Transformation:** Convert coordinates between two planes in both directions
14
- - **Topology Preservation:** Maintains homeomorphic properties during transformation
15
- - **Flexible Configuration:**
16
- - Vertex handling modes (normal/bird's-eye view)
17
- - Topology check modes (strict/auto/loose)
18
- - Y-axis direction control
19
- - **Edge Constraints:** Ability to specify constrained edges for more accurate transformation
20
- - **State Management:** Save and restore transformation definitions
22
+ <!-- SECTION 3: Language switch link -->
23
+ **[Read this document in Japanese / 日本語で読む](README.ja.md)**
21
24
 
22
- ## Requirements
25
+ <!-- SECTION 4: Key Features -->
26
+ ## Key Features
23
27
 
24
- - **Node.js**: 20.0.0 or higher
25
- - **Package Manager**: pnpm 9.0.0 or higher (recommended) or npm
28
+ - **Generate Transformation Definitions** — create coordinate transformation
29
+ definitions based on control points and edge constraints
30
+ - **Bidirectional Coordinate Transformation** — convert coordinates between
31
+ two planes in both directions
32
+ - **Topology Preservation** — maintains homeomorphic properties during
33
+ transformation
34
+ - **Flexible Configuration** — vertex handling modes (normal / bird's-eye
35
+ view), topology check modes (strict / auto / loose), Y-axis direction control
36
+ - **Edge Constraints** — specify constrained edges for more accurate transform
37
+ - **State Management** — save and restore transformation definitions
38
+ - Open-source (Apache 2.0 from version 0.14.2) — part of the Maplat ecosystem
26
39
 
27
- ## Installation
40
+ <!-- SECTION 5: Quick Start -->
41
+ ## Quick Start
28
42
 
29
- ### pnpm (Recommended)
43
+ > Release-dependent information (ADR-0012). The version `0.14.2` below is the
44
+ > current release; update it on each new release.
30
45
 
31
- ```sh
32
- pnpm add @maplat/tin
33
- ```
46
+ ### Install
34
47
 
35
- ### npm
48
+ ```bash
49
+ # pnpm (recommended)
50
+ pnpm add @maplat/tin
36
51
 
37
- ```sh
52
+ # npm
38
53
  npm install @maplat/tin
39
54
  ```
40
55
 
56
+ ### Minimal usage
41
57
 
42
- ## Development Setup
43
-
44
- ### Testing
45
-
46
- The project includes comprehensive unit tests for both the TIN transformation logic and the internal EdgeBound constraint engine.
58
+ ```typescript
59
+ import Tin from '@maplat/tin';
47
60
 
48
- **Run all tests:**
49
- ```sh
50
- pnpm test
51
- ```
52
-
53
- **Run specific test suite:**
54
- ```sh
55
- # EdgeBound constraint engine tests
56
- pnpm test tests/edgebound
57
-
58
- # TIN transformation tests
59
- pnpm test tests/tin
60
- ```
61
+ // Create a new instance with basic configuration
62
+ const tin = new Tin({
63
+ wh: [500, 500], // Width and height of the source plane
64
+ yaxisMode: Tin.YAXIS_FOLLOW,
65
+ });
61
66
 
62
- **Test coverage:**
63
- - `tests/edgebound/` - Internal EdgeBound constraint engine tests (455 tests)
64
- - `constrain.test.ts` - Integration tests for constraint operations
65
- - `constrain.unit.test.ts` - Unit tests for constraint methods
66
- - `intersect.test.ts` - Segment intersection detection tests
67
- - `validators.ts` - Test utilities for validating triangulation integrity
68
- - `tests/tin.test.ts` - TIN transformation tests with real map data
69
- - `tests/transform.test.ts` - Coordinate transformation tests
67
+ // Set control points: Array of [source, target] coordinates
68
+ tin.setPoints([
69
+ [[100, 100], [200, 200]],
70
+ [[200, 200], [400, 400]],
71
+ [[150, 150], [320, 350]],
72
+ [[200, 100], [420, 220]],
73
+ ]);
70
74
 
71
- ### Building
75
+ // Initialize the TIN network
76
+ tin.updateTin();
72
77
 
73
- Build the library:
74
- ```sh
75
- pnpm run build
76
- ```
78
+ // Forward transform: source to target
79
+ const transformed = tin.transform([160, 160], false);
77
80
 
78
- Build the demo site:
79
- ```sh
80
- pnpm run build:demo
81
+ // Backward transform: target to source
82
+ const restored = tin.transform(transformed, true);
81
83
  ```
82
84
 
83
- ### Browser
84
-
85
- When using in the browser:
85
+ ### CDN (jsDelivr)
86
86
 
87
87
  ```html
88
- <!-- Maplat Tin (UMD) -->
89
- <script src="https://unpkg.com/@maplat/tin/dist/tin.umd.js"></script>
88
+ <!-- MaplatTin (UMD) -->
89
+ <script src="https://cdn.jsdelivr.net/npm/@maplat/tin@0.14.2/dist/maplat_tin.umd.js"></script>
90
90
  <script>
91
- // Use the library
92
- const tin = new tin.default({
93
- wh: [500, 500]
94
- });
91
+ const tin = new maplatTin.default({ wh: [500, 500] });
95
92
  </script>
96
93
  ```
97
94
 
98
95
  Or using ES modules:
99
96
 
100
97
  ```html
101
- <!-- Maplat Tin (ESM) -->
102
98
  <script type="module">
103
- import Tin from "https://unpkg.com/@maplat/tin/dist/index.js";
104
- // Use the library
105
- const tin = new Tin({
106
- wh: [500, 500]
107
- });
99
+ import Tin from 'https://cdn.jsdelivr.net/npm/@maplat/tin@0.14.2/dist/maplat_tin.js';
100
+ const tin = new Tin({ wh: [500, 500] });
108
101
  </script>
109
102
  ```
110
103
 
111
- ## Basic Usage
104
+ *Note: Make sure to use the latest compatible versions.*
112
105
 
113
- ```javascript
114
- // Create a new instance with basic configuration
115
- const tin = new Tin({
116
- wh: [500, 500], // Width and height of the source plane
117
- yaxisMode: Tin.YAXIS_FOLLOW // Y-axis direction handling
118
- });
106
+ ### API reference
119
107
 
120
- // Set control points: Array of [source, target] coordinates
121
- tin.setPoints([
122
- [[100,100], [200, 200]], // Point 1
123
- [[200,200], [400, 400]], // Point 2
124
- [[150,150], [320, 350]], // Point 3
125
- [[200,100], [420, 220]] // Point 4
126
- ]);
108
+ - **API signatures** (release-dependent): see [`docs/api/`](docs/api/)
109
+ - **Conceptual guide** (release-independent): see the
110
+ [Wiki API-Reference](https://github.com/code4history/MaplatTin/wiki/API-Reference)
127
111
 
128
- // Initialize the TIN network
129
- tin.updateTin();
112
+ ### Development
130
113
 
131
- // Check topology status
132
- if (tin.strict_status === Tin.STATUS_STRICT) {
133
- console.log('Topology OK: Roundtrip transform is guaranteed');
134
- } else if (tin.strict_status === Tin.STATUS_LOOSE) {
135
- console.log('Topology warning: Roundtrip transform is not guaranteed');
136
- }
114
+ #### Setup
115
+ Clone the repository and install dependencies.
137
116
 
138
- // Forward transform: source to target
139
- const transformed = tin.transform([160, 160], false);
117
+ ```bash
118
+ git clone https://github.com/code4history/MaplatTin.git
119
+ cd MaplatTin
120
+ pnpm install
121
+ ```
140
122
 
141
- // Backward transform: target to source
142
- const restored = tin.transform(transformed, true);
123
+ #### Development Server
124
+ Start the development server with hot reload.
125
+
126
+ ```bash
127
+ pnpm dev
143
128
  ```
144
129
 
145
- ## Configuration
130
+ #### Build
146
131
 
147
- ### Constructor Options
132
+ ```bash
133
+ pnpm build # Build library (dist/)
134
+ pnpm build:demo # Build demo site (dist-demo/)
135
+ ```
148
136
 
149
- | **Option** | **Type** | **Description** | **Default** |
150
- | ------------ | --------------------------- | ----------------------------- | ----------- |
151
- | `bounds` | `Position[]` | **Boundary polygon vertices** | `-` |
152
- | `wh` | `number[]` | **Width and height [w, h]** | `-` |
153
- | `vertexMode` | `"plain"|"birdeye"` | **Vertex handling mode** | `"plain"` |
154
- | `strictMode` | `"strict"|"auto"|"loose"` | **Topology check mode** | `"auto"` |
155
- | `yaxisMode` | `"follow"|"invert"` | **Y-axis direction** | `"invert"` |
156
- | `importance` | `number` | **Map importance** | `0` |
157
- | `priority` | `number` | **Map priority** | `0` |
137
+ #### Test
158
138
 
159
- Either `bounds` or `wh` must be specified.
139
+ ```bash
140
+ pnpm test # Run unit tests (Vitest)
141
+ pnpm typecheck # Run type checks (TypeScript)
142
+ pnpm lint # Run linter and formatter (ESLint/Prettier)
143
+ ```
160
144
 
161
- ### Methods
145
+ Test coverage:
162
146
 
163
- | **Method** | **Description** |
164
- | ---------------------------- | ------------------------------------- |
165
- | `setPoints(points)` | **Set control points** |
166
- | `setEdges(edges)` | **Set constrained edges** |
167
- | `updateTin()` | **Initialize/update TIN network** |
168
- | `transform(coords, inverse)` | **Execute coordinate transformation** |
169
- | `getCompiled()` | **Get serializable state** |
170
- | `setCompiled(state)` | **Restore from serialized state** |
171
- | `getFormatVersion()` | **Get format version number** |
147
+ - `tests/edgebound/` — internal EdgeBound constraint engine tests (455 tests)
148
+ - `tests/tin.test.ts` — TIN transformation tests with real map data
149
+ - `tests/transform.test.ts` — coordinate transformation tests
172
150
 
173
- ### Constants
151
+ <!-- SECTION 6: Prerequisites -->
152
+ ## Prerequisites
174
153
 
175
- **Y-axis Mode:**
176
- - `Tin.YAXIS_FOLLOW` - Y-axis follows the coordinate system
177
- - `Tin.YAXIS_INVERT` - Y-axis is inverted
154
+ > Derived from the `engines` field in `package.json` (ADR-0012: release-dependent).
178
155
 
179
- **Status Values:**
180
- - `Tin.STATUS_STRICT` - Strict topology (roundtrip transform guaranteed)
181
- - `Tin.STATUS_LOOSE` - Loose topology (roundtrip transform not guaranteed)
156
+ - Node.js: `>=20.0.0` (LTS tested via GitHub Actions)
157
+ - pnpm: `>=9.0.0` (required; `package.json` enforces pnpm)
182
158
 
183
- **Format Version:**
184
- - `format_version` - Current TIN format version
159
+ <!-- SECTION 7 Peer Dependencies: omitted (no OpenLayers dependency) -->
185
160
 
186
- ### Utility Functions
161
+ <!-- SECTION 8: Ecosystem / Related Repositories -->
162
+ ## Ecosystem
187
163
 
188
- | **Function** | **Description** |
189
- | --------------------------------------------------------------------- | ----------------------------------------------- |
190
- | `constrainedTin(points, edges, z)` | **Generate constrained Delaunay triangulation** |
191
- | `findIntersections(features)` | **Find intersection points in features** |
192
- | `insertSearchIndex(tins, centroid, strict)` | **Insert search index for TIN** |
193
- | `counterPoint(point)` | **Calculate counter point** |
194
- | `createPoint(xy, mercator, forw)` | **Create point feature** |
195
- | `vertexCalc(points, edgeNodes, centroid, originPoly, xy, vertexMode)` | **Calculate vertex coordinates** |
164
+ MaplatTin is part of the Maplat ecosystem by [Code for History](https://github.com/code4history).
165
+ See the full ecosystem map (8 repositories + product/corporate sites):
196
166
 
197
- ## Documentation
167
+ 📖 **Ecosystem Map** — *(the diagram is currently kept in a private planning
168
+ repository; the Sister repositories table below is the public substitute)*
198
169
 
199
- For detailed information about TIN internals:
200
- - [TIN Internals](docs/tin-internals.md)
170
+ ### Sister repositories
201
171
 
202
- ### Error Handling
172
+ | Repository | License | npm | Role |
173
+ |---|---|---|---|
174
+ | [Maplat](https://github.com/code4history/Maplat) | Apache 2.0 | `@maplat/ui` | Main viewer |
175
+ | [MaplatCore](https://github.com/code4history/MaplatCore) | Apache 2.0 | `@maplat/core` | Core library |
176
+ | [MaplatTin](https://github.com/code4history/MaplatTin) | Apache 2.0 | `@maplat/tin` | TIN conversion |
177
+ | [MaplatTransform](https://github.com/code4history/MaplatTransform) | Apache 2.0 | `@maplat/transform` | Coordinate transform |
178
+ | [MaplatEditor](https://github.com/code4history/MaplatEditor) | Apache 2.0 | — | Data authoring tool (desktop) |
203
179
 
204
- The library may throw errors in the following cases:
180
+ > MaplatEditor is the data authoring tool used to create the maps and POIs
181
+ > that the viewers above render. The Maplat ecosystem is end-to-end:
182
+ > author with MaplatEditor, serve with any of the viewer libraries.
205
183
 
206
- - `"TOO LINEAR1"`,`"TOO LINEAR2"`: Control points are too linear
207
- - `"SOME POINTS OUTSIDE"`: Points outside boundary
208
- - Custom error when attempting backward transformation in a disallowed state
184
+ <!-- SECTION 9: Nayuta links -->
185
+ ## Links
209
186
 
187
+ | Audience | Link | Purpose |
188
+ |---|---|---|
189
+ | Project info / features / cases | <https://www.maplat.jp/en/> | Product site |
190
+ | Sponsor / business inquiry | <https://www.nayuta-inc.co.jp/en/> | Corporate site (Nayuta, Inc.) |
191
+
192
+ > ADR-0013: Apache-licensed repositories (this one) link to both sites.
193
+ > MIT-licensed sister repos (Weiwudi / Quyuan / Chuci) carry no Nayuta link.
194
+
195
+ <!-- SECTION 10: License -->
210
196
  ## License
211
197
 
212
- Maplat Limited License 1.1
198
+ Apache License 2.0 — see [LICENSE](LICENSE).
199
+
200
+ ```
201
+ Copyright 2019-2026 Kohei Otsuka, Code for History / Nayuta, Inc.
202
+
203
+ Licensed under the Apache License, Version 2.0 (the "License");
204
+ you may not use this file except in compliance with the License.
205
+ You may obtain a copy of the License at
206
+
207
+ http://www.apache.org/licenses/LICENSE-2.0
208
+
209
+ Unless required by applicable law or agreed to in writing, software
210
+ distributed under the License is distributed on an "AS IS" BASIS,
211
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212
+ See the License for the specific language governing permissions and
213
+ limitations under the License.
214
+ ```
215
+
216
+ > **Patent notice**: The Maplat coordinate-transform technology is patented
217
+ > in Japan (Patent No. 6684776).
213
218
 
214
- Copyright (c) 2024-2026 Code for History
219
+ > **Past versions**: Versions before 0.14.2 were distributed under the
220
+ > Maplat Limited License 1.1. The license restoration to Apache 2.0 takes
221
+ > effect from version 0.14.2 onward. Earlier versions available on npmjs.com
222
+ > remain under their original limited-license terms.
215
223
 
216
- ## Developers
224
+ <!-- SECTION 11: Contributors / Sponsors -->
225
+ ## Contributors
217
226
 
218
227
  - Kohei Otsuka
219
228
  - Code for History
220
229
 
221
- We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).
230
+ We welcome your contributions! Feel free to submit
231
+ [issues and pull requests](https://github.com/code4history/MaplatTin/issues).