@maplat/tin 0.11.2 → 0.11.4

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.
@@ -1,84 +1,84 @@
1
- import { featureCollection, polygon } from "@turf/helpers";
2
- import type { FeatureCollection, Point, Polygon } from "geojson";
3
- import Delaunator from "delaunator";
4
- import { Constrain as EdgeBound } from "@maplat/edgebound";
5
- import type { Edge } from "@maplat/transform";
6
- import type { TriangleProperties } from "./types/tin.d.ts";
7
-
8
- /**
9
- * 制約付きTIN(Triangulated Irregular Network)を生成します
10
- *
11
- * 点群から三角形分割を行い、指定されたエッジ(制約線)を
12
- * 必ず三角形の辺として含むように調整します。
13
- *
14
- * @param points - 点群を含むFeatureCollection
15
- * 各Featureは座標を持つPointである必要があります
16
- * @param edges - 制約として扱うエッジの配列
17
- * 各エッジは2つの頂点インデックスの組として指定
18
- * @param z - 生成される三角形のプロパティに含める項目の名前
19
- * (例: "target")
20
- *
21
- * @returns 三角形のFeatureCollectionを返します
22
- * 各三角形は以下の情報を持ちます:
23
- * - geometry: 三角形の座標
24
- * - properties: 頂点に関連付けられた情報(a, b, cプロパティ)
25
- *
26
- * @throws {Error} pointsがFeatureCollectionでない場合
27
- * @throws {Error} edgesが配列でない場合
28
- *
29
- * 処理の流れ:
30
- * 1. Delaunay三角分割を実行
31
- * 2. 制約エッジに基づいて三角分割を調整
32
- * 3. 結果をGeoJSON形式に変換
33
- */
34
- export default function (
35
- points: FeatureCollection<Point>,
36
- edges: Edge[],
37
- z: string,
38
- ): FeatureCollection<Polygon> {
39
- if (!edges) edges = [];
40
- if (typeof points !== "object" || points.type !== "FeatureCollection") {
41
- throw "Argument points must be FeatureCollection";
42
- }
43
- if (!Array.isArray(edges)) throw "Argument points must be Array of Array";
44
-
45
- // Delaunay三角分割の実行
46
- const del_points = points.features.map(
47
- (point) => point.geometry!.coordinates as number[],
48
- );
49
- const del = Delaunator.from(del_points);
50
-
51
- // 制約エッジの適用
52
- let con;
53
- const tris = [];
54
- if (del.triangles.length !== 0 && edges.length !== 0) {
55
- con = new EdgeBound(del);
56
- con.constrainAll(edges);
57
- }
58
-
59
- // 三角形リストの構築
60
- for (let i = 0; i < del.triangles.length; i += 3) {
61
- tris.push([del.triangles[i], del.triangles[i + 1], del.triangles[i + 2]]);
62
- }
63
-
64
- // GeoJSON形式での出力
65
- const keys = ["a", "b", "c"] as const;
66
- return featureCollection(
67
- tris.map((indices) => {
68
- const properties: TriangleProperties = {};
69
- const coords = indices.map((index, i) => {
70
- const point = points.features[index];
71
- const xyz = point.geometry!.coordinates as number[];
72
- const coord: number[] = [xyz[0], xyz[1]];
73
- if (xyz.length === 3) {
74
- coord[2] = xyz[2];
75
- } else {
76
- properties[keys[i]] = point.properties![z];
77
- }
78
- return coord;
79
- });
80
- coords[3] = coords[0];
81
- return polygon([coords], properties);
82
- }),
83
- );
84
- }
1
+ import { featureCollection, polygon } from "@turf/helpers";
2
+ import type { FeatureCollection, Point, Polygon } from "geojson";
3
+ import Delaunator from "delaunator";
4
+ import { Constrain as EdgeBound } from "@maplat/edgebound";
5
+ import type { Edge } from "@maplat/transform";
6
+ import type { TriangleProperties } from "./types/tin.d.ts";
7
+
8
+ /**
9
+ * 制約付きTIN(Triangulated Irregular Network)を生成します
10
+ *
11
+ * 点群から三角形分割を行い、指定されたエッジ(制約線)を
12
+ * 必ず三角形の辺として含むように調整します。
13
+ *
14
+ * @param points - 点群を含むFeatureCollection
15
+ * 各Featureは座標を持つPointである必要があります
16
+ * @param edges - 制約として扱うエッジの配列
17
+ * 各エッジは2つの頂点インデックスの組として指定
18
+ * @param z - 生成される三角形のプロパティに含める項目の名前
19
+ * (例: "target")
20
+ *
21
+ * @returns 三角形のFeatureCollectionを返します
22
+ * 各三角形は以下の情報を持ちます:
23
+ * - geometry: 三角形の座標
24
+ * - properties: 頂点に関連付けられた情報(a, b, cプロパティ)
25
+ *
26
+ * @throws {Error} pointsがFeatureCollectionでない場合
27
+ * @throws {Error} edgesが配列でない場合
28
+ *
29
+ * 処理の流れ:
30
+ * 1. Delaunay三角分割を実行
31
+ * 2. 制約エッジに基づいて三角分割を調整
32
+ * 3. 結果をGeoJSON形式に変換
33
+ */
34
+ export default function (
35
+ points: FeatureCollection<Point>,
36
+ edges: Edge[],
37
+ z: string,
38
+ ): FeatureCollection<Polygon> {
39
+ if (!edges) edges = [];
40
+ if (typeof points !== "object" || points.type !== "FeatureCollection") {
41
+ throw "Argument points must be FeatureCollection";
42
+ }
43
+ if (!Array.isArray(edges)) throw "Argument points must be Array of Array";
44
+
45
+ // Delaunay三角分割の実行
46
+ const del_points = points.features.map(
47
+ (point) => point.geometry!.coordinates as number[],
48
+ );
49
+ const del = Delaunator.from(del_points);
50
+
51
+ // 制約エッジの適用
52
+ let con;
53
+ const tris = [];
54
+ if (del.triangles.length !== 0 && edges.length !== 0) {
55
+ con = new EdgeBound(del);
56
+ con.constrainAll(edges);
57
+ }
58
+
59
+ // 三角形リストの構築
60
+ for (let i = 0; i < del.triangles.length; i += 3) {
61
+ tris.push([del.triangles[i], del.triangles[i + 1], del.triangles[i + 2]]);
62
+ }
63
+
64
+ // GeoJSON形式での出力
65
+ const keys = ["a", "b", "c"] as const;
66
+ return featureCollection(
67
+ tris.map((indices) => {
68
+ const properties: TriangleProperties = {};
69
+ const coords = indices.map((index, i) => {
70
+ const point = points.features[index];
71
+ const xyz = point.geometry!.coordinates as number[];
72
+ const coord: number[] = [xyz[0], xyz[1]];
73
+ if (xyz.length === 3) {
74
+ coord[2] = xyz[2];
75
+ } else {
76
+ properties[keys[i]] = point.properties![z];
77
+ }
78
+ return coord;
79
+ });
80
+ coords[3] = coords[0];
81
+ return polygon([coords], properties);
82
+ }),
83
+ );
84
+ }
package/src/index.ts CHANGED
@@ -1,41 +1,41 @@
1
- /**
2
- * @maplat/tin - TIN (Triangulated Irregular Network) generation library
3
- *
4
- * This is the main entry point for the library.
5
- * Provides TIN generation with constrained edges for map transformation.
6
- */
7
-
8
- // Main class exports
9
- export { Tin } from "./tin.ts";
10
- export type { Options } from "./tin.ts";
11
-
12
- // Utility function exports
13
- export { default as constrainedTin } from "./constrained-tin.ts";
14
- export { default as findIntersections } from "./kinks.ts";
15
- export { insertSearchIndex } from "./searchutils.ts";
16
- export { counterPoint, createPoint, vertexCalc } from "./vertexutils.ts";
17
-
18
- // Type exports
19
- export type { SearchIndex } from "./searchutils.ts";
20
- export type { IntersectionPoint } from "./types/kinks.d.ts";
21
- export type { TriangleProperties } from "./types/tin.d.ts";
22
-
23
- // Re-export types from @maplat/transform
24
- export type {
25
- Compiled,
26
- Edge,
27
- EdgeSet,
28
- EdgeSetLegacy,
29
- PointSet,
30
- PropertyTriKey,
31
- StrictMode,
32
- StrictStatus,
33
- Tins,
34
- Transform,
35
- Tri,
36
- VertexMode,
37
- YaxisMode,
38
- } from "@maplat/transform";
39
-
40
- // Re-export format_version
41
- export { format_version } from "@maplat/transform";
1
+ /**
2
+ * @maplat/tin - TIN (Triangulated Irregular Network) generation library
3
+ *
4
+ * This is the main entry point for the library.
5
+ * Provides TIN generation with constrained edges for map transformation.
6
+ */
7
+
8
+ // Main class exports
9
+ export { Tin } from "./tin.ts";
10
+ export type { Options } from "./tin.ts";
11
+
12
+ // Utility function exports
13
+ export { default as constrainedTin } from "./constrained-tin.ts";
14
+ export { default as findIntersections } from "./kinks.ts";
15
+ export { insertSearchIndex } from "./searchutils.ts";
16
+ export { counterPoint, createPoint, vertexCalc } from "./vertexutils.ts";
17
+
18
+ // Type exports
19
+ export type { SearchIndex } from "./searchutils.ts";
20
+ export type { IntersectionPoint } from "./types/kinks.d.ts";
21
+ export type { TriangleProperties } from "./types/tin.d.ts";
22
+
23
+ // Re-export types from @maplat/transform
24
+ export type {
25
+ Compiled,
26
+ Edge,
27
+ EdgeSet,
28
+ EdgeSetLegacy,
29
+ PointSet,
30
+ PropertyTriKey,
31
+ StrictMode,
32
+ StrictStatus,
33
+ Tins,
34
+ Transform,
35
+ Tri,
36
+ VertexMode,
37
+ YaxisMode,
38
+ } from "@maplat/transform";
39
+
40
+ // Re-export format_version
41
+ export { format_version } from "@maplat/transform";