@maplat/tin 0.9.4 → 0.11.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 +121 -0
- package/README.md +122 -111
- package/dist/index.d.ts +196 -0
- package/dist/index.html +42 -0
- package/dist/maplat_tin.cjs +3 -0
- package/dist/maplat_tin.js +3291 -0
- package/dist/maplat_tin.umd.js +3 -0
- package/package.json +64 -58
- package/src/constrained-tin.ts +78 -0
- package/src/index.ts +934 -0
- package/src/kinks.ts +1033 -0
- package/src/searchutils.ts +67 -0
- package/src/types/cdt2d.d.ts +4 -0
- package/src/types/constrainautor.d.ts +6 -0
- package/src/vertexutils.ts +81 -0
- package/es5/index.js +0 -3
- package/es5/index.js.LICENSE.txt +0 -10
- package/es5/index.js.map +0 -1
- package/lib/booleanPointInPolygon.d.ts +0 -4
- package/lib/booleanPointInPolygon.js +0 -103
- package/lib/booleanPointInPolygon.js.map +0 -1
- package/lib/constrained-tin.d.ts +0 -4
- package/lib/constrained-tin.js +0 -41
- package/lib/constrained-tin.js.map +0 -1
- package/lib/index.d.ts +0 -157
- package/lib/index.js +0 -1472
- package/lib/index.js.map +0 -1
- package/lib/kinks.d.ts +0 -2
- package/lib/kinks.js +0 -669
- package/lib/kinks.js.map +0 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Tri, Tins } from "@maplat/transform";
|
|
2
|
+
import type { PropertyTriKey } from "@maplat/transform";
|
|
3
|
+
|
|
4
|
+
type BiDirectionKey = "forw" | "bakw";
|
|
5
|
+
type TinsBD = { [key in BiDirectionKey]?: Tins };
|
|
6
|
+
type SearchTris = { [key in BiDirectionKey]: Tri };
|
|
7
|
+
export type SearchIndex = { [key: string]: SearchTris[] };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 三角形のインデックスキーを計算する
|
|
11
|
+
* 三つの頂点のインデックスから、ソートされたキー配列を生成
|
|
12
|
+
*
|
|
13
|
+
* @param tri インデックスキーを計算する三角形
|
|
14
|
+
* @returns ソートされたキー配列
|
|
15
|
+
*/
|
|
16
|
+
function calcSearchKeys(tri: Tri): string[] {
|
|
17
|
+
const vtx = (["a", "b", "c"] as PropertyTriKey[]).map(
|
|
18
|
+
key => tri.properties![key].index
|
|
19
|
+
);
|
|
20
|
+
return [
|
|
21
|
+
[0, 1],
|
|
22
|
+
[0, 2],
|
|
23
|
+
[1, 2],
|
|
24
|
+
[0, 1, 2]
|
|
25
|
+
]
|
|
26
|
+
.map(set =>
|
|
27
|
+
set
|
|
28
|
+
.map(i => vtx[i])
|
|
29
|
+
.sort()
|
|
30
|
+
.join("-")
|
|
31
|
+
)
|
|
32
|
+
.sort();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 検索インデックスに三角形を追加する
|
|
37
|
+
*
|
|
38
|
+
* @param searchIndex 検索インデックス
|
|
39
|
+
* @param tris 追加する三角形ペア
|
|
40
|
+
* @param tins (オプション)追加先の三角形群
|
|
41
|
+
* @throws キーの不一致エラー
|
|
42
|
+
*/
|
|
43
|
+
function insertSearchIndex(
|
|
44
|
+
searchIndex: SearchIndex,
|
|
45
|
+
tris: SearchTris,
|
|
46
|
+
tins?: TinsBD
|
|
47
|
+
) {
|
|
48
|
+
const keys = calcSearchKeys(tris.forw);
|
|
49
|
+
const bakKeys = calcSearchKeys(tris.bakw);
|
|
50
|
+
if (JSON.stringify(keys) != JSON.stringify(bakKeys))
|
|
51
|
+
throw `${JSON.stringify(tris, null, 2)}\n${JSON.stringify(
|
|
52
|
+
keys
|
|
53
|
+
)}\n${JSON.stringify(bakKeys)}`;
|
|
54
|
+
for (let i = 0; i < keys.length; i++) {
|
|
55
|
+
const key = keys[i];
|
|
56
|
+
if (!searchIndex[key]) searchIndex[key] = [];
|
|
57
|
+
searchIndex[key].push(tris);
|
|
58
|
+
}
|
|
59
|
+
if (tins) {
|
|
60
|
+
tins.forw!.features.push(tris.forw);
|
|
61
|
+
tins.bakw!.features.push(tris.bakw);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
insertSearchIndex
|
|
67
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { point } from "@turf/helpers";
|
|
2
|
+
import { featureCollection, polygon } from "@turf/helpers";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 座標と属性から点オブジェクトを生成する
|
|
6
|
+
* @param xy 座標値
|
|
7
|
+
* @param geom 変換先での座標値
|
|
8
|
+
* @param index インデックス
|
|
9
|
+
* @returns 生成された点オブジェクト
|
|
10
|
+
*/
|
|
11
|
+
function createPoint(xy: any, geom: any, index: any) {
|
|
12
|
+
return point(xy, { target: { geom, index } });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 点オブジェクトの座標系を反転する
|
|
17
|
+
* @param apoint 元の点オブジェクト
|
|
18
|
+
* @returns 座標系が反転された点オブジェクト
|
|
19
|
+
*/
|
|
20
|
+
function counterPoint(apoint: any) {
|
|
21
|
+
return point(apoint.properties.target.geom, {
|
|
22
|
+
target: {
|
|
23
|
+
geom: apoint.geometry.coordinates,
|
|
24
|
+
index: apoint.properties.target.index
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 頂点リストから頂点パラメータを計算する
|
|
31
|
+
* @param list 頂点リスト
|
|
32
|
+
* @param centroid 重心点
|
|
33
|
+
* @returns [角度リスト, 三角形リスト]
|
|
34
|
+
*/
|
|
35
|
+
function vertexCalc(list: any, centroid: any) {
|
|
36
|
+
const centCoord = centroid.geometry.coordinates;
|
|
37
|
+
return [0, 1, 2, 3]
|
|
38
|
+
.map(i => {
|
|
39
|
+
const j = (i + 1) % 4;
|
|
40
|
+
const itemi = list[i];
|
|
41
|
+
const itemj = list[j];
|
|
42
|
+
const coord = itemi.geometry.coordinates;
|
|
43
|
+
const radian = Math.atan2(
|
|
44
|
+
coord[0] - centCoord[0],
|
|
45
|
+
coord[1] - centCoord[1]
|
|
46
|
+
);
|
|
47
|
+
const coordinates = [centroid, itemi, itemj, centroid].map(
|
|
48
|
+
point => point.geometry.coordinates
|
|
49
|
+
);
|
|
50
|
+
const properties = {
|
|
51
|
+
a: {
|
|
52
|
+
geom: centroid.properties.target.geom,
|
|
53
|
+
index: centroid.properties.target.index
|
|
54
|
+
},
|
|
55
|
+
b: {
|
|
56
|
+
geom: itemi.properties.target.geom,
|
|
57
|
+
index: itemi.properties.target.index
|
|
58
|
+
},
|
|
59
|
+
c: {
|
|
60
|
+
geom: itemj.properties.target.geom,
|
|
61
|
+
index: itemj.properties.target.index
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const tin = featureCollection([polygon([coordinates], properties)]);
|
|
65
|
+
return [radian, tin];
|
|
66
|
+
})
|
|
67
|
+
.reduce(
|
|
68
|
+
(prev, curr) => {
|
|
69
|
+
prev[0].push(curr[0]);
|
|
70
|
+
prev[1].push(curr[1]);
|
|
71
|
+
return prev;
|
|
72
|
+
},
|
|
73
|
+
[[] as any[], [] as any[]]
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
createPoint,
|
|
79
|
+
counterPoint,
|
|
80
|
+
vertexCalc
|
|
81
|
+
};
|