@maplat/tin 0.13.1 → 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 -220
- package/README.md +221 -221
- 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 +2 -2
- 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/tin.ts
CHANGED
|
@@ -1,703 +1,821 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tin (Triangulated Irregular Network) クラス
|
|
3
|
-
* 2つの平面座標系間の同相変換を実現します。
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
booleanPointInPolygon,
|
|
8
|
-
centroid as turfCentroid,
|
|
9
|
-
convex,
|
|
10
|
-
featureCollection,
|
|
11
|
-
point,
|
|
12
|
-
polygon,
|
|
13
|
-
} from "@turf/turf";
|
|
14
|
-
import type { Feature, Point, Position } from "geojson";
|
|
15
|
-
import {
|
|
16
|
-
counterTri,
|
|
17
|
-
format_version,
|
|
18
|
-
normalizeEdges,
|
|
19
|
-
rotateVerticesTriangle,
|
|
20
|
-
Transform,
|
|
21
|
-
transformArr,
|
|
22
|
-
} from "@maplat/transform";
|
|
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
|
-
} from "./
|
|
48
|
-
import
|
|
49
|
-
import {
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Tin (Triangulated Irregular Network) クラス
|
|
77
|
-
* Transformクラスを拡張し、TINネットワークの生成機能を追加
|
|
78
|
-
*/
|
|
79
|
-
export class Tin extends Transform {
|
|
80
|
-
importance: number;
|
|
81
|
-
priority: number;
|
|
82
|
-
pointsSet: PointsSetBD | undefined;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this.
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let
|
|
155
|
-
let
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (bound[
|
|
163
|
-
if (bound[
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.
|
|
171
|
-
this.
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
compiled
|
|
183
|
-
compiled.
|
|
184
|
-
compiled.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
compiled.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
compiled.
|
|
238
|
-
compiled.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.
|
|
276
|
-
this.tins = undefined;
|
|
277
|
-
this.indexedTins = undefined;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
*
|
|
282
|
-
*/
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
]
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
let
|
|
529
|
-
if (
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
.
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
)
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tin (Triangulated Irregular Network) クラス
|
|
3
|
+
* 2つの平面座標系間の同相変換を実現します。
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
booleanPointInPolygon,
|
|
8
|
+
centroid as turfCentroid,
|
|
9
|
+
convex,
|
|
10
|
+
featureCollection,
|
|
11
|
+
point,
|
|
12
|
+
polygon,
|
|
13
|
+
} from "@turf/turf";
|
|
14
|
+
import type { Feature, Point, Polygon, Position } from "geojson";
|
|
15
|
+
import {
|
|
16
|
+
counterTri,
|
|
17
|
+
format_version as FORMAT_VERSION_V2,
|
|
18
|
+
normalizeEdges,
|
|
19
|
+
rotateVerticesTriangle,
|
|
20
|
+
Transform,
|
|
21
|
+
transformArr,
|
|
22
|
+
} from "@maplat/transform";
|
|
23
|
+
|
|
24
|
+
const FORMAT_VERSION_V3 = 3.00000;
|
|
25
|
+
import type {
|
|
26
|
+
Compiled,
|
|
27
|
+
CompiledLegacy,
|
|
28
|
+
Edge,
|
|
29
|
+
EdgeSet,
|
|
30
|
+
EdgeSetLegacy,
|
|
31
|
+
PointSet,
|
|
32
|
+
PropertyTriKey,
|
|
33
|
+
StrictMode,
|
|
34
|
+
Tins,
|
|
35
|
+
TinsBD,
|
|
36
|
+
Tri,
|
|
37
|
+
VertexMode,
|
|
38
|
+
YaxisMode,
|
|
39
|
+
} from "@maplat/transform";
|
|
40
|
+
import constrainedTin from "./constrained-tin.ts";
|
|
41
|
+
import {
|
|
42
|
+
calculateBirdeyeVertices,
|
|
43
|
+
calculatePlainVertices,
|
|
44
|
+
type BoundaryVerticesParams,
|
|
45
|
+
} from "./boundary-vertices.ts";
|
|
46
|
+
import findIntersections from "./kinks.ts";
|
|
47
|
+
import { insertSearchIndex } from "./searchutils.ts";
|
|
48
|
+
import { counterPoint, createPoint, vertexCalc } from "./vertexutils.ts";
|
|
49
|
+
import { buildPointsWeightBuffer } from "./weight-buffer.ts";
|
|
50
|
+
import { resolveOverlaps } from "./strict-overlap.ts";
|
|
51
|
+
import type { SearchIndex } from "./searchutils.ts";
|
|
52
|
+
import type { PointsSetBD, VertexPosition } from "./types/tin.d.ts";
|
|
53
|
+
|
|
54
|
+
type EdgeSegmentItem = [Position, number, number, number, string?];
|
|
55
|
+
type EdgeNodeItem = [Position, Position, number];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Tinクラスの初期化オプション
|
|
59
|
+
*/
|
|
60
|
+
export interface Options {
|
|
61
|
+
bounds?: Position[];
|
|
62
|
+
wh?: number[];
|
|
63
|
+
vertexMode?: VertexMode;
|
|
64
|
+
strictMode?: StrictMode;
|
|
65
|
+
yaxisMode?: YaxisMode;
|
|
66
|
+
importance?: number;
|
|
67
|
+
priority?: number;
|
|
68
|
+
stateFull?: boolean;
|
|
69
|
+
points?: PointSet[];
|
|
70
|
+
edges?: EdgeSet[];
|
|
71
|
+
/** true にすると v2 アルゴリズム(wh bbox・turf 重心・4 境界頂点)で build する */
|
|
72
|
+
useV2Algorithm?: boolean;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Tin (Triangulated Irregular Network) クラス
|
|
77
|
+
* Transformクラスを拡張し、TINネットワークの生成機能を追加
|
|
78
|
+
*/
|
|
79
|
+
export class Tin extends Transform {
|
|
80
|
+
importance: number;
|
|
81
|
+
priority: number;
|
|
82
|
+
pointsSet: PointsSetBD | undefined;
|
|
83
|
+
useV2Algorithm: boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Tinクラスのインスタンスを生成します
|
|
87
|
+
* @param options - 初期化オプション
|
|
88
|
+
*/
|
|
89
|
+
constructor(options: Options = {}) {
|
|
90
|
+
super();
|
|
91
|
+
|
|
92
|
+
if (options.bounds) {
|
|
93
|
+
this.setBounds(options.bounds);
|
|
94
|
+
} else {
|
|
95
|
+
this.setWh(options.wh);
|
|
96
|
+
this.vertexMode = options.vertexMode || Tin.VERTEX_PLAIN;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.strictMode = options.strictMode || Tin.MODE_AUTO;
|
|
100
|
+
this.yaxisMode = options.yaxisMode || Tin.YAXIS_INVERT;
|
|
101
|
+
this.importance = options.importance || 0;
|
|
102
|
+
this.priority = options.priority || 0;
|
|
103
|
+
this.stateFull = options.stateFull || false;
|
|
104
|
+
this.useV2Algorithm = options.useV2Algorithm ?? false;
|
|
105
|
+
|
|
106
|
+
if (options.points) {
|
|
107
|
+
this.setPoints(options.points);
|
|
108
|
+
}
|
|
109
|
+
if (options.edges) {
|
|
110
|
+
this.setEdges(options.edges);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* フォーマットバージョンを取得します
|
|
116
|
+
*/
|
|
117
|
+
getFormatVersion(): number {
|
|
118
|
+
return this.useV2Algorithm ? FORMAT_VERSION_V2 : FORMAT_VERSION_V3;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 制御点(GCP: Ground Control Points)を設定します。
|
|
123
|
+
* 指定した点群に合わせて内部のTINキャッシュをリセットします。
|
|
124
|
+
*/
|
|
125
|
+
setPoints(points: PointSet[]): void {
|
|
126
|
+
if (this.yaxisMode === Tin.YAXIS_FOLLOW) {
|
|
127
|
+
points = points.map((point) => [
|
|
128
|
+
point[0],
|
|
129
|
+
[point[1][0], -1 * point[1][1]],
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
this.points = points;
|
|
133
|
+
this.tins = undefined;
|
|
134
|
+
this.indexedTins = undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* エッジ(制約線)を設定します。
|
|
139
|
+
* 制約線を正規化した上で、依存するキャッシュをリセットします。
|
|
140
|
+
*/
|
|
141
|
+
setEdges(edges: EdgeSet[] | EdgeSetLegacy[] = []): void {
|
|
142
|
+
this.edges = normalizeEdges(edges);
|
|
143
|
+
this.edgeNodes = undefined;
|
|
144
|
+
this.tins = undefined;
|
|
145
|
+
this.indexedTins = undefined;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 境界ポリゴンを設定します
|
|
150
|
+
*/
|
|
151
|
+
setBounds(bounds: Position[]): void {
|
|
152
|
+
this.bounds = bounds;
|
|
153
|
+
|
|
154
|
+
let minx = bounds[0][0];
|
|
155
|
+
let maxx = minx;
|
|
156
|
+
let miny = bounds[0][1];
|
|
157
|
+
let maxy = miny;
|
|
158
|
+
const coords = [bounds[0]];
|
|
159
|
+
|
|
160
|
+
for (let i = 1; i < bounds.length; i++) {
|
|
161
|
+
const bound = bounds[i];
|
|
162
|
+
if (bound[0] < minx) minx = bound[0];
|
|
163
|
+
if (bound[0] > maxx) maxx = bound[0];
|
|
164
|
+
if (bound[1] < miny) miny = bound[1];
|
|
165
|
+
if (bound[1] > maxy) maxy = bound[1];
|
|
166
|
+
coords.push(bound);
|
|
167
|
+
}
|
|
168
|
+
coords.push(bounds[0]);
|
|
169
|
+
|
|
170
|
+
this.boundsPolygon = polygon([coords]);
|
|
171
|
+
this.xy = [minx, miny];
|
|
172
|
+
this.wh = [maxx - minx, maxy - miny];
|
|
173
|
+
this.vertexMode = Tin.VERTEX_PLAIN;
|
|
174
|
+
this.tins = undefined;
|
|
175
|
+
this.indexedTins = undefined;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 現在の設定を永続化可能な形式にコンパイルします
|
|
180
|
+
*/
|
|
181
|
+
getCompiled(): Compiled {
|
|
182
|
+
const compiled: Compiled = {} as Compiled;
|
|
183
|
+
compiled.version = this.useV2Algorithm ? FORMAT_VERSION_V2 : FORMAT_VERSION_V3;
|
|
184
|
+
compiled.points = this.points;
|
|
185
|
+
compiled.weight_buffer = this.pointsWeightBuffer ?? {};
|
|
186
|
+
compiled.centroid_point = [
|
|
187
|
+
this.centroid!.forw!.geometry!.coordinates,
|
|
188
|
+
this.centroid!.forw!.properties!.target.geom,
|
|
189
|
+
];
|
|
190
|
+
compiled.vertices_params = [
|
|
191
|
+
this.vertices_params!.forw![0],
|
|
192
|
+
this.vertices_params!.bakw![0],
|
|
193
|
+
];
|
|
194
|
+
compiled.vertices_points = [];
|
|
195
|
+
|
|
196
|
+
const vertices = this.vertices_params!.forw![1];
|
|
197
|
+
if (vertices) {
|
|
198
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
199
|
+
const vertex = vertices[i].features[0];
|
|
200
|
+
const forw = vertex.geometry!.coordinates[0][1];
|
|
201
|
+
const bakw = vertex.properties!.b.geom;
|
|
202
|
+
compiled.vertices_points[i] = [forw, bakw];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
compiled.strict_status = this.strict_status;
|
|
207
|
+
compiled.tins_points = [[]];
|
|
208
|
+
|
|
209
|
+
this.tins!.forw!.features.map((tin: Tri) => {
|
|
210
|
+
compiled.tins_points[0].push(
|
|
211
|
+
(["a", "b", "c"] as PropertyTriKey[]).map((key) =>
|
|
212
|
+
tin.properties![key].index
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
if (this.strict_status === Tin.STATUS_LOOSE) {
|
|
218
|
+
compiled.tins_points[1] = [];
|
|
219
|
+
this.tins!.bakw!.features.map((tin: Tri) => {
|
|
220
|
+
compiled.tins_points[1].push(
|
|
221
|
+
(["a", "b", "c"] as PropertyTriKey[]).map((key) =>
|
|
222
|
+
tin.properties![key].index
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
} else if (this.strict_status === Tin.STATUS_ERROR && this.kinks?.bakw) {
|
|
227
|
+
compiled.kinks_points = this.kinks.bakw.features.map(
|
|
228
|
+
(kink) => kink.geometry!.coordinates,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
compiled.yaxisMode = this.yaxisMode;
|
|
233
|
+
compiled.vertexMode = this.vertexMode;
|
|
234
|
+
compiled.strictMode = this.strictMode;
|
|
235
|
+
|
|
236
|
+
if (this.bounds) {
|
|
237
|
+
compiled.bounds = this.bounds;
|
|
238
|
+
compiled.boundsPolygon = this.boundsPolygon;
|
|
239
|
+
if (this.useV2Algorithm) {
|
|
240
|
+
// V2 submap: xy/wh define the bbox used for triangulation — must be preserved.
|
|
241
|
+
compiled.xy = this.xy;
|
|
242
|
+
compiled.wh = this.wh;
|
|
243
|
+
}
|
|
244
|
+
// V3 submap: bounds polygon is the envelope; xy/wh are not used for
|
|
245
|
+
// triangulation and are therefore not serialized.
|
|
246
|
+
} else {
|
|
247
|
+
// Main map: wh stores image dimensions for display and V2 bbox calculation.
|
|
248
|
+
compiled.wh = this.wh;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
compiled.edges = this.edges ?? [];
|
|
252
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
253
|
+
compiled.edgeNodes = (this.edgeNodes ?? []) as any;
|
|
254
|
+
|
|
255
|
+
return compiled;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* コンパイルされた設定を適用します(v3+フォーマット対応)
|
|
260
|
+
*
|
|
261
|
+
* バージョン3以上のコンパイル済みデータが渡された場合は restoreV3State() を
|
|
262
|
+
* 使用してN頂点対応の復元を行います。それ以外は基底クラスの実装に委譲します。
|
|
263
|
+
*/
|
|
264
|
+
override setCompiled(compiled: Compiled | CompiledLegacy): void {
|
|
265
|
+
super.setCompiled(compiled);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 幅と高さを設定します
|
|
270
|
+
*/
|
|
271
|
+
setWh(wh?: number[]): void {
|
|
272
|
+
this.wh = wh || [100, 100]; // デフォルト値を設定
|
|
273
|
+
this.xy = [0, 0];
|
|
274
|
+
this.bounds = undefined;
|
|
275
|
+
this.boundsPolygon = undefined;
|
|
276
|
+
this.tins = undefined;
|
|
277
|
+
this.indexedTins = undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 頂点モードを設定します
|
|
282
|
+
*/
|
|
283
|
+
setVertexMode(mode: VertexMode): void {
|
|
284
|
+
this.vertexMode = mode;
|
|
285
|
+
this.tins = undefined;
|
|
286
|
+
this.indexedTins = undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 厳密性モードを設定します
|
|
291
|
+
*/
|
|
292
|
+
setStrictMode(mode: StrictMode): void {
|
|
293
|
+
this.strictMode = mode;
|
|
294
|
+
this.tins = undefined;
|
|
295
|
+
this.indexedTins = undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 厳密なTINを計算します
|
|
300
|
+
*/
|
|
301
|
+
calcurateStrictTin(): void {
|
|
302
|
+
const bakTins = this.tins!.forw!.features.map((tri: Tri) =>
|
|
303
|
+
counterTri(tri)
|
|
304
|
+
);
|
|
305
|
+
this.tins!.bakw = featureCollection(bakTins);
|
|
306
|
+
|
|
307
|
+
const searchIndex: SearchIndex = {};
|
|
308
|
+
this.tins!.forw!.features.forEach((forTri: Tri, index: number) => {
|
|
309
|
+
const bakTri = this.tins!.bakw!.features[index];
|
|
310
|
+
insertSearchIndex(searchIndex, { forw: forTri, bakw: bakTri });
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
resolveOverlaps(
|
|
314
|
+
this.tins!,
|
|
315
|
+
searchIndex,
|
|
316
|
+
this.pointsSet?.edges || [],
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const kinks = ["forw", "bakw"].map((direction) => {
|
|
320
|
+
const tins = this.tins![direction as keyof TinsBD]!.features.map(
|
|
321
|
+
(tin: Tri) => tin.geometry!.coordinates[0],
|
|
322
|
+
);
|
|
323
|
+
return findIntersections(tins);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
if (kinks[0].length === 0 && kinks[1].length === 0) {
|
|
327
|
+
this.strict_status = Tin.STATUS_STRICT;
|
|
328
|
+
delete this.kinks;
|
|
329
|
+
} else {
|
|
330
|
+
this.strict_status = Tin.STATUS_ERROR;
|
|
331
|
+
this.kinks = {
|
|
332
|
+
forw: featureCollection(kinks[0]),
|
|
333
|
+
bakw: featureCollection(kinks[1]),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 点群セットを生成します。
|
|
340
|
+
* GCP と中間エッジノードを GeoJSON Point に変換し、後続の三角分割に備えます。
|
|
341
|
+
*/
|
|
342
|
+
generatePointsSet(): {
|
|
343
|
+
forw: Feature<Point>[];
|
|
344
|
+
bakw: Feature<Point>[];
|
|
345
|
+
edges: Edge[];
|
|
346
|
+
} {
|
|
347
|
+
const pointsSet: { forw: Feature<Point>[]; bakw: Feature<Point>[] } = {
|
|
348
|
+
forw: [],
|
|
349
|
+
bakw: [],
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
// Generate points
|
|
353
|
+
for (let i = 0; i < this.points.length; i++) {
|
|
354
|
+
const forw = this.points[i][0];
|
|
355
|
+
const bakw = this.points[i][1];
|
|
356
|
+
const forPoint = createPoint(forw, bakw, i);
|
|
357
|
+
pointsSet.forw.push(forPoint);
|
|
358
|
+
pointsSet.bakw.push(counterPoint(forPoint));
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Generate edge nodes
|
|
362
|
+
const edges: Edge[] = [];
|
|
363
|
+
let edgeNodeIndex = 0;
|
|
364
|
+
this.edgeNodes = [];
|
|
365
|
+
|
|
366
|
+
if (!this.edges) this.edges = [];
|
|
367
|
+
|
|
368
|
+
for (let i = 0; i < this.edges.length; i++) {
|
|
369
|
+
const edge = this.edges[i][2];
|
|
370
|
+
const illstNodes = Object.assign([], this.edges[i][0]);
|
|
371
|
+
const mercNodes = Object.assign([], this.edges[i][1]);
|
|
372
|
+
|
|
373
|
+
if (illstNodes.length === 0 && mercNodes.length === 0) {
|
|
374
|
+
edges.push(edge);
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Add start and end points
|
|
379
|
+
illstNodes.unshift(this.points[edge[0]][0]);
|
|
380
|
+
illstNodes.push(this.points[edge[1]][0]);
|
|
381
|
+
mercNodes.unshift(this.points[edge[0]][1]);
|
|
382
|
+
mercNodes.push(this.points[edge[1]][1]);
|
|
383
|
+
|
|
384
|
+
// Calculate edge segments
|
|
385
|
+
const segments = [illstNodes, mercNodes].map((nodes: Position[]): EdgeSegmentItem[] => {
|
|
386
|
+
const lengths = nodes.map((node: Position, index: number, arr: Position[]) => {
|
|
387
|
+
if (index === 0) return 0;
|
|
388
|
+
const prev = arr[index - 1];
|
|
389
|
+
return Math.sqrt(
|
|
390
|
+
Math.pow(node[0] - prev[0], 2) + Math.pow(node[1] - prev[1], 2),
|
|
391
|
+
);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
const accumLengths = lengths.reduce((acc: number[], len: number, idx: number) => {
|
|
395
|
+
if (idx === 0) return [0];
|
|
396
|
+
acc.push(acc[idx - 1] + len);
|
|
397
|
+
return acc;
|
|
398
|
+
}, [] as number[]);
|
|
399
|
+
|
|
400
|
+
return accumLengths.map((accum: number, idx: number, arr: number[]): EdgeSegmentItem => {
|
|
401
|
+
const ratio = accum / arr[arr.length - 1];
|
|
402
|
+
return [nodes[idx], lengths[idx], accumLengths[idx], ratio];
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
// Generate edge nodes
|
|
407
|
+
segments
|
|
408
|
+
.map((segment: EdgeSegmentItem[], idx: number) => {
|
|
409
|
+
const otherSegment = segments[idx ? 0 : 1];
|
|
410
|
+
return segment
|
|
411
|
+
.filter((item: EdgeSegmentItem, index: number) => {
|
|
412
|
+
return !(
|
|
413
|
+
index === 0 ||
|
|
414
|
+
index === segment.length - 1 ||
|
|
415
|
+
item[4] === "handled"
|
|
416
|
+
);
|
|
417
|
+
})
|
|
418
|
+
.flatMap((item: EdgeSegmentItem): EdgeNodeItem[] => {
|
|
419
|
+
const node = item[0];
|
|
420
|
+
const ratio = item[3];
|
|
421
|
+
|
|
422
|
+
const counterpart = otherSegment.reduce(
|
|
423
|
+
(prev: EdgeSegmentItem[] | undefined, curr: EdgeSegmentItem, currIdx: number, arr: EdgeSegmentItem[]) => {
|
|
424
|
+
if (prev) return prev;
|
|
425
|
+
const nextItem = arr[currIdx + 1];
|
|
426
|
+
if (curr[3] === ratio) {
|
|
427
|
+
curr[4] = "handled";
|
|
428
|
+
return [curr];
|
|
429
|
+
}
|
|
430
|
+
if (
|
|
431
|
+
curr[3] < ratio && nextItem &&
|
|
432
|
+
nextItem[3] > ratio
|
|
433
|
+
) {
|
|
434
|
+
return [curr, nextItem];
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
},
|
|
438
|
+
undefined as EdgeSegmentItem[] | undefined,
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
if (counterpart && counterpart.length === 1) {
|
|
442
|
+
return idx === 0
|
|
443
|
+
? [[node, counterpart[0][0], ratio]]
|
|
444
|
+
: [[counterpart[0][0], node, ratio]];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (counterpart && counterpart.length === 2) {
|
|
448
|
+
const curr = counterpart[0];
|
|
449
|
+
const next = counterpart[1];
|
|
450
|
+
const ratioInSegment = (ratio - (curr[3] as number)) /
|
|
451
|
+
((next[3] as number) - (curr[3] as number));
|
|
452
|
+
const interpNode: Position = [
|
|
453
|
+
(next[0][0] - curr[0][0]) *
|
|
454
|
+
ratioInSegment + curr[0][0],
|
|
455
|
+
(next[0][1] - curr[0][1]) *
|
|
456
|
+
ratioInSegment + curr[0][1],
|
|
457
|
+
];
|
|
458
|
+
return idx === 0
|
|
459
|
+
? [[node, interpNode, ratio]]
|
|
460
|
+
: [[interpNode, node, ratio]];
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return [];
|
|
464
|
+
});
|
|
465
|
+
})
|
|
466
|
+
.reduce((prev: EdgeNodeItem[], curr: EdgeNodeItem[]) => prev.concat(curr), [])
|
|
467
|
+
.sort((a: EdgeNodeItem, b: EdgeNodeItem) => a[2] < b[2] ? -1 : 1)
|
|
468
|
+
.map((item: EdgeNodeItem, index: number, arr: EdgeNodeItem[]) => {
|
|
469
|
+
this.edgeNodes![edgeNodeIndex] = [
|
|
470
|
+
item[0],
|
|
471
|
+
item[1],
|
|
472
|
+
];
|
|
473
|
+
const forPoint = createPoint(
|
|
474
|
+
item[0],
|
|
475
|
+
item[1],
|
|
476
|
+
`e${edgeNodeIndex}`,
|
|
477
|
+
);
|
|
478
|
+
edgeNodeIndex++;
|
|
479
|
+
pointsSet.forw!.push(forPoint);
|
|
480
|
+
pointsSet.bakw!.push(counterPoint(forPoint));
|
|
481
|
+
|
|
482
|
+
if (index === 0) {
|
|
483
|
+
edges.push([edge[0], pointsSet.forw!.length - 1]);
|
|
484
|
+
} else {
|
|
485
|
+
edges.push([
|
|
486
|
+
pointsSet.forw!.length - 2,
|
|
487
|
+
pointsSet.forw!.length - 1,
|
|
488
|
+
]);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (index === arr.length - 1) {
|
|
492
|
+
edges.push([pointsSet.forw!.length - 1, edge[1]]);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
return {
|
|
498
|
+
forw: pointsSet.forw,
|
|
499
|
+
bakw: pointsSet.bakw,
|
|
500
|
+
edges,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* 入力データの検証と初期データの準備
|
|
506
|
+
*/
|
|
507
|
+
private validateAndPrepareInputs() {
|
|
508
|
+
const minx = this.xy![0] - 0.05 * this.wh![0];
|
|
509
|
+
const maxx = this.xy![0] + 1.05 * this.wh![0];
|
|
510
|
+
const miny = this.xy![1] - 0.05 * this.wh![1];
|
|
511
|
+
const maxy = this.xy![1] + 1.05 * this.wh![1];
|
|
512
|
+
|
|
513
|
+
// Invariant: boundsPolygon is always set when bounds is set (see setBounds / setCompiled).
|
|
514
|
+
if (this.bounds && !this.boundsPolygon) throw new Error("Internal error: bounds is set but boundsPolygon is missing");
|
|
515
|
+
const bp = this.bounds ? this.boundsPolygon : undefined;
|
|
516
|
+
const allPointsInside = this.points.reduce((prev: boolean, point: PointSet) => {
|
|
517
|
+
return prev &&
|
|
518
|
+
(bp
|
|
519
|
+
? booleanPointInPolygon(point[0] as Position, bp)
|
|
520
|
+
: point[0][0] >= minx && point[0][0] <= maxx &&
|
|
521
|
+
point[0][1] >= miny && point[0][1] <= maxy);
|
|
522
|
+
}, true);
|
|
523
|
+
|
|
524
|
+
if (!allPointsInside) {
|
|
525
|
+
throw "SOME POINTS OUTSIDE";
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
let bbox: Position[] = [];
|
|
529
|
+
if (this.wh) {
|
|
530
|
+
bbox = [[minx, miny], [maxx, miny], [minx, maxy], [maxx, maxy]];
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return {
|
|
534
|
+
pointsSet: this.generatePointsSet(),
|
|
535
|
+
bbox,
|
|
536
|
+
minx,
|
|
537
|
+
maxx,
|
|
538
|
+
miny,
|
|
539
|
+
maxy,
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Compute a bounding box derived from GCP coordinates with a 5% margin.
|
|
545
|
+
* Used in V3 plain mode where no explicit image bounds are available.
|
|
546
|
+
*/
|
|
547
|
+
private computeGcpBbox(): {
|
|
548
|
+
minx: number; maxx: number; miny: number; maxy: number;
|
|
549
|
+
} {
|
|
550
|
+
let gcpMinx = Infinity, gcpMaxx = -Infinity;
|
|
551
|
+
let gcpMiny = Infinity, gcpMaxy = -Infinity;
|
|
552
|
+
for (const p of this.points) {
|
|
553
|
+
const x = p[0][0] as number, y = p[0][1] as number;
|
|
554
|
+
if (x < gcpMinx) gcpMinx = x;
|
|
555
|
+
if (x > gcpMaxx) gcpMaxx = x;
|
|
556
|
+
if (y < gcpMiny) gcpMiny = y;
|
|
557
|
+
if (y > gcpMaxy) gcpMaxy = y;
|
|
558
|
+
}
|
|
559
|
+
const gcpW = gcpMaxx - gcpMinx;
|
|
560
|
+
const gcpH = gcpMaxy - gcpMiny;
|
|
561
|
+
return {
|
|
562
|
+
minx: gcpMinx - 0.05 * gcpW,
|
|
563
|
+
maxx: gcpMaxx + 0.05 * gcpW,
|
|
564
|
+
miny: gcpMiny - 0.05 * gcpH,
|
|
565
|
+
maxy: gcpMaxy + 0.05 * gcpH,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* TINネットワークを同期的に更新し、座標変換の準備を行います。
|
|
571
|
+
* 重めの計算を伴うため、呼び出し側が非同期制御を行いたい場合は
|
|
572
|
+
* {@link updateTinAsync} を利用してください。
|
|
573
|
+
*/
|
|
574
|
+
updateTin(): void {
|
|
575
|
+
let strict = this.strictMode;
|
|
576
|
+
if (strict !== Tin.MODE_STRICT && strict !== Tin.MODE_LOOSE) {
|
|
577
|
+
strict = Tin.MODE_AUTO;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const isV3 = !this.useV2Algorithm;
|
|
581
|
+
let rawPointsSet: { forw: Feature<Point>[]; bakw: Feature<Point>[]; edges: Edge[] };
|
|
582
|
+
let minx: number, maxx: number, miny: number, maxy: number;
|
|
583
|
+
|
|
584
|
+
if (isV3) {
|
|
585
|
+
// V3 (main map and submap): always derive bbox from GCPs.
|
|
586
|
+
// When a bounds polygon (envelope) is provided, validate GCPs are inside it first.
|
|
587
|
+
if (this.bounds) {
|
|
588
|
+
// Invariant: boundsPolygon is always set when bounds is set (see setBounds / setCompiled).
|
|
589
|
+
const bp = this.boundsPolygon;
|
|
590
|
+
if (!bp) throw new Error("Internal error: bounds is set but boundsPolygon is missing");
|
|
591
|
+
const allInsideBounds = this.points.every(
|
|
592
|
+
(p: PointSet) => booleanPointInPolygon(p[0] as Position, bp),
|
|
593
|
+
);
|
|
594
|
+
if (!allInsideBounds) throw "SOME POINTS OUTSIDE";
|
|
595
|
+
}
|
|
596
|
+
rawPointsSet = this.generatePointsSet();
|
|
597
|
+
({ minx, maxx, miny, maxy } = this.computeGcpBbox());
|
|
598
|
+
} else {
|
|
599
|
+
// V2: use xy/wh bbox with full validation.
|
|
600
|
+
const validated = this.validateAndPrepareInputs();
|
|
601
|
+
rawPointsSet = validated.pointsSet;
|
|
602
|
+
minx = validated.minx;
|
|
603
|
+
maxx = validated.maxx;
|
|
604
|
+
miny = validated.miny;
|
|
605
|
+
maxy = validated.maxy;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// Create FeatureCollections for use in calculations
|
|
609
|
+
const pointsSetFC = {
|
|
610
|
+
forw: featureCollection(rawPointsSet.forw),
|
|
611
|
+
bakw: featureCollection(rawPointsSet.bakw),
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
const tinForw = constrainedTin(
|
|
615
|
+
pointsSetFC.forw,
|
|
616
|
+
rawPointsSet.edges,
|
|
617
|
+
"target",
|
|
618
|
+
);
|
|
619
|
+
const tinBakw = constrainedTin(
|
|
620
|
+
pointsSetFC.bakw,
|
|
621
|
+
rawPointsSet.edges,
|
|
622
|
+
"target",
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
if (tinForw.features.length === 0 || tinBakw.features.length === 0) {
|
|
626
|
+
throw "TOO LINEAR1";
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const forCentroid = turfCentroid(pointsSetFC.forw);
|
|
630
|
+
const forwConvex = convex(pointsSetFC.forw);
|
|
631
|
+
if (!forwConvex) throw "TOO LINEAR2";
|
|
632
|
+
|
|
633
|
+
const convexBuf: Record<string, { forw: Position; bakw: Position }> = {};
|
|
634
|
+
const forwCoords = forwConvex.geometry!.coordinates[0];
|
|
635
|
+
|
|
636
|
+
// Calculate forward convex hull transformation
|
|
637
|
+
let convexCalc;
|
|
638
|
+
try {
|
|
639
|
+
convexCalc = forwCoords.map((coord: Position) => ({
|
|
640
|
+
forw: coord,
|
|
641
|
+
bakw: transformArr(point(coord), tinForw as Tins) as Position,
|
|
642
|
+
}));
|
|
643
|
+
convexCalc.forEach((item: { forw: Position; bakw: Position }) => {
|
|
644
|
+
convexBuf[`${item.forw[0]}:${item.forw[1]}`] = item;
|
|
645
|
+
});
|
|
646
|
+
} catch {
|
|
647
|
+
throw "TOO LINEAR2";
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Calculate backward convex hull transformation
|
|
651
|
+
const bakwConvex = convex(pointsSetFC.bakw);
|
|
652
|
+
if (!bakwConvex) throw "TOO LINEAR2";
|
|
653
|
+
|
|
654
|
+
const bakwCoords = bakwConvex.geometry!.coordinates[0];
|
|
655
|
+
try {
|
|
656
|
+
convexCalc = bakwCoords.map((coord: Position) => ({
|
|
657
|
+
bakw: coord,
|
|
658
|
+
forw: transformArr(point(coord), tinBakw as Tins) as Position,
|
|
659
|
+
}));
|
|
660
|
+
convexCalc.forEach((item: { forw: Position; bakw: Position }) => {
|
|
661
|
+
convexBuf[`${item.forw[0]}:${item.forw[1]}`] = item;
|
|
662
|
+
});
|
|
663
|
+
} catch {
|
|
664
|
+
throw "TOO LINEAR2";
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// Set centroids
|
|
668
|
+
let centCalc: { forw: Position; bakw: Position };
|
|
669
|
+
if (isV3) {
|
|
670
|
+
// V3 (main map and submap): find the TIN triangle containing turf's centroid
|
|
671
|
+
// and use its geometric centre (mean of 3 vertices) as the new centroid.
|
|
672
|
+
const forCentCoord = forCentroid.geometry!.coordinates;
|
|
673
|
+
const containingTri = (tinForw as Tins).features.find((tri: Tri) =>
|
|
674
|
+
booleanPointInPolygon(
|
|
675
|
+
point(forCentCoord),
|
|
676
|
+
tri as unknown as Feature<Polygon>,
|
|
677
|
+
)
|
|
678
|
+
);
|
|
679
|
+
if (containingTri) {
|
|
680
|
+
const coords = containingTri.geometry!.coordinates[0];
|
|
681
|
+
const aGeom = containingTri.properties!.a.geom as Position;
|
|
682
|
+
const bGeom = containingTri.properties!.b.geom as Position;
|
|
683
|
+
const cGeom = containingTri.properties!.c.geom as Position;
|
|
684
|
+
centCalc = {
|
|
685
|
+
forw: [
|
|
686
|
+
(coords[0][0] + coords[1][0] + coords[2][0]) / 3,
|
|
687
|
+
(coords[0][1] + coords[1][1] + coords[2][1]) / 3,
|
|
688
|
+
],
|
|
689
|
+
bakw: [
|
|
690
|
+
(aGeom[0] + bGeom[0] + cGeom[0]) / 3,
|
|
691
|
+
(aGeom[1] + bGeom[1] + cGeom[1]) / 3,
|
|
692
|
+
],
|
|
693
|
+
};
|
|
694
|
+
} else {
|
|
695
|
+
// Fallback: use turf centroid directly.
|
|
696
|
+
centCalc = {
|
|
697
|
+
forw: forCentCoord,
|
|
698
|
+
bakw: transformArr(forCentroid, tinForw as Tins) as Position,
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
} else {
|
|
702
|
+
// V2: transform turf centroid through TIN.
|
|
703
|
+
centCalc = {
|
|
704
|
+
forw: forCentroid.geometry!.coordinates,
|
|
705
|
+
bakw: transformArr(forCentroid, tinForw as Tins) as Position,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const centroidPoint = createPoint(centCalc.forw, centCalc.bakw, "c");
|
|
710
|
+
this.centroid = {
|
|
711
|
+
forw: centroidPoint,
|
|
712
|
+
bakw: counterPoint(centroidPoint),
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// Calculate vertices
|
|
716
|
+
// allGcps includes both GCPs and edge intermediate nodes so that
|
|
717
|
+
// checkAndAdjustVerticesN can guarantee all constrained-edge bakw positions
|
|
718
|
+
// are enclosed within the boundary polygon.
|
|
719
|
+
const allGcps: BoundaryVerticesParams["allGcps"] = [
|
|
720
|
+
...this.points.map((p) => ({ forw: p[0] as Position, bakw: p[1] as Position })),
|
|
721
|
+
...(this.edgeNodes ?? []).map((n) => ({ forw: n[0] as Position, bakw: n[1] as Position })),
|
|
722
|
+
];
|
|
723
|
+
const boundaryParams: BoundaryVerticesParams = {
|
|
724
|
+
convexBuf,
|
|
725
|
+
centroid: centCalc,
|
|
726
|
+
allGcps,
|
|
727
|
+
minx,
|
|
728
|
+
maxx,
|
|
729
|
+
miny,
|
|
730
|
+
maxy,
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// V3 enables the 36-bin edge vertex pass for both main maps and submaps.
|
|
734
|
+
const verticesSet: VertexPosition[] = this.vertexMode === Tin.VERTEX_BIRDEYE
|
|
735
|
+
? calculateBirdeyeVertices(boundaryParams, isV3)
|
|
736
|
+
: calculatePlainVertices(boundaryParams, isV3);
|
|
737
|
+
|
|
738
|
+
// Add vertices to points set
|
|
739
|
+
const verticesList = {
|
|
740
|
+
forw: [] as Feature<Point>[],
|
|
741
|
+
bakw: [] as Feature<Point>[],
|
|
742
|
+
};
|
|
743
|
+
for (let i = 0; i < verticesSet.length; i++) {
|
|
744
|
+
const forw = verticesSet[i].forw;
|
|
745
|
+
const bakw = verticesSet[i].bakw;
|
|
746
|
+
const forPoint = createPoint(forw, bakw, `b${i}`);
|
|
747
|
+
const bakPoint = counterPoint(forPoint);
|
|
748
|
+
rawPointsSet.forw.push(forPoint);
|
|
749
|
+
rawPointsSet.bakw.push(bakPoint);
|
|
750
|
+
verticesList.forw.push(forPoint);
|
|
751
|
+
verticesList.bakw.push(bakPoint);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
this.pointsSet = {
|
|
755
|
+
forw: featureCollection(rawPointsSet.forw),
|
|
756
|
+
bakw: featureCollection(rawPointsSet.bakw),
|
|
757
|
+
edges: rawPointsSet.edges,
|
|
758
|
+
};
|
|
759
|
+
|
|
760
|
+
// Generate forward TIN
|
|
761
|
+
this.tins = {
|
|
762
|
+
forw: rotateVerticesTriangle(
|
|
763
|
+
constrainedTin(
|
|
764
|
+
this.pointsSet!.forw,
|
|
765
|
+
rawPointsSet.edges,
|
|
766
|
+
"target",
|
|
767
|
+
) as Tins,
|
|
768
|
+
),
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// Calculate strict TIN if needed
|
|
772
|
+
if (strict === Tin.MODE_STRICT || strict === Tin.MODE_AUTO) {
|
|
773
|
+
this.calcurateStrictTin();
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Generate backward TIN if needed
|
|
777
|
+
if (
|
|
778
|
+
strict === Tin.MODE_LOOSE ||
|
|
779
|
+
(strict === Tin.MODE_AUTO && this.strict_status === Tin.STATUS_ERROR)
|
|
780
|
+
) {
|
|
781
|
+
this.tins!.bakw = rotateVerticesTriangle(
|
|
782
|
+
constrainedTin(
|
|
783
|
+
this.pointsSet!.bakw,
|
|
784
|
+
rawPointsSet.edges,
|
|
785
|
+
"target",
|
|
786
|
+
) as Tins,
|
|
787
|
+
);
|
|
788
|
+
delete this.kinks;
|
|
789
|
+
this.strict_status = Tin.STATUS_LOOSE;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// Calculate vertices parameters
|
|
793
|
+
this.vertices_params = {
|
|
794
|
+
forw: vertexCalc(verticesList.forw, this.centroid.forw!),
|
|
795
|
+
bakw: vertexCalc(verticesList.bakw, this.centroid.bakw!),
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
this.addIndexedTin();
|
|
799
|
+
|
|
800
|
+
const targets: Array<keyof TinsBD> = ["forw"];
|
|
801
|
+
if (this.strict_status === Tin.STATUS_LOOSE) {
|
|
802
|
+
targets.push("bakw");
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const includeReciprocals = this.strict_status === Tin.STATUS_STRICT;
|
|
806
|
+
this.pointsWeightBuffer = buildPointsWeightBuffer({
|
|
807
|
+
tins: this.tins!,
|
|
808
|
+
targets,
|
|
809
|
+
includeReciprocals,
|
|
810
|
+
numBoundaryVertices: verticesSet.length,
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* 非同期ラッパーを提供します。
|
|
816
|
+
* 互換性のために Promise ベースの API を維持しますが、内部処理は同期的です。
|
|
817
|
+
*/
|
|
818
|
+
async updateTinAsync(): Promise<void> {
|
|
819
|
+
this.updateTin();
|
|
820
|
+
}
|
|
821
|
+
}
|