@maplat/tin 0.12.0 → 0.13.1

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,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: any);
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
+ }
@@ -1,49 +1,51 @@
1
- export interface IntersectionPoint {
2
- x: number;
3
- y: number;
4
- }
5
-
6
- export type ArcCallback = (
7
- i: number,
8
- j: number,
9
- xx: Float64Array,
10
- yy: Float64Array,
11
- ) => void;
12
- export type ForEachSegmentCallback = (
13
- v1: number,
14
- v2: number,
15
- xx: Float64Array,
16
- yy: Float64Array,
17
- ) => void;
18
-
19
- export interface Arc {
20
- i: number;
21
- j: number;
22
- }
23
-
24
- export class ArcIter {
25
- _xx: Float64Array | null;
26
- _yy: Float64Array | null;
27
- _zz: Float64Array | null;
28
- _arc: Arc | null;
29
- _i: number;
30
- _n: number;
31
- _inc: number;
32
- _useZ: boolean;
33
- x: number;
34
- y: number;
35
- z: number;
36
-
37
- constructor(
38
- xx: Float64Array | null,
39
- yy: Float64Array | null,
40
- zz?: Float64Array | null,
41
- );
42
- init(i: number, len: number, fw: boolean, zlim?: number): ArcIter;
43
- hasNext(): boolean;
44
- next(): void;
45
- }
46
-
47
- export class FilteredArcIter extends ArcIter {
48
- constructor();
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
+ }
@@ -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?: any;
26
- b?: any;
27
- c?: any;
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?: any; // This should match the z parameter type from @maplat/transform
40
- b?: any;
41
- c?: any;
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[][];
@@ -1,88 +1,87 @@
1
- import { point } from "@turf/helpers";
2
- import { featureCollection, polygon } from "@turf/helpers";
3
- import type { Feature, Point, Position } from "geojson";
4
- import type { Tins } from "@maplat/transform";
5
-
6
- /**
7
- * 座標と属性から点オブジェクトを生成する
8
- * @param xy 座標値
9
- * @param geom 変換先での座標値
10
- * @param index インデックス
11
- * @returns 生成された点オブジェクト
12
- */
13
- function createPoint(
14
- xy: Position,
15
- geom: Position,
16
- index: string | number,
17
- ): Feature<Point> {
18
- return point(xy, { target: { geom, index } });
19
- }
20
-
21
- /**
22
- * 点オブジェクトの座標系を反転する
23
- * @param apoint 元の点オブジェクト
24
- * @returns 座標系が反転された点オブジェクト
25
- */
26
- function counterPoint(apoint: Feature<Point>): Feature<Point> {
27
- return point(apoint.properties!.target.geom, {
28
- target: {
29
- geom: apoint.geometry!.coordinates,
30
- index: apoint.properties!.target.index,
31
- },
32
- });
33
- }
34
-
35
- /**
36
- * 頂点リストから頂点パラメータを計算する
37
- * @param list 頂点リスト
38
- * @param centroid 重心点
39
- * @returns [角度リスト, 三角形リスト]
40
- */
41
- function vertexCalc(
42
- list: Feature<Point>[],
43
- centroid: Feature<Point>,
44
- ): [number[], Tins[]?] {
45
- const centCoord = centroid.geometry!.coordinates;
46
- return [0, 1, 2, 3]
47
- .map((i) => {
48
- const j = (i + 1) % 4;
49
- const itemi = list[i];
50
- const itemj = list[j];
51
- const coord = itemi.geometry!.coordinates;
52
- const radian = Math.atan2(
53
- coord[0] - centCoord[0],
54
- coord[1] - centCoord[1],
55
- );
56
- const coordinates = [centroid, itemi, itemj, centroid].map(
57
- (point) => point.geometry!.coordinates,
58
- );
59
- const properties = {
60
- a: {
61
- geom: centroid.properties!.target.geom,
62
- index: centroid.properties!.target.index,
63
- },
64
- b: {
65
- geom: itemi.properties!.target.geom,
66
- index: itemi.properties!.target.index,
67
- },
68
- c: {
69
- geom: itemj.properties!.target.geom,
70
- index: itemj.properties!.target.index,
71
- },
72
- };
73
- const tin = featureCollection([
74
- polygon([coordinates], properties),
75
- ]) as Tins;
76
- return [radian, tin] as [number, Tins];
77
- })
78
- .reduce(
79
- (prev, curr) => {
80
- prev[0].push(curr[0]);
81
- prev[1].push(curr[1]);
82
- return prev;
83
- },
84
- [[] as number[], [] as Tins[]],
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 };
@@ -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;