@maplat/tin 0.9.3 → 0.11.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/README.ja.md +121 -0
- package/README.md +122 -111
- package/dist/index.d.ts +196 -0
- package/dist/index.html +42 -0
- package/dist/maplat_tin.cjs +3 -0
- package/dist/maplat_tin.js +3291 -0
- package/dist/maplat_tin.umd.js +3 -0
- package/package.json +64 -58
- package/src/constrained-tin.ts +78 -0
- package/src/index.ts +934 -0
- package/src/kinks.ts +1033 -0
- package/src/searchutils.ts +67 -0
- package/src/types/cdt2d.d.ts +4 -0
- package/src/types/constrainautor.d.ts +6 -0
- package/src/vertexutils.ts +81 -0
- package/es5/index.js +0 -3
- package/es5/index.js.LICENSE.txt +0 -10
- package/es5/index.js.map +0 -1
- package/lib/booleanPointInPolygon.d.ts +0 -4
- package/lib/booleanPointInPolygon.js +0 -103
- package/lib/booleanPointInPolygon.js.map +0 -1
- package/lib/constrained-tin.d.ts +0 -4
- package/lib/constrained-tin.js +0 -41
- package/lib/constrained-tin.js.map +0 -1
- package/lib/index.d.ts +0 -157
- package/lib/index.js +0 -1472
- package/lib/index.js.map +0 -1
- package/lib/kinks.d.ts +0 -2
- package/lib/kinks.js +0 -669
- package/lib/kinks.js.map +0 -1
package/lib/index.js
DELETED
|
@@ -1,1472 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import booleanPointInPolygon from "./booleanPointInPolygon";
|
|
3
|
-
import centroid from "@turf/centroid";
|
|
4
|
-
import convex from "@turf/convex";
|
|
5
|
-
import difference from "@turf/difference";
|
|
6
|
-
import { featureCollection, lineString, point, polygon } from "@turf/helpers";
|
|
7
|
-
import intersect from "@turf/intersect";
|
|
8
|
-
import { getCoords } from "@turf/invariant";
|
|
9
|
-
import lineIntersect from "@turf/line-intersect";
|
|
10
|
-
import union from "@turf/union";
|
|
11
|
-
import findIntersections from "./kinks";
|
|
12
|
-
const format_version = 2.00703;
|
|
13
|
-
import constrainedTin from "./constrained-tin";
|
|
14
|
-
export default class Tin {
|
|
15
|
-
constructor(options = {}) {
|
|
16
|
-
this.points = [];
|
|
17
|
-
if (options.bounds) {
|
|
18
|
-
this.setBounds(options.bounds);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
this.setWh(options.wh);
|
|
22
|
-
this.vertexMode = options.vertexMode || Tin.VERTEX_PLAIN;
|
|
23
|
-
}
|
|
24
|
-
this.strictMode = options.strictMode || Tin.MODE_AUTO;
|
|
25
|
-
this.yaxisMode = options.yaxisMode || Tin.YAXIS_INVERT;
|
|
26
|
-
this.importance = options.importance || 0;
|
|
27
|
-
this.priority = options.priority || 0;
|
|
28
|
-
this.stateFull = options.stateFull || false;
|
|
29
|
-
if (options.points) {
|
|
30
|
-
this.setPoints(options.points);
|
|
31
|
-
}
|
|
32
|
-
if (options.edges) {
|
|
33
|
-
this.setEdges(options.edges);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
getFormatVersion() {
|
|
37
|
-
return format_version;
|
|
38
|
-
}
|
|
39
|
-
setPoints(points) {
|
|
40
|
-
if (this.yaxisMode == Tin.YAXIS_FOLLOW) {
|
|
41
|
-
points = points.map(point => [point[0], [point[1][0], -1 * point[1][1]]]);
|
|
42
|
-
}
|
|
43
|
-
this.points = points;
|
|
44
|
-
this.tins = undefined;
|
|
45
|
-
this.indexedTins = undefined;
|
|
46
|
-
}
|
|
47
|
-
setEdges(edges = []) {
|
|
48
|
-
this.edges = normalizeEdges(edges);
|
|
49
|
-
this.edgeNodes = undefined;
|
|
50
|
-
this.tins = undefined;
|
|
51
|
-
this.indexedTins = undefined;
|
|
52
|
-
}
|
|
53
|
-
setBounds(bounds) {
|
|
54
|
-
this.bounds = bounds;
|
|
55
|
-
let minx = bounds[0][0];
|
|
56
|
-
let maxx = minx;
|
|
57
|
-
let miny = bounds[0][1];
|
|
58
|
-
let maxy = miny;
|
|
59
|
-
const coords = [bounds[0]];
|
|
60
|
-
for (let i = 1; i < bounds.length; i++) {
|
|
61
|
-
const xy = bounds[i];
|
|
62
|
-
if (xy[0] < minx)
|
|
63
|
-
minx = xy[0];
|
|
64
|
-
if (xy[0] > maxx)
|
|
65
|
-
maxx = xy[0];
|
|
66
|
-
if (xy[1] < miny)
|
|
67
|
-
miny = xy[1];
|
|
68
|
-
if (xy[1] > maxy)
|
|
69
|
-
maxy = xy[1];
|
|
70
|
-
coords.push(xy);
|
|
71
|
-
}
|
|
72
|
-
coords.push(bounds[0]);
|
|
73
|
-
this.boundsPolygon = polygon([coords]);
|
|
74
|
-
this.xy = [minx, miny];
|
|
75
|
-
this.wh = [maxx - minx, maxy - miny];
|
|
76
|
-
this.vertexMode = Tin.VERTEX_PLAIN;
|
|
77
|
-
this.tins = undefined;
|
|
78
|
-
this.indexedTins = undefined;
|
|
79
|
-
}
|
|
80
|
-
setCompiled(compiled) {
|
|
81
|
-
if (compiled.version ||
|
|
82
|
-
(!compiled.tins && compiled.points && compiled.tins_points)) {
|
|
83
|
-
this.points = compiled.points;
|
|
84
|
-
this.pointsWeightBuffer =
|
|
85
|
-
!compiled.version || compiled.version < 2.00703
|
|
86
|
-
? ["forw", "bakw"].reduce((bd, forb) => {
|
|
87
|
-
const base = compiled.weight_buffer[forb];
|
|
88
|
-
if (base) {
|
|
89
|
-
bd[forb] = Object.keys(base).reduce((buffer, key) => {
|
|
90
|
-
const normKey = normalizeNodeKey(key);
|
|
91
|
-
buffer[normKey] = base[key];
|
|
92
|
-
return buffer;
|
|
93
|
-
}, {});
|
|
94
|
-
}
|
|
95
|
-
return bd;
|
|
96
|
-
}, {})
|
|
97
|
-
: compiled.weight_buffer;
|
|
98
|
-
if (compiled.strict_status) {
|
|
99
|
-
this.strict_status = compiled.strict_status;
|
|
100
|
-
}
|
|
101
|
-
else if (compiled.kinks_points) {
|
|
102
|
-
this.strict_status = Tin.STATUS_ERROR;
|
|
103
|
-
}
|
|
104
|
-
else if (compiled.tins_points.length == 2) {
|
|
105
|
-
this.strict_status = Tin.STATUS_LOOSE;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
this.strict_status = Tin.STATUS_STRICT;
|
|
109
|
-
}
|
|
110
|
-
this.vertices_params = {
|
|
111
|
-
forw: [compiled.vertices_params[0]],
|
|
112
|
-
bakw: [compiled.vertices_params[1]]
|
|
113
|
-
};
|
|
114
|
-
this.vertices_params.forw[1] = [0, 1, 2, 3].map(idx => {
|
|
115
|
-
const idxNxt = (idx + 1) % 4;
|
|
116
|
-
const tri = indexesToTri(["c", `b${idx}`, `b${idxNxt}`], compiled.points, compiled.edgeNodes || [], compiled.centroid_point, compiled.vertices_points, false, format_version);
|
|
117
|
-
return featureCollection([tri]);
|
|
118
|
-
});
|
|
119
|
-
this.vertices_params.bakw[1] = [0, 1, 2, 3].map(idx => {
|
|
120
|
-
const idxNxt = (idx + 1) % 4;
|
|
121
|
-
const tri = indexesToTri(["c", `b${idx}`, `b${idxNxt}`], compiled.points, compiled.edgeNodes || [], compiled.centroid_point, compiled.vertices_points, true, format_version);
|
|
122
|
-
return featureCollection([tri]);
|
|
123
|
-
});
|
|
124
|
-
this.centroid = {
|
|
125
|
-
forw: point(compiled.centroid_point[0], {
|
|
126
|
-
target: {
|
|
127
|
-
geom: compiled.centroid_point[1],
|
|
128
|
-
index: "c"
|
|
129
|
-
}
|
|
130
|
-
}),
|
|
131
|
-
bakw: point(compiled.centroid_point[1], {
|
|
132
|
-
target: {
|
|
133
|
-
geom: compiled.centroid_point[0],
|
|
134
|
-
index: "c"
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
|
-
};
|
|
138
|
-
this.edges = normalizeEdges(compiled.edges || []);
|
|
139
|
-
this.edgeNodes = compiled.edgeNodes || [];
|
|
140
|
-
const bakwI = compiled.tins_points.length == 1 ? 0 : 1;
|
|
141
|
-
this.tins = {
|
|
142
|
-
forw: featureCollection(compiled.tins_points[0].map((idxes) => indexesToTri(idxes, compiled.points, compiled.edgeNodes || [], compiled.centroid_point, compiled.vertices_points, false, compiled.version))),
|
|
143
|
-
bakw: featureCollection(compiled.tins_points[bakwI].map((idxes) => indexesToTri(idxes, compiled.points, compiled.edgeNodes || [], compiled.centroid_point, compiled.vertices_points, true, compiled.version)))
|
|
144
|
-
};
|
|
145
|
-
this.addIndexedTin();
|
|
146
|
-
if (compiled.kinks_points) {
|
|
147
|
-
this.kinks = {
|
|
148
|
-
bakw: featureCollection(compiled.kinks_points.map((coord) => point(coord)))
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
if (compiled.yaxisMode) {
|
|
152
|
-
this.yaxisMode = compiled.yaxisMode;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.yaxisMode = Tin.YAXIS_INVERT;
|
|
156
|
-
}
|
|
157
|
-
if (compiled.vertexMode) {
|
|
158
|
-
this.vertexMode = compiled.vertexMode;
|
|
159
|
-
}
|
|
160
|
-
if (compiled.strictMode) {
|
|
161
|
-
this.strictMode = compiled.strictMode;
|
|
162
|
-
}
|
|
163
|
-
if (compiled.bounds) {
|
|
164
|
-
this.bounds = compiled.bounds;
|
|
165
|
-
this.boundsPolygon = compiled.boundsPolygon;
|
|
166
|
-
this.xy = compiled.xy;
|
|
167
|
-
this.wh = compiled.wh;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
this.xy = [0, 0];
|
|
171
|
-
if (compiled.wh)
|
|
172
|
-
this.wh = compiled.wh;
|
|
173
|
-
this.bounds = undefined;
|
|
174
|
-
this.boundsPolygon = undefined;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
compiled = JSON.parse(JSON.stringify(compiled)
|
|
179
|
-
.replace('"cent"', '"c"')
|
|
180
|
-
.replace(/"bbox(\d+)"/g, '"b$1"'));
|
|
181
|
-
this.tins = compiled.tins;
|
|
182
|
-
this.addIndexedTin();
|
|
183
|
-
this.strict_status = compiled.strict_status;
|
|
184
|
-
this.pointsWeightBuffer = compiled.weight_buffer;
|
|
185
|
-
this.vertices_params = compiled.vertices_params;
|
|
186
|
-
this.centroid = compiled.centroid;
|
|
187
|
-
this.kinks = compiled.kinks;
|
|
188
|
-
const points = [];
|
|
189
|
-
for (let i = 0; i < this.tins.forw.features.length; i++) {
|
|
190
|
-
const tri = this.tins.forw.features[i];
|
|
191
|
-
["a", "b", "c"].map((key, idx) => {
|
|
192
|
-
const forw = tri.geometry.coordinates[0][idx];
|
|
193
|
-
const bakw = tri.properties[key].geom;
|
|
194
|
-
const pIdx = tri.properties[key].index;
|
|
195
|
-
points[pIdx] = [forw, bakw];
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
this.points = points;
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
tins: this.tins,
|
|
202
|
-
strict_status: this.strict_status,
|
|
203
|
-
weight_buffer: this.pointsWeightBuffer,
|
|
204
|
-
vertices_params: this.vertices_params,
|
|
205
|
-
centroid: this.centroid,
|
|
206
|
-
kinks: this.kinks
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
getCompiled() {
|
|
210
|
-
const compiled = {};
|
|
211
|
-
compiled.version = format_version;
|
|
212
|
-
compiled.points = this.points;
|
|
213
|
-
compiled.weight_buffer = this.pointsWeightBuffer;
|
|
214
|
-
compiled.centroid_point = [
|
|
215
|
-
this.centroid.forw.geometry.coordinates,
|
|
216
|
-
this.centroid.forw.properties.target.geom
|
|
217
|
-
];
|
|
218
|
-
compiled.vertices_params = [
|
|
219
|
-
this.vertices_params.forw[0],
|
|
220
|
-
this.vertices_params.bakw[0]
|
|
221
|
-
];
|
|
222
|
-
compiled.vertices_points = [];
|
|
223
|
-
const vertices = this.vertices_params.forw[1];
|
|
224
|
-
[0, 1, 2, 3].map(i => {
|
|
225
|
-
const vertex_data = vertices[i].features[0];
|
|
226
|
-
const forw = vertex_data.geometry.coordinates[0][1];
|
|
227
|
-
const bakw = vertex_data.properties.b.geom;
|
|
228
|
-
compiled.vertices_points[i] = [forw, bakw];
|
|
229
|
-
});
|
|
230
|
-
compiled.strict_status = this.strict_status;
|
|
231
|
-
compiled.tins_points = [[]];
|
|
232
|
-
this.tins.forw.features.map((tin) => {
|
|
233
|
-
compiled.tins_points[0].push(["a", "b", "c"].map(idx => tin.properties[idx].index));
|
|
234
|
-
});
|
|
235
|
-
if (this.strict_status == Tin.STATUS_LOOSE) {
|
|
236
|
-
compiled.tins_points[1] = [];
|
|
237
|
-
this.tins.bakw.features.map((tin) => {
|
|
238
|
-
compiled.tins_points[1].push(["a", "b", "c"].map(idx => tin.properties[idx].index));
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
else if (this.strict_status == Tin.STATUS_ERROR) {
|
|
242
|
-
compiled.kinks_points = this.kinks.bakw.features.map((kink) => kink.geometry.coordinates);
|
|
243
|
-
}
|
|
244
|
-
compiled.yaxisMode = this.yaxisMode;
|
|
245
|
-
compiled.vertexMode = this.vertexMode;
|
|
246
|
-
compiled.strictMode = this.strictMode;
|
|
247
|
-
if (this.bounds) {
|
|
248
|
-
compiled.bounds = this.bounds;
|
|
249
|
-
compiled.boundsPolygon = this.boundsPolygon;
|
|
250
|
-
compiled.xy = this.xy;
|
|
251
|
-
compiled.wh = this.wh;
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
compiled.wh = this.wh;
|
|
255
|
-
}
|
|
256
|
-
compiled.edges = this.edges;
|
|
257
|
-
compiled.edgeNodes = this.edgeNodes;
|
|
258
|
-
return compiled;
|
|
259
|
-
}
|
|
260
|
-
addIndexedTin() {
|
|
261
|
-
const tins = this.tins;
|
|
262
|
-
const forw = tins.forw;
|
|
263
|
-
const bakw = tins.bakw;
|
|
264
|
-
const gridNum = Math.ceil(Math.sqrt(forw.features.length));
|
|
265
|
-
if (gridNum < 3) {
|
|
266
|
-
this.indexedTins = undefined;
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
let forwBound = [];
|
|
270
|
-
let bakwBound = [];
|
|
271
|
-
const forwEachBound = forw.features.map((tri) => {
|
|
272
|
-
let eachBound = [];
|
|
273
|
-
getCoords(tri)[0].map((point) => {
|
|
274
|
-
if (forwBound.length === 0)
|
|
275
|
-
forwBound = [Array.from(point), Array.from(point)];
|
|
276
|
-
else {
|
|
277
|
-
if (point[0] < forwBound[0][0])
|
|
278
|
-
forwBound[0][0] = point[0];
|
|
279
|
-
if (point[0] > forwBound[1][0])
|
|
280
|
-
forwBound[1][0] = point[0];
|
|
281
|
-
if (point[1] < forwBound[0][1])
|
|
282
|
-
forwBound[0][1] = point[1];
|
|
283
|
-
if (point[1] > forwBound[1][1])
|
|
284
|
-
forwBound[1][1] = point[1];
|
|
285
|
-
}
|
|
286
|
-
if (eachBound.length === 0)
|
|
287
|
-
eachBound = [Array.from(point), Array.from(point)];
|
|
288
|
-
else {
|
|
289
|
-
if (point[0] < eachBound[0][0])
|
|
290
|
-
eachBound[0][0] = point[0];
|
|
291
|
-
if (point[0] > eachBound[1][0])
|
|
292
|
-
eachBound[1][0] = point[0];
|
|
293
|
-
if (point[1] < eachBound[0][1])
|
|
294
|
-
eachBound[0][1] = point[1];
|
|
295
|
-
if (point[1] > eachBound[1][1])
|
|
296
|
-
eachBound[1][1] = point[1];
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
return eachBound;
|
|
300
|
-
});
|
|
301
|
-
const forwXUnit = (forwBound[1][0] - forwBound[0][0]) / gridNum;
|
|
302
|
-
const forwYUnit = (forwBound[1][1] - forwBound[0][1]) / gridNum;
|
|
303
|
-
const forwGridCache = forwEachBound.reduce((prev, bound, index) => {
|
|
304
|
-
const normXMin = unitCalc(bound[0][0], forwBound[0][0], forwXUnit, gridNum);
|
|
305
|
-
const normXMax = unitCalc(bound[1][0], forwBound[0][0], forwXUnit, gridNum);
|
|
306
|
-
const normYMin = unitCalc(bound[0][1], forwBound[0][1], forwYUnit, gridNum);
|
|
307
|
-
const normYMax = unitCalc(bound[1][1], forwBound[0][1], forwYUnit, gridNum);
|
|
308
|
-
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
309
|
-
if (!prev[cx])
|
|
310
|
-
prev[cx] = [];
|
|
311
|
-
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
312
|
-
if (!prev[cx][cy])
|
|
313
|
-
prev[cx][cy] = [];
|
|
314
|
-
prev[cx][cy].push(index);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
return prev;
|
|
318
|
-
}, []);
|
|
319
|
-
const bakwEachBound = bakw.features.map((tri) => {
|
|
320
|
-
let eachBound = [];
|
|
321
|
-
getCoords(tri)[0].map((point) => {
|
|
322
|
-
if (bakwBound.length === 0)
|
|
323
|
-
bakwBound = [Array.from(point), Array.from(point)];
|
|
324
|
-
else {
|
|
325
|
-
if (point[0] < bakwBound[0][0])
|
|
326
|
-
bakwBound[0][0] = point[0];
|
|
327
|
-
if (point[0] > bakwBound[1][0])
|
|
328
|
-
bakwBound[1][0] = point[0];
|
|
329
|
-
if (point[1] < bakwBound[0][1])
|
|
330
|
-
bakwBound[0][1] = point[1];
|
|
331
|
-
if (point[1] > bakwBound[1][1])
|
|
332
|
-
bakwBound[1][1] = point[1];
|
|
333
|
-
}
|
|
334
|
-
if (eachBound.length === 0)
|
|
335
|
-
eachBound = [Array.from(point), Array.from(point)];
|
|
336
|
-
else {
|
|
337
|
-
if (point[0] < eachBound[0][0])
|
|
338
|
-
eachBound[0][0] = point[0];
|
|
339
|
-
if (point[0] > eachBound[1][0])
|
|
340
|
-
eachBound[1][0] = point[0];
|
|
341
|
-
if (point[1] < eachBound[0][1])
|
|
342
|
-
eachBound[0][1] = point[1];
|
|
343
|
-
if (point[1] > eachBound[1][1])
|
|
344
|
-
eachBound[1][1] = point[1];
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
return eachBound;
|
|
348
|
-
});
|
|
349
|
-
const bakwXUnit = (bakwBound[1][0] - bakwBound[0][0]) / gridNum;
|
|
350
|
-
const bakwYUnit = (bakwBound[1][1] - bakwBound[0][1]) / gridNum;
|
|
351
|
-
const bakwGridCache = bakwEachBound.reduce((prev, bound, index) => {
|
|
352
|
-
const normXMin = unitCalc(bound[0][0], bakwBound[0][0], bakwXUnit, gridNum);
|
|
353
|
-
const normXMax = unitCalc(bound[1][0], bakwBound[0][0], bakwXUnit, gridNum);
|
|
354
|
-
const normYMin = unitCalc(bound[0][1], bakwBound[0][1], bakwYUnit, gridNum);
|
|
355
|
-
const normYMax = unitCalc(bound[1][1], bakwBound[0][1], bakwYUnit, gridNum);
|
|
356
|
-
for (let cx = normXMin; cx <= normXMax; cx++) {
|
|
357
|
-
if (!prev[cx])
|
|
358
|
-
prev[cx] = [];
|
|
359
|
-
for (let cy = normYMin; cy <= normYMax; cy++) {
|
|
360
|
-
if (!prev[cx][cy])
|
|
361
|
-
prev[cx][cy] = [];
|
|
362
|
-
prev[cx][cy].push(index);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return prev;
|
|
366
|
-
}, []);
|
|
367
|
-
this.indexedTins = {
|
|
368
|
-
forw: {
|
|
369
|
-
gridNum,
|
|
370
|
-
xOrigin: forwBound[0][0],
|
|
371
|
-
yOrigin: forwBound[0][1],
|
|
372
|
-
xUnit: forwXUnit,
|
|
373
|
-
yUnit: forwYUnit,
|
|
374
|
-
gridCache: forwGridCache
|
|
375
|
-
},
|
|
376
|
-
bakw: {
|
|
377
|
-
gridNum,
|
|
378
|
-
xOrigin: bakwBound[0][0],
|
|
379
|
-
yOrigin: bakwBound[0][1],
|
|
380
|
-
xUnit: bakwXUnit,
|
|
381
|
-
yUnit: bakwYUnit,
|
|
382
|
-
gridCache: bakwGridCache
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
setWh(wh) {
|
|
387
|
-
this.wh = wh;
|
|
388
|
-
this.xy = [0, 0];
|
|
389
|
-
this.bounds = undefined;
|
|
390
|
-
this.boundsPolygon = undefined;
|
|
391
|
-
this.tins = undefined;
|
|
392
|
-
this.indexedTins = undefined;
|
|
393
|
-
}
|
|
394
|
-
setVertexMode(mode) {
|
|
395
|
-
this.vertexMode = mode;
|
|
396
|
-
this.tins = undefined;
|
|
397
|
-
this.indexedTins = undefined;
|
|
398
|
-
}
|
|
399
|
-
setStrictMode(mode) {
|
|
400
|
-
this.strictMode = mode;
|
|
401
|
-
this.tins = undefined;
|
|
402
|
-
this.indexedTins = undefined;
|
|
403
|
-
}
|
|
404
|
-
calcurateStrictTinAsync() {
|
|
405
|
-
const edges = this.pointsSet.edges;
|
|
406
|
-
return Promise.all(this.tins.forw.features.map((tri) => Promise.resolve(counterTri(tri))))
|
|
407
|
-
.then((tris) => {
|
|
408
|
-
this.tins.bakw = featureCollection(tris);
|
|
409
|
-
})
|
|
410
|
-
.then(() => {
|
|
411
|
-
const searchIndex = {};
|
|
412
|
-
return Promise.all(this.tins.forw.features.map((forTri, index) => {
|
|
413
|
-
const bakTri = this.tins.bakw.features[index];
|
|
414
|
-
return Promise.resolve(insertSearchIndex(searchIndex, { forw: forTri, bakw: bakTri }));
|
|
415
|
-
}))
|
|
416
|
-
.then(() => Promise.all([
|
|
417
|
-
overlapCheckAsync(searchIndex),
|
|
418
|
-
Promise.resolve(searchIndex)
|
|
419
|
-
]))
|
|
420
|
-
.catch(err => {
|
|
421
|
-
throw err;
|
|
422
|
-
});
|
|
423
|
-
})
|
|
424
|
-
.then((prevResult) => {
|
|
425
|
-
const overlapped = prevResult[0];
|
|
426
|
-
const searchIndex = prevResult[1];
|
|
427
|
-
if (overlapped.bakw)
|
|
428
|
-
Object.keys(overlapped.bakw).map(key => {
|
|
429
|
-
if (overlapped.bakw[key] == "Not include case")
|
|
430
|
-
return;
|
|
431
|
-
const trises = searchIndex[key];
|
|
432
|
-
const forUnion = union(trises[0].forw, trises[1].forw);
|
|
433
|
-
const forConvex = convex(featureCollection([trises[0].forw, trises[1].forw]));
|
|
434
|
-
const forDiff = difference(forConvex, forUnion);
|
|
435
|
-
if (forDiff)
|
|
436
|
-
return;
|
|
437
|
-
const splittedKey = key.split("-");
|
|
438
|
-
if (splittedKey[0].match(/^[0-9]+$/) &&
|
|
439
|
-
splittedKey[1].match(/^[0-9]+$/)) {
|
|
440
|
-
const numberKey = splittedKey
|
|
441
|
-
.map(key => parseInt(key))
|
|
442
|
-
.sort((a, b) => (a < b ? -1 : 1));
|
|
443
|
-
for (let i = 0; i < edges.length - 1; i++) {
|
|
444
|
-
if (numberKey[0] == edges[i][0] && numberKey[1] == edges[i][1])
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
const sharedVtx = splittedKey.map(val => ["a", "b", "c"]
|
|
449
|
-
.map((alpha, index) => {
|
|
450
|
-
const prop = trises[0].bakw.properties[alpha];
|
|
451
|
-
const geom = trises[0].bakw.geometry.coordinates[0][index];
|
|
452
|
-
return { geom, prop };
|
|
453
|
-
})
|
|
454
|
-
.filter(vtx => vtx.prop.index == val)[0]);
|
|
455
|
-
const nonSharedVtx = trises.map((tris) => ["a", "b", "c"]
|
|
456
|
-
.map((alpha, index) => {
|
|
457
|
-
const prop = tris.bakw.properties[alpha];
|
|
458
|
-
const geom = tris.bakw.geometry.coordinates[0][index];
|
|
459
|
-
return { geom, prop };
|
|
460
|
-
})
|
|
461
|
-
.filter(vtx => vtx.prop.index != sharedVtx[0].prop.index &&
|
|
462
|
-
vtx.prop.index != sharedVtx[1].prop.index)[0]);
|
|
463
|
-
removeSearchIndex(searchIndex, trises[0], this.tins);
|
|
464
|
-
removeSearchIndex(searchIndex, trises[1], this.tins);
|
|
465
|
-
sharedVtx.map(sVtx => {
|
|
466
|
-
const newTriCoords = [
|
|
467
|
-
sVtx.geom,
|
|
468
|
-
nonSharedVtx[0].geom,
|
|
469
|
-
nonSharedVtx[1].geom,
|
|
470
|
-
sVtx.geom
|
|
471
|
-
];
|
|
472
|
-
const newTriProp = {
|
|
473
|
-
a: sVtx.prop,
|
|
474
|
-
b: nonSharedVtx[0].prop,
|
|
475
|
-
c: nonSharedVtx[1].prop
|
|
476
|
-
};
|
|
477
|
-
const newBakTri = polygon([newTriCoords], newTriProp);
|
|
478
|
-
const newForTri = counterTri(newBakTri);
|
|
479
|
-
insertSearchIndex(searchIndex, { forw: newForTri, bakw: newBakTri }, this.tins);
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
return Promise.all(["forw", "bakw"].map(direc => new Promise(resolve => {
|
|
483
|
-
const coords = this.tins[direc].features.map(poly => poly.geometry.coordinates[0]);
|
|
484
|
-
resolve(findIntersections(coords));
|
|
485
|
-
}).catch(err => {
|
|
486
|
-
throw err;
|
|
487
|
-
})))
|
|
488
|
-
.then((result) => {
|
|
489
|
-
if (result[0].length == 0 && result[1].length == 0) {
|
|
490
|
-
this.strict_status = Tin.STATUS_STRICT;
|
|
491
|
-
delete this.kinks;
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
this.strict_status = Tin.STATUS_ERROR;
|
|
495
|
-
this.kinks = {};
|
|
496
|
-
if (result[0].length > 0)
|
|
497
|
-
this.kinks.forw = featureCollection(result[0]);
|
|
498
|
-
if (result[1].length > 0)
|
|
499
|
-
this.kinks.bakw = featureCollection(result[1]);
|
|
500
|
-
}
|
|
501
|
-
})
|
|
502
|
-
.catch(err => {
|
|
503
|
-
throw err;
|
|
504
|
-
});
|
|
505
|
-
})
|
|
506
|
-
.catch(err => {
|
|
507
|
-
throw err;
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
generatePointsSet() {
|
|
511
|
-
const pointsArray = { forw: [], bakw: [] };
|
|
512
|
-
for (let i = 0; i < this.points.length; i++) {
|
|
513
|
-
const mapxy = this.points[i][0];
|
|
514
|
-
const mercs = this.points[i][1];
|
|
515
|
-
const forPoint = createPoint(mapxy, mercs, i);
|
|
516
|
-
pointsArray.forw.push(forPoint);
|
|
517
|
-
pointsArray.bakw.push(counterPoint(forPoint));
|
|
518
|
-
}
|
|
519
|
-
const edges = [];
|
|
520
|
-
let edgeNodeIndex = 0;
|
|
521
|
-
this.edgeNodes = [];
|
|
522
|
-
if (!this.edges)
|
|
523
|
-
this.edges = [];
|
|
524
|
-
for (let i = 0; i < this.edges.length; i++) {
|
|
525
|
-
const startEnd = this.edges[i][2];
|
|
526
|
-
const illstNodes = Object.assign([], this.edges[i][0]);
|
|
527
|
-
const mercNodes = Object.assign([], this.edges[i][1]);
|
|
528
|
-
if (illstNodes.length === 0 && mercNodes.length === 0) {
|
|
529
|
-
edges.push(startEnd);
|
|
530
|
-
continue;
|
|
531
|
-
}
|
|
532
|
-
illstNodes.unshift(this.points[startEnd[0]][0]);
|
|
533
|
-
illstNodes.push(this.points[startEnd[1]][0]);
|
|
534
|
-
mercNodes.unshift(this.points[startEnd[0]][1]);
|
|
535
|
-
mercNodes.push(this.points[startEnd[1]][1]);
|
|
536
|
-
const lengths = [illstNodes, mercNodes].map(nodes => {
|
|
537
|
-
const eachLengths = nodes.map((node, index, arr) => {
|
|
538
|
-
if (index === 0)
|
|
539
|
-
return 0;
|
|
540
|
-
const prev = arr[index - 1];
|
|
541
|
-
return Math.sqrt(Math.pow(node[0] - prev[0], 2) + Math.pow(node[1] - prev[1], 2));
|
|
542
|
-
});
|
|
543
|
-
const sumLengths = eachLengths.reduce((prev, node, index) => {
|
|
544
|
-
if (index === 0)
|
|
545
|
-
return [0];
|
|
546
|
-
prev.push(prev[index - 1] + node);
|
|
547
|
-
return prev;
|
|
548
|
-
}, []);
|
|
549
|
-
return sumLengths.map((eachSum, index, arr) => {
|
|
550
|
-
const ratio = eachSum / arr[arr.length - 1];
|
|
551
|
-
return [nodes[index], eachLengths[index], sumLengths[index], ratio];
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
lengths
|
|
555
|
-
.map((thisLengths, i) => {
|
|
556
|
-
const anotherLengths = lengths[i ? 0 : 1];
|
|
557
|
-
return thisLengths
|
|
558
|
-
.filter((val, index) => !(index === 0 ||
|
|
559
|
-
index === thisLengths.length - 1 ||
|
|
560
|
-
val[4] === "handled"))
|
|
561
|
-
.map((lengthItem) => {
|
|
562
|
-
const node = lengthItem[0];
|
|
563
|
-
const ratio = lengthItem[3];
|
|
564
|
-
const anotherSets = anotherLengths.reduce((prev, item, index, arr) => {
|
|
565
|
-
if (prev)
|
|
566
|
-
return prev;
|
|
567
|
-
const next = arr[index + 1];
|
|
568
|
-
if (item[3] === ratio) {
|
|
569
|
-
item[4] = "handled";
|
|
570
|
-
return [item];
|
|
571
|
-
}
|
|
572
|
-
if (item[3] < ratio && next[3] > ratio)
|
|
573
|
-
return [item, next];
|
|
574
|
-
return;
|
|
575
|
-
}, undefined);
|
|
576
|
-
if (anotherSets.length === 1) {
|
|
577
|
-
return i === 0
|
|
578
|
-
? [node, anotherSets[0][0], ratio]
|
|
579
|
-
: [anotherSets[0][0], node, ratio];
|
|
580
|
-
}
|
|
581
|
-
else {
|
|
582
|
-
const anotherPrev = anotherSets[0];
|
|
583
|
-
const anotherNext = anotherSets[1];
|
|
584
|
-
const ratioDelta = ratio - anotherPrev[3];
|
|
585
|
-
const ratioAnother = anotherNext[3] - anotherPrev[3];
|
|
586
|
-
const ratioInEdge = ratioDelta / ratioAnother;
|
|
587
|
-
const anotherNode = [
|
|
588
|
-
(anotherNext[0][0] - anotherPrev[0][0]) * ratioInEdge +
|
|
589
|
-
anotherPrev[0][0],
|
|
590
|
-
(anotherNext[0][1] - anotherPrev[0][1]) * ratioInEdge +
|
|
591
|
-
anotherPrev[0][1]
|
|
592
|
-
];
|
|
593
|
-
return i === 0
|
|
594
|
-
? [node, anotherNode, ratio]
|
|
595
|
-
: [anotherNode, node, ratio];
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
})
|
|
599
|
-
.reduce((prev, nodes) => prev.concat(nodes), [])
|
|
600
|
-
.sort((a, b) => (a[2] < b[2] ? -1 : 1))
|
|
601
|
-
.map((node, index, arr) => {
|
|
602
|
-
this.edgeNodes[edgeNodeIndex] = [node[0], node[1]];
|
|
603
|
-
const forPoint = createPoint(node[0], node[1], `e${edgeNodeIndex}`);
|
|
604
|
-
edgeNodeIndex++;
|
|
605
|
-
pointsArray.forw.push(forPoint);
|
|
606
|
-
pointsArray.bakw.push(counterPoint(forPoint));
|
|
607
|
-
if (index === 0) {
|
|
608
|
-
edges.push([startEnd[0], pointsArray.forw.length - 1]);
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
edges.push([
|
|
612
|
-
pointsArray.forw.length - 2,
|
|
613
|
-
pointsArray.forw.length - 1
|
|
614
|
-
]);
|
|
615
|
-
}
|
|
616
|
-
if (index === arr.length - 1) {
|
|
617
|
-
edges.push([pointsArray.forw.length - 1, startEnd[1]]);
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
return {
|
|
622
|
-
forw: featureCollection(pointsArray.forw),
|
|
623
|
-
bakw: featureCollection(pointsArray.bakw),
|
|
624
|
-
edges
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
updateTinAsync() {
|
|
628
|
-
let strict = this.strictMode;
|
|
629
|
-
const minx = this.xy[0] - 0.05 * this.wh[0];
|
|
630
|
-
const maxx = this.xy[0] + 1.05 * this.wh[0];
|
|
631
|
-
const miny = this.xy[1] - 0.05 * this.wh[1];
|
|
632
|
-
const maxy = this.xy[1] + 1.05 * this.wh[1];
|
|
633
|
-
const insideCheck = this.bounds
|
|
634
|
-
? (xy) => booleanPointInPolygon(xy, this.boundsPolygon)
|
|
635
|
-
: (xy) => xy[0] >= this.xy[0] &&
|
|
636
|
-
xy[0] <= this.xy[0] + this.wh[0] &&
|
|
637
|
-
xy[1] >= this.xy[1] &&
|
|
638
|
-
xy[1] <= this.xy[1] + this.wh[1];
|
|
639
|
-
const inside = this.points.reduce((prev, curr) => prev && insideCheck(curr[0]), true);
|
|
640
|
-
if (!inside) {
|
|
641
|
-
return new Promise((resolve, reject) => {
|
|
642
|
-
reject("SOME POINTS OUTSIDE");
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
return new Promise(resolve => {
|
|
646
|
-
if (strict != Tin.MODE_STRICT && strict != Tin.MODE_LOOSE)
|
|
647
|
-
strict = Tin.MODE_AUTO;
|
|
648
|
-
let bbox = [];
|
|
649
|
-
if (this.wh) {
|
|
650
|
-
bbox = [
|
|
651
|
-
[minx, miny],
|
|
652
|
-
[maxx, miny],
|
|
653
|
-
[minx, maxy],
|
|
654
|
-
[maxx, maxy]
|
|
655
|
-
];
|
|
656
|
-
}
|
|
657
|
-
const pointsSet = this.generatePointsSet();
|
|
658
|
-
resolve([pointsSet, bbox]);
|
|
659
|
-
})
|
|
660
|
-
.then((prevResults) => {
|
|
661
|
-
const pointsSet = prevResults[0];
|
|
662
|
-
return Promise.all([
|
|
663
|
-
new Promise(resolve => {
|
|
664
|
-
resolve(constrainedTin(pointsSet.forw, pointsSet.edges, "target"));
|
|
665
|
-
}),
|
|
666
|
-
new Promise(resolve => {
|
|
667
|
-
resolve(constrainedTin(pointsSet.bakw, pointsSet.edges, "target"));
|
|
668
|
-
}),
|
|
669
|
-
new Promise(resolve => {
|
|
670
|
-
resolve(centroid(pointsSet.forw));
|
|
671
|
-
}),
|
|
672
|
-
Promise.resolve(prevResults)
|
|
673
|
-
]).catch(err => {
|
|
674
|
-
throw err;
|
|
675
|
-
});
|
|
676
|
-
})
|
|
677
|
-
.then(prevResults => {
|
|
678
|
-
const tinForCentroid = prevResults[0];
|
|
679
|
-
const tinBakCentroid = prevResults[1];
|
|
680
|
-
const forCentroidFt = prevResults[2];
|
|
681
|
-
const pointsSetBbox = prevResults[3];
|
|
682
|
-
const pointsSet = pointsSetBbox[0];
|
|
683
|
-
if (tinForCentroid.features.length == 0 ||
|
|
684
|
-
tinBakCentroid.features.length == 0)
|
|
685
|
-
throw "TOO LINEAR1";
|
|
686
|
-
const centroid = {
|
|
687
|
-
forw: forCentroidFt.geometry.coordinates,
|
|
688
|
-
bakw: transformArr(forCentroidFt, tinForCentroid)
|
|
689
|
-
};
|
|
690
|
-
const forwBuf = createPoint(centroid.forw, centroid.bakw, "c");
|
|
691
|
-
this.centroid = {
|
|
692
|
-
forw: forwBuf,
|
|
693
|
-
bakw: counterPoint(forwBuf)
|
|
694
|
-
};
|
|
695
|
-
const convexBuf = {};
|
|
696
|
-
return Promise.all([
|
|
697
|
-
new Promise(resolve => {
|
|
698
|
-
const forConvex = convex(pointsSet.forw).geometry
|
|
699
|
-
.coordinates[0];
|
|
700
|
-
let vconvex;
|
|
701
|
-
try {
|
|
702
|
-
vconvex = forConvex.map((forw) => ({
|
|
703
|
-
forw,
|
|
704
|
-
bakw: transformArr(point(forw), tinForCentroid)
|
|
705
|
-
}));
|
|
706
|
-
}
|
|
707
|
-
catch (e) {
|
|
708
|
-
throw "TOO LINEAR2";
|
|
709
|
-
}
|
|
710
|
-
vconvex.map((vertex) => {
|
|
711
|
-
convexBuf[`${vertex.forw[0]}:${vertex.forw[1]}`] = vertex;
|
|
712
|
-
});
|
|
713
|
-
resolve(undefined);
|
|
714
|
-
}),
|
|
715
|
-
new Promise(resolve => {
|
|
716
|
-
const bakConvex = convex(pointsSet.bakw).geometry
|
|
717
|
-
.coordinates[0];
|
|
718
|
-
let vconvex;
|
|
719
|
-
try {
|
|
720
|
-
vconvex = bakConvex.map((bakw) => ({
|
|
721
|
-
bakw,
|
|
722
|
-
forw: transformArr(point(bakw), tinBakCentroid)
|
|
723
|
-
}));
|
|
724
|
-
}
|
|
725
|
-
catch (e) {
|
|
726
|
-
throw "TOO LINEAR2";
|
|
727
|
-
}
|
|
728
|
-
vconvex.map((vertex) => {
|
|
729
|
-
convexBuf[`${vertex.forw[0]}:${vertex.forw[1]}`] = vertex;
|
|
730
|
-
});
|
|
731
|
-
resolve(undefined);
|
|
732
|
-
})
|
|
733
|
-
])
|
|
734
|
-
.then(() => [centroid, convexBuf, pointsSetBbox])
|
|
735
|
-
.catch(err => {
|
|
736
|
-
throw err;
|
|
737
|
-
});
|
|
738
|
-
})
|
|
739
|
-
.then(prevResults => {
|
|
740
|
-
const centroid = prevResults[0];
|
|
741
|
-
const convexBuf = prevResults[1];
|
|
742
|
-
const pointsSetBbox = prevResults[2];
|
|
743
|
-
const expandConvex = Object.keys(convexBuf).reduce((prev, key, _, _array) => {
|
|
744
|
-
const forVertex = convexBuf[key].forw;
|
|
745
|
-
const bakVertex = convexBuf[key].bakw;
|
|
746
|
-
const vertexDelta = {
|
|
747
|
-
forw: [
|
|
748
|
-
forVertex[0] - centroid.forw[0],
|
|
749
|
-
forVertex[1] - centroid.forw[1]
|
|
750
|
-
]
|
|
751
|
-
};
|
|
752
|
-
vertexDelta.bakw = [
|
|
753
|
-
bakVertex[0] - centroid.bakw[0],
|
|
754
|
-
bakVertex[1] - centroid.bakw[1]
|
|
755
|
-
];
|
|
756
|
-
const xRate = vertexDelta.forw[0] == 0
|
|
757
|
-
? Infinity
|
|
758
|
-
: ((vertexDelta.forw[0] < 0 ? minx : maxx) - centroid.forw[0]) /
|
|
759
|
-
vertexDelta.forw[0];
|
|
760
|
-
const yRate = vertexDelta.forw[1] == 0
|
|
761
|
-
? Infinity
|
|
762
|
-
: ((vertexDelta.forw[1] < 0 ? miny : maxy) - centroid.forw[1]) /
|
|
763
|
-
vertexDelta.forw[1];
|
|
764
|
-
if (Math.abs(xRate) / Math.abs(yRate) < 1.1) {
|
|
765
|
-
const point = {
|
|
766
|
-
forw: [
|
|
767
|
-
vertexDelta.forw[0] * xRate + centroid.forw[0],
|
|
768
|
-
vertexDelta.forw[1] * xRate + centroid.forw[1]
|
|
769
|
-
],
|
|
770
|
-
bakw: [
|
|
771
|
-
vertexDelta.bakw[0] * xRate + centroid.bakw[0],
|
|
772
|
-
vertexDelta.bakw[1] * xRate + centroid.bakw[1]
|
|
773
|
-
]
|
|
774
|
-
};
|
|
775
|
-
if (vertexDelta.forw[0] < 0)
|
|
776
|
-
prev[3].push(point);
|
|
777
|
-
else
|
|
778
|
-
prev[1].push(point);
|
|
779
|
-
}
|
|
780
|
-
if (Math.abs(yRate) / Math.abs(xRate) < 1.1) {
|
|
781
|
-
const point = {
|
|
782
|
-
forw: [
|
|
783
|
-
vertexDelta.forw[0] * yRate + centroid.forw[0],
|
|
784
|
-
vertexDelta.forw[1] * yRate + centroid.forw[1]
|
|
785
|
-
],
|
|
786
|
-
bakw: [
|
|
787
|
-
vertexDelta.bakw[0] * yRate + centroid.bakw[0],
|
|
788
|
-
vertexDelta.bakw[1] * yRate + centroid.bakw[1]
|
|
789
|
-
]
|
|
790
|
-
};
|
|
791
|
-
if (vertexDelta.forw[1] < 0)
|
|
792
|
-
prev[0].push(point);
|
|
793
|
-
else
|
|
794
|
-
prev[2].push(point);
|
|
795
|
-
}
|
|
796
|
-
return prev;
|
|
797
|
-
}, [[], [], [], []]);
|
|
798
|
-
let orthant = Object.keys(convexBuf)
|
|
799
|
-
.reduce((prev, key, idx, array) => {
|
|
800
|
-
const forVertex = convexBuf[key].forw;
|
|
801
|
-
const bakVertex = convexBuf[key].bakw;
|
|
802
|
-
const vertexDelta = {
|
|
803
|
-
forw: [
|
|
804
|
-
forVertex[0] - centroid.forw[0],
|
|
805
|
-
forVertex[1] - centroid.forw[1]
|
|
806
|
-
]
|
|
807
|
-
};
|
|
808
|
-
vertexDelta.bakw = [
|
|
809
|
-
bakVertex[0] - centroid.bakw[0],
|
|
810
|
-
centroid.bakw[1] - bakVertex[1]
|
|
811
|
-
];
|
|
812
|
-
if (vertexDelta.forw[0] == 0 || vertexDelta.forw[1] == 0)
|
|
813
|
-
return prev;
|
|
814
|
-
let index = 0;
|
|
815
|
-
if (vertexDelta.forw[0] > 0)
|
|
816
|
-
index += 1;
|
|
817
|
-
if (vertexDelta.forw[1] > 0)
|
|
818
|
-
index += 2;
|
|
819
|
-
prev[index].push([
|
|
820
|
-
vertexDelta.forw,
|
|
821
|
-
vertexDelta.bakw
|
|
822
|
-
]);
|
|
823
|
-
if (idx == array.length - 1) {
|
|
824
|
-
return prev.length ==
|
|
825
|
-
prev.filter(val => val.length > 0).length &&
|
|
826
|
-
this.vertexMode == Tin.VERTEX_BIRDEYE
|
|
827
|
-
? prev
|
|
828
|
-
: prev.reduce((pre, cur) => [pre[0].concat(cur)], [[]]);
|
|
829
|
-
}
|
|
830
|
-
return prev;
|
|
831
|
-
}, [[], [], [], []])
|
|
832
|
-
.map(item => item.reduce((prev, curr, index, arr) => {
|
|
833
|
-
if (!prev)
|
|
834
|
-
prev = [Infinity, 0, 0];
|
|
835
|
-
let distanceSum = Math.sqrt(Math.pow(curr[0][0], 2) + Math.pow(curr[0][1], 2)) /
|
|
836
|
-
Math.sqrt(Math.pow(curr[1][0], 2) + Math.pow(curr[1][1], 2));
|
|
837
|
-
distanceSum = distanceSum < prev[0] ? distanceSum : prev[0];
|
|
838
|
-
const thetaDelta = Math.atan2(curr[0][0], curr[0][1]) -
|
|
839
|
-
Math.atan2(curr[1][0], curr[1][1]);
|
|
840
|
-
const sumThetaX = prev[1] + Math.cos(thetaDelta);
|
|
841
|
-
const sumThetaY = prev[2] + Math.sin(thetaDelta);
|
|
842
|
-
if (index == arr.length - 1) {
|
|
843
|
-
return [distanceSum, Math.atan2(sumThetaY, sumThetaX)];
|
|
844
|
-
}
|
|
845
|
-
return [distanceSum, sumThetaX, sumThetaY];
|
|
846
|
-
}, null));
|
|
847
|
-
if (orthant.length == 1)
|
|
848
|
-
orthant = [orthant[0], orthant[0], orthant[0], orthant[0]];
|
|
849
|
-
return [orthant, centroid, expandConvex, pointsSetBbox];
|
|
850
|
-
})
|
|
851
|
-
.then(prevResults => {
|
|
852
|
-
const orthant = prevResults[0];
|
|
853
|
-
const centroid = prevResults[1];
|
|
854
|
-
const expandConvex = prevResults[2];
|
|
855
|
-
const pointsSet = prevResults[3][0];
|
|
856
|
-
const bbox = prevResults[3][1];
|
|
857
|
-
let verticesSet = orthant.map((delta, index) => {
|
|
858
|
-
const forVertex = bbox[index];
|
|
859
|
-
const forDelta = [
|
|
860
|
-
forVertex[0] - centroid.forw[0],
|
|
861
|
-
forVertex[1] - centroid.forw[1]
|
|
862
|
-
];
|
|
863
|
-
const forDistance = Math.sqrt(Math.pow(forDelta[0], 2) + Math.pow(forDelta[1], 2));
|
|
864
|
-
const bakDistance = forDistance / delta[0];
|
|
865
|
-
const forTheta = Math.atan2(forDelta[0], forDelta[1]);
|
|
866
|
-
const bakTheta = forTheta - delta[1];
|
|
867
|
-
const bakVertex = [
|
|
868
|
-
centroid.bakw[0] + bakDistance * Math.sin(bakTheta),
|
|
869
|
-
centroid.bakw[1] - bakDistance * Math.cos(bakTheta)
|
|
870
|
-
];
|
|
871
|
-
return { forw: forVertex, bakw: bakVertex };
|
|
872
|
-
});
|
|
873
|
-
const swap = verticesSet[2];
|
|
874
|
-
verticesSet[2] = verticesSet[3];
|
|
875
|
-
verticesSet[3] = swap;
|
|
876
|
-
const expandRate = [1, 1, 1, 1];
|
|
877
|
-
for (let i = 0; i < 4; i++) {
|
|
878
|
-
const j = (i + 1) % 4;
|
|
879
|
-
const side = lineString([verticesSet[i].bakw, verticesSet[j].bakw]);
|
|
880
|
-
const expands = expandConvex[i];
|
|
881
|
-
expands.map((expand) => {
|
|
882
|
-
const expandLine = lineString([centroid.bakw, expand.bakw]);
|
|
883
|
-
const intersect = lineIntersect(side, expandLine);
|
|
884
|
-
if (intersect.features.length > 0 &&
|
|
885
|
-
intersect.features[0].geometry) {
|
|
886
|
-
const intersect_ = intersect.features[0];
|
|
887
|
-
const expandDist = Math.sqrt(Math.pow(expand.bakw[0] - centroid.bakw[0], 2) +
|
|
888
|
-
Math.pow(expand.bakw[1] - centroid.bakw[1], 2));
|
|
889
|
-
const onSideDist = Math.sqrt(Math.pow(intersect_.geometry.coordinates[0] -
|
|
890
|
-
centroid.bakw[0], 2) +
|
|
891
|
-
Math.pow(intersect_.geometry.coordinates[1] -
|
|
892
|
-
centroid.bakw[1], 2));
|
|
893
|
-
const rate = expandDist / onSideDist;
|
|
894
|
-
if (rate > expandRate[i])
|
|
895
|
-
expandRate[i] = rate;
|
|
896
|
-
if (rate > expandRate[j])
|
|
897
|
-
expandRate[j] = rate;
|
|
898
|
-
}
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
verticesSet = verticesSet.map((vertex, index) => {
|
|
902
|
-
const rate = expandRate[index];
|
|
903
|
-
const point = [
|
|
904
|
-
(vertex.bakw[0] - centroid.bakw[0]) * rate + centroid.bakw[0],
|
|
905
|
-
(vertex.bakw[1] - centroid.bakw[1]) * rate + centroid.bakw[1]
|
|
906
|
-
];
|
|
907
|
-
return { forw: vertex.forw, bakw: point };
|
|
908
|
-
});
|
|
909
|
-
return [verticesSet, pointsSet];
|
|
910
|
-
})
|
|
911
|
-
.then(prevResults => {
|
|
912
|
-
const verticesSet = prevResults[0];
|
|
913
|
-
const pointsSet = prevResults[1];
|
|
914
|
-
const verticesList = { forw: [], bakw: [] };
|
|
915
|
-
for (let i = 0; i < verticesSet.length; i++) {
|
|
916
|
-
const forVertex = verticesSet[i].forw;
|
|
917
|
-
const bakVertex = verticesSet[i].bakw;
|
|
918
|
-
const forVertexFt = createPoint(forVertex, bakVertex, `b${i}`);
|
|
919
|
-
const bakVertexFt = counterPoint(forVertexFt);
|
|
920
|
-
pointsSet.forw.features.push(forVertexFt);
|
|
921
|
-
pointsSet.bakw.features.push(bakVertexFt);
|
|
922
|
-
verticesList.forw.push(forVertexFt);
|
|
923
|
-
verticesList.bakw.push(bakVertexFt);
|
|
924
|
-
}
|
|
925
|
-
this.pointsSet = pointsSet;
|
|
926
|
-
this.tins = {
|
|
927
|
-
forw: rotateVerticesTriangle(constrainedTin(pointsSet.forw, pointsSet.edges, "target"))
|
|
928
|
-
};
|
|
929
|
-
let prom;
|
|
930
|
-
if (strict == Tin.MODE_STRICT || strict == Tin.MODE_AUTO) {
|
|
931
|
-
prom = this.calcurateStrictTinAsync();
|
|
932
|
-
}
|
|
933
|
-
else {
|
|
934
|
-
prom = Promise.resolve();
|
|
935
|
-
}
|
|
936
|
-
return prom
|
|
937
|
-
.then(() => {
|
|
938
|
-
if (strict == Tin.MODE_LOOSE ||
|
|
939
|
-
(strict == Tin.MODE_AUTO &&
|
|
940
|
-
this.strict_status == Tin.STATUS_ERROR)) {
|
|
941
|
-
this.tins.bakw = rotateVerticesTriangle(constrainedTin(pointsSet.bakw, pointsSet.edges, "target"));
|
|
942
|
-
delete this.kinks;
|
|
943
|
-
this.strict_status = Tin.STATUS_LOOSE;
|
|
944
|
-
}
|
|
945
|
-
this.vertices_params = {
|
|
946
|
-
forw: vertexCalc(verticesList.forw, this.centroid.forw),
|
|
947
|
-
bakw: vertexCalc(verticesList.bakw, this.centroid.bakw)
|
|
948
|
-
};
|
|
949
|
-
this.addIndexedTin();
|
|
950
|
-
return this.calculatePointsWeightAsync();
|
|
951
|
-
})
|
|
952
|
-
.catch(err => {
|
|
953
|
-
throw err;
|
|
954
|
-
});
|
|
955
|
-
})
|
|
956
|
-
.catch(err => {
|
|
957
|
-
throw err;
|
|
958
|
-
});
|
|
959
|
-
}
|
|
960
|
-
transform(apoint, backward, ignoreBounds) {
|
|
961
|
-
if (backward && this.strict_status == Tin.STATUS_ERROR)
|
|
962
|
-
throw 'Backward transform is not allowed if strict_status == "strict_error"';
|
|
963
|
-
if (this.yaxisMode == Tin.YAXIS_FOLLOW && backward) {
|
|
964
|
-
apoint = [apoint[0], -1 * apoint[1]];
|
|
965
|
-
}
|
|
966
|
-
const tpoint = point(apoint);
|
|
967
|
-
if (this.bounds && !backward && !ignoreBounds) {
|
|
968
|
-
if (!booleanPointInPolygon(tpoint, this.boundsPolygon))
|
|
969
|
-
return false;
|
|
970
|
-
}
|
|
971
|
-
const tins = backward ? this.tins.bakw : this.tins.forw;
|
|
972
|
-
const indexedTins = backward
|
|
973
|
-
? this.indexedTins.bakw
|
|
974
|
-
: this.indexedTins.forw;
|
|
975
|
-
const verticesParams = backward
|
|
976
|
-
? this.vertices_params.bakw
|
|
977
|
-
: this.vertices_params.forw;
|
|
978
|
-
const centroid = backward ? this.centroid.bakw : this.centroid.forw;
|
|
979
|
-
const weightBuffer = backward
|
|
980
|
-
? this.pointsWeightBuffer.bakw
|
|
981
|
-
: this.pointsWeightBuffer.forw;
|
|
982
|
-
let stateTriangle = undefined, stateSetFunc = undefined;
|
|
983
|
-
if (this.stateFull) {
|
|
984
|
-
if (this.stateBackward == backward) {
|
|
985
|
-
stateTriangle = this.stateTriangle;
|
|
986
|
-
}
|
|
987
|
-
else {
|
|
988
|
-
this.stateBackward = backward;
|
|
989
|
-
this.stateTriangle = undefined;
|
|
990
|
-
}
|
|
991
|
-
stateSetFunc = (tri) => {
|
|
992
|
-
this.stateTriangle = tri;
|
|
993
|
-
};
|
|
994
|
-
}
|
|
995
|
-
let ret = transformArr(tpoint, tins, indexedTins, verticesParams, centroid, weightBuffer, stateTriangle, stateSetFunc);
|
|
996
|
-
if (this.bounds && backward && !ignoreBounds) {
|
|
997
|
-
const rpoint = point(ret);
|
|
998
|
-
if (!booleanPointInPolygon(rpoint, this.boundsPolygon))
|
|
999
|
-
return false;
|
|
1000
|
-
}
|
|
1001
|
-
else if (this.yaxisMode == Tin.YAXIS_FOLLOW && !backward) {
|
|
1002
|
-
ret = [ret[0], -1 * ret[1]];
|
|
1003
|
-
}
|
|
1004
|
-
return ret;
|
|
1005
|
-
}
|
|
1006
|
-
calculatePointsWeightAsync() {
|
|
1007
|
-
const calcTargets = ["forw"];
|
|
1008
|
-
if (this.strict_status == Tin.STATUS_LOOSE)
|
|
1009
|
-
calcTargets.push("bakw");
|
|
1010
|
-
const weightBuffer = {};
|
|
1011
|
-
return Promise.all(calcTargets.map(target => {
|
|
1012
|
-
weightBuffer[target] = {};
|
|
1013
|
-
const alreadyChecked = {};
|
|
1014
|
-
const tin = this.tins[target];
|
|
1015
|
-
return Promise.all(tin.features.map((tri) => {
|
|
1016
|
-
const vtxes = ["a", "b", "c"];
|
|
1017
|
-
return new Promise(resolve => {
|
|
1018
|
-
for (let i = 0; i < 3; i++) {
|
|
1019
|
-
const j = (i + 1) % 3;
|
|
1020
|
-
const vi = vtxes[i];
|
|
1021
|
-
const vj = vtxes[j];
|
|
1022
|
-
const indexi = tri.properties[vi].index;
|
|
1023
|
-
const indexj = tri.properties[vj].index;
|
|
1024
|
-
const key = [indexi, indexj].sort().join("-");
|
|
1025
|
-
if (!alreadyChecked[key]) {
|
|
1026
|
-
const fromi = tri.geometry.coordinates[0][i];
|
|
1027
|
-
const fromj = tri.geometry.coordinates[0][j];
|
|
1028
|
-
const toi = tri.properties[vi].geom;
|
|
1029
|
-
const toj = tri.properties[vj].geom;
|
|
1030
|
-
alreadyChecked[key] = 1;
|
|
1031
|
-
const weight = Math.sqrt(Math.pow(toi[0] - toj[0], 2) +
|
|
1032
|
-
Math.pow(toi[1] - toj[1], 2)) /
|
|
1033
|
-
Math.sqrt(Math.pow(fromi[0] - fromj[0], 2) +
|
|
1034
|
-
Math.pow(fromi[1] - fromj[1], 2));
|
|
1035
|
-
if (!weightBuffer[target][indexi])
|
|
1036
|
-
weightBuffer[target][indexi] = {};
|
|
1037
|
-
if (!weightBuffer[target][indexj])
|
|
1038
|
-
weightBuffer[target][indexj] = {};
|
|
1039
|
-
weightBuffer[target][indexi][key] = weight;
|
|
1040
|
-
weightBuffer[target][indexj][key] = weight;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
resolve(undefined);
|
|
1044
|
-
});
|
|
1045
|
-
})).catch(err => {
|
|
1046
|
-
throw err;
|
|
1047
|
-
});
|
|
1048
|
-
}))
|
|
1049
|
-
.then(() => {
|
|
1050
|
-
const pointsWeightBuffer = {};
|
|
1051
|
-
calcTargets.map(target => {
|
|
1052
|
-
pointsWeightBuffer[target] = {};
|
|
1053
|
-
if (this.strict_status == Tin.STATUS_STRICT)
|
|
1054
|
-
pointsWeightBuffer["bakw"] = {};
|
|
1055
|
-
Object.keys(weightBuffer[target]).map(vtx => {
|
|
1056
|
-
pointsWeightBuffer[target][vtx] = Object.keys(weightBuffer[target][vtx]).reduce((prev, key, idx, arr) => {
|
|
1057
|
-
prev = prev + weightBuffer[target][vtx][key];
|
|
1058
|
-
return idx == arr.length - 1 ? prev / arr.length : prev;
|
|
1059
|
-
}, 0);
|
|
1060
|
-
if (this.strict_status == Tin.STATUS_STRICT)
|
|
1061
|
-
pointsWeightBuffer["bakw"][vtx] =
|
|
1062
|
-
1 / pointsWeightBuffer[target][vtx];
|
|
1063
|
-
});
|
|
1064
|
-
pointsWeightBuffer[target]["c"] = [0, 1, 2, 3].reduce((prev, curr) => {
|
|
1065
|
-
const key = `b${curr}`;
|
|
1066
|
-
prev = prev + pointsWeightBuffer[target][key];
|
|
1067
|
-
return curr == 3 ? prev / 4 : prev;
|
|
1068
|
-
}, 0);
|
|
1069
|
-
if (this.strict_status == Tin.STATUS_STRICT)
|
|
1070
|
-
pointsWeightBuffer["bakw"]["c"] =
|
|
1071
|
-
1 / pointsWeightBuffer[target]["c"];
|
|
1072
|
-
});
|
|
1073
|
-
this.pointsWeightBuffer = pointsWeightBuffer;
|
|
1074
|
-
})
|
|
1075
|
-
.catch(err => {
|
|
1076
|
-
throw err;
|
|
1077
|
-
});
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
Tin.VERTEX_PLAIN = "plain";
|
|
1081
|
-
Tin.VERTEX_BIRDEYE = "birdeye";
|
|
1082
|
-
Tin.MODE_STRICT = "strict";
|
|
1083
|
-
Tin.MODE_AUTO = "auto";
|
|
1084
|
-
Tin.MODE_LOOSE = "loose";
|
|
1085
|
-
Tin.STATUS_STRICT = "strict";
|
|
1086
|
-
Tin.STATUS_ERROR = "strict_error";
|
|
1087
|
-
Tin.STATUS_LOOSE = "loose";
|
|
1088
|
-
Tin.YAXIS_FOLLOW = "follow";
|
|
1089
|
-
Tin.YAXIS_INVERT = "invert";
|
|
1090
|
-
function rotateVerticesTriangle(tins) {
|
|
1091
|
-
const features = tins.features;
|
|
1092
|
-
for (let i = 0; i < features.length; i++) {
|
|
1093
|
-
const feature = features[i];
|
|
1094
|
-
if (`${feature.properties.a.index}`.substring(0, 1) === "b" &&
|
|
1095
|
-
`${feature.properties.b.index}`.substring(0, 1) === "b") {
|
|
1096
|
-
features[i] = {
|
|
1097
|
-
geometry: {
|
|
1098
|
-
type: "Polygon",
|
|
1099
|
-
coordinates: [
|
|
1100
|
-
[
|
|
1101
|
-
feature.geometry.coordinates[0][2],
|
|
1102
|
-
feature.geometry.coordinates[0][0],
|
|
1103
|
-
feature.geometry.coordinates[0][1],
|
|
1104
|
-
feature.geometry.coordinates[0][2]
|
|
1105
|
-
]
|
|
1106
|
-
]
|
|
1107
|
-
},
|
|
1108
|
-
properties: {
|
|
1109
|
-
a: {
|
|
1110
|
-
geom: feature.properties.c.geom,
|
|
1111
|
-
index: feature.properties.c.index
|
|
1112
|
-
},
|
|
1113
|
-
b: {
|
|
1114
|
-
geom: feature.properties.a.geom,
|
|
1115
|
-
index: feature.properties.a.index
|
|
1116
|
-
},
|
|
1117
|
-
c: {
|
|
1118
|
-
geom: feature.properties.b.geom,
|
|
1119
|
-
index: feature.properties.b.index
|
|
1120
|
-
}
|
|
1121
|
-
},
|
|
1122
|
-
type: "Feature"
|
|
1123
|
-
};
|
|
1124
|
-
}
|
|
1125
|
-
else if (`${feature.properties.c.index}`.substring(0, 1) === "b" &&
|
|
1126
|
-
`${feature.properties.a.index}`.substring(0, 1) === "b") {
|
|
1127
|
-
features[i] = {
|
|
1128
|
-
geometry: {
|
|
1129
|
-
type: "Polygon",
|
|
1130
|
-
coordinates: [
|
|
1131
|
-
[
|
|
1132
|
-
feature.geometry.coordinates[0][1],
|
|
1133
|
-
feature.geometry.coordinates[0][2],
|
|
1134
|
-
feature.geometry.coordinates[0][0],
|
|
1135
|
-
feature.geometry.coordinates[0][1]
|
|
1136
|
-
]
|
|
1137
|
-
]
|
|
1138
|
-
},
|
|
1139
|
-
properties: {
|
|
1140
|
-
a: {
|
|
1141
|
-
geom: feature.properties.b.geom,
|
|
1142
|
-
index: feature.properties.b.index
|
|
1143
|
-
},
|
|
1144
|
-
b: {
|
|
1145
|
-
geom: feature.properties.c.geom,
|
|
1146
|
-
index: feature.properties.c.index
|
|
1147
|
-
},
|
|
1148
|
-
c: {
|
|
1149
|
-
geom: feature.properties.a.geom,
|
|
1150
|
-
index: feature.properties.a.index
|
|
1151
|
-
}
|
|
1152
|
-
},
|
|
1153
|
-
type: "Feature"
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
return tins;
|
|
1158
|
-
}
|
|
1159
|
-
function vertexCalc(list, centroid) {
|
|
1160
|
-
const centCoord = centroid.geometry.coordinates;
|
|
1161
|
-
return [0, 1, 2, 3]
|
|
1162
|
-
.map(i => {
|
|
1163
|
-
const j = (i + 1) % 4;
|
|
1164
|
-
const itemi = list[i];
|
|
1165
|
-
const itemj = list[j];
|
|
1166
|
-
const coord = itemi.geometry.coordinates;
|
|
1167
|
-
const radian = Math.atan2(coord[0] - centCoord[0], coord[1] - centCoord[1]);
|
|
1168
|
-
const coordinates = [centroid, itemi, itemj, centroid].map(point => point.geometry.coordinates);
|
|
1169
|
-
const properties = {
|
|
1170
|
-
a: {
|
|
1171
|
-
geom: centroid.properties.target.geom,
|
|
1172
|
-
index: centroid.properties.target.index
|
|
1173
|
-
},
|
|
1174
|
-
b: {
|
|
1175
|
-
geom: itemi.properties.target.geom,
|
|
1176
|
-
index: itemi.properties.target.index
|
|
1177
|
-
},
|
|
1178
|
-
c: {
|
|
1179
|
-
geom: itemj.properties.target.geom,
|
|
1180
|
-
index: itemj.properties.target.index
|
|
1181
|
-
}
|
|
1182
|
-
};
|
|
1183
|
-
const tin = featureCollection([polygon([coordinates], properties)]);
|
|
1184
|
-
return [radian, tin];
|
|
1185
|
-
})
|
|
1186
|
-
.reduce((prev, curr) => {
|
|
1187
|
-
prev[0].push(curr[0]);
|
|
1188
|
-
prev[1].push(curr[1]);
|
|
1189
|
-
return prev;
|
|
1190
|
-
}, [[], []]);
|
|
1191
|
-
}
|
|
1192
|
-
function normalizeRadian(target, noNegative = false) {
|
|
1193
|
-
const rangeFunc = noNegative
|
|
1194
|
-
? function (val) {
|
|
1195
|
-
return !(val >= 0 && val < Math.PI * 2);
|
|
1196
|
-
}
|
|
1197
|
-
: function (val) {
|
|
1198
|
-
return !(val > -1 * Math.PI && val <= Math.PI);
|
|
1199
|
-
};
|
|
1200
|
-
while (rangeFunc(target)) {
|
|
1201
|
-
target = target + 2 * Math.PI * (target > 0 ? -1 : 1);
|
|
1202
|
-
}
|
|
1203
|
-
return target;
|
|
1204
|
-
}
|
|
1205
|
-
function decideUseVertex(radian, radianList) {
|
|
1206
|
-
let idel = normalizeRadian(radian - radianList[0]);
|
|
1207
|
-
let minTheta = Math.PI * 2;
|
|
1208
|
-
let minIndex;
|
|
1209
|
-
for (let i = 0; i < radianList.length; i++) {
|
|
1210
|
-
const j = (i + 1) % radianList.length;
|
|
1211
|
-
const jdel = normalizeRadian(radian - radianList[j]);
|
|
1212
|
-
const minDel = Math.min(Math.abs(idel), Math.abs(jdel));
|
|
1213
|
-
if (idel * jdel <= 0 && minDel < minTheta) {
|
|
1214
|
-
minTheta = minDel;
|
|
1215
|
-
minIndex = i;
|
|
1216
|
-
}
|
|
1217
|
-
idel = jdel;
|
|
1218
|
-
}
|
|
1219
|
-
return minIndex;
|
|
1220
|
-
}
|
|
1221
|
-
function createPoint(xy, geom, index) {
|
|
1222
|
-
return point(xy, { target: { geom, index } });
|
|
1223
|
-
}
|
|
1224
|
-
function counterPoint(apoint) {
|
|
1225
|
-
return point(apoint.properties.target.geom, {
|
|
1226
|
-
target: {
|
|
1227
|
-
geom: apoint.geometry.coordinates,
|
|
1228
|
-
index: apoint.properties.target.index
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1232
|
-
function transformTin(of, tri, weightBuffer) {
|
|
1233
|
-
return point(transformTinArr(of, tri, weightBuffer));
|
|
1234
|
-
}
|
|
1235
|
-
function transformTinArr(of, tri, weightBuffer) {
|
|
1236
|
-
const a = tri.geometry.coordinates[0][0];
|
|
1237
|
-
const b = tri.geometry.coordinates[0][1];
|
|
1238
|
-
const c = tri.geometry.coordinates[0][2];
|
|
1239
|
-
const o = of.geometry.coordinates;
|
|
1240
|
-
const ad = tri.properties.a.geom;
|
|
1241
|
-
const bd = tri.properties.b.geom;
|
|
1242
|
-
const cd = tri.properties.c.geom;
|
|
1243
|
-
const ab = [b[0] - a[0], b[1] - a[1]];
|
|
1244
|
-
const ac = [c[0] - a[0], c[1] - a[1]];
|
|
1245
|
-
const ao = [o[0] - a[0], o[1] - a[1]];
|
|
1246
|
-
const abd = [bd[0] - ad[0], bd[1] - ad[1]];
|
|
1247
|
-
const acd = [cd[0] - ad[0], cd[1] - ad[1]];
|
|
1248
|
-
let abv = (ac[1] * ao[0] - ac[0] * ao[1]) / (ab[0] * ac[1] - ab[1] * ac[0]);
|
|
1249
|
-
let acv = (ab[0] * ao[1] - ab[1] * ao[0]) / (ab[0] * ac[1] - ab[1] * ac[0]);
|
|
1250
|
-
if (weightBuffer) {
|
|
1251
|
-
const aW = weightBuffer[tri.properties.a.index];
|
|
1252
|
-
const bW = weightBuffer[tri.properties.b.index];
|
|
1253
|
-
const cW = weightBuffer[tri.properties.c.index];
|
|
1254
|
-
let nabv;
|
|
1255
|
-
if (abv < 0 || acv < 0 || 1 - abv - acv < 0) {
|
|
1256
|
-
const normB = abv / (abv + acv);
|
|
1257
|
-
const normC = acv / (abv + acv);
|
|
1258
|
-
nabv = abv / bW / (normB / bW + normC / cW);
|
|
1259
|
-
acv = acv / cW / (normB / bW + normC / cW);
|
|
1260
|
-
}
|
|
1261
|
-
else {
|
|
1262
|
-
nabv = abv / bW / (abv / bW + acv / cW + (1 - abv - acv) / aW);
|
|
1263
|
-
acv = acv / cW / (abv / bW + acv / cW + (1 - abv - acv) / aW);
|
|
1264
|
-
}
|
|
1265
|
-
abv = nabv;
|
|
1266
|
-
}
|
|
1267
|
-
return [
|
|
1268
|
-
abv * abd[0] + acv * acd[0] + ad[0],
|
|
1269
|
-
abv * abd[1] + acv * acd[1] + ad[1]
|
|
1270
|
-
];
|
|
1271
|
-
}
|
|
1272
|
-
function useVertices(o, verticesParams, centroid, weightBuffer) {
|
|
1273
|
-
return point(useVerticesArr(o, verticesParams, centroid, weightBuffer));
|
|
1274
|
-
}
|
|
1275
|
-
function useVerticesArr(o, verticesParams, centroid, weightBuffer) {
|
|
1276
|
-
const coord = o.geometry.coordinates;
|
|
1277
|
-
const centCoord = centroid.geometry.coordinates;
|
|
1278
|
-
const radian = Math.atan2(coord[0] - centCoord[0], coord[1] - centCoord[1]);
|
|
1279
|
-
const index = decideUseVertex(radian, verticesParams[0]);
|
|
1280
|
-
const tin = verticesParams[1][index];
|
|
1281
|
-
return transformTinArr(o, tin.features[0], weightBuffer);
|
|
1282
|
-
}
|
|
1283
|
-
function hit(point, tins) {
|
|
1284
|
-
for (let i = 0; i < tins.features.length; i++) {
|
|
1285
|
-
const inside = booleanPointInPolygon(point, tins.features[i]);
|
|
1286
|
-
if (inside) {
|
|
1287
|
-
return tins.features[i];
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
function unitCalc(coord, origin, unit, gridNum) {
|
|
1292
|
-
let normCoord = Math.floor((coord - origin) / unit);
|
|
1293
|
-
if (normCoord >= gridNum)
|
|
1294
|
-
normCoord = gridNum - 1;
|
|
1295
|
-
return normCoord;
|
|
1296
|
-
}
|
|
1297
|
-
function transform(apoint, tins, indexedTins, verticesParams, centroid, weightBuffer, stateTriangle, stateSetFunc) {
|
|
1298
|
-
return point(transformArr(apoint, tins, indexedTins, verticesParams, centroid, weightBuffer, stateTriangle, stateSetFunc));
|
|
1299
|
-
}
|
|
1300
|
-
function transformArr(point, tins, indexedTins, verticesParams, centroid, weightBuffer, stateTriangle, stateSetFunc) {
|
|
1301
|
-
let tin;
|
|
1302
|
-
if (stateTriangle) {
|
|
1303
|
-
tin = hit(point, featureCollection([stateTriangle]));
|
|
1304
|
-
}
|
|
1305
|
-
if (!tin) {
|
|
1306
|
-
if (indexedTins) {
|
|
1307
|
-
const coords = point.geometry.coordinates;
|
|
1308
|
-
const gridNum = indexedTins.gridNum;
|
|
1309
|
-
const xOrigin = indexedTins.xOrigin;
|
|
1310
|
-
const yOrigin = indexedTins.yOrigin;
|
|
1311
|
-
const xUnit = indexedTins.xUnit;
|
|
1312
|
-
const yUnit = indexedTins.yUnit;
|
|
1313
|
-
const gridCache = indexedTins.gridCache;
|
|
1314
|
-
const normX = unitCalc(coords[0], xOrigin, xUnit, gridNum);
|
|
1315
|
-
const normY = unitCalc(coords[1], yOrigin, yUnit, gridNum);
|
|
1316
|
-
const tinsKey = gridCache[normX]
|
|
1317
|
-
? gridCache[normX][normY]
|
|
1318
|
-
? gridCache[normX][normY]
|
|
1319
|
-
: []
|
|
1320
|
-
: [];
|
|
1321
|
-
tins = featureCollection(tinsKey.map((key) => tins.features[key]));
|
|
1322
|
-
}
|
|
1323
|
-
tin = hit(point, tins);
|
|
1324
|
-
}
|
|
1325
|
-
if (stateSetFunc)
|
|
1326
|
-
stateSetFunc(tin);
|
|
1327
|
-
return tin
|
|
1328
|
-
? transformTinArr(point, tin, weightBuffer)
|
|
1329
|
-
: useVerticesArr(point, verticesParams, centroid, weightBuffer);
|
|
1330
|
-
}
|
|
1331
|
-
function counterTri(tri) {
|
|
1332
|
-
const coordinates = ["a", "b", "c", "a"].map(key => tri.properties[key].geom);
|
|
1333
|
-
const geoms = tri.geometry.coordinates[0];
|
|
1334
|
-
const props = tri.properties;
|
|
1335
|
-
const properties = {
|
|
1336
|
-
a: { geom: geoms[0], index: props["a"].index },
|
|
1337
|
-
b: { geom: geoms[1], index: props["b"].index },
|
|
1338
|
-
c: { geom: geoms[2], index: props["c"].index }
|
|
1339
|
-
};
|
|
1340
|
-
return polygon([coordinates], properties);
|
|
1341
|
-
}
|
|
1342
|
-
function buildTri(points) {
|
|
1343
|
-
const coordinates = [0, 1, 2, 0].map(i => points[i][0][0]);
|
|
1344
|
-
const properties = {
|
|
1345
|
-
a: { geom: points[0][0][1], index: points[0][1] },
|
|
1346
|
-
b: { geom: points[1][0][1], index: points[1][1] },
|
|
1347
|
-
c: { geom: points[2][0][1], index: points[2][1] }
|
|
1348
|
-
};
|
|
1349
|
-
return polygon([coordinates], properties);
|
|
1350
|
-
}
|
|
1351
|
-
function indexesToTri(indexes, points, edgeNodes, cent, bboxes, bakw = false, version) {
|
|
1352
|
-
const points_ = indexes.map((index) => {
|
|
1353
|
-
if (!version || version < 2.00703)
|
|
1354
|
-
index = normalizeNodeKey(index);
|
|
1355
|
-
const point_base = isFinite(index)
|
|
1356
|
-
? points[index]
|
|
1357
|
-
: index === "c"
|
|
1358
|
-
? cent
|
|
1359
|
-
: index === "b0"
|
|
1360
|
-
? bboxes[0]
|
|
1361
|
-
: index === "b1"
|
|
1362
|
-
? bboxes[1]
|
|
1363
|
-
: index === "b2"
|
|
1364
|
-
? bboxes[2]
|
|
1365
|
-
: index === "b3"
|
|
1366
|
-
? bboxes[3]
|
|
1367
|
-
: (function () {
|
|
1368
|
-
const match = index.match(/e(\d+)/);
|
|
1369
|
-
if (match) {
|
|
1370
|
-
const nodeIndex = parseInt(match[1]);
|
|
1371
|
-
return edgeNodes[nodeIndex];
|
|
1372
|
-
}
|
|
1373
|
-
throw "Bad index value for indexesToTri";
|
|
1374
|
-
})();
|
|
1375
|
-
return bakw
|
|
1376
|
-
? [[point_base[1], point_base[0]], index]
|
|
1377
|
-
: [[point_base[0], point_base[1]], index];
|
|
1378
|
-
});
|
|
1379
|
-
return buildTri(points_);
|
|
1380
|
-
}
|
|
1381
|
-
function normalizeNodeKey(index) {
|
|
1382
|
-
if (typeof index === "number")
|
|
1383
|
-
return index;
|
|
1384
|
-
return index.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2");
|
|
1385
|
-
}
|
|
1386
|
-
function normalizeEdges(edges, version) {
|
|
1387
|
-
if ((version && version >= 2.00703) || Array.isArray(edges[0]))
|
|
1388
|
-
return edges;
|
|
1389
|
-
return edges.map(edge => [
|
|
1390
|
-
edge.illstNodes,
|
|
1391
|
-
edge.mercNodes,
|
|
1392
|
-
edge.startEnd
|
|
1393
|
-
]);
|
|
1394
|
-
}
|
|
1395
|
-
function overlapCheckAsync(searchIndex) {
|
|
1396
|
-
const retValue = { forw: {}, bakw: {} };
|
|
1397
|
-
return Promise.all(Object.keys(searchIndex).map(key => new Promise(resolve => {
|
|
1398
|
-
const searchResult = searchIndex[key];
|
|
1399
|
-
if (searchResult.length < 2)
|
|
1400
|
-
return resolve(undefined);
|
|
1401
|
-
["forw", "bakw"].map(dir => {
|
|
1402
|
-
const result = intersect(searchResult[0][dir], searchResult[1][dir]);
|
|
1403
|
-
if (!result ||
|
|
1404
|
-
result.geometry.type == "Point" ||
|
|
1405
|
-
result.geometry.type == "LineString")
|
|
1406
|
-
return resolve(undefined);
|
|
1407
|
-
resolve(undefined);
|
|
1408
|
-
});
|
|
1409
|
-
})))
|
|
1410
|
-
.then(() => {
|
|
1411
|
-
if (Object.keys(retValue.forw).length == 0)
|
|
1412
|
-
delete retValue.forw;
|
|
1413
|
-
if (Object.keys(retValue.bakw).length == 0)
|
|
1414
|
-
delete retValue.bakw;
|
|
1415
|
-
return retValue;
|
|
1416
|
-
})
|
|
1417
|
-
.catch(err => {
|
|
1418
|
-
throw err;
|
|
1419
|
-
});
|
|
1420
|
-
}
|
|
1421
|
-
function insertSearchIndex(searchIndex, tris, tins) {
|
|
1422
|
-
const keys = calcSearchKeys(tris.forw);
|
|
1423
|
-
const bakKeys = calcSearchKeys(tris.bakw);
|
|
1424
|
-
if (JSON.stringify(keys) != JSON.stringify(bakKeys))
|
|
1425
|
-
throw `${JSON.stringify(tris, null, 2)}\n${JSON.stringify(keys)}\n${JSON.stringify(bakKeys)}`;
|
|
1426
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1427
|
-
const key = keys[i];
|
|
1428
|
-
if (!searchIndex[key])
|
|
1429
|
-
searchIndex[key] = [];
|
|
1430
|
-
searchIndex[key].push(tris);
|
|
1431
|
-
}
|
|
1432
|
-
if (tins) {
|
|
1433
|
-
tins.forw.features.push(tris.forw);
|
|
1434
|
-
tins.bakw.features.push(tris.bakw);
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
function removeSearchIndex(searchIndex, tris, tins) {
|
|
1438
|
-
const keys = calcSearchKeys(tris.forw);
|
|
1439
|
-
const bakKeys = calcSearchKeys(tris.bakw);
|
|
1440
|
-
if (JSON.stringify(keys) != JSON.stringify(bakKeys))
|
|
1441
|
-
throw `${JSON.stringify(tris, null, 2)}\n${JSON.stringify(keys)}\n${JSON.stringify(bakKeys)}`;
|
|
1442
|
-
for (let i = 0; i < keys.length; i++) {
|
|
1443
|
-
const key = keys[i];
|
|
1444
|
-
const newArray = searchIndex[key].filter((eachTris) => eachTris.forw != tris.forw);
|
|
1445
|
-
if (newArray.length == 0)
|
|
1446
|
-
delete searchIndex[key];
|
|
1447
|
-
else
|
|
1448
|
-
searchIndex[key] = newArray;
|
|
1449
|
-
}
|
|
1450
|
-
if (tins) {
|
|
1451
|
-
let newArray = tins.forw.features.filter((eachTri) => eachTri != tris.forw);
|
|
1452
|
-
tins.forw.features = newArray;
|
|
1453
|
-
newArray = tins.bakw.features.filter((eachTri) => eachTri != tris.bakw);
|
|
1454
|
-
tins.bakw.features = newArray;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
function calcSearchKeys(tri) {
|
|
1458
|
-
const vtx = ["a", "b", "c"].map(key => tri.properties[key].index);
|
|
1459
|
-
return [
|
|
1460
|
-
[0, 1],
|
|
1461
|
-
[0, 2],
|
|
1462
|
-
[1, 2],
|
|
1463
|
-
[0, 1, 2]
|
|
1464
|
-
]
|
|
1465
|
-
.map(set => set
|
|
1466
|
-
.map(i => vtx[i])
|
|
1467
|
-
.sort()
|
|
1468
|
-
.join("-"))
|
|
1469
|
-
.sort();
|
|
1470
|
-
}
|
|
1471
|
-
global.Tin = Tin;
|
|
1472
|
-
//# sourceMappingURL=index.js.map
|