@maplat/tin 0.13.0 → 0.14.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/LICENSE +224 -224
- package/README.ja.md +220 -214
- package/README.md +221 -215
- package/dist/boundary-vertices.d.ts +33 -6
- package/dist/maplat_tin.js +2078 -1864
- package/dist/maplat_tin.umd.js +3 -3
- package/dist/tin.d.ts +16 -1
- package/dist/vertexutils.d.ts +6 -2
- package/dist/weight-buffer.d.ts +2 -0
- package/package.json +5 -5
- package/src/boundary-vertices.ts +557 -283
- package/src/constrained-tin.ts +84 -84
- package/src/edgebound/base.ts +65 -65
- package/src/edgebound/bitset.ts +109 -109
- package/src/edgebound/constrain.license.txt +15 -15
- package/src/edgebound/constrain.ts +498 -498
- package/src/edgebound/index.ts +10 -10
- package/src/index.ts +42 -42
- package/src/kinks.ts +1092 -1092
- package/src/searchutils.ts +102 -102
- package/src/strict-overlap.ts +461 -281
- package/src/tin.ts +821 -703
- package/src/types/cdt2d.d.ts +4 -4
- package/src/types/constrainautor.d.ts +6 -6
- package/src/types/kinks.d.ts +51 -51
- package/src/types/tin.d.ts +54 -54
- package/src/vertexutils.ts +92 -87
- package/src/weight-buffer.ts +114 -111
package/src/types/cdt2d.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module "cdt2d" {
|
|
2
|
-
type P2 = [number, number];
|
|
3
|
-
export default function cdt2d(points: P2[], edges: P2[]): number[][];
|
|
4
|
-
}
|
|
1
|
+
declare module "cdt2d" {
|
|
2
|
+
type P2 = [number, number];
|
|
3
|
+
export default function cdt2d(points: P2[], edges: P2[]): number[][];
|
|
4
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare module "@kninnug/constrainautor" {
|
|
2
|
-
export default class Constrainautor {
|
|
3
|
-
constructor(delaunay: unknown);
|
|
4
|
-
constrainAll(edges: [number, number][]): void;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
1
|
+
declare module "@kninnug/constrainautor" {
|
|
2
|
+
export default class Constrainautor {
|
|
3
|
+
constructor(delaunay: unknown);
|
|
4
|
+
constrainAll(edges: [number, number][]): void;
|
|
5
|
+
}
|
|
6
|
+
}
|
package/src/types/kinks.d.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export interface IntersectionPoint {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
a: number[];
|
|
5
|
-
b: number[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type ArcCallback = (
|
|
9
|
-
i: number,
|
|
10
|
-
j: number,
|
|
11
|
-
xx: Float64Array,
|
|
12
|
-
yy: Float64Array,
|
|
13
|
-
) => void;
|
|
14
|
-
export type ForEachSegmentCallback = (
|
|
15
|
-
v1: number,
|
|
16
|
-
v2: number,
|
|
17
|
-
xx: Float64Array,
|
|
18
|
-
yy: Float64Array,
|
|
19
|
-
) => void;
|
|
20
|
-
|
|
21
|
-
export interface Arc {
|
|
22
|
-
i: number;
|
|
23
|
-
j: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export class ArcIter {
|
|
27
|
-
_xx: Float64Array | null;
|
|
28
|
-
_yy: Float64Array | null;
|
|
29
|
-
_zz: Float64Array | null;
|
|
30
|
-
_arc: Arc | null;
|
|
31
|
-
_i: number;
|
|
32
|
-
_n: number;
|
|
33
|
-
_inc: number;
|
|
34
|
-
_useZ: boolean;
|
|
35
|
-
x: number;
|
|
36
|
-
y: number;
|
|
37
|
-
z: number;
|
|
38
|
-
|
|
39
|
-
constructor(
|
|
40
|
-
xx: Float64Array | null,
|
|
41
|
-
yy: Float64Array | null,
|
|
42
|
-
zz?: Float64Array | null,
|
|
43
|
-
);
|
|
44
|
-
init(i: number, len: number, fw: boolean, zlim?: number): ArcIter;
|
|
45
|
-
hasNext(): boolean;
|
|
46
|
-
next(): void;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class FilteredArcIter extends ArcIter {
|
|
50
|
-
constructor();
|
|
51
|
-
}
|
|
1
|
+
export interface IntersectionPoint {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
a: number[];
|
|
5
|
+
b: number[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type ArcCallback = (
|
|
9
|
+
i: number,
|
|
10
|
+
j: number,
|
|
11
|
+
xx: Float64Array,
|
|
12
|
+
yy: Float64Array,
|
|
13
|
+
) => void;
|
|
14
|
+
export type ForEachSegmentCallback = (
|
|
15
|
+
v1: number,
|
|
16
|
+
v2: number,
|
|
17
|
+
xx: Float64Array,
|
|
18
|
+
yy: Float64Array,
|
|
19
|
+
) => void;
|
|
20
|
+
|
|
21
|
+
export interface Arc {
|
|
22
|
+
i: number;
|
|
23
|
+
j: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class ArcIter {
|
|
27
|
+
_xx: Float64Array | null;
|
|
28
|
+
_yy: Float64Array | null;
|
|
29
|
+
_zz: Float64Array | null;
|
|
30
|
+
_arc: Arc | null;
|
|
31
|
+
_i: number;
|
|
32
|
+
_n: number;
|
|
33
|
+
_inc: number;
|
|
34
|
+
_useZ: boolean;
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
z: number;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
xx: Float64Array | null,
|
|
41
|
+
yy: Float64Array | null,
|
|
42
|
+
zz?: Float64Array | null,
|
|
43
|
+
);
|
|
44
|
+
init(i: number, len: number, fw: boolean, zlim?: number): ArcIter;
|
|
45
|
+
hasNext(): boolean;
|
|
46
|
+
next(): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class FilteredArcIter extends ArcIter {
|
|
50
|
+
constructor();
|
|
51
|
+
}
|
package/src/types/tin.d.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import type { FeatureCollection, Point, Polygon, Position } from "geojson";
|
|
2
|
-
|
|
3
|
-
export interface PointsSetBD {
|
|
4
|
-
forw: FeatureCollection<Point>;
|
|
5
|
-
bakw: FeatureCollection<Point>;
|
|
6
|
-
edges: number[][];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface VertexDelta {
|
|
10
|
-
forw: [number, number];
|
|
11
|
-
bakw?: [number, number];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface WeightBuffer {
|
|
15
|
-
[target: string]: {
|
|
16
|
-
[vertexKey: string]: {
|
|
17
|
-
[edgeKey: string]: number;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type LengthItem = [Position, number, number, number, string?];
|
|
23
|
-
|
|
24
|
-
export interface EdgeProperties {
|
|
25
|
-
a?: unknown;
|
|
26
|
-
b?: unknown;
|
|
27
|
-
c?: unknown;
|
|
28
|
-
index?: string | number;
|
|
29
|
-
geom?: Position;
|
|
30
|
-
target?: {
|
|
31
|
-
geom: Position;
|
|
32
|
-
index: string | number;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type VertexParams = [number[], FeatureCollection<Polygon>[]];
|
|
37
|
-
|
|
38
|
-
export interface TriangleProperties {
|
|
39
|
-
a?: unknown; // This should match the z parameter type from @maplat/transform
|
|
40
|
-
b?: unknown;
|
|
41
|
-
c?: unknown;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface VertexPosition {
|
|
45
|
-
forw: Position;
|
|
46
|
-
bakw: Position;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface ExpandConvexItem {
|
|
50
|
-
forw: Position;
|
|
51
|
-
bakw: Position;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type ExpandConvexArray = ExpandConvexItem[][];
|
|
1
|
+
import type { FeatureCollection, Point, Polygon, Position } from "geojson";
|
|
2
|
+
|
|
3
|
+
export interface PointsSetBD {
|
|
4
|
+
forw: FeatureCollection<Point>;
|
|
5
|
+
bakw: FeatureCollection<Point>;
|
|
6
|
+
edges: number[][];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface VertexDelta {
|
|
10
|
+
forw: [number, number];
|
|
11
|
+
bakw?: [number, number];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface WeightBuffer {
|
|
15
|
+
[target: string]: {
|
|
16
|
+
[vertexKey: string]: {
|
|
17
|
+
[edgeKey: string]: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type LengthItem = [Position, number, number, number, string?];
|
|
23
|
+
|
|
24
|
+
export interface EdgeProperties {
|
|
25
|
+
a?: unknown;
|
|
26
|
+
b?: unknown;
|
|
27
|
+
c?: unknown;
|
|
28
|
+
index?: string | number;
|
|
29
|
+
geom?: Position;
|
|
30
|
+
target?: {
|
|
31
|
+
geom: Position;
|
|
32
|
+
index: string | number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type VertexParams = [number[], FeatureCollection<Polygon>[]];
|
|
37
|
+
|
|
38
|
+
export interface TriangleProperties {
|
|
39
|
+
a?: unknown; // This should match the z parameter type from @maplat/transform
|
|
40
|
+
b?: unknown;
|
|
41
|
+
c?: unknown;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface VertexPosition {
|
|
45
|
+
forw: Position;
|
|
46
|
+
bakw: Position;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ExpandConvexItem {
|
|
50
|
+
forw: Position;
|
|
51
|
+
bakw: Position;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type ExpandConvexArray = ExpandConvexItem[][];
|
package/src/vertexutils.ts
CHANGED
|
@@ -1,87 +1,92 @@
|
|
|
1
|
-
import { point, featureCollection, polygon } from "@turf/turf";
|
|
2
|
-
import type { Feature, Point, Position } from "geojson";
|
|
3
|
-
import type { Tins } from "@maplat/transform";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 座標と属性から点オブジェクトを生成する
|
|
7
|
-
* @param xy 座標値
|
|
8
|
-
* @param geom 変換先での座標値
|
|
9
|
-
* @param index インデックス
|
|
10
|
-
* @returns 生成された点オブジェクト
|
|
11
|
-
*/
|
|
12
|
-
function createPoint(
|
|
13
|
-
xy: Position,
|
|
14
|
-
geom: Position,
|
|
15
|
-
index: string | number,
|
|
16
|
-
): Feature<Point> {
|
|
17
|
-
return point(xy, { target: { geom, index } });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 点オブジェクトの座標系を反転する
|
|
22
|
-
* @param apoint 元の点オブジェクト
|
|
23
|
-
* @returns 座標系が反転された点オブジェクト
|
|
24
|
-
*/
|
|
25
|
-
function counterPoint(apoint: Feature<Point>): Feature<Point> {
|
|
26
|
-
return point(apoint.properties!.target.geom, {
|
|
27
|
-
target: {
|
|
28
|
-
geom: apoint.geometry!.coordinates,
|
|
29
|
-
index: apoint.properties!.target.index,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 頂点リストから頂点パラメータを計算する
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
import { point, featureCollection, polygon } from "@turf/turf";
|
|
2
|
+
import type { Feature, Point, Position } from "geojson";
|
|
3
|
+
import type { Tins } from "@maplat/transform";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 座標と属性から点オブジェクトを生成する
|
|
7
|
+
* @param xy 座標値
|
|
8
|
+
* @param geom 変換先での座標値
|
|
9
|
+
* @param index インデックス
|
|
10
|
+
* @returns 生成された点オブジェクト
|
|
11
|
+
*/
|
|
12
|
+
function createPoint(
|
|
13
|
+
xy: Position,
|
|
14
|
+
geom: Position,
|
|
15
|
+
index: string | number,
|
|
16
|
+
): Feature<Point> {
|
|
17
|
+
return point(xy, { target: { geom, index } });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 点オブジェクトの座標系を反転する
|
|
22
|
+
* @param apoint 元の点オブジェクト
|
|
23
|
+
* @returns 座標系が反転された点オブジェクト
|
|
24
|
+
*/
|
|
25
|
+
function counterPoint(apoint: Feature<Point>): Feature<Point> {
|
|
26
|
+
return point(apoint.properties!.target.geom, {
|
|
27
|
+
target: {
|
|
28
|
+
geom: apoint.geometry!.coordinates,
|
|
29
|
+
index: apoint.properties!.target.index,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 頂点リストから頂点パラメータを計算する
|
|
36
|
+
*
|
|
37
|
+
* N 個の境界頂点(v2 では常に 4 個、v3 では任意)に対応した汎用版。
|
|
38
|
+
* 各頂点について (重心, b_i, b_{(i+1)%N}) の扇形三角形と角度を計算する。
|
|
39
|
+
*
|
|
40
|
+
* @param list 境界頂点リスト(N 個)
|
|
41
|
+
* @param centroid 重心点
|
|
42
|
+
* @returns [角度リスト(N 個), 三角形リスト(N 個)]
|
|
43
|
+
*/
|
|
44
|
+
function vertexCalc(
|
|
45
|
+
list: Feature<Point>[],
|
|
46
|
+
centroid: Feature<Point>,
|
|
47
|
+
): [number[], Tins[]?] {
|
|
48
|
+
const N = list.length;
|
|
49
|
+
const centCoord = centroid.geometry!.coordinates;
|
|
50
|
+
return Array.from({ length: N }, (_, i) => i)
|
|
51
|
+
.map((i) => {
|
|
52
|
+
const j = (i + 1) % N;
|
|
53
|
+
const itemi = list[i];
|
|
54
|
+
const itemj = list[j];
|
|
55
|
+
const coord = itemi.geometry!.coordinates;
|
|
56
|
+
const radian = Math.atan2(
|
|
57
|
+
coord[0] - centCoord[0],
|
|
58
|
+
coord[1] - centCoord[1],
|
|
59
|
+
);
|
|
60
|
+
const coordinates = [centroid, itemi, itemj, centroid].map(
|
|
61
|
+
(point) => point.geometry!.coordinates,
|
|
62
|
+
);
|
|
63
|
+
const properties = {
|
|
64
|
+
a: {
|
|
65
|
+
geom: centroid.properties!.target.geom,
|
|
66
|
+
index: centroid.properties!.target.index,
|
|
67
|
+
},
|
|
68
|
+
b: {
|
|
69
|
+
geom: itemi.properties!.target.geom,
|
|
70
|
+
index: itemi.properties!.target.index,
|
|
71
|
+
},
|
|
72
|
+
c: {
|
|
73
|
+
geom: itemj.properties!.target.geom,
|
|
74
|
+
index: itemj.properties!.target.index,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const tin = featureCollection([
|
|
78
|
+
polygon([coordinates], properties),
|
|
79
|
+
]) as Tins;
|
|
80
|
+
return [radian, tin] as [number, Tins];
|
|
81
|
+
})
|
|
82
|
+
.reduce(
|
|
83
|
+
(prev, curr) => {
|
|
84
|
+
prev[0].push(curr[0]);
|
|
85
|
+
prev[1].push(curr[1]);
|
|
86
|
+
return prev;
|
|
87
|
+
},
|
|
88
|
+
[[] as number[], [] as Tins[]],
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { counterPoint, createPoint, vertexCalc };
|
package/src/weight-buffer.ts
CHANGED
|
@@ -1,111 +1,114 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
PropertyTriKey,
|
|
3
|
-
TinsBD,
|
|
4
|
-
Tri,
|
|
5
|
-
WeightBufferBD,
|
|
6
|
-
} from "@maplat/transform";
|
|
7
|
-
|
|
8
|
-
interface WeightBufferOptions {
|
|
9
|
-
tins: TinsBD;
|
|
10
|
-
targets: Array<keyof TinsBD>;
|
|
11
|
-
includeReciprocals: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
targetBuffer
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
1
|
+
import type {
|
|
2
|
+
PropertyTriKey,
|
|
3
|
+
TinsBD,
|
|
4
|
+
Tri,
|
|
5
|
+
WeightBufferBD,
|
|
6
|
+
} from "@maplat/transform";
|
|
7
|
+
|
|
8
|
+
interface WeightBufferOptions {
|
|
9
|
+
tins: TinsBD;
|
|
10
|
+
targets: Array<keyof TinsBD>;
|
|
11
|
+
includeReciprocals: boolean;
|
|
12
|
+
/** Number of boundary vertices (b0..b{N-1}). Defaults to 4 for v2 format. */
|
|
13
|
+
numBoundaryVertices?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Calculate per-point stretch ratios used for non-linear interpolation.
|
|
18
|
+
*/
|
|
19
|
+
export function buildPointsWeightBuffer(
|
|
20
|
+
options: WeightBufferOptions,
|
|
21
|
+
): WeightBufferBD {
|
|
22
|
+
const { tins, targets, includeReciprocals, numBoundaryVertices = 4 } = options;
|
|
23
|
+
const edgeRatios: WeightBufferBD = {};
|
|
24
|
+
|
|
25
|
+
targets.forEach((target) => {
|
|
26
|
+
const triCollection = tins[target];
|
|
27
|
+
if (!triCollection || !triCollection.features) return;
|
|
28
|
+
|
|
29
|
+
edgeRatios[target as keyof WeightBufferBD] = {};
|
|
30
|
+
const seenEdges: Record<string, boolean> = {};
|
|
31
|
+
|
|
32
|
+
triCollection.features.forEach((tri: Tri) => {
|
|
33
|
+
const props = ["a", "b", "c"] as PropertyTriKey[];
|
|
34
|
+
for (let i = 0; i < 3; i++) {
|
|
35
|
+
const j = (i + 1) % 3;
|
|
36
|
+
const prop_i = props[i];
|
|
37
|
+
const prop_j = props[j];
|
|
38
|
+
const index_i = tri.properties![prop_i].index;
|
|
39
|
+
const index_j = tri.properties![prop_j].index;
|
|
40
|
+
const key = [index_i, index_j].sort().join("-");
|
|
41
|
+
|
|
42
|
+
if (seenEdges[key]) continue;
|
|
43
|
+
seenEdges[key] = true;
|
|
44
|
+
|
|
45
|
+
const i_xy = tri.geometry!.coordinates[0][i];
|
|
46
|
+
const j_xy = tri.geometry!.coordinates[0][j];
|
|
47
|
+
const i_merc = tri.properties![prop_i].geom;
|
|
48
|
+
const j_merc = tri.properties![prop_j].geom;
|
|
49
|
+
|
|
50
|
+
const ratio = Math.sqrt(
|
|
51
|
+
Math.pow(i_merc[0] - j_merc[0], 2) +
|
|
52
|
+
Math.pow(i_merc[1] - j_merc[1], 2),
|
|
53
|
+
) / Math.sqrt(
|
|
54
|
+
Math.pow(i_xy[0] - j_xy[0], 2) + Math.pow(i_xy[1] - j_xy[1], 2),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const targetBuffer = edgeRatios[target as keyof WeightBufferBD]!;
|
|
58
|
+
targetBuffer[`${index_i}:${key}`] = ratio;
|
|
59
|
+
targetBuffer[`${index_j}:${key}`] = ratio;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const pointsWeightBuffer: WeightBufferBD = {};
|
|
65
|
+
if (includeReciprocals) {
|
|
66
|
+
pointsWeightBuffer.bakw = {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
targets.forEach((target) => {
|
|
70
|
+
const targetBuffer = edgeRatios[target as keyof WeightBufferBD];
|
|
71
|
+
pointsWeightBuffer[target as keyof WeightBufferBD] = {};
|
|
72
|
+
|
|
73
|
+
if (!targetBuffer) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const pointWeights: Record<string, number[]> = {};
|
|
78
|
+
Object.keys(targetBuffer).forEach((key) => {
|
|
79
|
+
const [pointId] = key.split(":");
|
|
80
|
+
if (!pointWeights[pointId]) {
|
|
81
|
+
pointWeights[pointId] = [];
|
|
82
|
+
}
|
|
83
|
+
pointWeights[pointId].push(targetBuffer[key]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
Object.keys(pointWeights).forEach((pointId) => {
|
|
87
|
+
const weights = pointWeights[pointId];
|
|
88
|
+
const avgWeight = weights.reduce((sum, w) => sum + w, 0) / weights.length;
|
|
89
|
+
|
|
90
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]![pointId] = avgWeight;
|
|
91
|
+
|
|
92
|
+
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
93
|
+
pointsWeightBuffer.bakw[pointId] = 1 / avgWeight;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
let centroidSum = 0;
|
|
98
|
+
for (let i = 0; i < numBoundaryVertices; i++) {
|
|
99
|
+
const key = `b${i}`;
|
|
100
|
+
const weight =
|
|
101
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]![key] || 0;
|
|
102
|
+
centroidSum += weight;
|
|
103
|
+
}
|
|
104
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"] =
|
|
105
|
+
centroidSum / numBoundaryVertices;
|
|
106
|
+
|
|
107
|
+
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
108
|
+
pointsWeightBuffer.bakw["c"] = 1 /
|
|
109
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"];
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return pointsWeightBuffer;
|
|
114
|
+
}
|