@maplat/tin 0.12.0 → 0.13.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 +214 -214
- package/README.md +215 -215
- package/dist/maplat_tin.js +2286 -2299
- package/dist/maplat_tin.umd.js +5 -5
- package/package.json +26 -28
- package/src/boundary-vertices.ts +283 -284
- 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 -1036
- package/src/searchutils.ts +102 -102
- package/src/strict-overlap.ts +281 -281
- package/src/tin.ts +703 -695
- package/src/types/cdt2d.d.ts +4 -4
- package/src/types/constrainautor.d.ts +6 -6
- package/src/types/kinks.d.ts +51 -49
- package/src/types/tin.d.ts +54 -54
- package/src/vertexutils.ts +87 -88
- package/src/weight-buffer.ts +111 -111
- package/dist/index.cjs +0 -7
- package/dist/index.html +0 -49
- package/dist/maplat_tin.cjs +0 -5
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:
|
|
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,49 +1,51 @@
|
|
|
1
|
-
export interface IntersectionPoint {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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?:
|
|
26
|
-
b?:
|
|
27
|
-
c?:
|
|
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?:
|
|
40
|
-
b?:
|
|
41
|
-
c?:
|
|
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,88 +1,87 @@
|
|
|
1
|
-
import { point } from "@turf/
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
coord[
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
prev[
|
|
81
|
-
prev
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
export { counterPoint, createPoint, vertexCalc };
|
|
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
|
+
* @param list 頂点リスト
|
|
37
|
+
* @param centroid 重心点
|
|
38
|
+
* @returns [角度リスト, 三角形リスト]
|
|
39
|
+
*/
|
|
40
|
+
function vertexCalc(
|
|
41
|
+
list: Feature<Point>[],
|
|
42
|
+
centroid: Feature<Point>,
|
|
43
|
+
): [number[], Tins[]?] {
|
|
44
|
+
const centCoord = centroid.geometry!.coordinates;
|
|
45
|
+
return [0, 1, 2, 3]
|
|
46
|
+
.map((i) => {
|
|
47
|
+
const j = (i + 1) % 4;
|
|
48
|
+
const itemi = list[i];
|
|
49
|
+
const itemj = list[j];
|
|
50
|
+
const coord = itemi.geometry!.coordinates;
|
|
51
|
+
const radian = Math.atan2(
|
|
52
|
+
coord[0] - centCoord[0],
|
|
53
|
+
coord[1] - centCoord[1],
|
|
54
|
+
);
|
|
55
|
+
const coordinates = [centroid, itemi, itemj, centroid].map(
|
|
56
|
+
(point) => point.geometry!.coordinates,
|
|
57
|
+
);
|
|
58
|
+
const properties = {
|
|
59
|
+
a: {
|
|
60
|
+
geom: centroid.properties!.target.geom,
|
|
61
|
+
index: centroid.properties!.target.index,
|
|
62
|
+
},
|
|
63
|
+
b: {
|
|
64
|
+
geom: itemi.properties!.target.geom,
|
|
65
|
+
index: itemi.properties!.target.index,
|
|
66
|
+
},
|
|
67
|
+
c: {
|
|
68
|
+
geom: itemj.properties!.target.geom,
|
|
69
|
+
index: itemj.properties!.target.index,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const tin = featureCollection([
|
|
73
|
+
polygon([coordinates], properties),
|
|
74
|
+
]) as Tins;
|
|
75
|
+
return [radian, tin] as [number, Tins];
|
|
76
|
+
})
|
|
77
|
+
.reduce(
|
|
78
|
+
(prev, curr) => {
|
|
79
|
+
prev[0].push(curr[0]);
|
|
80
|
+
prev[1].push(curr[1]);
|
|
81
|
+
return prev;
|
|
82
|
+
},
|
|
83
|
+
[[] as number[], [] as Tins[]],
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { counterPoint, createPoint, vertexCalc };
|
package/src/weight-buffer.ts
CHANGED
|
@@ -1,111 +1,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
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Calculate per-point stretch ratios used for non-linear interpolation.
|
|
16
|
-
*/
|
|
17
|
-
export function buildPointsWeightBuffer(
|
|
18
|
-
options: WeightBufferOptions,
|
|
19
|
-
): WeightBufferBD {
|
|
20
|
-
const { tins, targets, includeReciprocals } = options;
|
|
21
|
-
const edgeRatios: WeightBufferBD = {};
|
|
22
|
-
|
|
23
|
-
targets.forEach((target) => {
|
|
24
|
-
const triCollection = tins[target];
|
|
25
|
-
if (!triCollection || !triCollection.features) return;
|
|
26
|
-
|
|
27
|
-
edgeRatios[target as keyof WeightBufferBD] = {};
|
|
28
|
-
const seenEdges: Record<string, boolean> = {};
|
|
29
|
-
|
|
30
|
-
triCollection.features.forEach((tri: Tri) => {
|
|
31
|
-
const props = ["a", "b", "c"] as PropertyTriKey[];
|
|
32
|
-
for (let i = 0; i < 3; i++) {
|
|
33
|
-
const j = (i + 1) % 3;
|
|
34
|
-
const prop_i = props[i];
|
|
35
|
-
const prop_j = props[j];
|
|
36
|
-
const index_i = tri.properties![prop_i].index;
|
|
37
|
-
const index_j = tri.properties![prop_j].index;
|
|
38
|
-
const key = [index_i, index_j].sort().join("-");
|
|
39
|
-
|
|
40
|
-
if (seenEdges[key]) continue;
|
|
41
|
-
seenEdges[key] = true;
|
|
42
|
-
|
|
43
|
-
const i_xy = tri.geometry!.coordinates[0][i];
|
|
44
|
-
const j_xy = tri.geometry!.coordinates[0][j];
|
|
45
|
-
const i_merc = tri.properties![prop_i].geom;
|
|
46
|
-
const j_merc = tri.properties![prop_j].geom;
|
|
47
|
-
|
|
48
|
-
const ratio = Math.sqrt(
|
|
49
|
-
Math.pow(i_merc[0] - j_merc[0], 2) +
|
|
50
|
-
Math.pow(i_merc[1] - j_merc[1], 2),
|
|
51
|
-
) / Math.sqrt(
|
|
52
|
-
Math.pow(i_xy[0] - j_xy[0], 2) + Math.pow(i_xy[1] - j_xy[1], 2),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const targetBuffer = edgeRatios[target as keyof WeightBufferBD]!;
|
|
56
|
-
targetBuffer[`${index_i}:${key}`] = ratio;
|
|
57
|
-
targetBuffer[`${index_j}:${key}`] = ratio;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const pointsWeightBuffer: WeightBufferBD = {};
|
|
63
|
-
if (includeReciprocals) {
|
|
64
|
-
pointsWeightBuffer.bakw = {};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
targets.forEach((target) => {
|
|
68
|
-
const targetBuffer = edgeRatios[target as keyof WeightBufferBD];
|
|
69
|
-
pointsWeightBuffer[target as keyof WeightBufferBD] = {};
|
|
70
|
-
|
|
71
|
-
if (!targetBuffer) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const pointWeights: Record<string, number[]> = {};
|
|
76
|
-
Object.keys(targetBuffer).forEach((key) => {
|
|
77
|
-
const [pointId] = key.split(":");
|
|
78
|
-
if (!pointWeights[pointId]) {
|
|
79
|
-
pointWeights[pointId] = [];
|
|
80
|
-
}
|
|
81
|
-
pointWeights[pointId].push(targetBuffer[key]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
Object.keys(pointWeights).forEach((pointId) => {
|
|
85
|
-
const weights = pointWeights[pointId];
|
|
86
|
-
const avgWeight = weights.reduce((sum, w) => sum + w, 0) / weights.length;
|
|
87
|
-
|
|
88
|
-
pointsWeightBuffer[target as keyof WeightBufferBD]![pointId] = avgWeight;
|
|
89
|
-
|
|
90
|
-
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
91
|
-
pointsWeightBuffer.bakw[pointId] = 1 / avgWeight;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
let centroidSum = 0;
|
|
96
|
-
for (let i = 0; i < 4; i++) {
|
|
97
|
-
const key = `b${i}`;
|
|
98
|
-
const weight =
|
|
99
|
-
pointsWeightBuffer[target as keyof WeightBufferBD]![key] || 0;
|
|
100
|
-
centroidSum += weight;
|
|
101
|
-
}
|
|
102
|
-
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"] = centroidSum / 4;
|
|
103
|
-
|
|
104
|
-
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
105
|
-
pointsWeightBuffer.bakw["c"] = 1 /
|
|
106
|
-
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return pointsWeightBuffer;
|
|
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
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Calculate per-point stretch ratios used for non-linear interpolation.
|
|
16
|
+
*/
|
|
17
|
+
export function buildPointsWeightBuffer(
|
|
18
|
+
options: WeightBufferOptions,
|
|
19
|
+
): WeightBufferBD {
|
|
20
|
+
const { tins, targets, includeReciprocals } = options;
|
|
21
|
+
const edgeRatios: WeightBufferBD = {};
|
|
22
|
+
|
|
23
|
+
targets.forEach((target) => {
|
|
24
|
+
const triCollection = tins[target];
|
|
25
|
+
if (!triCollection || !triCollection.features) return;
|
|
26
|
+
|
|
27
|
+
edgeRatios[target as keyof WeightBufferBD] = {};
|
|
28
|
+
const seenEdges: Record<string, boolean> = {};
|
|
29
|
+
|
|
30
|
+
triCollection.features.forEach((tri: Tri) => {
|
|
31
|
+
const props = ["a", "b", "c"] as PropertyTriKey[];
|
|
32
|
+
for (let i = 0; i < 3; i++) {
|
|
33
|
+
const j = (i + 1) % 3;
|
|
34
|
+
const prop_i = props[i];
|
|
35
|
+
const prop_j = props[j];
|
|
36
|
+
const index_i = tri.properties![prop_i].index;
|
|
37
|
+
const index_j = tri.properties![prop_j].index;
|
|
38
|
+
const key = [index_i, index_j].sort().join("-");
|
|
39
|
+
|
|
40
|
+
if (seenEdges[key]) continue;
|
|
41
|
+
seenEdges[key] = true;
|
|
42
|
+
|
|
43
|
+
const i_xy = tri.geometry!.coordinates[0][i];
|
|
44
|
+
const j_xy = tri.geometry!.coordinates[0][j];
|
|
45
|
+
const i_merc = tri.properties![prop_i].geom;
|
|
46
|
+
const j_merc = tri.properties![prop_j].geom;
|
|
47
|
+
|
|
48
|
+
const ratio = Math.sqrt(
|
|
49
|
+
Math.pow(i_merc[0] - j_merc[0], 2) +
|
|
50
|
+
Math.pow(i_merc[1] - j_merc[1], 2),
|
|
51
|
+
) / Math.sqrt(
|
|
52
|
+
Math.pow(i_xy[0] - j_xy[0], 2) + Math.pow(i_xy[1] - j_xy[1], 2),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const targetBuffer = edgeRatios[target as keyof WeightBufferBD]!;
|
|
56
|
+
targetBuffer[`${index_i}:${key}`] = ratio;
|
|
57
|
+
targetBuffer[`${index_j}:${key}`] = ratio;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const pointsWeightBuffer: WeightBufferBD = {};
|
|
63
|
+
if (includeReciprocals) {
|
|
64
|
+
pointsWeightBuffer.bakw = {};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
targets.forEach((target) => {
|
|
68
|
+
const targetBuffer = edgeRatios[target as keyof WeightBufferBD];
|
|
69
|
+
pointsWeightBuffer[target as keyof WeightBufferBD] = {};
|
|
70
|
+
|
|
71
|
+
if (!targetBuffer) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const pointWeights: Record<string, number[]> = {};
|
|
76
|
+
Object.keys(targetBuffer).forEach((key) => {
|
|
77
|
+
const [pointId] = key.split(":");
|
|
78
|
+
if (!pointWeights[pointId]) {
|
|
79
|
+
pointWeights[pointId] = [];
|
|
80
|
+
}
|
|
81
|
+
pointWeights[pointId].push(targetBuffer[key]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
Object.keys(pointWeights).forEach((pointId) => {
|
|
85
|
+
const weights = pointWeights[pointId];
|
|
86
|
+
const avgWeight = weights.reduce((sum, w) => sum + w, 0) / weights.length;
|
|
87
|
+
|
|
88
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]![pointId] = avgWeight;
|
|
89
|
+
|
|
90
|
+
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
91
|
+
pointsWeightBuffer.bakw[pointId] = 1 / avgWeight;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
let centroidSum = 0;
|
|
96
|
+
for (let i = 0; i < 4; i++) {
|
|
97
|
+
const key = `b${i}`;
|
|
98
|
+
const weight =
|
|
99
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]![key] || 0;
|
|
100
|
+
centroidSum += weight;
|
|
101
|
+
}
|
|
102
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"] = centroidSum / 4;
|
|
103
|
+
|
|
104
|
+
if (includeReciprocals && pointsWeightBuffer.bakw) {
|
|
105
|
+
pointsWeightBuffer.bakw["c"] = 1 /
|
|
106
|
+
pointsWeightBuffer[target as keyof WeightBufferBD]!["c"];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return pointsWeightBuffer;
|
|
111
|
+
}
|
package/dist/index.cjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
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;
|