@maplat/transform 0.2.2 → 0.3.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 +68 -68
- package/README.md +143 -143
- package/dist/index.d.ts +15 -23
- package/dist/index.html +42 -39
- package/dist/maplat_transform.cjs +1 -1
- package/dist/maplat_transform.js +505 -440
- package/dist/maplat_transform.umd.js +1 -1
- package/package.json +34 -38
- package/src/compiled-state.ts +211 -0
- package/src/edgeutils.ts +47 -47
- package/src/geometry.ts +248 -248
- package/src/index.ts +382 -567
- package/src/triangulation.ts +179 -179
- package/src/types.ts +122 -0
package/src/index.ts
CHANGED
|
@@ -1,567 +1,382 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
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
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
const forwXUnit = (forwBound[1][0] - forwBound[0][0]) / gridNum;
|
|
384
|
-
const forwYUnit = (forwBound[1][1] - forwBound[0][1]) / gridNum;
|
|
385
|
-
const forwGridCache = forwEachBound.reduce(
|
|
386
|
-
(prev: number[][][], bound: Position[], index: number) => {
|
|
387
|
-
const normXMin = unitCalc(
|
|
388
|
-
bound[0][0],
|
|
389
|
-
forwBound[0][0],
|
|
390
|
-
forwXUnit,
|
|
391
|
-
gridNum
|
|
392
|
-
);
|
|
393
|
-
const normXMax = unitCalc(
|
|
394
|
-
bound[1][0],
|
|
395
|
-
forwBound[0][0],
|
|
396
|
-
forwXUnit,
|
|
397
|
-
gridNum
|
|
398
|
-
);
|
|
399
|
-
const normYMin = unitCalc(
|
|
400
|
-
bound[0][1],
|
|
401
|
-
forwBound[0][1],
|
|
402
|
-
forwYUnit,
|
|
403
|
-
gridNum
|
|
404
|
-
);
|
|
405
|
-
const normYMax = unitCalc(
|
|
406
|
-
bound[1][1],
|
|
407
|
-
forwBound[0][1],
|
|
408
|
-
forwYUnit,
|
|
409
|
-
gridNum
|
|
410
|
-
);
|
|
411
|
-
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
412
|
-
if (!prev[cx]) prev[cx] = [];
|
|
413
|
-
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
414
|
-
if (!prev[cx][cy]) prev[cx][cy] = [];
|
|
415
|
-
prev[cx][cy].push(index);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return prev;
|
|
419
|
-
},
|
|
420
|
-
[]
|
|
421
|
-
);
|
|
422
|
-
const bakwEachBound = bakw!.features.map((tri: Tri) => {
|
|
423
|
-
let eachBound: Position[] = [];
|
|
424
|
-
getCoords(tri)[0].map((point: Position) => {
|
|
425
|
-
if (bakwBound.length === 0)
|
|
426
|
-
bakwBound = [Array.from(point), Array.from(point)];
|
|
427
|
-
else {
|
|
428
|
-
if (point[0] < bakwBound[0][0]) bakwBound[0][0] = point[0];
|
|
429
|
-
if (point[0] > bakwBound[1][0]) bakwBound[1][0] = point[0];
|
|
430
|
-
if (point[1] < bakwBound[0][1]) bakwBound[0][1] = point[1];
|
|
431
|
-
if (point[1] > bakwBound[1][1]) bakwBound[1][1] = point[1];
|
|
432
|
-
}
|
|
433
|
-
if (eachBound.length === 0)
|
|
434
|
-
eachBound = [Array.from(point), Array.from(point)];
|
|
435
|
-
else {
|
|
436
|
-
if (point[0] < eachBound[0][0]) eachBound[0][0] = point[0];
|
|
437
|
-
if (point[0] > eachBound[1][0]) eachBound[1][0] = point[0];
|
|
438
|
-
if (point[1] < eachBound[0][1]) eachBound[0][1] = point[1];
|
|
439
|
-
if (point[1] > eachBound[1][1]) eachBound[1][1] = point[1];
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
return eachBound;
|
|
443
|
-
});
|
|
444
|
-
const bakwXUnit = (bakwBound[1][0] - bakwBound[0][0]) / gridNum;
|
|
445
|
-
const bakwYUnit = (bakwBound[1][1] - bakwBound[0][1]) / gridNum;
|
|
446
|
-
const bakwGridCache = bakwEachBound.reduce(
|
|
447
|
-
(prev: number[][][], bound: Position[], index: number) => {
|
|
448
|
-
const normXMin = unitCalc(
|
|
449
|
-
bound[0][0],
|
|
450
|
-
bakwBound[0][0],
|
|
451
|
-
bakwXUnit,
|
|
452
|
-
gridNum
|
|
453
|
-
);
|
|
454
|
-
const normXMax = unitCalc(
|
|
455
|
-
bound[1][0],
|
|
456
|
-
bakwBound[0][0],
|
|
457
|
-
bakwXUnit,
|
|
458
|
-
gridNum
|
|
459
|
-
);
|
|
460
|
-
const normYMin = unitCalc(
|
|
461
|
-
bound[0][1],
|
|
462
|
-
bakwBound[0][1],
|
|
463
|
-
bakwYUnit,
|
|
464
|
-
gridNum
|
|
465
|
-
);
|
|
466
|
-
const normYMax = unitCalc(
|
|
467
|
-
bound[1][1],
|
|
468
|
-
bakwBound[0][1],
|
|
469
|
-
bakwYUnit,
|
|
470
|
-
gridNum
|
|
471
|
-
);
|
|
472
|
-
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
473
|
-
if (!prev[cx]) prev[cx] = [];
|
|
474
|
-
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
475
|
-
if (!prev[cx][cy]) prev[cx][cy] = [];
|
|
476
|
-
prev[cx][cy].push(index);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
return prev;
|
|
480
|
-
},
|
|
481
|
-
[]
|
|
482
|
-
);
|
|
483
|
-
this.indexedTins = {
|
|
484
|
-
forw: {
|
|
485
|
-
gridNum,
|
|
486
|
-
xOrigin: forwBound[0][0],
|
|
487
|
-
yOrigin: forwBound[0][1],
|
|
488
|
-
xUnit: forwXUnit,
|
|
489
|
-
yUnit: forwYUnit,
|
|
490
|
-
gridCache: forwGridCache
|
|
491
|
-
},
|
|
492
|
-
bakw: {
|
|
493
|
-
gridNum,
|
|
494
|
-
xOrigin: bakwBound[0][0],
|
|
495
|
-
yOrigin: bakwBound[0][1],
|
|
496
|
-
xUnit: bakwXUnit,
|
|
497
|
-
yUnit: bakwYUnit,
|
|
498
|
-
gridCache: bakwGridCache
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/**
|
|
504
|
-
* 座標変換を実行します
|
|
505
|
-
*
|
|
506
|
-
* @param apoint - 変換する座標
|
|
507
|
-
* @param backward - 逆方向の変換かどうか
|
|
508
|
-
* @param ignoreBounds - 境界チェックを無視するかどうか
|
|
509
|
-
* @returns 変換後の座標、または境界外の場合はfalse
|
|
510
|
-
*
|
|
511
|
-
* @throws {Error} 逆方向変換が許可されていない状態での逆変換時
|
|
512
|
-
*/
|
|
513
|
-
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false {
|
|
514
|
-
if (backward && this.strict_status == Transform.STATUS_ERROR)
|
|
515
|
-
throw 'Backward transform is not allowed if strict_status == "strict_error"';
|
|
516
|
-
// if (!this.tins) this.updateTin();
|
|
517
|
-
if (this.yaxisMode == Transform.YAXIS_FOLLOW && backward) {
|
|
518
|
-
apoint = [apoint[0], -1 * apoint[1]];
|
|
519
|
-
}
|
|
520
|
-
const tpoint = point(apoint);
|
|
521
|
-
if (this.bounds && !backward && !ignoreBounds) {
|
|
522
|
-
if (!booleanPointInPolygon(tpoint, this.boundsPolygon!)) return false;
|
|
523
|
-
}
|
|
524
|
-
const tins = backward ? this.tins!.bakw : this.tins!.forw;
|
|
525
|
-
const indexedTins = backward
|
|
526
|
-
? this.indexedTins!.bakw
|
|
527
|
-
: this.indexedTins!.forw;
|
|
528
|
-
const verticesParams = backward
|
|
529
|
-
? this.vertices_params!.bakw
|
|
530
|
-
: this.vertices_params!.forw;
|
|
531
|
-
const centroid = backward ? this.centroid!.bakw : this.centroid!.forw;
|
|
532
|
-
const weightBuffer = backward
|
|
533
|
-
? this.pointsWeightBuffer!.bakw
|
|
534
|
-
: this.pointsWeightBuffer!.forw;
|
|
535
|
-
let stateTriangle = undefined,
|
|
536
|
-
stateSetFunc = undefined;
|
|
537
|
-
if (this.stateFull) {
|
|
538
|
-
if (this.stateBackward == backward) {
|
|
539
|
-
stateTriangle = this.stateTriangle;
|
|
540
|
-
} else {
|
|
541
|
-
this.stateBackward = backward;
|
|
542
|
-
this.stateTriangle = undefined;
|
|
543
|
-
}
|
|
544
|
-
stateSetFunc = (tri?: Tri) => {
|
|
545
|
-
this.stateTriangle = tri;
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
let ret = transformArr(
|
|
549
|
-
tpoint,
|
|
550
|
-
tins!,
|
|
551
|
-
indexedTins,
|
|
552
|
-
verticesParams,
|
|
553
|
-
centroid,
|
|
554
|
-
weightBuffer,
|
|
555
|
-
stateTriangle,
|
|
556
|
-
stateSetFunc
|
|
557
|
-
);
|
|
558
|
-
if (this.bounds && backward && !ignoreBounds) {
|
|
559
|
-
const rpoint = point(ret);
|
|
560
|
-
if (!booleanPointInPolygon(rpoint, this.boundsPolygon!)) return false;
|
|
561
|
-
} else if (this.yaxisMode == Transform.YAXIS_FOLLOW && !backward) {
|
|
562
|
-
ret = [ret[0], -1 * ret[1]];
|
|
563
|
-
}
|
|
564
|
-
return ret;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
}
|
|
1
|
+
import type { Feature, Polygon, Position } from "geojson";
|
|
2
|
+
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
3
|
+
import { point } from "@turf/helpers";
|
|
4
|
+
import { getCoords } from "@turf/invariant";
|
|
5
|
+
import { unitCalc, transformArr } from "./geometry.ts";
|
|
6
|
+
import type { Tri } from "./geometry.ts";
|
|
7
|
+
import {
|
|
8
|
+
FORMAT_VERSION,
|
|
9
|
+
isModernCompiled,
|
|
10
|
+
restoreLegacyState,
|
|
11
|
+
restoreModernState
|
|
12
|
+
} from "./compiled-state.ts";
|
|
13
|
+
import type { EdgeSet } from "./edgeutils.ts";
|
|
14
|
+
import type {
|
|
15
|
+
Compiled,
|
|
16
|
+
CompiledLegacy,
|
|
17
|
+
IndexedTinsBD,
|
|
18
|
+
KinksBD,
|
|
19
|
+
LegacyStatePayload,
|
|
20
|
+
ModernStatePayload,
|
|
21
|
+
PointSet,
|
|
22
|
+
StrictMode,
|
|
23
|
+
StrictStatus,
|
|
24
|
+
TinsBD,
|
|
25
|
+
VertexMode,
|
|
26
|
+
VerticesParamsBD,
|
|
27
|
+
WeightBufferBD,
|
|
28
|
+
YaxisMode,
|
|
29
|
+
CentroidBD
|
|
30
|
+
} from "./types.ts";
|
|
31
|
+
export type {
|
|
32
|
+
PointSet,
|
|
33
|
+
BiDirectionKey,
|
|
34
|
+
WeightBufferBD,
|
|
35
|
+
VertexMode,
|
|
36
|
+
StrictMode,
|
|
37
|
+
StrictStatus,
|
|
38
|
+
YaxisMode,
|
|
39
|
+
CentroidBD,
|
|
40
|
+
TinsBD,
|
|
41
|
+
KinksBD,
|
|
42
|
+
VerticesParamsBD,
|
|
43
|
+
IndexedTinsBD,
|
|
44
|
+
Compiled,
|
|
45
|
+
CompiledLegacy
|
|
46
|
+
} from "./types.ts";
|
|
47
|
+
export type { Tins, Tri, PropertyTriKey } from "./geometry.ts";
|
|
48
|
+
export { transformArr } from "./geometry.ts";
|
|
49
|
+
export { rotateVerticesTriangle, counterTri } from "./triangulation.ts";
|
|
50
|
+
export type { Edge, EdgeSet, EdgeSetLegacy } from "./edgeutils.ts";
|
|
51
|
+
export { normalizeEdges } from "./edgeutils.ts";
|
|
52
|
+
export const format_version = FORMAT_VERSION;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 座標変換の基本機能を提供するクラス
|
|
56
|
+
*
|
|
57
|
+
* 2つの座標系間の変換を、TINネットワークを使用して実現します。
|
|
58
|
+
* このクラスは基本的な変換機能のみを提供し、
|
|
59
|
+
* 設定ファイルの生成などの追加機能はTinクラスで提供されます。
|
|
60
|
+
*/
|
|
61
|
+
export class Transform {
|
|
62
|
+
/**
|
|
63
|
+
* 各種モードの定数定義
|
|
64
|
+
* すべてreadonlyで、型安全性を確保
|
|
65
|
+
*/
|
|
66
|
+
static VERTEX_PLAIN = "plain" as const;
|
|
67
|
+
static VERTEX_BIRDEYE = "birdeye" as const;
|
|
68
|
+
static MODE_STRICT = "strict" as const;
|
|
69
|
+
static MODE_AUTO = "auto" as const;
|
|
70
|
+
static MODE_LOOSE = "loose" as const;
|
|
71
|
+
static STATUS_STRICT = "strict" as const;
|
|
72
|
+
static STATUS_ERROR = "strict_error" as const;
|
|
73
|
+
static STATUS_LOOSE = "loose" as const;
|
|
74
|
+
static YAXIS_FOLLOW = "follow" as const;
|
|
75
|
+
static YAXIS_INVERT = "invert" as const;
|
|
76
|
+
|
|
77
|
+
points: PointSet[] = [];
|
|
78
|
+
pointsWeightBuffer?: WeightBufferBD;
|
|
79
|
+
strict_status?: StrictStatus;
|
|
80
|
+
vertices_params?: VerticesParamsBD;
|
|
81
|
+
centroid?: CentroidBD;
|
|
82
|
+
edgeNodes?: PointSet[];
|
|
83
|
+
edges?: EdgeSet[];
|
|
84
|
+
tins?: TinsBD;
|
|
85
|
+
kinks?: KinksBD;
|
|
86
|
+
yaxisMode: YaxisMode = Transform.YAXIS_INVERT;
|
|
87
|
+
strictMode: StrictMode = Transform.MODE_AUTO;
|
|
88
|
+
vertexMode?: VertexMode = Transform.VERTEX_PLAIN;
|
|
89
|
+
bounds?: number[][];
|
|
90
|
+
boundsPolygon?: Feature<Polygon>;
|
|
91
|
+
wh?: number[];
|
|
92
|
+
xy?: number[];
|
|
93
|
+
indexedTins?: IndexedTinsBD;
|
|
94
|
+
stateFull = false;
|
|
95
|
+
stateTriangle?: Tri;
|
|
96
|
+
stateBackward?: boolean;
|
|
97
|
+
|
|
98
|
+
constructor() {}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* コンパイルされた設定を適用します
|
|
102
|
+
*
|
|
103
|
+
* @param compiled - コンパイルされた設定オブジェクト
|
|
104
|
+
* @returns 変換に必要な主要なオブジェクトのセット
|
|
105
|
+
*
|
|
106
|
+
* 以下の処理を行います:
|
|
107
|
+
* 1. バージョンに応じた設定の解釈
|
|
108
|
+
* 2. 各種パラメータの復元
|
|
109
|
+
* 3. TINネットワークの再構築
|
|
110
|
+
* 4. インデックスの作成
|
|
111
|
+
*/
|
|
112
|
+
setCompiled(compiled: Compiled | CompiledLegacy): void {
|
|
113
|
+
if (isModernCompiled(compiled)) {
|
|
114
|
+
this.applyModernState(restoreModernState(compiled));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.applyLegacyState(restoreLegacyState(compiled as CompiledLegacy));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private applyModernState(state: ModernStatePayload): void {
|
|
121
|
+
this.points = state.points;
|
|
122
|
+
this.pointsWeightBuffer = state.pointsWeightBuffer;
|
|
123
|
+
this.strict_status = state.strictStatus;
|
|
124
|
+
this.vertices_params = state.verticesParams;
|
|
125
|
+
this.centroid = state.centroid;
|
|
126
|
+
this.edges = state.edges;
|
|
127
|
+
this.edgeNodes = state.edgeNodes || [];
|
|
128
|
+
this.tins = state.tins;
|
|
129
|
+
this.addIndexedTin();
|
|
130
|
+
this.kinks = state.kinks;
|
|
131
|
+
this.yaxisMode = state.yaxisMode ?? Transform.YAXIS_INVERT;
|
|
132
|
+
this.vertexMode = state.vertexMode ?? Transform.VERTEX_PLAIN;
|
|
133
|
+
this.strictMode = state.strictMode ?? Transform.MODE_AUTO;
|
|
134
|
+
if (state.bounds) {
|
|
135
|
+
this.bounds = state.bounds;
|
|
136
|
+
this.boundsPolygon = state.boundsPolygon;
|
|
137
|
+
this.xy = state.xy;
|
|
138
|
+
this.wh = state.wh;
|
|
139
|
+
} else {
|
|
140
|
+
this.bounds = undefined;
|
|
141
|
+
this.boundsPolygon = undefined;
|
|
142
|
+
this.xy = state.xy ?? [0, 0];
|
|
143
|
+
if (state.wh) this.wh = state.wh;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private applyLegacyState(state: LegacyStatePayload): void {
|
|
148
|
+
this.tins = state.tins;
|
|
149
|
+
this.addIndexedTin();
|
|
150
|
+
this.strict_status = state.strictStatus;
|
|
151
|
+
this.pointsWeightBuffer = state.pointsWeightBuffer;
|
|
152
|
+
this.vertices_params = state.verticesParams;
|
|
153
|
+
this.centroid = state.centroid;
|
|
154
|
+
this.kinks = state.kinks;
|
|
155
|
+
this.points = state.points;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* TINネットワークのインデックスを作成します
|
|
160
|
+
*
|
|
161
|
+
* インデックスは変換処理を高速化するために使用されます。
|
|
162
|
+
* グリッド形式のインデックスを作成し、各グリッドに
|
|
163
|
+
* 含まれる三角形を記録します。
|
|
164
|
+
*/
|
|
165
|
+
addIndexedTin() {
|
|
166
|
+
const tins = this.tins!;
|
|
167
|
+
const forw = tins.forw;
|
|
168
|
+
const bakw = tins.bakw;
|
|
169
|
+
const gridNum = Math.ceil(Math.sqrt(forw!.features.length));
|
|
170
|
+
if (gridNum < 3) {
|
|
171
|
+
this.indexedTins = undefined;
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
let forwBound: Position[] = [];
|
|
175
|
+
let bakwBound: Position[] = [];
|
|
176
|
+
const forwEachBound = forw!.features.map((tri: Tri) => {
|
|
177
|
+
let eachBound: Position[] = [];
|
|
178
|
+
getCoords(tri)[0].map((point: Position) => {
|
|
179
|
+
if (forwBound.length === 0)
|
|
180
|
+
forwBound = [Array.from(point), Array.from(point)];
|
|
181
|
+
else {
|
|
182
|
+
if (point[0] < forwBound[0][0]) forwBound[0][0] = point[0];
|
|
183
|
+
if (point[0] > forwBound[1][0]) forwBound[1][0] = point[0];
|
|
184
|
+
if (point[1] < forwBound[0][1]) forwBound[0][1] = point[1];
|
|
185
|
+
if (point[1] > forwBound[1][1]) forwBound[1][1] = point[1];
|
|
186
|
+
}
|
|
187
|
+
if (eachBound.length === 0)
|
|
188
|
+
eachBound = [Array.from(point), Array.from(point)];
|
|
189
|
+
else {
|
|
190
|
+
if (point[0] < eachBound[0][0]) eachBound[0][0] = point[0];
|
|
191
|
+
if (point[0] > eachBound[1][0]) eachBound[1][0] = point[0];
|
|
192
|
+
if (point[1] < eachBound[0][1]) eachBound[0][1] = point[1];
|
|
193
|
+
if (point[1] > eachBound[1][1]) eachBound[1][1] = point[1];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return eachBound;
|
|
197
|
+
});
|
|
198
|
+
const forwXUnit = (forwBound[1][0] - forwBound[0][0]) / gridNum;
|
|
199
|
+
const forwYUnit = (forwBound[1][1] - forwBound[0][1]) / gridNum;
|
|
200
|
+
const forwGridCache = forwEachBound.reduce(
|
|
201
|
+
(prev: number[][][], bound: Position[], index: number) => {
|
|
202
|
+
const normXMin = unitCalc(
|
|
203
|
+
bound[0][0],
|
|
204
|
+
forwBound[0][0],
|
|
205
|
+
forwXUnit,
|
|
206
|
+
gridNum
|
|
207
|
+
);
|
|
208
|
+
const normXMax = unitCalc(
|
|
209
|
+
bound[1][0],
|
|
210
|
+
forwBound[0][0],
|
|
211
|
+
forwXUnit,
|
|
212
|
+
gridNum
|
|
213
|
+
);
|
|
214
|
+
const normYMin = unitCalc(
|
|
215
|
+
bound[0][1],
|
|
216
|
+
forwBound[0][1],
|
|
217
|
+
forwYUnit,
|
|
218
|
+
gridNum
|
|
219
|
+
);
|
|
220
|
+
const normYMax = unitCalc(
|
|
221
|
+
bound[1][1],
|
|
222
|
+
forwBound[0][1],
|
|
223
|
+
forwYUnit,
|
|
224
|
+
gridNum
|
|
225
|
+
);
|
|
226
|
+
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
227
|
+
if (!prev[cx]) prev[cx] = [];
|
|
228
|
+
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
229
|
+
if (!prev[cx][cy]) prev[cx][cy] = [];
|
|
230
|
+
prev[cx][cy].push(index);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return prev;
|
|
234
|
+
},
|
|
235
|
+
[]
|
|
236
|
+
);
|
|
237
|
+
const bakwEachBound = bakw!.features.map((tri: Tri) => {
|
|
238
|
+
let eachBound: Position[] = [];
|
|
239
|
+
getCoords(tri)[0].map((point: Position) => {
|
|
240
|
+
if (bakwBound.length === 0)
|
|
241
|
+
bakwBound = [Array.from(point), Array.from(point)];
|
|
242
|
+
else {
|
|
243
|
+
if (point[0] < bakwBound[0][0]) bakwBound[0][0] = point[0];
|
|
244
|
+
if (point[0] > bakwBound[1][0]) bakwBound[1][0] = point[0];
|
|
245
|
+
if (point[1] < bakwBound[0][1]) bakwBound[0][1] = point[1];
|
|
246
|
+
if (point[1] > bakwBound[1][1]) bakwBound[1][1] = point[1];
|
|
247
|
+
}
|
|
248
|
+
if (eachBound.length === 0)
|
|
249
|
+
eachBound = [Array.from(point), Array.from(point)];
|
|
250
|
+
else {
|
|
251
|
+
if (point[0] < eachBound[0][0]) eachBound[0][0] = point[0];
|
|
252
|
+
if (point[0] > eachBound[1][0]) eachBound[1][0] = point[0];
|
|
253
|
+
if (point[1] < eachBound[0][1]) eachBound[0][1] = point[1];
|
|
254
|
+
if (point[1] > eachBound[1][1]) eachBound[1][1] = point[1];
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
return eachBound;
|
|
258
|
+
});
|
|
259
|
+
const bakwXUnit = (bakwBound[1][0] - bakwBound[0][0]) / gridNum;
|
|
260
|
+
const bakwYUnit = (bakwBound[1][1] - bakwBound[0][1]) / gridNum;
|
|
261
|
+
const bakwGridCache = bakwEachBound.reduce(
|
|
262
|
+
(prev: number[][][], bound: Position[], index: number) => {
|
|
263
|
+
const normXMin = unitCalc(
|
|
264
|
+
bound[0][0],
|
|
265
|
+
bakwBound[0][0],
|
|
266
|
+
bakwXUnit,
|
|
267
|
+
gridNum
|
|
268
|
+
);
|
|
269
|
+
const normXMax = unitCalc(
|
|
270
|
+
bound[1][0],
|
|
271
|
+
bakwBound[0][0],
|
|
272
|
+
bakwXUnit,
|
|
273
|
+
gridNum
|
|
274
|
+
);
|
|
275
|
+
const normYMin = unitCalc(
|
|
276
|
+
bound[0][1],
|
|
277
|
+
bakwBound[0][1],
|
|
278
|
+
bakwYUnit,
|
|
279
|
+
gridNum
|
|
280
|
+
);
|
|
281
|
+
const normYMax = unitCalc(
|
|
282
|
+
bound[1][1],
|
|
283
|
+
bakwBound[0][1],
|
|
284
|
+
bakwYUnit,
|
|
285
|
+
gridNum
|
|
286
|
+
);
|
|
287
|
+
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
288
|
+
if (!prev[cx]) prev[cx] = [];
|
|
289
|
+
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
290
|
+
if (!prev[cx][cy]) prev[cx][cy] = [];
|
|
291
|
+
prev[cx][cy].push(index);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return prev;
|
|
295
|
+
},
|
|
296
|
+
[]
|
|
297
|
+
);
|
|
298
|
+
this.indexedTins = {
|
|
299
|
+
forw: {
|
|
300
|
+
gridNum,
|
|
301
|
+
xOrigin: forwBound[0][0],
|
|
302
|
+
yOrigin: forwBound[0][1],
|
|
303
|
+
xUnit: forwXUnit,
|
|
304
|
+
yUnit: forwYUnit,
|
|
305
|
+
gridCache: forwGridCache
|
|
306
|
+
},
|
|
307
|
+
bakw: {
|
|
308
|
+
gridNum,
|
|
309
|
+
xOrigin: bakwBound[0][0],
|
|
310
|
+
yOrigin: bakwBound[0][1],
|
|
311
|
+
xUnit: bakwXUnit,
|
|
312
|
+
yUnit: bakwYUnit,
|
|
313
|
+
gridCache: bakwGridCache
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 座標変換を実行します
|
|
320
|
+
*
|
|
321
|
+
* @param apoint - 変換する座標
|
|
322
|
+
* @param backward - 逆方向の変換かどうか
|
|
323
|
+
* @param ignoreBounds - 境界チェックを無視するかどうか
|
|
324
|
+
* @returns 変換後の座標、または境界外の場合はfalse
|
|
325
|
+
*
|
|
326
|
+
* @throws {Error} 逆方向変換が許可されていない状態での逆変換時
|
|
327
|
+
*/
|
|
328
|
+
transform(apoint: number[], backward?: boolean, ignoreBounds?: boolean): number[] | false {
|
|
329
|
+
if (backward && this.strict_status == Transform.STATUS_ERROR)
|
|
330
|
+
throw 'Backward transform is not allowed if strict_status == "strict_error"';
|
|
331
|
+
// if (!this.tins) this.updateTin();
|
|
332
|
+
if (this.yaxisMode == Transform.YAXIS_FOLLOW && backward) {
|
|
333
|
+
apoint = [apoint[0], -1 * apoint[1]];
|
|
334
|
+
}
|
|
335
|
+
const tpoint = point(apoint);
|
|
336
|
+
if (this.bounds && !backward && !ignoreBounds) {
|
|
337
|
+
if (!booleanPointInPolygon(tpoint, this.boundsPolygon!)) return false;
|
|
338
|
+
}
|
|
339
|
+
const tins = backward ? this.tins!.bakw : this.tins!.forw;
|
|
340
|
+
const indexedTins = backward
|
|
341
|
+
? this.indexedTins!.bakw
|
|
342
|
+
: this.indexedTins!.forw;
|
|
343
|
+
const verticesParams = backward
|
|
344
|
+
? this.vertices_params!.bakw
|
|
345
|
+
: this.vertices_params!.forw;
|
|
346
|
+
const centroid = backward ? this.centroid!.bakw : this.centroid!.forw;
|
|
347
|
+
const weightBuffer = backward
|
|
348
|
+
? this.pointsWeightBuffer!.bakw
|
|
349
|
+
: this.pointsWeightBuffer!.forw;
|
|
350
|
+
let stateTriangle = undefined,
|
|
351
|
+
stateSetFunc = undefined;
|
|
352
|
+
if (this.stateFull) {
|
|
353
|
+
if (this.stateBackward == backward) {
|
|
354
|
+
stateTriangle = this.stateTriangle;
|
|
355
|
+
} else {
|
|
356
|
+
this.stateBackward = backward;
|
|
357
|
+
this.stateTriangle = undefined;
|
|
358
|
+
}
|
|
359
|
+
stateSetFunc = (tri?: Tri) => {
|
|
360
|
+
this.stateTriangle = tri;
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
let ret = transformArr(
|
|
364
|
+
tpoint,
|
|
365
|
+
tins!,
|
|
366
|
+
indexedTins,
|
|
367
|
+
verticesParams,
|
|
368
|
+
centroid,
|
|
369
|
+
weightBuffer,
|
|
370
|
+
stateTriangle,
|
|
371
|
+
stateSetFunc
|
|
372
|
+
);
|
|
373
|
+
if (this.bounds && backward && !ignoreBounds) {
|
|
374
|
+
const rpoint = point(ret);
|
|
375
|
+
if (!booleanPointInPolygon(rpoint, this.boundsPolygon!)) return false;
|
|
376
|
+
} else if (this.yaxisMode == Transform.YAXIS_FOLLOW && !backward) {
|
|
377
|
+
ret = [ret[0], -1 * ret[1]];
|
|
378
|
+
}
|
|
379
|
+
return ret;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
}
|