@maplat/tin 1.1.2-rc.1 → 1.1.2-rc.2
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 +3 -3
- package/README.md +3 -3
- package/dist/edge-nodes.d.ts +27 -0
- package/dist/maplat_tin.js +773 -762
- package/dist/maplat_tin.umd.js +2 -2
- package/package.json +1 -1
- package/src/edge-nodes.ts +126 -0
- package/src/tin.ts +3 -86
package/src/tin.ts
CHANGED
|
@@ -40,6 +40,8 @@ import type {
|
|
|
40
40
|
YaxisMode,
|
|
41
41
|
} from "@maplat/transform";
|
|
42
42
|
import constrainedTin from "./constrained-tin.ts";
|
|
43
|
+
import { interpolateEdgeNodes } from "./edge-nodes.ts";
|
|
44
|
+
import type { EdgeNodeItem } from "./edge-nodes.ts";
|
|
43
45
|
import {
|
|
44
46
|
calculateBirdeyeVertices,
|
|
45
47
|
calculatePlainVertices,
|
|
@@ -52,9 +54,6 @@ import { resolveOverlaps } from "./strict-overlap.ts";
|
|
|
52
54
|
import type { SearchIndex } from "./searchutils.ts";
|
|
53
55
|
import type { PointsSetBD, VertexPosition } from "./types/tin.ts";
|
|
54
56
|
|
|
55
|
-
type EdgeSegmentItem = [Position, number, number, number, string?];
|
|
56
|
-
type EdgeNodeItem = [Position, Position, number];
|
|
57
|
-
|
|
58
57
|
/**
|
|
59
58
|
* Tinクラスの初期化オプション
|
|
60
59
|
*/
|
|
@@ -400,90 +399,8 @@ export class Tin extends Transform {
|
|
|
400
399
|
mercNodes.unshift(this.points[edge[0]][1]);
|
|
401
400
|
mercNodes.push(this.points[edge[1]][1]);
|
|
402
401
|
|
|
403
|
-
// Calculate edge segments
|
|
404
|
-
const segments = [illstNodes, mercNodes].map((nodes: Position[]): EdgeSegmentItem[] => {
|
|
405
|
-
const lengths = nodes.map((node: Position, index: number, arr: Position[]) => {
|
|
406
|
-
if (index === 0) return 0;
|
|
407
|
-
const prev = arr[index - 1];
|
|
408
|
-
return Math.sqrt(
|
|
409
|
-
Math.pow(node[0] - prev[0], 2) + Math.pow(node[1] - prev[1], 2),
|
|
410
|
-
);
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
const accumLengths = lengths.reduce((acc: number[], len: number, idx: number) => {
|
|
414
|
-
if (idx === 0) return [0];
|
|
415
|
-
acc.push(acc[idx - 1] + len);
|
|
416
|
-
return acc;
|
|
417
|
-
}, [] as number[]);
|
|
418
|
-
|
|
419
|
-
return accumLengths.map((accum: number, idx: number, arr: number[]): EdgeSegmentItem => {
|
|
420
|
-
const ratio = accum / arr[arr.length - 1];
|
|
421
|
-
return [nodes[idx], lengths[idx], accumLengths[idx], ratio];
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
|
|
425
402
|
// Generate edge nodes
|
|
426
|
-
|
|
427
|
-
.map((segment: EdgeSegmentItem[], idx: number) => {
|
|
428
|
-
const otherSegment = segments[idx ? 0 : 1];
|
|
429
|
-
return segment
|
|
430
|
-
.filter((item: EdgeSegmentItem, index: number) => {
|
|
431
|
-
return !(
|
|
432
|
-
index === 0 ||
|
|
433
|
-
index === segment.length - 1 ||
|
|
434
|
-
item[4] === "handled"
|
|
435
|
-
);
|
|
436
|
-
})
|
|
437
|
-
.flatMap((item: EdgeSegmentItem): EdgeNodeItem[] => {
|
|
438
|
-
const node = item[0];
|
|
439
|
-
const ratio = item[3];
|
|
440
|
-
|
|
441
|
-
const counterpart = otherSegment.reduce(
|
|
442
|
-
(prev: EdgeSegmentItem[] | undefined, curr: EdgeSegmentItem, currIdx: number, arr: EdgeSegmentItem[]) => {
|
|
443
|
-
if (prev) return prev;
|
|
444
|
-
const nextItem = arr[currIdx + 1];
|
|
445
|
-
if (curr[3] === ratio) {
|
|
446
|
-
curr[4] = "handled";
|
|
447
|
-
return [curr];
|
|
448
|
-
}
|
|
449
|
-
if (
|
|
450
|
-
curr[3] < ratio && nextItem &&
|
|
451
|
-
nextItem[3] > ratio
|
|
452
|
-
) {
|
|
453
|
-
return [curr, nextItem];
|
|
454
|
-
}
|
|
455
|
-
return undefined;
|
|
456
|
-
},
|
|
457
|
-
undefined as EdgeSegmentItem[] | undefined,
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
if (counterpart && counterpart.length === 1) {
|
|
461
|
-
return idx === 0
|
|
462
|
-
? [[node, counterpart[0][0], ratio]]
|
|
463
|
-
: [[counterpart[0][0], node, ratio]];
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (counterpart && counterpart.length === 2) {
|
|
467
|
-
const curr = counterpart[0];
|
|
468
|
-
const next = counterpart[1];
|
|
469
|
-
const ratioInSegment = (ratio - (curr[3] as number)) /
|
|
470
|
-
((next[3] as number) - (curr[3] as number));
|
|
471
|
-
const interpNode: Position = [
|
|
472
|
-
(next[0][0] - curr[0][0]) *
|
|
473
|
-
ratioInSegment + curr[0][0],
|
|
474
|
-
(next[0][1] - curr[0][1]) *
|
|
475
|
-
ratioInSegment + curr[0][1],
|
|
476
|
-
];
|
|
477
|
-
return idx === 0
|
|
478
|
-
? [[node, interpNode, ratio]]
|
|
479
|
-
: [[interpNode, node, ratio]];
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return [];
|
|
483
|
-
});
|
|
484
|
-
})
|
|
485
|
-
.reduce((prev: EdgeNodeItem[], curr: EdgeNodeItem[]) => prev.concat(curr), [])
|
|
486
|
-
.sort((a: EdgeNodeItem, b: EdgeNodeItem) => a[2] < b[2] ? -1 : 1)
|
|
403
|
+
interpolateEdgeNodes(illstNodes, mercNodes)
|
|
487
404
|
.map((item: EdgeNodeItem, index: number, arr: EdgeNodeItem[]) => {
|
|
488
405
|
this.edgeNodes![edgeNodeIndex] = [
|
|
489
406
|
item[0],
|