@maplat/tin 0.11.3 → 0.12.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.ja.md CHANGED
@@ -29,34 +29,6 @@ npm install @maplat/tin
29
29
  npm install delaunator
30
30
  ```
31
31
 
32
- ### JSR (JavaScript Registry)
33
-
34
- ```sh
35
- # Deno向け
36
- deno add @maplat/tin
37
-
38
- # npm/Node.js向け
39
- npx jsr add @maplat/tin
40
- ```
41
-
42
- ### Deno
43
-
44
- ```typescript
45
- // JSR経由(推奨)
46
- import Tin from "jsr:@maplat/tin";
47
-
48
- // deno.jsonのimport mapを使用
49
- import Tin from "@maplat/tin";
50
-
51
- // またはnpmから直接
52
- import Tin from "npm:@maplat/tin@0.11.3";
53
-
54
- // ライブラリを使用
55
- const tin = new Tin({
56
- wh: [500, 500],
57
- yaxisMode: Tin.YAXIS_FOLLOW
58
- });
59
- ```
60
32
 
61
33
  ## 開発環境のセットアップ
62
34
 
@@ -74,16 +46,12 @@ const tin = new Tin({
74
46
  # MaplatTransformディレクトリで
75
47
  cd ../MaplatTransform
76
48
  yalc publish
77
-
78
- # MaplatEdgeBoundディレクトリで
79
- cd ../MaplatEdgeBound
80
- yalc publish
81
49
  ```
82
50
 
83
51
  3. **このプロジェクトでローカル依存関係をリンク:**
84
52
  ```sh
85
53
  # MaplatTinディレクトリで
86
- yalc add @maplat/transform @maplat/edgebound
54
+ yalc add @maplat/transform
87
55
  ```
88
56
 
89
57
  4. **変更時にローカル依存関係を更新:**
@@ -95,12 +63,39 @@ const tin = new Tin({
95
63
  5. **ローカル依存関係を削除(npmパッケージを使用する場合):**
96
64
  ```sh
97
65
  # MaplatTinディレクトリで
98
- yalc remove @maplat/transform @maplat/edgebound
66
+ yalc remove @maplat/transform
99
67
  npm install
100
68
  ```
101
69
 
102
70
  **注意:** `.yalc`ディレクトリと`yalc.lock`ファイルはgitに無視され、コミットされません。
103
71
 
72
+ ### テスト
73
+
74
+ プロジェクトには、TIN変換ロジックと内部EdgeBound制約エンジンの両方に対する包括的なユニットテストが含まれています。
75
+
76
+ **すべてのテストを実行:**
77
+ ```sh
78
+ pnpm test
79
+ ```
80
+
81
+ **特定のテストスイートを実行:**
82
+ ```sh
83
+ # EdgeBound制約エンジンのテスト
84
+ pnpm test tests/edgebound
85
+
86
+ # TIN変換のテスト
87
+ pnpm test tests/tin
88
+ ```
89
+
90
+ **テストカバレッジ:**
91
+ - `tests/edgebound/` - 内部EdgeBound制約エンジンのテスト(455テスト)
92
+ - `constrain.test.ts` - 制約操作の統合テスト
93
+ - `constrain.unit.test.ts` - 制約メソッドのユニットテスト
94
+ - `intersect.test.ts` - 線分交差検出テスト
95
+ - `validators.ts` - 三角形分割の整合性検証用テストユーティリティ
96
+ - `tests/tin.test.ts` - 実際の地図データを使用したTIN変換テスト
97
+ - `tests/transform.test.ts` - 座標変換テスト
98
+
104
99
  ### ブラウザ
105
100
 
106
101
  ブラウザで使用する場合、ピア依存関係を含める必要があります:
@@ -216,4 +211,4 @@ Copyright (c) 2024 Code for History
216
211
  - Kohei Otsuka
217
212
  - Code for History
218
213
 
219
- あなたの貢献をお待ちしています![イシューやプルリクエスト](https://github.com/code4history/MaplatTin/issues)は大歓迎です。
214
+ あなたの貢献をお待ちしています![イシューやプルリクエスト](https://github.com/code4history/MaplatTin/issues)は大歓迎です。
package/README.md CHANGED
@@ -29,34 +29,6 @@ npm install @maplat/tin
29
29
  npm install delaunator
30
30
  ```
31
31
 
32
- ### JSR (JavaScript Registry)
33
-
34
- ```sh
35
- # For Deno
36
- deno add @maplat/tin
37
-
38
- # For npm/Node.js
39
- npx jsr add @maplat/tin
40
- ```
41
-
42
- ### Deno
43
-
44
- ```typescript
45
- // Using JSR (recommended)
46
- import Tin from "jsr:@maplat/tin";
47
-
48
- // Using deno.json import map
49
- import Tin from "@maplat/tin";
50
-
51
- // Or directly from npm
52
- import Tin from "npm:@maplat/tin@0.11.3";
53
-
54
- // Use the library
55
- const tin = new Tin({
56
- wh: [500, 500],
57
- yaxisMode: Tin.YAXIS_FOLLOW
58
- });
59
- ```
60
32
 
61
33
  ## Development Setup
62
34
 
@@ -74,16 +46,12 @@ This project supports using local dependencies for development. We recommend usi
74
46
  # In the MaplatTransform directory
75
47
  cd ../MaplatTransform
76
48
  yalc publish
77
-
78
- # In the MaplatEdgeBound directory
79
- cd ../MaplatEdgeBound
80
- yalc publish
81
49
  ```
82
50
 
83
51
  3. **Link local dependencies in this project:**
84
52
  ```sh
85
53
  # In the MaplatTin directory
86
- yalc add @maplat/transform @maplat/edgebound
54
+ yalc add @maplat/transform
87
55
  ```
88
56
 
89
57
  4. **Update local dependencies when changed:**
@@ -95,12 +63,39 @@ This project supports using local dependencies for development. We recommend usi
95
63
  5. **Remove local dependencies (to use npm packages):**
96
64
  ```sh
97
65
  # In the MaplatTin directory
98
- yalc remove @maplat/transform @maplat/edgebound
66
+ yalc remove @maplat/transform
99
67
  npm install
100
68
  ```
101
69
 
102
70
  **Note:** The `.yalc` directory and `yalc.lock` file are ignored by git and will not be committed.
103
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
+
104
99
  ### Browser
105
100
 
106
101
  When using in the browser, you need to include the peer dependencies:
@@ -217,4 +212,4 @@ Copyright (c) 2024 Code for History
217
212
  - Kohei Otsuka
218
213
  - Code for History
219
214
 
220
- We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).
215
+ We welcome your contributions! Feel free to submit [issues and pull requests](https://github.com/code4history/MaplatTin/issues).
@@ -0,0 +1,27 @@
1
+ import { Position } from 'geojson';
2
+ import { VertexPosition } from "./types/tin.d";
3
+ interface ConvexEntry {
4
+ forw: Position;
5
+ bakw: Position;
6
+ }
7
+ interface BoundaryVerticesParams {
8
+ convexBuf: Record<string, ConvexEntry>;
9
+ centroid: {
10
+ forw: Position;
11
+ bakw: Position;
12
+ };
13
+ bbox: Position[];
14
+ minx: number;
15
+ maxx: number;
16
+ miny: number;
17
+ maxy: number;
18
+ }
19
+ /**
20
+ * Calculate the standard four boundary vertices around the centroid.
21
+ */
22
+ export declare function calculatePlainVertices(params: BoundaryVerticesParams): VertexPosition[];
23
+ /**
24
+ * Calculate boundary vertices for bird's-eye mode using quadrant-aware ratios.
25
+ */
26
+ export declare function calculateBirdeyeVertices(params: BoundaryVerticesParams): VertexPosition[];
27
+ export {};
@@ -0,0 +1,31 @@
1
+ export interface DelaunatorLike {
2
+ coords: {
3
+ readonly length: number;
4
+ readonly [index: number]: number;
5
+ };
6
+ triangles: {
7
+ readonly length: number;
8
+ [index: number]: number;
9
+ };
10
+ halfedges: {
11
+ readonly length: number;
12
+ [index: number]: number;
13
+ };
14
+ hull: {
15
+ readonly length: number;
16
+ readonly [index: number]: number;
17
+ };
18
+ }
19
+ export declare function nextEdge(edge: number): number;
20
+ export declare function prevEdge(edge: number): number;
21
+ /**
22
+ * Compute if two line segments [p1, p2] and [p3, p4] intersect.
23
+ */
24
+ export declare function intersectSegments(p1x: number, p1y: number, p2x: number, p2y: number, p3x: number, p3y: number, p4x: number, p4y: number): boolean;
25
+ export declare class Base {
26
+ /**
27
+ * The triangulation object from Delaunator.
28
+ */
29
+ del: DelaunatorLike;
30
+ constructor(del: DelaunatorLike);
31
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * A set of numbers, stored as bits in a typed array.
3
+ * The amount of numbers that can be stored is limited by the length,
4
+ * which is fixed at construction time.
5
+ */
6
+ declare abstract class BitSet {
7
+ protected readonly bs: Uint8Array | Uint16Array | Uint32Array;
8
+ protected readonly width: 8 | 16 | 32;
9
+ protected constructor(width: BitSet["width"], bs: BitSet["bs"]);
10
+ /**
11
+ * Add a number to the set.
12
+ *
13
+ * @param idx The number to add. Must be 0 <= idx < len.
14
+ */
15
+ add(idx: number): this;
16
+ /**
17
+ * Delete a number from the set.
18
+ *
19
+ * @param idx The number to delete. Must be 0 <= idx < len.
20
+ */
21
+ delete(idx: number): this;
22
+ /**
23
+ * Add or delete a number in the set, depending on the second argument.
24
+ *
25
+ * @param idx The number to add or delete. Must be 0 <= idx < len.
26
+ * @param val If true, add the number, otherwise delete.
27
+ */
28
+ set(idx: number, val: boolean): boolean;
29
+ /**
30
+ * Whether the number is in the set.
31
+ *
32
+ * @param idx The number to test. Must be 0 <= idx < len.
33
+ */
34
+ has(idx: number): boolean;
35
+ /**
36
+ * Iterate over the numbers that are in the set.
37
+ */
38
+ forEach(fn: (idx: number) => void): this;
39
+ }
40
+ export type { BitSet };
41
+ /**
42
+ * A bit set using 8 bits per cell.
43
+ */
44
+ export declare class BitSet8 extends BitSet {
45
+ constructor(len: number);
46
+ }
47
+ /**
48
+ * A bit set using 16 bits per cell.
49
+ */
50
+ export declare class BitSet16 extends BitSet {
51
+ constructor(len: number);
52
+ }
53
+ /**
54
+ * A bit set using 32 bits per cell.
55
+ */
56
+ export declare class BitSet32 extends BitSet {
57
+ constructor(len: number);
58
+ }
@@ -0,0 +1,68 @@
1
+ import { Base, DelaunatorLike, intersectSegments as baseIntersectSegments } from "./base";
2
+ import { BitSet } from "./bitset";
3
+ export declare class Constrain extends Base {
4
+ vertMap: Uint32Array;
5
+ flips: BitSet;
6
+ consd: BitSet;
7
+ /**
8
+ * Create a Constrain instance.
9
+ *
10
+ * @param del The triangulation output from Delaunator.
11
+ * @param edges If provided, constrain these edges via constrainAll.
12
+ */
13
+ constructor(del: DelaunatorLike, edges?: readonly [number, number][]);
14
+ /**
15
+ * Constrain the triangulation such that there is an edge between p1 and p2.
16
+ */
17
+ constrainOne(segP1: number, segP2: number): number;
18
+ /**
19
+ * Fix the Delaunay condition.
20
+ */
21
+ delaunify(deep?: boolean): this;
22
+ /**
23
+ * Call constrainOne on each edge.
24
+ */
25
+ constrainAll(edges: readonly [number, number][]): this;
26
+ /**
27
+ * Whether an edge is constrained.
28
+ */
29
+ isConstrained(edg: number): boolean;
30
+ /**
31
+ * Find the edge that points from p1 -> p2. If there is only an edge from
32
+ * p2 -> p1 (i.e. it is on the hull), returns the negative id of it.
33
+ */
34
+ findEdge(p1: number, p2: number): number;
35
+ /**
36
+ * Mark an edge as constrained, i.e. should not be touched by `delaunify`.
37
+ */
38
+ private protect;
39
+ /**
40
+ * Mark an edge as flipped unless constrained.
41
+ */
42
+ private markFlip;
43
+ /**
44
+ * Flip the edge shared by two triangles.
45
+ */
46
+ private flipDiagonal;
47
+ /**
48
+ * Whether point p1, p2, and p are collinear.
49
+ */
50
+ private isCollinear;
51
+ /**
52
+ * Whether the triangle formed by p1, p2, p3 keeps px outside the circumcircle.
53
+ */
54
+ private inCircle;
55
+ /**
56
+ * Whether the triangles sharing edg conform to the Delaunay condition.
57
+ */
58
+ private isDelaunay;
59
+ /**
60
+ * Update the vertex -> incoming edge map.
61
+ */
62
+ private updateVert;
63
+ /**
64
+ * Whether the segments between vertices intersect.
65
+ */
66
+ protected intersectSegments(p1: number, p2: number, p3: number, p4: number): boolean;
67
+ static intersectSegments: typeof baseIntersectSegments;
68
+ }
@@ -0,0 +1,4 @@
1
+ export { Constrain } from "./constrain";
2
+ export { nextEdge, prevEdge, intersectSegments, type DelaunatorLike, Base, } from "./base";
3
+ export { BitSet8, BitSet16, BitSet32 } from "./bitset";
4
+ export type { BitSet } from "./bitset";
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ const pkg = require("./maplat_tin.cjs");
3
+ const Tin = pkg && pkg.default ? pkg.default : pkg;
4
+ module.exports = Tin;
5
+ Object.assign(module.exports, pkg);
6
+ Object.defineProperty(module.exports, "__esModule", { value: true });
7
+ module.exports.default = Tin;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  export { Tin } from "./tin";
8
8
  export type { Options } from "./tin";
9
+ export { Tin as default } from "./tin";
9
10
  export { default as constrainedTin } from "./constrained-tin";
10
11
  export { default as findIntersections } from "./kinks";
11
12
  export { insertSearchIndex } from "./searchutils";
package/dist/index.html CHANGED
@@ -26,17 +26,24 @@
26
26
  [[70, 150], [140, -150]]
27
27
  ]);
28
28
 
29
- tin.updateTinAsync().then(() => {
30
- const output = document.getElementById('output');
31
- const result1 = tin.transform([140, 150]);
32
- const result2 = tin.transform(result1, true);
33
-
34
- output.innerHTML = `
35
- <h2>Test Results:</h2>
36
- <p>Forward transform [140, 150] => [${result1.join(', ')}]</p>
37
- <p>Backward transform [${result1.join(', ')}] => [${result2.join(', ')}]</p>
38
- `;
39
- });
29
+ const run = async () => {
30
+ try {
31
+ await tin.updateTinAsync();
32
+ const output = document.getElementById('output');
33
+ const result1 = tin.transform([140, 150]);
34
+ const result2 = tin.transform(result1, true);
35
+
36
+ output.innerHTML = `
37
+ <h2>Test Results:</h2>
38
+ <p>Forward transform [140, 150] => [${result1.join(', ')}]</p>
39
+ <p>Backward transform [${result1.join(', ')}] => [${result2.join(', ')}]</p>
40
+ `;
41
+ } catch (error) {
42
+ console.error("Failed to update TIN", error);
43
+ }
44
+ };
45
+
46
+ run();
40
47
  </script>
41
48
  </body>
42
- </html>
49
+ </html>