@maplat/tin 0.9.4 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tin.js ADDED
@@ -0,0 +1,2090 @@
1
+ var Ke = Object.defineProperty;
2
+ var Qe = (o, t, e) => t in o ? Ke(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
+ var rt = (o, t, e) => Qe(o, typeof t != "symbol" ? t + "" : t, e);
4
+ import Ze from "@turf/boolean-point-in-polygon";
5
+ import ts from "@turf/centroid";
6
+ import ke from "@turf/convex";
7
+ import { featureCollection as Ot, polygon as me, point as Jt, lineString as xe } from "@turf/helpers";
8
+ import es from "@turf/line-intersect";
9
+ import ss from "delaunator";
10
+ var ns = Object.defineProperty, is = (o, t, e) => t in o ? ns(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, nt = (o, t, e) => is(o, typeof t != "symbol" ? t + "" : t, e);
11
+ const Tt = 11102230246251565e-32, lt = 134217729, rs = (3 + 8 * Tt) * Tt;
12
+ function he(o, t, e, s, i) {
13
+ let n, r, a, f, c = t[0], u = s[0], h = 0, l = 0;
14
+ u > c == u > -c ? (n = c, c = t[++h]) : (n = u, u = s[++l]);
15
+ let p = 0;
16
+ if (h < o && l < e)
17
+ for (u > c == u > -c ? (r = c + n, a = n - (r - c), c = t[++h]) : (r = u + n, a = n - (r - u), u = s[++l]), n = r, a !== 0 && (i[p++] = a); h < o && l < e; )
18
+ u > c == u > -c ? (r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h]) : (r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l]), n = r, a !== 0 && (i[p++] = a);
19
+ for (; h < o; )
20
+ r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h], n = r, a !== 0 && (i[p++] = a);
21
+ for (; l < e; )
22
+ r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l], n = r, a !== 0 && (i[p++] = a);
23
+ return (n !== 0 || p === 0) && (i[p++] = n), p;
24
+ }
25
+ function os(o, t) {
26
+ let e = t[0];
27
+ for (let s = 1; s < o; s++) e += t[s];
28
+ return e;
29
+ }
30
+ function Ht(o) {
31
+ return new Float64Array(o);
32
+ }
33
+ const as = (3 + 16 * Tt) * Tt, hs = (2 + 12 * Tt) * Tt, cs = (9 + 64 * Tt) * Tt * Tt, Vt = Ht(4), _e = Ht(8), Me = Ht(12), Se = Ht(16), gt = Ht(4);
34
+ function fs(o, t, e, s, i, n, r) {
35
+ let a, f, c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V;
36
+ const z = o - i, G = e - i, tt = t - n, X = s - n;
37
+ v = z * X, l = lt * z, p = l - (l - z), y = z - p, l = lt * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = tt * G, l = lt * tt, p = l - (l - tt), y = tt - p, l = lt * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, Vt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, Vt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, Vt[2] = S - (V - h) + (w - h), Vt[3] = V;
38
+ let it = os(4, Vt), d = hs * r;
39
+ if (it >= d || -it >= d || (h = o - z, a = o - (z + h) + (h - i), h = e - G, c = e - (G + h) + (h - i), h = t - tt, f = t - (tt + h) + (h - n), h = s - X, u = s - (X + h) + (h - n), a === 0 && f === 0 && c === 0 && u === 0) || (d = cs * r + rs * Math.abs(it), it += z * u + X * a - (tt * c + G * f), it >= d || -it >= d)) return it;
40
+ v = a * X, l = lt * a, p = l - (l - a), y = a - p, l = lt * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = f * G, l = lt * f, p = l - (l - f), y = f - p, l = lt * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V;
41
+ const m = he(4, Vt, 4, gt, _e);
42
+ v = z * u, l = lt * z, p = l - (l - z), y = z - p, l = lt * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = tt * c, l = lt * tt, p = l - (l - tt), y = tt - p, l = lt * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V;
43
+ const x = he(m, _e, 4, gt, Me);
44
+ v = a * u, l = lt * a, p = l - (l - a), y = a - p, l = lt * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = f * c, l = lt * f, p = l - (l - f), y = f - p, l = lt * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V;
45
+ const A = he(x, Me, 4, gt, Se);
46
+ return Se[A - 1];
47
+ }
48
+ function us(o, t, e, s, i, n) {
49
+ const r = (t - n) * (e - i), a = (o - i) * (s - n), f = r - a, c = Math.abs(r + a);
50
+ return Math.abs(f) >= as * c ? f : -fs(o, t, e, s, i, n, c);
51
+ }
52
+ function ls(o, t) {
53
+ var e, s, i = 0, n, r, a, f, c, u, h, l = o[0], p = o[1], y = t.length;
54
+ for (e = 0; e < y; e++) {
55
+ s = 0;
56
+ var g = t[e], b = g.length - 1;
57
+ if (u = g[0], u[0] !== g[b][0] && u[1] !== g[b][1])
58
+ throw new Error("First and last coordinates in a ring must be the same");
59
+ for (r = u[0] - l, a = u[1] - p, s; s < b; s++) {
60
+ if (h = g[s + 1], f = h[0] - l, c = h[1] - p, a === 0 && c === 0) {
61
+ if (f <= 0 && r >= 0 || r <= 0 && f >= 0)
62
+ return 0;
63
+ } else if (c >= 0 && a <= 0 || c <= 0 && a >= 0) {
64
+ if (n = us(r, f, a, c, 0, 0), n === 0)
65
+ return 0;
66
+ (n > 0 && c > 0 && a <= 0 || n < 0 && c <= 0 && a > 0) && i++;
67
+ }
68
+ u = h, a = c, r = f;
69
+ }
70
+ }
71
+ return i % 2 !== 0;
72
+ }
73
+ function je(o, t, e = {}) {
74
+ const s = { type: "Feature" };
75
+ return (e.id === 0 || e.id) && (s.id = e.id), e.bbox && (s.bbox = e.bbox), s.properties = t || {}, s.geometry = o, s;
76
+ }
77
+ function Yt(o, t, e = {}) {
78
+ if (!o)
79
+ throw new Error("coordinates is required");
80
+ if (!Array.isArray(o))
81
+ throw new Error("coordinates must be an Array");
82
+ if (o.length < 2)
83
+ throw new Error("coordinates must be at least 2 numbers long");
84
+ if (!Ae(o[0]) || !Ae(o[1]))
85
+ throw new Error("coordinates must contain numbers");
86
+ return je({
87
+ type: "Point",
88
+ coordinates: o
89
+ }, t, e);
90
+ }
91
+ function Le(o, t, e = {}) {
92
+ for (const s of o) {
93
+ if (s.length < 4)
94
+ throw new Error(
95
+ "Each LinearRing of a Polygon must have 4 or more Positions."
96
+ );
97
+ if (s[s.length - 1].length !== s[0].length)
98
+ throw new Error("First and last Position are not equivalent.");
99
+ for (let i = 0; i < s[s.length - 1].length; i++)
100
+ if (s[s.length - 1][i] !== s[0][i])
101
+ throw new Error("First and last Position are not equivalent.");
102
+ }
103
+ return je({
104
+ type: "Polygon",
105
+ coordinates: o
106
+ }, t, e);
107
+ }
108
+ function Lt(o, t = {}) {
109
+ const e = { type: "FeatureCollection" };
110
+ return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = o, e;
111
+ }
112
+ function Ae(o) {
113
+ return !isNaN(o) && o !== null && !Array.isArray(o);
114
+ }
115
+ function ds(o) {
116
+ if (!o)
117
+ throw new Error("coord is required");
118
+ if (!Array.isArray(o)) {
119
+ if (o.type === "Feature" && o.geometry !== null && o.geometry.type === "Point")
120
+ return [...o.geometry.coordinates];
121
+ if (o.type === "Point")
122
+ return [...o.coordinates];
123
+ }
124
+ if (Array.isArray(o) && o.length >= 2 && !Array.isArray(o[0]) && !Array.isArray(o[1]))
125
+ return [...o];
126
+ throw new Error("coord must be GeoJSON Point or an Array of numbers");
127
+ }
128
+ function Ee(o) {
129
+ if (Array.isArray(o))
130
+ return o;
131
+ if (o.type === "Feature") {
132
+ if (o.geometry !== null)
133
+ return o.geometry.coordinates;
134
+ } else if (o.coordinates)
135
+ return o.coordinates;
136
+ throw new Error(
137
+ "coords must be GeoJSON Feature, Geometry Object or an Array"
138
+ );
139
+ }
140
+ function gs(o) {
141
+ return o.type === "Feature" ? o.geometry : o;
142
+ }
143
+ function ps(o, t, e = {}) {
144
+ if (!o)
145
+ throw new Error("point is required");
146
+ if (!t)
147
+ throw new Error("polygon is required");
148
+ const s = ds(o), i = gs(t), n = i.type, r = t.bbox;
149
+ let a = i.coordinates;
150
+ if (r && ws(s, r) === !1)
151
+ return !1;
152
+ n === "Polygon" && (a = [a]);
153
+ let f = !1;
154
+ for (var c = 0; c < a.length; ++c) {
155
+ const u = ls(s, a[c]);
156
+ if (u === 0) return !e.ignoreBoundary;
157
+ u && (f = !0);
158
+ }
159
+ return f;
160
+ }
161
+ function ws(o, t) {
162
+ return t[0] <= o[0] && t[1] <= o[1] && t[2] >= o[0] && t[3] >= o[1];
163
+ }
164
+ var we = ps;
165
+ function ve(o) {
166
+ const t = o.features;
167
+ for (let e = 0; e < t.length; e++) {
168
+ const s = t[e];
169
+ `${s.properties.a.index}`.substring(0, 1) === "b" && `${s.properties.b.index}`.substring(0, 1) === "b" ? t[e] = {
170
+ geometry: {
171
+ type: "Polygon",
172
+ coordinates: [
173
+ [
174
+ s.geometry.coordinates[0][2],
175
+ s.geometry.coordinates[0][0],
176
+ s.geometry.coordinates[0][1],
177
+ s.geometry.coordinates[0][2]
178
+ ]
179
+ ]
180
+ },
181
+ properties: {
182
+ a: {
183
+ geom: s.properties.c.geom,
184
+ index: s.properties.c.index
185
+ },
186
+ b: {
187
+ geom: s.properties.a.geom,
188
+ index: s.properties.a.index
189
+ },
190
+ c: {
191
+ geom: s.properties.b.geom,
192
+ index: s.properties.b.index
193
+ }
194
+ },
195
+ type: "Feature"
196
+ } : `${s.properties.c.index}`.substring(0, 1) === "b" && `${s.properties.a.index}`.substring(0, 1) === "b" && (t[e] = {
197
+ geometry: {
198
+ type: "Polygon",
199
+ coordinates: [
200
+ [
201
+ s.geometry.coordinates[0][1],
202
+ s.geometry.coordinates[0][2],
203
+ s.geometry.coordinates[0][0],
204
+ s.geometry.coordinates[0][1]
205
+ ]
206
+ ]
207
+ },
208
+ properties: {
209
+ a: {
210
+ geom: s.properties.b.geom,
211
+ index: s.properties.b.index
212
+ },
213
+ b: {
214
+ geom: s.properties.c.geom,
215
+ index: s.properties.c.index
216
+ },
217
+ c: {
218
+ geom: s.properties.a.geom,
219
+ index: s.properties.a.index
220
+ }
221
+ },
222
+ type: "Feature"
223
+ });
224
+ }
225
+ return o;
226
+ }
227
+ function ms(o) {
228
+ const t = ["a", "b", "c", "a"].map(
229
+ (n) => o.properties[n].geom
230
+ ), e = o.geometry.coordinates[0], s = o.properties, i = {
231
+ a: { geom: e[0], index: s.a.index },
232
+ b: { geom: e[1], index: s.b.index },
233
+ c: { geom: e[2], index: s.c.index }
234
+ };
235
+ return Le([t], i);
236
+ }
237
+ function bs(o) {
238
+ const t = [0, 1, 2, 0].map((s) => o[s][0][0]), e = {
239
+ a: { geom: o[0][0][1], index: o[0][1] },
240
+ b: { geom: o[1][0][1], index: o[1][1] },
241
+ c: { geom: o[2][0][1], index: o[2][1] }
242
+ };
243
+ return Le([t], e);
244
+ }
245
+ function Gt(o, t, e, s, i, n = !1, r) {
246
+ const a = o.map(
247
+ (f) => {
248
+ (!r || r < 2.00703) && (f = Ve(f));
249
+ const c = isFinite(f) ? t[f] : f === "c" ? s : f === "b0" ? i[0] : f === "b1" ? i[1] : f === "b2" ? i[2] : f === "b3" ? i[3] : function() {
250
+ const u = f.match(/e(\d+)/);
251
+ if (u) {
252
+ const h = parseInt(u[1]);
253
+ return e[h];
254
+ }
255
+ throw "Bad index value for indexesToTri";
256
+ }();
257
+ return n ? [[c[1], c[0]], f] : [[c[0], c[1]], f];
258
+ }
259
+ );
260
+ return bs(a);
261
+ }
262
+ function Ve(o) {
263
+ return typeof o == "number" ? o : o.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2");
264
+ }
265
+ function We(o, t) {
266
+ return t && t >= 2.00703 || Array.isArray(o[0]) ? o : o.map((e) => [
267
+ e.illstNodes,
268
+ e.mercNodes,
269
+ e.startEnd
270
+ ]);
271
+ }
272
+ function Oe(o, t) {
273
+ for (let e = 0; e < t.features.length; e++)
274
+ if (we(o, t.features[e]))
275
+ return t.features[e];
276
+ }
277
+ function ze(o, t, e) {
278
+ const s = t.geometry.coordinates[0][0], i = t.geometry.coordinates[0][1], n = t.geometry.coordinates[0][2], r = o.geometry.coordinates, a = t.properties.a.geom, f = t.properties.b.geom, c = t.properties.c.geom, u = [i[0] - s[0], i[1] - s[1]], h = [n[0] - s[0], n[1] - s[1]], l = [r[0] - s[0], r[1] - s[1]], p = [f[0] - a[0], f[1] - a[1]], y = [c[0] - a[0], c[1] - a[1]];
279
+ let g = (h[1] * l[0] - h[0] * l[1]) / (u[0] * h[1] - u[1] * h[0]), b = (u[0] * l[1] - u[1] * l[0]) / (u[0] * h[1] - u[1] * h[0]);
280
+ if (e) {
281
+ const w = e[t.properties.a.index], S = e[t.properties.b.index], _ = e[t.properties.c.index];
282
+ let v;
283
+ if (g < 0 || b < 0 || 1 - g - b < 0) {
284
+ const T = g / (g + b), I = b / (g + b);
285
+ v = g / S / (T / S + I / _), b = b / _ / (T / S + I / _);
286
+ } else
287
+ v = g / S / (g / S + b / _ + (1 - g - b) / w), b = b / _ / (g / S + b / _ + (1 - g - b) / w);
288
+ g = v;
289
+ }
290
+ return [
291
+ g * p[0] + b * y[0] + a[0],
292
+ g * p[1] + b * y[1] + a[1]
293
+ ];
294
+ }
295
+ function ys(o, t, e, s) {
296
+ const i = o.geometry.coordinates, n = e.geometry.coordinates, r = Math.atan2(i[0] - n[0], i[1] - n[1]), a = ks(r, t[0]);
297
+ if (a === void 0)
298
+ throw new Error("Unable to determine vertex index");
299
+ const f = t[1][a];
300
+ return ze(o, f.features[0], s);
301
+ }
302
+ function re(o, t, e, s, i, n, r, a) {
303
+ let f;
304
+ if (r && (f = Oe(o, Lt([r]))), !f) {
305
+ if (e) {
306
+ const c = o.geometry.coordinates, u = e.gridNum, h = e.xOrigin, l = e.yOrigin, p = e.xUnit, y = e.yUnit, g = e.gridCache, b = At(c[0], h, p, u), w = At(c[1], l, y, u), S = g[b] ? g[b][w] ? g[b][w] : [] : [];
307
+ t = Lt(S.map((_) => t.features[_]));
308
+ }
309
+ f = Oe(o, t);
310
+ }
311
+ return a && a(f), f ? ze(o, f, n) : ys(o, s, i, n);
312
+ }
313
+ function At(o, t, e, s) {
314
+ let i = Math.floor((o - t) / e);
315
+ return i >= s && (i = s - 1), i;
316
+ }
317
+ function ks(o, t) {
318
+ let e = Te(o - t[0]), s = Math.PI * 2, i;
319
+ for (let n = 0; n < t.length; n++) {
320
+ const r = (n + 1) % t.length, a = Te(o - t[r]), f = Math.min(Math.abs(e), Math.abs(a));
321
+ e * a <= 0 && f < s && (s = f, i = n), e = a;
322
+ }
323
+ return i;
324
+ }
325
+ function Te(o, t = !1) {
326
+ const e = t ? function(s) {
327
+ return !(s >= 0 && s < Math.PI * 2);
328
+ } : function(s) {
329
+ return !(s > -1 * Math.PI && s <= Math.PI);
330
+ };
331
+ for (; e(o); )
332
+ o = o + 2 * Math.PI * (o > 0 ? -1 : 1);
333
+ return o;
334
+ }
335
+ const oe = 2.00703, kt = class xt {
336
+ constructor() {
337
+ nt(this, "points", []), nt(this, "pointsWeightBuffer"), nt(this, "strict_status"), nt(this, "vertices_params"), nt(this, "centroid"), nt(this, "edgeNodes"), nt(this, "edges"), nt(this, "tins"), nt(this, "kinks"), nt(this, "yaxisMode", xt.YAXIS_INVERT), nt(this, "strictMode", xt.MODE_AUTO), nt(this, "vertexMode", xt.VERTEX_PLAIN), nt(this, "bounds"), nt(this, "boundsPolygon"), nt(this, "wh"), nt(this, "xy"), nt(this, "indexedTins"), nt(this, "stateFull", !1), nt(this, "stateTriangle"), nt(this, "stateBackward");
338
+ }
339
+ /**
340
+ * コンパイルされた設定を適用します
341
+ *
342
+ * @param compiled - コンパイルされた設定オブジェクト
343
+ * @returns 変換に必要な主要なオブジェクトのセット
344
+ *
345
+ * 以下の処理を行います:
346
+ * 1. バージョンに応じた設定の解釈
347
+ * 2. 各種パラメータの復元
348
+ * 3. TINネットワークの再構築
349
+ * 4. インデックスの作成
350
+ */
351
+ setCompiled(t) {
352
+ if (t.version || !t.tins && t.points && t.tins_points) {
353
+ this.points = t.points, this.pointsWeightBuffer = !t.version || t.version < 2.00703 ? ["forw", "bakw"].reduce((s, i) => {
354
+ const n = t.weight_buffer[i];
355
+ return n && (s[i] = Object.keys(n).reduce((r, a) => {
356
+ const f = Ve(a);
357
+ return r[f] = n[a], r;
358
+ }, {})), s;
359
+ }, {}) : t.weight_buffer, t.strict_status ? this.strict_status = t.strict_status : t.kinks_points ? this.strict_status = xt.STATUS_ERROR : t.tins_points.length == 2 ? this.strict_status = xt.STATUS_LOOSE : this.strict_status = xt.STATUS_STRICT, this.vertices_params = {
360
+ forw: [t.vertices_params[0]],
361
+ bakw: [t.vertices_params[1]]
362
+ }, this.vertices_params.forw[1] = [0, 1, 2, 3].map((s) => {
363
+ const i = (s + 1) % 4, n = Gt(
364
+ ["c", `b${s}`, `b${i}`],
365
+ t.points,
366
+ t.edgeNodes || [],
367
+ t.centroid_point,
368
+ t.vertices_points,
369
+ !1,
370
+ oe
371
+ );
372
+ return Lt([n]);
373
+ }), this.vertices_params.bakw[1] = [0, 1, 2, 3].map((s) => {
374
+ const i = (s + 1) % 4, n = Gt(
375
+ ["c", `b${s}`, `b${i}`],
376
+ t.points,
377
+ t.edgeNodes || [],
378
+ t.centroid_point,
379
+ t.vertices_points,
380
+ !0,
381
+ oe
382
+ );
383
+ return Lt([n]);
384
+ }), this.centroid = {
385
+ forw: Yt(t.centroid_point[0], {
386
+ target: {
387
+ geom: t.centroid_point[1],
388
+ index: "c"
389
+ }
390
+ }),
391
+ bakw: Yt(t.centroid_point[1], {
392
+ target: {
393
+ geom: t.centroid_point[0],
394
+ index: "c"
395
+ }
396
+ })
397
+ }, this.edges = We(t.edges || []), this.edgeNodes = t.edgeNodes || [];
398
+ const e = t.tins_points.length == 1 ? 0 : 1;
399
+ this.tins = {
400
+ forw: Lt(
401
+ t.tins_points[0].map(
402
+ (s) => Gt(
403
+ s,
404
+ t.points,
405
+ t.edgeNodes || [],
406
+ t.centroid_point,
407
+ t.vertices_points,
408
+ !1,
409
+ t.version
410
+ )
411
+ )
412
+ ),
413
+ bakw: Lt(
414
+ t.tins_points[e].map(
415
+ (s) => Gt(
416
+ s,
417
+ t.points,
418
+ t.edgeNodes || [],
419
+ t.centroid_point,
420
+ t.vertices_points,
421
+ !0,
422
+ t.version
423
+ )
424
+ )
425
+ )
426
+ }, this.addIndexedTin(), t.kinks_points && (this.kinks = {
427
+ bakw: Lt(
428
+ t.kinks_points.map((s) => Yt(s))
429
+ )
430
+ }), t.yaxisMode ? this.yaxisMode = t.yaxisMode : this.yaxisMode = xt.YAXIS_INVERT, t.vertexMode && (this.vertexMode = t.vertexMode), t.strictMode && (this.strictMode = t.strictMode), t.bounds ? (this.bounds = t.bounds, this.boundsPolygon = t.boundsPolygon, this.xy = t.xy, this.wh = t.wh) : (this.xy = [0, 0], t.wh && (this.wh = t.wh), this.bounds = void 0, this.boundsPolygon = void 0);
431
+ } else {
432
+ t = JSON.parse(
433
+ JSON.stringify(t).replace('"cent"', '"c"').replace(/"bbox(\d+)"/g, '"b$1"')
434
+ ), this.tins = t.tins, this.addIndexedTin(), this.strict_status = t.strict_status, this.pointsWeightBuffer = t.weight_buffer, this.vertices_params = t.vertices_params, this.centroid = t.centroid, this.kinks = t.kinks;
435
+ const e = [];
436
+ for (let s = 0; s < this.tins.forw.features.length; s++) {
437
+ const i = this.tins.forw.features[s];
438
+ ["a", "b", "c"].map((n, r) => {
439
+ const a = i.geometry.coordinates[0][r], f = i.properties[n].geom, c = i.properties[n].index;
440
+ typeof c == "number" && (e[c] = [a, f]);
441
+ });
442
+ }
443
+ this.points = e;
444
+ }
445
+ }
446
+ /**
447
+ * TINネットワークのインデックスを作成します
448
+ *
449
+ * インデックスは変換処理を高速化するために使用されます。
450
+ * グリッド形式のインデックスを作成し、各グリッドに
451
+ * 含まれる三角形を記録します。
452
+ */
453
+ addIndexedTin() {
454
+ const t = this.tins, e = t.forw, s = t.bakw, i = Math.ceil(Math.sqrt(e.features.length));
455
+ if (i < 3) {
456
+ this.indexedTins = void 0;
457
+ return;
458
+ }
459
+ let n = [], r = [];
460
+ const a = e.features.map((g) => {
461
+ let b = [];
462
+ return Ee(g)[0].map((w) => {
463
+ n.length === 0 ? n = [Array.from(w), Array.from(w)] : (w[0] < n[0][0] && (n[0][0] = w[0]), w[0] > n[1][0] && (n[1][0] = w[0]), w[1] < n[0][1] && (n[0][1] = w[1]), w[1] > n[1][1] && (n[1][1] = w[1])), b.length === 0 ? b = [Array.from(w), Array.from(w)] : (w[0] < b[0][0] && (b[0][0] = w[0]), w[0] > b[1][0] && (b[1][0] = w[0]), w[1] < b[0][1] && (b[0][1] = w[1]), w[1] > b[1][1] && (b[1][1] = w[1]));
464
+ }), b;
465
+ }), f = (n[1][0] - n[0][0]) / i, c = (n[1][1] - n[0][1]) / i, u = a.reduce(
466
+ (g, b, w) => {
467
+ const S = At(
468
+ b[0][0],
469
+ n[0][0],
470
+ f,
471
+ i
472
+ ), _ = At(
473
+ b[1][0],
474
+ n[0][0],
475
+ f,
476
+ i
477
+ ), v = At(
478
+ b[0][1],
479
+ n[0][1],
480
+ c,
481
+ i
482
+ ), T = At(
483
+ b[1][1],
484
+ n[0][1],
485
+ c,
486
+ i
487
+ );
488
+ for (let I = S; I <= _; I++) {
489
+ g[I] || (g[I] = []);
490
+ for (let N = v; N <= T; N++)
491
+ g[I][N] || (g[I][N] = []), g[I][N].push(w);
492
+ }
493
+ return g;
494
+ },
495
+ []
496
+ ), h = s.features.map((g) => {
497
+ let b = [];
498
+ return Ee(g)[0].map((w) => {
499
+ r.length === 0 ? r = [Array.from(w), Array.from(w)] : (w[0] < r[0][0] && (r[0][0] = w[0]), w[0] > r[1][0] && (r[1][0] = w[0]), w[1] < r[0][1] && (r[0][1] = w[1]), w[1] > r[1][1] && (r[1][1] = w[1])), b.length === 0 ? b = [Array.from(w), Array.from(w)] : (w[0] < b[0][0] && (b[0][0] = w[0]), w[0] > b[1][0] && (b[1][0] = w[0]), w[1] < b[0][1] && (b[0][1] = w[1]), w[1] > b[1][1] && (b[1][1] = w[1]));
500
+ }), b;
501
+ }), l = (r[1][0] - r[0][0]) / i, p = (r[1][1] - r[0][1]) / i, y = h.reduce(
502
+ (g, b, w) => {
503
+ const S = At(
504
+ b[0][0],
505
+ r[0][0],
506
+ l,
507
+ i
508
+ ), _ = At(
509
+ b[1][0],
510
+ r[0][0],
511
+ l,
512
+ i
513
+ ), v = At(
514
+ b[0][1],
515
+ r[0][1],
516
+ p,
517
+ i
518
+ ), T = At(
519
+ b[1][1],
520
+ r[0][1],
521
+ p,
522
+ i
523
+ );
524
+ for (let I = S; I <= _; I++) {
525
+ g[I] || (g[I] = []);
526
+ for (let N = v; N <= T; N++)
527
+ g[I][N] || (g[I][N] = []), g[I][N].push(w);
528
+ }
529
+ return g;
530
+ },
531
+ []
532
+ );
533
+ this.indexedTins = {
534
+ forw: {
535
+ gridNum: i,
536
+ xOrigin: n[0][0],
537
+ yOrigin: n[0][1],
538
+ xUnit: f,
539
+ yUnit: c,
540
+ gridCache: u
541
+ },
542
+ bakw: {
543
+ gridNum: i,
544
+ xOrigin: r[0][0],
545
+ yOrigin: r[0][1],
546
+ xUnit: l,
547
+ yUnit: p,
548
+ gridCache: y
549
+ }
550
+ };
551
+ }
552
+ /**
553
+ * 座標変換を実行します
554
+ *
555
+ * @param apoint - 変換する座標
556
+ * @param backward - 逆方向の変換かどうか
557
+ * @param ignoreBounds - 境界チェックを無視するかどうか
558
+ * @returns 変換後の座標、または境界外の場合はfalse
559
+ *
560
+ * @throws {Error} 逆方向変換が許可されていない状態での逆変換時
561
+ */
562
+ transform(t, e, s) {
563
+ if (e && this.strict_status == xt.STATUS_ERROR)
564
+ throw 'Backward transform is not allowed if strict_status == "strict_error"';
565
+ this.yaxisMode == xt.YAXIS_FOLLOW && e && (t = [t[0], -1 * t[1]]);
566
+ const i = Yt(t);
567
+ if (this.bounds && !e && !s && !we(i, this.boundsPolygon))
568
+ return !1;
569
+ const n = e ? this.tins.bakw : this.tins.forw, r = e ? this.indexedTins.bakw : this.indexedTins.forw, a = e ? this.vertices_params.bakw : this.vertices_params.forw, f = e ? this.centroid.bakw : this.centroid.forw, c = e ? this.pointsWeightBuffer.bakw : this.pointsWeightBuffer.forw;
570
+ let u, h;
571
+ this.stateFull && (this.stateBackward == e ? u = this.stateTriangle : (this.stateBackward = e, this.stateTriangle = void 0), h = (p) => {
572
+ this.stateTriangle = p;
573
+ });
574
+ let l = re(
575
+ i,
576
+ n,
577
+ r,
578
+ a,
579
+ f,
580
+ c,
581
+ u,
582
+ h
583
+ );
584
+ if (this.bounds && e && !s) {
585
+ const p = Yt(l);
586
+ if (!we(p, this.boundsPolygon)) return !1;
587
+ } else this.yaxisMode == xt.YAXIS_FOLLOW && !e && (l = [l[0], -1 * l[1]]);
588
+ return l;
589
+ }
590
+ };
591
+ nt(kt, "VERTEX_PLAIN", "plain"), nt(kt, "VERTEX_BIRDEYE", "birdeye"), nt(kt, "MODE_STRICT", "strict"), nt(kt, "MODE_AUTO", "auto"), nt(kt, "MODE_LOOSE", "loose"), nt(kt, "STATUS_STRICT", "strict"), nt(kt, "STATUS_ERROR", "strict_error"), nt(kt, "STATUS_LOOSE", "loose"), nt(kt, "YAXIS_FOLLOW", "follow"), nt(kt, "YAXIS_INVERT", "invert");
592
+ let xs = kt;
593
+ const dt = 11102230246251565e-32, $ = 134217729, Xe = (3 + 8 * dt) * dt;
594
+ function ct(o, t, e, s, i) {
595
+ let n, r, a, f, c = t[0], u = s[0], h = 0, l = 0;
596
+ u > c == u > -c ? (n = c, c = t[++h]) : (n = u, u = s[++l]);
597
+ let p = 0;
598
+ if (h < o && l < e)
599
+ for (u > c == u > -c ? (r = c + n, a = n - (r - c), c = t[++h]) : (r = u + n, a = n - (r - u), u = s[++l]), n = r, a !== 0 && (i[p++] = a); h < o && l < e; )
600
+ u > c == u > -c ? (r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h]) : (r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l]), n = r, a !== 0 && (i[p++] = a);
601
+ for (; h < o; )
602
+ r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h], n = r, a !== 0 && (i[p++] = a);
603
+ for (; l < e; )
604
+ r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l], n = r, a !== 0 && (i[p++] = a);
605
+ return (n !== 0 || p === 0) && (i[p++] = n), p;
606
+ }
607
+ function yt(o, t, e, s, i, n, r, a) {
608
+ return ct(ct(o, t, e, s, r), r, i, n, a);
609
+ }
610
+ function M(o, t, e, s) {
611
+ let i, n, r, a, f, c, u, h, l, p, y;
612
+ u = $ * e, p = u - (u - e), y = e - p;
613
+ let g = t[0];
614
+ i = g * e, u = $ * g, h = u - (u - g), l = g - h, r = l * y - (i - h * p - l * p - h * y);
615
+ let b = 0;
616
+ r !== 0 && (s[b++] = r);
617
+ for (let w = 1; w < o; w++)
618
+ g = t[w], a = g * e, u = $ * g, h = u - (u - g), l = g - h, f = l * y - (a - h * p - l * p - h * y), n = i + f, c = n - i, r = i - (n - c) + (f - c), r !== 0 && (s[b++] = r), i = a + n, r = n - (i - a), r !== 0 && (s[b++] = r);
619
+ return (i !== 0 || b === 0) && (s[b++] = i), b;
620
+ }
621
+ function Ye(o, t) {
622
+ let e = t[0];
623
+ for (let s = 1; s < o; s++) e += t[s];
624
+ return e;
625
+ }
626
+ function H(o) {
627
+ return new Float64Array(o);
628
+ }
629
+ const _s = (3 + 16 * dt) * dt, Ms = (2 + 12 * dt) * dt, Ss = (9 + 64 * dt) * dt * dt, Wt = H(4), Ie = H(8), Pe = H(12), $e = H(16), pt = H(4);
630
+ function As(o, t, e, s, i, n, r) {
631
+ let a, f, c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V;
632
+ const z = o - i, G = e - i, tt = t - n, X = s - n;
633
+ v = z * X, l = $ * z, p = l - (l - z), y = z - p, l = $ * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = tt * G, l = $ * tt, p = l - (l - tt), y = tt - p, l = $ * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, Wt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, Wt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, Wt[2] = S - (V - h) + (w - h), Wt[3] = V;
634
+ let it = Ye(4, Wt), d = Ms * r;
635
+ if (it >= d || -it >= d || (h = o - z, a = o - (z + h) + (h - i), h = e - G, c = e - (G + h) + (h - i), h = t - tt, f = t - (tt + h) + (h - n), h = s - X, u = s - (X + h) + (h - n), a === 0 && f === 0 && c === 0 && u === 0) || (d = Ss * r + Xe * Math.abs(it), it += z * u + X * a - (tt * c + G * f), it >= d || -it >= d)) return it;
636
+ v = a * X, l = $ * a, p = l - (l - a), y = a - p, l = $ * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = f * G, l = $ * f, p = l - (l - f), y = f - p, l = $ * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V;
637
+ const m = ct(4, Wt, 4, pt, Ie);
638
+ v = z * u, l = $ * z, p = l - (l - z), y = z - p, l = $ * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = tt * c, l = $ * tt, p = l - (l - tt), y = tt - p, l = $ * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V;
639
+ const x = ct(m, Ie, 4, pt, Pe);
640
+ v = a * u, l = $ * a, p = l - (l - a), y = a - p, l = $ * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = f * c, l = $ * f, p = l - (l - f), y = f - p, l = $ * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V;
641
+ const A = ct(x, Pe, 4, pt, $e);
642
+ return $e[A - 1];
643
+ }
644
+ function Ct(o, t, e, s, i, n) {
645
+ const r = (t - n) * (e - i), a = (o - i) * (s - n), f = r - a, c = Math.abs(r + a);
646
+ return Math.abs(f) >= _s * c ? f : -As(o, t, e, s, i, n, c);
647
+ }
648
+ const Es = (10 + 96 * dt) * dt, vs = (4 + 48 * dt) * dt, Os = (44 + 576 * dt) * dt * dt, It = H(4), Pt = H(4), $t = H(4), _t = H(4), Mt = H(4), St = H(4), wt = H(4), mt = H(4), ce = H(8), fe = H(8), ue = H(8), le = H(8), de = H(8), ge = H(8), Kt = H(8), Qt = H(8), Zt = H(8), Bt = H(4), Dt = H(4), Ft = H(4), U = H(8), L = H(16), et = H(16), st = H(16), Z = H(32), Rt = H(32), ot = H(48), bt = H(64);
649
+ let zt = H(1152), pe = H(1152);
650
+ function at(o, t, e) {
651
+ o = ct(o, zt, t, e, pe);
652
+ const s = zt;
653
+ return zt = pe, pe = s, o;
654
+ }
655
+ function Ts(o, t, e, s, i, n, r, a, f) {
656
+ let c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V, z, G, tt, X, it, d, m, x, A, E, R, k, O, B, P, D, F, W, j;
657
+ const Y = o - r, C = e - r, q = i - r, K = t - a, J = s - a, Q = n - a;
658
+ P = C * Q, m = $ * C, x = m - (m - C), A = C - x, m = $ * Q, E = m - (m - Q), R = Q - E, D = A * R - (P - x * E - A * E - x * R), F = q * J, m = $ * q, x = m - (m - q), A = q - x, m = $ * J, E = m - (m - J), R = J - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, It[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, It[1] = B - (k + d) + (d - F), j = O + k, d = j - O, It[2] = O - (j - d) + (k - d), It[3] = j, P = q * K, m = $ * q, x = m - (m - q), A = q - x, m = $ * K, E = m - (m - K), R = K - E, D = A * R - (P - x * E - A * E - x * R), F = Y * Q, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * Q, E = m - (m - Q), R = Q - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Pt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Pt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Pt[2] = O - (j - d) + (k - d), Pt[3] = j, P = Y * J, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * J, E = m - (m - J), R = J - E, D = A * R - (P - x * E - A * E - x * R), F = C * K, m = $ * C, x = m - (m - C), A = C - x, m = $ * K, E = m - (m - K), R = K - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, $t[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, $t[1] = B - (k + d) + (d - F), j = O + k, d = j - O, $t[2] = O - (j - d) + (k - d), $t[3] = j, c = ct(
659
+ ct(
660
+ ct(
661
+ M(M(4, It, Y, U), U, Y, L),
662
+ L,
663
+ M(M(4, It, K, U), U, K, et),
664
+ et,
665
+ Z
666
+ ),
667
+ Z,
668
+ ct(
669
+ M(M(4, Pt, C, U), U, C, L),
670
+ L,
671
+ M(M(4, Pt, J, U), U, J, et),
672
+ et,
673
+ Rt
674
+ ),
675
+ Rt,
676
+ bt
677
+ ),
678
+ bt,
679
+ ct(
680
+ M(M(4, $t, q, U), U, q, L),
681
+ L,
682
+ M(M(4, $t, Q, U), U, Q, et),
683
+ et,
684
+ Z
685
+ ),
686
+ Z,
687
+ zt
688
+ );
689
+ let Ut = Ye(c, zt), Xt = vs * f;
690
+ if (Ut >= Xt || -Ut >= Xt || (d = o - Y, u = o - (Y + d) + (d - r), d = t - K, p = t - (K + d) + (d - a), d = e - C, h = e - (C + d) + (d - r), d = s - J, y = s - (J + d) + (d - a), d = i - q, l = i - (q + d) + (d - r), d = n - Q, g = n - (Q + d) + (d - a), u === 0 && h === 0 && l === 0 && p === 0 && y === 0 && g === 0) || (Xt = Os * f + Xe * Math.abs(Ut), Ut += (Y * Y + K * K) * (C * g + Q * h - (J * l + q * y)) + 2 * (Y * u + K * p) * (C * Q - J * q) + ((C * C + J * J) * (q * p + K * l - (Q * u + Y * g)) + 2 * (C * h + J * y) * (q * K - Q * Y)) + ((q * q + Q * Q) * (Y * y + J * u - (K * h + C * p)) + 2 * (q * l + Q * g) * (Y * J - K * C)), Ut >= Xt || -Ut >= Xt))
691
+ return Ut;
692
+ if ((h !== 0 || y !== 0 || l !== 0 || g !== 0) && (P = Y * Y, m = $ * Y, x = m - (m - Y), A = Y - x, D = A * A - (P - x * x - (x + x) * A), F = K * K, m = $ * K, x = m - (m - K), A = K - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, _t[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, _t[1] = B - (k - d) + (F - d), j = O + k, d = j - O, _t[2] = O - (j - d) + (k - d), _t[3] = j), (l !== 0 || g !== 0 || u !== 0 || p !== 0) && (P = C * C, m = $ * C, x = m - (m - C), A = C - x, D = A * A - (P - x * x - (x + x) * A), F = J * J, m = $ * J, x = m - (m - J), A = J - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, Mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, Mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, Mt[2] = O - (j - d) + (k - d), Mt[3] = j), (u !== 0 || p !== 0 || h !== 0 || y !== 0) && (P = q * q, m = $ * q, x = m - (m - q), A = q - x, D = A * A - (P - x * x - (x + x) * A), F = Q * Q, m = $ * Q, x = m - (m - Q), A = Q - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, St[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, St[1] = B - (k - d) + (F - d), j = O + k, d = j - O, St[2] = O - (j - d) + (k - d), St[3] = j), u !== 0 && (b = M(4, It, u, ce), c = at(c, yt(
693
+ M(b, ce, 2 * Y, L),
694
+ L,
695
+ M(M(4, St, u, U), U, J, et),
696
+ et,
697
+ M(M(4, Mt, u, U), U, -Q, st),
698
+ st,
699
+ Z,
700
+ ot
701
+ ), ot)), p !== 0 && (w = M(4, It, p, fe), c = at(c, yt(
702
+ M(w, fe, 2 * K, L),
703
+ L,
704
+ M(M(4, Mt, p, U), U, q, et),
705
+ et,
706
+ M(M(4, St, p, U), U, -C, st),
707
+ st,
708
+ Z,
709
+ ot
710
+ ), ot)), h !== 0 && (S = M(4, Pt, h, ue), c = at(c, yt(
711
+ M(S, ue, 2 * C, L),
712
+ L,
713
+ M(M(4, _t, h, U), U, Q, et),
714
+ et,
715
+ M(M(4, St, h, U), U, -K, st),
716
+ st,
717
+ Z,
718
+ ot
719
+ ), ot)), y !== 0 && (_ = M(4, Pt, y, le), c = at(c, yt(
720
+ M(_, le, 2 * J, L),
721
+ L,
722
+ M(M(4, St, y, U), U, Y, et),
723
+ et,
724
+ M(M(4, _t, y, U), U, -q, st),
725
+ st,
726
+ Z,
727
+ ot
728
+ ), ot)), l !== 0 && (v = M(4, $t, l, de), c = at(c, yt(
729
+ M(v, de, 2 * q, L),
730
+ L,
731
+ M(M(4, Mt, l, U), U, K, et),
732
+ et,
733
+ M(M(4, _t, l, U), U, -J, st),
734
+ st,
735
+ Z,
736
+ ot
737
+ ), ot)), g !== 0 && (T = M(4, $t, g, ge), c = at(c, yt(
738
+ M(T, ge, 2 * Q, L),
739
+ L,
740
+ M(M(4, _t, g, U), U, C, et),
741
+ et,
742
+ M(M(4, Mt, g, U), U, -Y, st),
743
+ st,
744
+ Z,
745
+ ot
746
+ ), ot)), u !== 0 || p !== 0) {
747
+ if (h !== 0 || y !== 0 || l !== 0 || g !== 0 ? (P = h * Q, m = $ * h, x = m - (m - h), A = h - x, m = $ * Q, E = m - (m - Q), R = Q - E, D = A * R - (P - x * E - A * E - x * R), F = C * g, m = $ * C, x = m - (m - C), A = C - x, m = $ * g, E = m - (m - g), R = g - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, P = l * -J, m = $ * l, x = m - (m - l), A = l - x, m = $ * -J, E = m - (m - -J), R = -J - E, D = A * R - (P - x * E - A * E - x * R), F = q * -y, m = $ * q, x = m - (m - q), A = q - x, m = $ * -y, E = m - (m - -y), R = -y - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, N = ct(4, wt, 4, mt, Qt), P = h * g, m = $ * h, x = m - (m - h), A = h - x, m = $ * g, E = m - (m - g), R = g - E, D = A * R - (P - x * E - A * E - x * R), F = l * y, m = $ * l, x = m - (m - l), A = l - x, m = $ * y, E = m - (m - y), R = y - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Dt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Dt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Dt[2] = O - (j - d) + (k - d), Dt[3] = j, G = 4) : (Qt[0] = 0, N = 1, Dt[0] = 0, G = 1), u !== 0) {
748
+ const ft = M(N, Qt, u, st);
749
+ c = at(c, ct(
750
+ M(b, ce, u, L),
751
+ L,
752
+ M(ft, st, 2 * Y, Z),
753
+ Z,
754
+ ot
755
+ ), ot);
756
+ const ut = M(G, Dt, u, U);
757
+ c = at(c, yt(
758
+ M(ut, U, 2 * Y, L),
759
+ L,
760
+ M(ut, U, u, et),
761
+ et,
762
+ M(ft, st, u, Z),
763
+ Z,
764
+ Rt,
765
+ bt
766
+ ), bt), y !== 0 && (c = at(c, M(M(4, St, u, U), U, y, L), L)), g !== 0 && (c = at(c, M(M(4, Mt, -u, U), U, g, L), L));
767
+ }
768
+ if (p !== 0) {
769
+ const ft = M(N, Qt, p, st);
770
+ c = at(c, ct(
771
+ M(w, fe, p, L),
772
+ L,
773
+ M(ft, st, 2 * K, Z),
774
+ Z,
775
+ ot
776
+ ), ot);
777
+ const ut = M(G, Dt, p, U);
778
+ c = at(c, yt(
779
+ M(ut, U, 2 * K, L),
780
+ L,
781
+ M(ut, U, p, et),
782
+ et,
783
+ M(ft, st, p, Z),
784
+ Z,
785
+ Rt,
786
+ bt
787
+ ), bt);
788
+ }
789
+ }
790
+ if (h !== 0 || y !== 0) {
791
+ if (l !== 0 || g !== 0 || u !== 0 || p !== 0 ? (P = l * K, m = $ * l, x = m - (m - l), A = l - x, m = $ * K, E = m - (m - K), R = K - E, D = A * R - (P - x * E - A * E - x * R), F = q * p, m = $ * q, x = m - (m - q), A = q - x, m = $ * p, E = m - (m - p), R = p - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, X = -Q, it = -g, P = u * X, m = $ * u, x = m - (m - u), A = u - x, m = $ * X, E = m - (m - X), R = X - E, D = A * R - (P - x * E - A * E - x * R), F = Y * it, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * it, E = m - (m - it), R = it - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, V = ct(4, wt, 4, mt, Zt), P = l * p, m = $ * l, x = m - (m - l), A = l - x, m = $ * p, E = m - (m - p), R = p - E, D = A * R - (P - x * E - A * E - x * R), F = u * g, m = $ * u, x = m - (m - u), A = u - x, m = $ * g, E = m - (m - g), R = g - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Ft[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Ft[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Ft[2] = O - (j - d) + (k - d), Ft[3] = j, tt = 4) : (Zt[0] = 0, V = 1, Ft[0] = 0, tt = 1), h !== 0) {
792
+ const ft = M(V, Zt, h, st);
793
+ c = at(c, ct(
794
+ M(S, ue, h, L),
795
+ L,
796
+ M(ft, st, 2 * C, Z),
797
+ Z,
798
+ ot
799
+ ), ot);
800
+ const ut = M(tt, Ft, h, U);
801
+ c = at(c, yt(
802
+ M(ut, U, 2 * C, L),
803
+ L,
804
+ M(ut, U, h, et),
805
+ et,
806
+ M(ft, st, h, Z),
807
+ Z,
808
+ Rt,
809
+ bt
810
+ ), bt), g !== 0 && (c = at(c, M(M(4, _t, h, U), U, g, L), L)), p !== 0 && (c = at(c, M(M(4, St, -h, U), U, p, L), L));
811
+ }
812
+ if (y !== 0) {
813
+ const ft = M(V, Zt, y, st);
814
+ c = at(c, ct(
815
+ M(_, le, y, L),
816
+ L,
817
+ M(ft, st, 2 * J, Z),
818
+ Z,
819
+ ot
820
+ ), ot);
821
+ const ut = M(tt, Ft, y, U);
822
+ c = at(c, yt(
823
+ M(ut, U, 2 * J, L),
824
+ L,
825
+ M(ut, U, y, et),
826
+ et,
827
+ M(ft, st, y, Z),
828
+ Z,
829
+ Rt,
830
+ bt
831
+ ), bt);
832
+ }
833
+ }
834
+ if (l !== 0 || g !== 0) {
835
+ if (u !== 0 || p !== 0 || h !== 0 || y !== 0 ? (P = u * J, m = $ * u, x = m - (m - u), A = u - x, m = $ * J, E = m - (m - J), R = J - E, D = A * R - (P - x * E - A * E - x * R), F = Y * y, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * y, E = m - (m - y), R = y - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, X = -K, it = -p, P = h * X, m = $ * h, x = m - (m - h), A = h - x, m = $ * X, E = m - (m - X), R = X - E, D = A * R - (P - x * E - A * E - x * R), F = C * it, m = $ * C, x = m - (m - C), A = C - x, m = $ * it, E = m - (m - it), R = it - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, I = ct(4, wt, 4, mt, Kt), P = u * y, m = $ * u, x = m - (m - u), A = u - x, m = $ * y, E = m - (m - y), R = y - E, D = A * R - (P - x * E - A * E - x * R), F = h * p, m = $ * h, x = m - (m - h), A = h - x, m = $ * p, E = m - (m - p), R = p - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Bt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Bt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Bt[2] = O - (j - d) + (k - d), Bt[3] = j, z = 4) : (Kt[0] = 0, I = 1, Bt[0] = 0, z = 1), l !== 0) {
836
+ const ft = M(I, Kt, l, st);
837
+ c = at(c, ct(
838
+ M(v, de, l, L),
839
+ L,
840
+ M(ft, st, 2 * q, Z),
841
+ Z,
842
+ ot
843
+ ), ot);
844
+ const ut = M(z, Bt, l, U);
845
+ c = at(c, yt(
846
+ M(ut, U, 2 * q, L),
847
+ L,
848
+ M(ut, U, l, et),
849
+ et,
850
+ M(ft, st, l, Z),
851
+ Z,
852
+ Rt,
853
+ bt
854
+ ), bt), p !== 0 && (c = at(c, M(M(4, Mt, l, U), U, p, L), L)), y !== 0 && (c = at(c, M(M(4, _t, -l, U), U, y, L), L));
855
+ }
856
+ if (g !== 0) {
857
+ const ft = M(I, Kt, g, st);
858
+ c = at(c, ct(
859
+ M(T, ge, g, L),
860
+ L,
861
+ M(ft, st, 2 * Q, Z),
862
+ Z,
863
+ ot
864
+ ), ot);
865
+ const ut = M(z, Bt, g, U);
866
+ c = at(c, yt(
867
+ M(ut, U, 2 * Q, L),
868
+ L,
869
+ M(ut, U, g, et),
870
+ et,
871
+ M(ft, st, g, Z),
872
+ Z,
873
+ Rt,
874
+ bt
875
+ ), bt);
876
+ }
877
+ }
878
+ return zt[c - 1];
879
+ }
880
+ function Is(o, t, e, s, i, n, r, a) {
881
+ const f = o - r, c = e - r, u = i - r, h = t - a, l = s - a, p = n - a, y = c * p, g = u * l, b = f * f + h * h, w = u * h, S = f * p, _ = c * c + l * l, v = f * l, T = c * h, I = u * u + p * p, N = b * (y - g) + _ * (w - S) + I * (v - T), V = (Math.abs(y) + Math.abs(g)) * b + (Math.abs(w) + Math.abs(S)) * _ + (Math.abs(v) + Math.abs(T)) * I, z = Es * V;
882
+ return N > z || -N > z ? N : Ts(o, t, e, s, i, n, r, a, V);
883
+ }
884
+ class Ps {
885
+ constructor(t, e) {
886
+ this.W = t, this.bs = e;
887
+ }
888
+ /**
889
+ * Add a number to the set.
890
+ *
891
+ * @param idx The number to add. Must be 0 <= idx < len.
892
+ * @return this.
893
+ */
894
+ add(t) {
895
+ const e = this.W, s = t / e | 0, i = t % e;
896
+ return this.bs[s] |= 1 << i, this;
897
+ }
898
+ /**
899
+ * Delete a number from the set.
900
+ *
901
+ * @param idx The number to delete. Must be 0 <= idx < len.
902
+ * @return this.
903
+ */
904
+ delete(t) {
905
+ const e = this.W, s = t / e | 0, i = t % e;
906
+ return this.bs[s] &= ~(1 << i), this;
907
+ }
908
+ /**
909
+ * Add or delete a number in the set, depending on the second argument.
910
+ *
911
+ * @param idx The number to add or delete. Must be 0 <= idx < len.
912
+ * @param val If true, add the number, otherwise delete.
913
+ * @return val.
914
+ */
915
+ set(t, e) {
916
+ const s = this.W, i = t / s | 0, n = t % s, r = 1 << n;
917
+ return this.bs[i] ^= (-e ^ this.bs[i]) & r, e;
918
+ }
919
+ /**
920
+ * Whether the number is in the set.
921
+ *
922
+ * @param idx The number to test. Must be 0 <= idx < len.
923
+ * @return True if the number is in the set.
924
+ */
925
+ has(t) {
926
+ const e = this.W, s = t / e | 0, i = t % e;
927
+ return !!(this.bs[s] & 1 << i);
928
+ }
929
+ /**
930
+ * Iterate over the numbers that are in the set. The callback is invoked
931
+ * with each number that is set. It is allowed to change the BitSet during
932
+ * iteration. If it deletes a number that has not been iterated over, that
933
+ * number will not show up in a later call. If it adds a number during
934
+ * iteration, that number may or may not show up in a later call.
935
+ *
936
+ * @param fn The function to call for each number.
937
+ * @return this.
938
+ */
939
+ forEach(t) {
940
+ const e = this.W, s = this.bs, i = s.length;
941
+ for (let n = 0; n < i; n++) {
942
+ let r = 0;
943
+ for (; s[n] && r < e; )
944
+ s[n] & 1 << r && t(n * e + r), r++;
945
+ }
946
+ return this;
947
+ }
948
+ }
949
+ class Re extends Ps {
950
+ /**
951
+ * Create a bit set.
952
+ *
953
+ * @param len The length of the bit set, limiting the maximum value that
954
+ * can be stored in it to len - 1.
955
+ */
956
+ constructor(t) {
957
+ const e = new Uint8Array(Math.ceil(t / 8)).fill(0);
958
+ super(8, e);
959
+ }
960
+ }
961
+ function jt(o) {
962
+ return o % 3 === 2 ? o - 2 : o + 1;
963
+ }
964
+ function Et(o) {
965
+ return o % 3 === 0 ? o + 2 : o - 1;
966
+ }
967
+ function Ce(o, t, e, s, i, n, r, a) {
968
+ const f = Ct(o, t, i, n, r, a), c = Ct(e, s, i, n, r, a);
969
+ if (f > 0 && c > 0 || f < 0 && c < 0)
970
+ return !1;
971
+ const u = Ct(i, n, o, t, e, s), h = Ct(r, a, o, t, e, s);
972
+ return u > 0 && h > 0 || u < 0 && h < 0 ? !1 : f === 0 && c === 0 && u === 0 && h === 0 ? !(Math.max(i, r) < Math.min(o, e) || Math.max(o, e) < Math.min(i, r) || Math.max(n, a) < Math.min(t, s) || Math.max(t, s) < Math.min(n, a)) : !0;
973
+ }
974
+ class $s {
975
+ constructor(t) {
976
+ this.del = t;
977
+ }
978
+ }
979
+ const qe = class extends $s {
980
+ /**
981
+ * Make a Constrain.
982
+ *
983
+ * @param del The triangulation output from Delaunator.
984
+ * @param edges If provided, constrain these edges as by constrainAll.
985
+ */
986
+ constructor(t, e) {
987
+ if (!t || typeof t != "object" || !t.triangles || !t.halfedges || !t.coords)
988
+ throw new Error("Expected an object with Delaunator output");
989
+ if (t.triangles.length % 3 || t.halfedges.length !== t.triangles.length || t.coords.length % 2)
990
+ throw new Error("Delaunator output appears inconsistent");
991
+ if (t.triangles.length < 3)
992
+ throw new Error("No edges in triangulation");
993
+ super(t);
994
+ const s = 2 ** 32 - 1, i = t.coords.length >> 1, n = t.triangles.length;
995
+ this.vertMap = new Uint32Array(i).fill(s), this.flips = new Re(n), this.consd = new Re(n);
996
+ for (let r = 0; r < n; r++) {
997
+ const a = t.triangles[r];
998
+ this.vertMap[a] === s && this.updateVert(r);
999
+ }
1000
+ e && this.constrainAll(e);
1001
+ }
1002
+ /**
1003
+ * Constrain the triangulation such that there is an edge between p1 and p2.
1004
+ */
1005
+ constrainOne(t, e) {
1006
+ const { triangles: s, halfedges: i } = this.del, n = this.vertMap[t];
1007
+ let r = n;
1008
+ do {
1009
+ const c = s[r], u = jt(r);
1010
+ if (c === e)
1011
+ return this.protect(r);
1012
+ const h = Et(r), l = s[h];
1013
+ if (l === e)
1014
+ return this.protect(u), u;
1015
+ if (this.intersectSegments(t, e, l, c)) {
1016
+ r = h;
1017
+ break;
1018
+ }
1019
+ r = i[u];
1020
+ } while (r !== -1 && r !== n);
1021
+ let a = r, f = -1;
1022
+ for (; r !== -1; ) {
1023
+ const c = i[r], u = Et(r), h = Et(c), l = jt(c);
1024
+ if (c === -1)
1025
+ throw new Error("Constraining edge exited the hull");
1026
+ if (this.consd.has(r))
1027
+ throw new Error("Edge intersects already constrained edge");
1028
+ if (this.isCollinear(t, e, s[r]) || this.isCollinear(t, e, s[c]))
1029
+ throw new Error("Constraining edge intersects point");
1030
+ if (!this.intersectSegments(
1031
+ s[r],
1032
+ s[c],
1033
+ s[u],
1034
+ s[h]
1035
+ )) {
1036
+ if (f === -1 && (f = r), s[h] === e) {
1037
+ if (r === f)
1038
+ throw new Error("Infinite loop: non-convex quadrilateral");
1039
+ r = f, f = -1;
1040
+ continue;
1041
+ }
1042
+ if (this.intersectSegments(t, e, s[h], s[c]))
1043
+ r = h;
1044
+ else if (this.intersectSegments(t, e, s[l], s[h]))
1045
+ r = l;
1046
+ else if (f === r)
1047
+ throw new Error("Infinite loop: no further intersect after non-convex");
1048
+ continue;
1049
+ }
1050
+ if (this.flipDiagonal(r), this.intersectSegments(t, e, s[u], s[h]) && (f === -1 && (f = u), f === u))
1051
+ throw new Error("Infinite loop: flipped diagonal still intersects");
1052
+ s[h] === e ? (a = h, r = f, f = -1) : this.intersectSegments(t, e, s[l], s[h]) && (r = l);
1053
+ }
1054
+ return this.protect(a), this.delaunify(!0), this.findEdge(t, e);
1055
+ }
1056
+ /**
1057
+ * Fix the Delaunay condition.
1058
+ */
1059
+ delaunify(t = !1) {
1060
+ const { halfedges: e } = this.del, s = this.flips, i = this.consd, n = e.length;
1061
+ do {
1062
+ var r = 0;
1063
+ for (let a = 0; a < n; a++) {
1064
+ if (i.has(a))
1065
+ continue;
1066
+ s.delete(a);
1067
+ const f = e[a];
1068
+ f !== -1 && (s.delete(f), this.isDelaunay(a) || (this.flipDiagonal(a), r++));
1069
+ }
1070
+ } while (t && r > 0);
1071
+ return this;
1072
+ }
1073
+ /**
1074
+ * Call constrainOne on each edge
1075
+ */
1076
+ constrainAll(t) {
1077
+ const e = t.length;
1078
+ for (let s = 0; s < e; s++) {
1079
+ const i = t[s];
1080
+ this.constrainOne(i[0], i[1]);
1081
+ }
1082
+ return this;
1083
+ }
1084
+ /**
1085
+ * Whether an edge is constrained
1086
+ */
1087
+ isConstrained(t) {
1088
+ return this.consd.has(t);
1089
+ }
1090
+ /**
1091
+ * Find the edge that points from p1 -> p2. If there is only an edge from
1092
+ * p2 -> p1 (i.e. it is on the hull), returns the negative id of it.
1093
+ */
1094
+ findEdge(t, e) {
1095
+ const s = this.vertMap[e], { triangles: i, halfedges: n } = this.del;
1096
+ let r = s, a = -1;
1097
+ do {
1098
+ if (i[r] === t)
1099
+ return r;
1100
+ a = jt(r), r = n[a];
1101
+ } while (r !== -1 && r !== s);
1102
+ return i[jt(a)] === t ? -a : 1 / 0;
1103
+ }
1104
+ /**
1105
+ * Mark an edge as constrained, i.e. should not be touched by `delaunify`.
1106
+ */
1107
+ protect(t) {
1108
+ const e = this.del.halfedges[t], s = this.flips, i = this.consd;
1109
+ return s.delete(t), i.add(t), e !== -1 ? (s.delete(e), i.add(e), e) : -t;
1110
+ }
1111
+ /**
1112
+ * Mark an edge as flipped unless constrained.
1113
+ */
1114
+ markFlip(t) {
1115
+ const e = this.del.halfedges, s = this.flips;
1116
+ if (this.consd.has(t))
1117
+ return !1;
1118
+ const i = e[t];
1119
+ return i !== -1 && (s.add(t), s.add(i)), !0;
1120
+ }
1121
+ /**
1122
+ * Flip the edge shared by two triangles.
1123
+ */
1124
+ flipDiagonal(t) {
1125
+ const { triangles: e, halfedges: s } = this.del, i = this.flips, n = this.consd, r = s[t], a = Et(t), f = jt(t), c = Et(r), u = jt(r), h = s[a], l = s[c];
1126
+ if (n.has(t))
1127
+ throw new Error("Trying to flip a constrained edge");
1128
+ return e[t] = e[c], s[t] = l, i.set(t, i.has(c)) || n.set(t, n.has(c)), l !== -1 && (s[l] = t), s[a] = c, e[r] = e[a], s[r] = h, i.set(r, i.has(a)) || n.set(r, n.has(a)), h !== -1 && (s[h] = r), s[c] = a, this.markFlip(t), this.markFlip(f), this.markFlip(r), this.markFlip(u), i.add(a), n.delete(a), i.add(c), n.delete(c), this.updateVert(t), this.updateVert(f), this.updateVert(r), this.updateVert(u), a;
1129
+ }
1130
+ /**
1131
+ * Whether point p1, p2, and p are collinear
1132
+ */
1133
+ isCollinear(t, e, s) {
1134
+ const i = this.del.coords;
1135
+ return Ct(
1136
+ i[t * 2],
1137
+ i[t * 2 + 1],
1138
+ i[e * 2],
1139
+ i[e * 2 + 1],
1140
+ i[s * 2],
1141
+ i[s * 2 + 1]
1142
+ ) === 0;
1143
+ }
1144
+ /**
1145
+ * Whether px is in the circumcircle of the triangle formed by p1, p2, p3
1146
+ */
1147
+ inCircle(t, e, s, i) {
1148
+ const n = this.del.coords;
1149
+ return Is(
1150
+ n[t * 2],
1151
+ n[t * 2 + 1],
1152
+ n[e * 2],
1153
+ n[e * 2 + 1],
1154
+ n[s * 2],
1155
+ n[s * 2 + 1],
1156
+ n[i * 2],
1157
+ n[i * 2 + 1]
1158
+ ) < 0;
1159
+ }
1160
+ /**
1161
+ * Whether the triangles sharing edg conform to the Delaunay condition
1162
+ */
1163
+ isDelaunay(t) {
1164
+ const { triangles: e, halfedges: s } = this.del, i = s[t];
1165
+ if (i === -1)
1166
+ return !0;
1167
+ const n = e[Et(t)], r = e[t], a = e[jt(t)], f = e[Et(i)];
1168
+ return !this.inCircle(n, r, a, f);
1169
+ }
1170
+ /**
1171
+ * Update the vertex -> incoming edge map
1172
+ */
1173
+ updateVert(t) {
1174
+ const { triangles: e, halfedges: s } = this.del, i = this.vertMap, n = e[t];
1175
+ let r = Et(t), a = s[r];
1176
+ for (; a !== -1 && a !== t; )
1177
+ r = Et(a), a = s[r];
1178
+ return i[n] = r, r;
1179
+ }
1180
+ /**
1181
+ * Whether the segments between vertices intersect
1182
+ */
1183
+ intersectSegments(t, e, s, i) {
1184
+ const n = this.del.coords;
1185
+ return t === s || t === i || e === s || e === i ? !1 : Ce(
1186
+ n[t * 2],
1187
+ n[t * 2 + 1],
1188
+ n[e * 2],
1189
+ n[e * 2 + 1],
1190
+ n[s * 2],
1191
+ n[s * 2 + 1],
1192
+ n[i * 2],
1193
+ n[i * 2 + 1]
1194
+ );
1195
+ }
1196
+ };
1197
+ qe.intersectSegments = Ce;
1198
+ let Rs = qe;
1199
+ function te(o, t, e) {
1200
+ if (t || (t = []), typeof o != "object" || o.type !== "FeatureCollection")
1201
+ throw "Argument points must be FeatureCollection";
1202
+ if (!Array.isArray(t)) throw "Argument points must be Array of Array";
1203
+ const s = o.features.map(
1204
+ (f) => f.geometry.coordinates
1205
+ ), i = ss.from(s);
1206
+ let n;
1207
+ const r = [];
1208
+ i.triangles.length !== 0 && t.length !== 0 && (n = new Rs(i), n.constrainAll(t));
1209
+ for (let f = 0; f < i.triangles.length; f += 3)
1210
+ r.push([i.triangles[f], i.triangles[f + 1], i.triangles[f + 2]]);
1211
+ const a = ["a", "b", "c"];
1212
+ return Ot(
1213
+ r.map((f) => {
1214
+ const c = {}, u = f.map((h, l) => {
1215
+ const p = o.features[h], y = p.geometry.coordinates, g = [y[0], y[1]];
1216
+ return y.length === 3 ? g[2] = y[2] : c[a[l]] = p.properties[e], g;
1217
+ });
1218
+ return u[3] = u[0], me([u], c);
1219
+ })
1220
+ );
1221
+ }
1222
+ function Ns(o) {
1223
+ const e = new Us(o).findSegmentIntersections();
1224
+ return Ge(e).reduce(
1225
+ (s, i, n, r) => Array.isArray(s) || (s || (s = {}), s[`${i.x}:${i.y}`] = i, n != r.length - 1) ? s : Object.keys(s).map((a) => Jt([s[a].x, s[a].y])),
1226
+ {}
1227
+ );
1228
+ }
1229
+ class Us {
1230
+ /**
1231
+ * 線分群からArcCollectionを初期化
1232
+ * @param coords - 線分群の座標配列
1233
+ */
1234
+ constructor(t) {
1235
+ /**
1236
+ * 座標データの配列
1237
+ * _xx, _yy: Float64Array形式で座標を保持
1238
+ * _ii: 各線分の開始インデックス
1239
+ * _nn: 各線分の頂点数
1240
+ */
1241
+ rt(this, "_xx");
1242
+ rt(this, "_yy");
1243
+ // coordinates data
1244
+ rt(this, "_ii");
1245
+ rt(this, "_nn");
1246
+ // indexes, sizes
1247
+ rt(this, "_zz");
1248
+ rt(this, "_zlimit", 0);
1249
+ // simplification
1250
+ rt(this, "_bb");
1251
+ rt(this, "_allBounds");
1252
+ // bounding boxes
1253
+ rt(this, "_arcIter");
1254
+ rt(this, "_filteredArcIter");
1255
+ // path iterators
1256
+ rt(this, "buf");
1257
+ this.initArcs(t);
1258
+ }
1259
+ initArcs(t) {
1260
+ const e = [], s = [], i = t.map((n) => {
1261
+ const r = n ? n.length : 0;
1262
+ for (let a = 0; a < r; a++)
1263
+ e.push(n[a][0]), s.push(n[a][1]);
1264
+ return r;
1265
+ });
1266
+ this.initXYData(i, e, s);
1267
+ }
1268
+ initXYData(t, e, s) {
1269
+ const i = t.length;
1270
+ this._xx = new Float64Array(e), this._yy = new Float64Array(s), this._nn = new Uint32Array(t), this._zz = null, this._zlimit = 0, this._filteredArcIter = null, this._ii = new Uint32Array(i);
1271
+ let n = 0;
1272
+ for (let r = 0; r < i; r++)
1273
+ this._ii[r] = n, n += t[r];
1274
+ (n != this._xx.length || this._xx.length != this._yy.length) && be("ArcCollection#initXYData() Counting error"), this.initBounds(), this._arcIter = new en(this._xx, this._yy);
1275
+ }
1276
+ initBounds() {
1277
+ const t = this.calcArcBounds_(this._xx, this._yy, this._nn);
1278
+ this._bb = t.bb, this._allBounds = t.bounds;
1279
+ }
1280
+ /**
1281
+ * データの境界を計算
1282
+ * @returns バウンディングボックス情報
1283
+ */
1284
+ calcArcBounds_(t, e, s) {
1285
+ const i = s.length, n = new Float64Array(i * 4), r = new ae();
1286
+ let a = 0, f, c, u;
1287
+ for (let h = 0; h < i; h++)
1288
+ f = s[h], f > 0 && (c = h * 4, u = sn(t, e, a, f), n[c++] = u[0], n[c++] = u[1], n[c++] = u[2], n[c] = u[3], a += f, r.mergeBounds(u));
1289
+ return {
1290
+ bb: n,
1291
+ bounds: r
1292
+ };
1293
+ }
1294
+ getBounds() {
1295
+ return this._allBounds.clone();
1296
+ }
1297
+ // @cb function(i, j, xx, yy)
1298
+ forEachSegment(t) {
1299
+ let e = 0;
1300
+ for (let s = 0, i = this.size(); s < i; s++)
1301
+ e += this.forEachArcSegment(s, t);
1302
+ return e;
1303
+ }
1304
+ size() {
1305
+ return this._ii && this._ii.length || 0;
1306
+ }
1307
+ // @cb function(i, j, xx, yy)
1308
+ forEachArcSegment(t, e) {
1309
+ const s = t >= 0, i = s ? t : ~t, n = this.getRetainedInterval(), r = this._nn[i], a = s ? 1 : -1;
1310
+ let f = s ? this._ii[i] : this._ii[i] + r - 1, c = f, u = 0;
1311
+ for (let h = 1; h < r; h++)
1312
+ c += a, (n === 0 || this._zz[c] >= n) && (e(f, c, this._xx, this._yy), f = c, u++);
1313
+ return u;
1314
+ }
1315
+ getRetainedInterval() {
1316
+ return this._zlimit;
1317
+ }
1318
+ // Give access to raw data arrays...
1319
+ getVertexData() {
1320
+ return {
1321
+ xx: this._xx,
1322
+ yy: this._yy,
1323
+ zz: this._zz,
1324
+ bb: this._bb,
1325
+ nn: this._nn,
1326
+ ii: this._ii
1327
+ };
1328
+ }
1329
+ getUint32Array(t) {
1330
+ const e = t * 4;
1331
+ return (!this.buf || this.buf.byteLength < e) && (this.buf = new ArrayBuffer(e)), new Uint32Array(this.buf, 0, t);
1332
+ }
1333
+ // Return average magnitudes of dx, dy (with simplification)
1334
+ getAvgSegment2() {
1335
+ let t = 0, e = 0;
1336
+ const s = this.forEachSegment(
1337
+ (i, n, r, a) => {
1338
+ t += Math.abs(r[i] - r[n]), e += Math.abs(a[i] - a[n]);
1339
+ }
1340
+ );
1341
+ return [t / s || 0, e / s || 0];
1342
+ }
1343
+ /**
1344
+ * 交差判定のためのストライプ数を計算
1345
+ * 線分の平均長さに基づいて最適な分割数を決定
1346
+ */
1347
+ calcSegmentIntersectionStripeCount() {
1348
+ const t = this.getBounds().height(), e = this.getAvgSegment2()[1];
1349
+ let s = 1;
1350
+ return e > 0 && t > 0 && (s = Math.ceil(t / e / 20)), s || 1;
1351
+ }
1352
+ /**
1353
+ * 線分の交差を検出
1354
+ * ストライプ分割による効率的な判定を実装
1355
+ *
1356
+ * @returns 検出された交差点の配列
1357
+ */
1358
+ findSegmentIntersections() {
1359
+ const t = this.getBounds(), e = t.ymin, s = t.ymax - e, i = this.calcSegmentIntersectionStripeCount(), n = new Uint32Array(i), r = i > 1 ? (g) => Math.floor((i - 1) * (g - e) / s) : () => 0;
1360
+ let a, f;
1361
+ this.forEachSegment(
1362
+ (g, b, w, S) => {
1363
+ let _ = r(S[g]);
1364
+ const v = r(S[b]);
1365
+ for (; n[_] = n[_] + 2, _ != v; )
1366
+ _ += v > _ ? 1 : -1;
1367
+ }
1368
+ );
1369
+ const c = this.getUint32Array(Fs(n));
1370
+ let u = 0;
1371
+ const h = [];
1372
+ js(n, (g) => {
1373
+ const b = u;
1374
+ u += g, h.push(c.subarray(b, u));
1375
+ }), Ls(n, 0), this.forEachSegment(
1376
+ (g, b, w, S) => {
1377
+ let _ = r(S[g]);
1378
+ const v = r(S[b]);
1379
+ let T, I;
1380
+ for (; T = n[_], n[_] = T + 2, I = h[_], I[T] = g, I[T + 1] = b, _ != v; )
1381
+ _ += v > _ ? 1 : -1;
1382
+ }
1383
+ );
1384
+ const l = this.getVertexData(), p = [];
1385
+ let y;
1386
+ for (a = 0; a < i; a++)
1387
+ for (y = Vs(h[a], l.xx, l.yy), f = 0; f < y.length; f++)
1388
+ p.push(y[f]);
1389
+ return Ge(p);
1390
+ }
1391
+ }
1392
+ function be(...o) {
1393
+ const t = o.join(" ");
1394
+ throw new Error(t);
1395
+ }
1396
+ function ye(o) {
1397
+ return o ? Ds(o) ? !0 : Bs(o) ? !1 : o.length === 0 ? !0 : o.length > 0 : !1;
1398
+ }
1399
+ function Bs(o) {
1400
+ return o != null && o.toString === String.prototype.toString;
1401
+ }
1402
+ function Ds(o) {
1403
+ return Array.isArray(o);
1404
+ }
1405
+ function Fs(o, t) {
1406
+ ye(o) || be("utils.sum() expects an array, received:", o);
1407
+ let e = 0, s;
1408
+ for (let i = 0, n = o.length; i < n; i++)
1409
+ s = o[i], s && (e += s);
1410
+ return e;
1411
+ }
1412
+ function js(o, t, e) {
1413
+ if (!ye(o))
1414
+ throw new Error(`#forEach() takes an array-like argument. ${o}`);
1415
+ for (let s = 0, i = o.length; s < i; s++)
1416
+ t.call(e, o[s], s);
1417
+ }
1418
+ function Ls(o, t) {
1419
+ for (let e = 0, s = o.length; e < s; e++)
1420
+ o[e] = t;
1421
+ return o;
1422
+ }
1423
+ function Vs(o, t, e) {
1424
+ const s = o.length - 2, i = [];
1425
+ let n, r, a, f, c, u, h, l, p, y, g, b, w, S, _, v, T;
1426
+ for (Ks(t, o), v = 0; v < s; ) {
1427
+ for (n = o[v], r = o[v + 1], c = t[n], u = t[r], p = e[n], y = e[r], T = v; T < s && (T += 2, a = o[T], h = t[a], !(u < h)); ) {
1428
+ if (g = e[a], f = o[T + 1], l = t[f], b = e[f], p >= g) {
1429
+ if (p > b && y > g && y > b) continue;
1430
+ } else if (p < b && y < g && y < b) continue;
1431
+ n == a || n == f || r == a || r == f || (w = Ws(
1432
+ c,
1433
+ p,
1434
+ u,
1435
+ y,
1436
+ h,
1437
+ g,
1438
+ l,
1439
+ b
1440
+ ), w && (S = [n, r], _ = [a, f], i.push(Ue(w, S, _, t, e)), w.length == 4 && i.push(
1441
+ Ue(w.slice(2), S, _, t, e)
1442
+ )));
1443
+ }
1444
+ v += 2;
1445
+ }
1446
+ return i;
1447
+ }
1448
+ function Ws(o, t, e, s, i, n, r, a) {
1449
+ const f = zs(o, t, e, s, i, n, r, a);
1450
+ let c = null;
1451
+ return f && (c = Xs(o, t, e, s, i, n, r, a), c ? Gs(o, t, e, s, i, n, r, a) && (c = null) : c = Hs(o, t, e, s, i, n, r, a)), c;
1452
+ }
1453
+ function zs(o, t, e, s, i, n, r, a) {
1454
+ return qt(o, t, e, s, i, n) * qt(o, t, e, s, r, a) <= 0 && qt(i, n, r, a, o, t) * qt(i, n, r, a, e, s) <= 0;
1455
+ }
1456
+ function qt(o, t, e, s, i, n) {
1457
+ return Je(o - i, t - n, e - i, s - n);
1458
+ }
1459
+ function Je(o, t, e, s) {
1460
+ return o * s - t * e;
1461
+ }
1462
+ function Xs(o, t, e, s, i, n, r, a) {
1463
+ let f = ee(o, t, e, s, i, n, r, a), c;
1464
+ return f && (c = Cs(f[0], f[1], o, t, e, s, i, n, r, a), c == 1 ? f = ee(e, s, o, t, i, n, r, a) : c == 2 ? f = ee(i, n, r, a, o, t, e, s) : c == 3 && (f = ee(r, a, i, n, o, t, e, s))), f && Js(f, o, t, e, s, i, n, r, a), f;
1465
+ }
1466
+ function ee(o, t, e, s, i, n, r, a) {
1467
+ const f = Je(e - o, s - t, r - i, a - n), c = 1e-18;
1468
+ let u;
1469
+ if (f === 0) return null;
1470
+ const h = qt(i, n, r, a, o, t) / f;
1471
+ return f <= c && f >= -c ? u = Ys(o, t, e, s, i, n, r, a) : u = [o + h * (e - o), t + h * (s - t)], u;
1472
+ }
1473
+ function Ys(o, t, e, s, i, n, r, a) {
1474
+ let f = null;
1475
+ return !vt(o, i, r) && !vt(t, n, a) ? f = [o, t] : !vt(e, i, r) && !vt(s, n, a) ? f = [e, s] : !vt(i, o, e) && !vt(n, t, s) ? f = [i, n] : !vt(r, o, e) && !vt(a, t, s) && (f = [r, a]), f;
1476
+ }
1477
+ function vt(o, t, e) {
1478
+ let s;
1479
+ return t < e ? s = o < t || o > e : t > e ? s = o > t || o < e : s = o != t, s;
1480
+ }
1481
+ function Cs(o, t, ...e) {
1482
+ let s = -1, i = 1 / 0, n;
1483
+ for (let r = 0, a = 0, f = e.length; a < f; r++, a += 2)
1484
+ n = qs(o, t, e[a], e[a + 1]), n < i && (i = n, s = r);
1485
+ return s;
1486
+ }
1487
+ function qs(o, t, e, s) {
1488
+ const i = o - e, n = t - s;
1489
+ return i * i + n * n;
1490
+ }
1491
+ function Js(o, t, e, s, i, n, r, a, f) {
1492
+ let c = o[0], u = o[1];
1493
+ c = se(c, t, s), c = se(c, n, a), u = se(u, e, i), u = se(u, r, f), o[0] = c, o[1] = u;
1494
+ }
1495
+ function se(o, t, e) {
1496
+ let s;
1497
+ return vt(o, t, e) && (s = Math.abs(o - t) < Math.abs(o - e) ? t : e, o = s), o;
1498
+ }
1499
+ function Hs(o, t, e, s, i, n, r, a) {
1500
+ const f = Math.min(o, e, i, r), c = Math.max(o, e, i, r), u = Math.min(t, s, n, a), h = Math.max(t, s, n, a), l = h - u > c - f;
1501
+ let p = [];
1502
+ return (l ? Nt(t, u, h) : Nt(o, f, c)) && p.push(o, t), (l ? Nt(s, u, h) : Nt(e, f, c)) && p.push(e, s), (l ? Nt(n, u, h) : Nt(i, f, c)) && p.push(i, n), (l ? Nt(a, u, h) : Nt(r, f, c)) && p.push(r, a), (p.length != 2 && p.length != 4 || p.length == 4 && p[0] == p[2] && p[1] == p[3]) && (p = null), p;
1503
+ }
1504
+ function Gs(o, t, e, s, i, n, r, a) {
1505
+ return o == i && t == n || o == r && t == a || e == i && s == n || e == r && s == a;
1506
+ }
1507
+ function Nt(o, t, e) {
1508
+ return o > t && o < e;
1509
+ }
1510
+ function Ks(o, t) {
1511
+ Qs(o, t), He(o, t, 0, t.length - 2);
1512
+ }
1513
+ function Qs(o, t) {
1514
+ for (let e = 0, s = t.length; e < s; e += 2)
1515
+ o[t[e]] > o[t[e + 1]] && Zs(t, e, e + 1);
1516
+ }
1517
+ function Zs(o, t, e) {
1518
+ const s = o[t];
1519
+ o[t] = o[e], o[e] = s;
1520
+ }
1521
+ function He(o, t, e, s) {
1522
+ let i = e, n = s, r, a;
1523
+ for (; i < s; ) {
1524
+ for (r = o[t[e + s >> 2 << 1]]; i <= n; ) {
1525
+ for (; o[t[i]] < r; ) i += 2;
1526
+ for (; o[t[n]] > r; ) n -= 2;
1527
+ i <= n && (a = t[i], t[i] = t[n], t[n] = a, a = t[i + 1], t[i + 1] = t[n + 1], t[n + 1] = a, i += 2, n -= 2);
1528
+ }
1529
+ if (n - e < 40 ? Ne(o, t, e, n) : He(o, t, e, n), s - i < 40) {
1530
+ Ne(o, t, i, s);
1531
+ return;
1532
+ }
1533
+ e = i, n = s;
1534
+ }
1535
+ }
1536
+ function Ne(o, t, e, s) {
1537
+ let i, n;
1538
+ for (let r = e + 2; r <= s; r += 2) {
1539
+ i = t[r], n = t[r + 1];
1540
+ let a;
1541
+ for (a = r - 2; a >= e && o[i] < o[t[a]]; a -= 2)
1542
+ t[a + 2] = t[a], t[a + 3] = t[a + 1];
1543
+ t[a + 2] = i, t[a + 3] = n;
1544
+ }
1545
+ }
1546
+ function Ue(o, t, e, s, i) {
1547
+ const n = o[0], r = o[1];
1548
+ t = Be(n, r, t[0], t[1], s, i), e = Be(n, r, e[0], e[1], s, i);
1549
+ const a = t[0] < e[0] ? t : e, f = a == t ? e : t;
1550
+ return { x: n, y: r, a, b: f };
1551
+ }
1552
+ function Be(o, t, e, s, i, n) {
1553
+ let r = e < s ? e : s, a = r === e ? s : e;
1554
+ return i[r] == o && n[r] == t ? a = r : i[a] == o && n[a] == t && (r = a), [r, a];
1555
+ }
1556
+ function Ge(o) {
1557
+ const t = {};
1558
+ return o.filter((e) => {
1559
+ const s = tn(e);
1560
+ return s in t ? !1 : (t[s] = !0, !0);
1561
+ });
1562
+ }
1563
+ function tn(o) {
1564
+ return `${o.a.join(",")};${o.b.join(",")}`;
1565
+ }
1566
+ class en {
1567
+ constructor(t, e) {
1568
+ rt(this, "_i", 0);
1569
+ rt(this, "_n", 0);
1570
+ rt(this, "_inc", 1);
1571
+ rt(this, "_xx");
1572
+ rt(this, "_yy");
1573
+ rt(this, "i", 0);
1574
+ rt(this, "x", 0);
1575
+ rt(this, "y", 0);
1576
+ this._xx = t, this._yy = e;
1577
+ }
1578
+ }
1579
+ function sn(o, t, e, s) {
1580
+ let i = e | 0;
1581
+ const n = isNaN(s) ? o.length - i : s + i;
1582
+ let r, a, f, c, u, h;
1583
+ if (n > 0)
1584
+ f = u = o[i], c = h = t[i];
1585
+ else return [void 0, void 0, void 0, void 0];
1586
+ for (i++; i < n; i++)
1587
+ r = o[i], a = t[i], r < f && (f = r), r > u && (u = r), a < c && (c = a), a > h && (h = a);
1588
+ return [f, c, u, h];
1589
+ }
1590
+ class ae {
1591
+ constructor(...t) {
1592
+ rt(this, "xmin");
1593
+ rt(this, "ymin");
1594
+ rt(this, "xmax");
1595
+ rt(this, "ymax");
1596
+ t.length > 0 && this.setBounds(t);
1597
+ }
1598
+ // Return a bounding box with the same extent as this one.
1599
+ cloneBounds() {
1600
+ return this.clone();
1601
+ }
1602
+ clone() {
1603
+ return new ae(this.xmin, this.ymin, this.xmax, this.ymax);
1604
+ }
1605
+ width() {
1606
+ return this.xmax - this.xmin || 0;
1607
+ }
1608
+ height() {
1609
+ return this.ymax - this.ymin || 0;
1610
+ }
1611
+ setBounds(t, e, s, i) {
1612
+ return arguments.length == 1 && (ye(t) ? (e = t[1], s = t[2], i = t[3], t = t[0]) : (e = t.ymin, s = t.xmax, i = t.ymax, t = t.xmin)), this.xmin = t, this.ymin = e, this.xmax = s, this.ymax = i, (t > s || e > i) && this.update(), this;
1613
+ }
1614
+ update() {
1615
+ let t;
1616
+ this.xmin > this.xmax && (t = this.xmin, this.xmin = this.xmax, this.xmax = t), this.ymin > this.ymax && (t = this.ymin, this.ymin = this.ymax, this.ymax = t);
1617
+ }
1618
+ mergeBounds(t, ...e) {
1619
+ let s, i, n, r;
1620
+ return t instanceof ae ? (s = t.xmin, i = t.ymin, n = t.xmax, r = t.ymax) : e.length == 3 ? (s = t, i = e[0], n = e[1], r = e[2]) : t.length == 4 ? (s = t[0], i = t[1], n = t[2], r = t[3]) : be("Bounds#mergeBounds() invalid argument:", t), this.xmin === void 0 ? this.setBounds(s, i, n, r) : (s < this.xmin && (this.xmin = s), i < this.ymin && (this.ymin = i), n > this.xmax && (this.xmax = n), r > this.ymax && (this.ymax = r)), this;
1621
+ }
1622
+ }
1623
+ function De(o) {
1624
+ const t = ["a", "b", "c"].map(
1625
+ (e) => o.properties[e].index
1626
+ );
1627
+ return [
1628
+ [0, 1],
1629
+ [0, 2],
1630
+ [1, 2],
1631
+ [0, 1, 2]
1632
+ ].map(
1633
+ (e) => e.map((s) => t[s]).sort().join("-")
1634
+ ).sort();
1635
+ }
1636
+ function nn(o, t, e) {
1637
+ const s = De(t.forw), i = De(t.bakw);
1638
+ if (JSON.stringify(s) != JSON.stringify(i))
1639
+ throw `${JSON.stringify(t, null, 2)}
1640
+ ${JSON.stringify(
1641
+ s
1642
+ )}
1643
+ ${JSON.stringify(i)}`;
1644
+ for (let n = 0; n < s.length; n++) {
1645
+ const r = s[n];
1646
+ o[r] || (o[r] = []), o[r].push(t);
1647
+ }
1648
+ e && (e.forw.features.push(t.forw), e.bakw.features.push(t.bakw));
1649
+ }
1650
+ function ne(o, t, e) {
1651
+ return Jt(o, { target: { geom: t, index: e } });
1652
+ }
1653
+ function ie(o) {
1654
+ return Jt(o.properties.target.geom, {
1655
+ target: {
1656
+ geom: o.geometry.coordinates,
1657
+ index: o.properties.target.index
1658
+ }
1659
+ });
1660
+ }
1661
+ function Fe(o, t) {
1662
+ const e = t.geometry.coordinates;
1663
+ return [0, 1, 2, 3].map((s) => {
1664
+ const i = (s + 1) % 4, n = o[s], r = o[i], a = n.geometry.coordinates, f = Math.atan2(
1665
+ a[0] - e[0],
1666
+ a[1] - e[1]
1667
+ ), c = [t, n, r, t].map(
1668
+ (l) => l.geometry.coordinates
1669
+ ), u = {
1670
+ a: {
1671
+ geom: t.properties.target.geom,
1672
+ index: t.properties.target.index
1673
+ },
1674
+ b: {
1675
+ geom: n.properties.target.geom,
1676
+ index: n.properties.target.index
1677
+ },
1678
+ c: {
1679
+ geom: r.properties.target.geom,
1680
+ index: r.properties.target.index
1681
+ }
1682
+ }, h = Ot([me([c], u)]);
1683
+ return [f, h];
1684
+ }).reduce(
1685
+ (s, i) => (s[0].push(i[0]), s[1].push(i[1]), s),
1686
+ [[], []]
1687
+ );
1688
+ }
1689
+ class ht extends xs {
1690
+ /**
1691
+ * Tinクラスのインスタンスを生成します
1692
+ * @param options - 初期化オプション
1693
+ */
1694
+ constructor(e = {}) {
1695
+ super();
1696
+ rt(this, "importance");
1697
+ rt(this, "priority");
1698
+ rt(this, "pointsSet");
1699
+ e.bounds ? this.setBounds(e.bounds) : (this.setWh(e.wh), this.vertexMode = e.vertexMode || ht.VERTEX_PLAIN), this.strictMode = e.strictMode || ht.MODE_AUTO, this.yaxisMode = e.yaxisMode || ht.YAXIS_INVERT, this.importance = e.importance || 0, this.priority = e.priority || 0, this.stateFull = e.stateFull || !1, e.points && this.setPoints(e.points), e.edges && this.setEdges(e.edges);
1700
+ }
1701
+ /**
1702
+ * フォーマットバージョンを取得します
1703
+ */
1704
+ getFormatVersion() {
1705
+ return oe;
1706
+ }
1707
+ /**
1708
+ * 制御点(GCP: Ground Control Points)を設定します
1709
+ */
1710
+ setPoints(e) {
1711
+ this.yaxisMode === ht.YAXIS_FOLLOW && (e = e.map((s) => [
1712
+ s[0],
1713
+ [s[1][0], -1 * s[1][1]]
1714
+ ])), this.points = e, this.tins = void 0, this.indexedTins = void 0;
1715
+ }
1716
+ /**
1717
+ * エッジ(制約線)を設定します
1718
+ */
1719
+ setEdges(e = []) {
1720
+ this.edges = We(e), this.edgeNodes = void 0, this.tins = void 0, this.indexedTins = void 0;
1721
+ }
1722
+ /**
1723
+ * 境界ポリゴンを設定します
1724
+ */
1725
+ setBounds(e) {
1726
+ this.bounds = e;
1727
+ let s = e[0][0], i = s, n = e[0][1], r = n;
1728
+ const a = [e[0]];
1729
+ for (let f = 1; f < e.length; f++) {
1730
+ const c = e[f];
1731
+ c[0] < s && (s = c[0]), c[0] > i && (i = c[0]), c[1] < n && (n = c[1]), c[1] > r && (r = c[1]), a.push(c);
1732
+ }
1733
+ a.push(e[0]), this.boundsPolygon = me([a]), this.xy = [s, n], this.wh = [i - s, r - n], this.vertexMode = ht.VERTEX_PLAIN, this.tins = void 0, this.indexedTins = void 0;
1734
+ }
1735
+ /**
1736
+ * 現在の設定を永続化可能な形式にコンパイルします
1737
+ */
1738
+ getCompiled() {
1739
+ var i;
1740
+ const e = {};
1741
+ e.version = oe, e.points = this.points, e.weight_buffer = this.pointsWeightBuffer, e.centroid_point = [
1742
+ this.centroid.forw.geometry.coordinates,
1743
+ this.centroid.forw.properties.target.geom
1744
+ ], e.vertices_params = [
1745
+ this.vertices_params.forw[0],
1746
+ this.vertices_params.bakw[0]
1747
+ ], e.vertices_points = [];
1748
+ const s = this.vertices_params.forw[1];
1749
+ return s && [0, 1, 2, 3].map((n) => {
1750
+ const r = s[n].features[0], a = r.geometry.coordinates[0][1], f = r.properties.b.geom;
1751
+ e.vertices_points[n] = [a, f];
1752
+ }), e.strict_status = this.strict_status, e.tins_points = [[]], this.tins.forw.features.map((n) => {
1753
+ e.tins_points[0].push(
1754
+ ["a", "b", "c"].map((r) => n.properties[r].index)
1755
+ );
1756
+ }), this.strict_status === ht.STATUS_LOOSE ? (e.tins_points[1] = [], this.tins.bakw.features.map((n) => {
1757
+ e.tins_points[1].push(
1758
+ ["a", "b", "c"].map((r) => n.properties[r].index)
1759
+ );
1760
+ })) : this.strict_status === ht.STATUS_ERROR && ((i = this.kinks) != null && i.bakw) && (e.kinks_points = this.kinks.bakw.features.map(
1761
+ (n) => n.geometry.coordinates
1762
+ )), e.yaxisMode = this.yaxisMode, e.vertexMode = this.vertexMode, e.strictMode = this.strictMode, this.bounds ? (e.bounds = this.bounds, e.boundsPolygon = this.boundsPolygon, e.xy = this.xy, e.wh = this.wh) : e.wh = this.wh, e.edges = this.edges, e.edgeNodes = this.edgeNodes, e;
1763
+ }
1764
+ /**
1765
+ * 幅と高さを設定します
1766
+ */
1767
+ setWh(e) {
1768
+ this.wh = e || [100, 100], this.xy = [0, 0], this.bounds = void 0, this.boundsPolygon = void 0, this.tins = void 0, this.indexedTins = void 0;
1769
+ }
1770
+ /**
1771
+ * 頂点モードを設定します
1772
+ */
1773
+ setVertexMode(e) {
1774
+ this.vertexMode = e, this.tins = void 0, this.indexedTins = void 0;
1775
+ }
1776
+ /**
1777
+ * 厳密性モードを設定します
1778
+ */
1779
+ setStrictMode(e) {
1780
+ this.strictMode = e, this.tins = void 0, this.indexedTins = void 0;
1781
+ }
1782
+ /**
1783
+ * 厳密なTINを計算します
1784
+ */
1785
+ calcurateStrictTin() {
1786
+ const e = this.tins.forw.features.map((n) => ms(n));
1787
+ this.tins.bakw = Ot(e);
1788
+ const s = {};
1789
+ this.tins.forw.features.forEach((n, r) => {
1790
+ const a = this.tins.bakw.features[r];
1791
+ nn(s, { forw: n, bakw: a });
1792
+ });
1793
+ const i = ["forw", "bakw"].map((n) => {
1794
+ const r = this.tins[n].features.map(
1795
+ (a) => a.geometry.coordinates[0]
1796
+ );
1797
+ return Ns(r);
1798
+ });
1799
+ i[0].length === 0 && i[1].length === 0 ? (this.strict_status = ht.STATUS_STRICT, delete this.kinks) : (this.strict_status = ht.STATUS_ERROR, this.kinks = {}, i[0].length > 0 && (this.kinks.forw = Ot(i[0])), i[1].length > 0 && (this.kinks.bakw = Ot(i[1])));
1800
+ }
1801
+ /**
1802
+ * 点群セットを生成します
1803
+ */
1804
+ generatePointsSet() {
1805
+ const e = { forw: [], bakw: [] };
1806
+ for (let n = 0; n < this.points.length; n++) {
1807
+ const r = this.points[n][0], a = this.points[n][1], f = ne(r, a, n);
1808
+ e.forw.push(f), e.bakw.push(ie(f));
1809
+ }
1810
+ const s = [];
1811
+ let i = 0;
1812
+ this.edgeNodes = [], this.edges || (this.edges = []);
1813
+ for (let n = 0; n < this.edges.length; n++) {
1814
+ const r = this.edges[n][2], a = Object.assign([], this.edges[n][0]), f = Object.assign([], this.edges[n][1]);
1815
+ if (a.length === 0 && f.length === 0) {
1816
+ s.push(r);
1817
+ continue;
1818
+ }
1819
+ a.unshift(this.points[r[0]][0]), a.push(this.points[r[1]][0]), f.unshift(this.points[r[0]][1]), f.push(this.points[r[1]][1]);
1820
+ const c = [a, f].map((u) => {
1821
+ const h = u.map((p, y, g) => {
1822
+ if (y === 0) return 0;
1823
+ const b = g[y - 1];
1824
+ return Math.sqrt(
1825
+ Math.pow(p[0] - b[0], 2) + Math.pow(p[1] - b[1], 2)
1826
+ );
1827
+ }), l = h.reduce((p, y, g) => g === 0 ? [0] : (p.push(p[g - 1] + y), p), []);
1828
+ return l.map((p, y, g) => {
1829
+ const b = p / g[g.length - 1];
1830
+ return [u[y], h[y], l[y], b];
1831
+ });
1832
+ });
1833
+ c.map((u, h) => {
1834
+ const l = c[h ? 0 : 1];
1835
+ return u.filter((p, y) => !(y === 0 || y === u.length - 1 || p[4] === "handled")).map((p) => {
1836
+ const y = p[0], g = p[3], b = l.reduce((w, S, _, v) => {
1837
+ if (w) return w;
1838
+ const T = v[_ + 1];
1839
+ if (S[3] === g)
1840
+ return S[4] = "handled", [S];
1841
+ if (S[3] < g && T && T[3] > g)
1842
+ return [S, T];
1843
+ }, void 0);
1844
+ if (b && b.length === 1)
1845
+ return h === 0 ? [y, b[0][0], g] : [b[0][0], y, g];
1846
+ if (b && b.length === 2) {
1847
+ const w = b[0], S = b[1], _ = (g - w[3]) / (S[3] - w[3]), v = [
1848
+ (S[0][0] - w[0][0]) * _ + w[0][0],
1849
+ (S[0][1] - w[0][1]) * _ + w[0][1]
1850
+ ];
1851
+ return h === 0 ? [y, v, g] : [v, y, g];
1852
+ }
1853
+ return [];
1854
+ });
1855
+ }).reduce((u, h) => u.concat(h), []).sort((u, h) => u[2] < h[2] ? -1 : 1).map((u, h, l) => {
1856
+ this.edgeNodes[i] = [u[0], u[1]];
1857
+ const p = ne(u[0], u[1], `e${i}`);
1858
+ i++, e.forw.push(p), e.bakw.push(ie(p)), h === 0 ? s.push([r[0], e.forw.length - 1]) : s.push([e.forw.length - 2, e.forw.length - 1]), h === l.length - 1 && s.push([e.forw.length - 1, r[1]]);
1859
+ });
1860
+ }
1861
+ return {
1862
+ forw: e.forw,
1863
+ bakw: e.bakw,
1864
+ edges: s
1865
+ };
1866
+ }
1867
+ /**
1868
+ * 入力データの検証と初期データの準備
1869
+ */
1870
+ validateAndPrepareInputs() {
1871
+ const e = this.xy[0] - 0.05 * this.wh[0], s = this.xy[0] + 1.05 * this.wh[0], i = this.xy[1] - 0.05 * this.wh[1], n = this.xy[1] + 1.05 * this.wh[1];
1872
+ if (!this.points.reduce((f, c) => f && (this.bounds ? Ze(c[0], this.boundsPolygon) : c[0][0] >= e && c[0][0] <= s && c[0][1] >= i && c[0][1] <= n), !0))
1873
+ throw "SOME POINTS OUTSIDE";
1874
+ let a = [];
1875
+ return this.wh && (a = [[e, i], [s, i], [e, n], [s, n]]), {
1876
+ pointsSet: this.generatePointsSet(),
1877
+ bbox: a,
1878
+ minx: e,
1879
+ maxx: s,
1880
+ miny: i,
1881
+ maxy: n
1882
+ };
1883
+ }
1884
+ /**
1885
+ * TINネットワークを更新し、座標変換の準備を行います
1886
+ */
1887
+ updateTin() {
1888
+ let e = this.strictMode;
1889
+ e !== ht.MODE_STRICT && e !== ht.MODE_LOOSE && (e = ht.MODE_AUTO);
1890
+ const { pointsSet: s, bbox: i, minx: n, maxx: r, miny: a, maxy: f } = this.validateAndPrepareInputs(), c = {
1891
+ forw: Ot(s.forw),
1892
+ bakw: Ot(s.bakw)
1893
+ }, u = te(c.forw, s.edges, "target"), h = te(c.bakw, s.edges, "target");
1894
+ if (u.features.length === 0 || h.features.length === 0)
1895
+ throw "TOO LINEAR1";
1896
+ const l = ts(c.forw), p = ke(c.forw);
1897
+ if (!p) throw "TOO LINEAR2";
1898
+ const y = {}, g = p.geometry.coordinates[0];
1899
+ let b;
1900
+ try {
1901
+ b = g.map((N) => ({
1902
+ forw: N,
1903
+ bakw: re(Jt(N), u)
1904
+ })), b.forEach((N) => {
1905
+ y[`${N.forw[0]}:${N.forw[1]}`] = N;
1906
+ });
1907
+ } catch {
1908
+ throw "TOO LINEAR2";
1909
+ }
1910
+ const w = ke(c.bakw);
1911
+ if (!w) throw "TOO LINEAR2";
1912
+ const S = w.geometry.coordinates[0];
1913
+ try {
1914
+ b = S.map((N) => ({
1915
+ bakw: N,
1916
+ forw: re(Jt(N), h)
1917
+ })), b.forEach((N) => {
1918
+ y[`${N.forw[0]}:${N.forw[1]}`] = N;
1919
+ });
1920
+ } catch {
1921
+ throw "TOO LINEAR2";
1922
+ }
1923
+ const _ = {
1924
+ forw: l.geometry.coordinates,
1925
+ bakw: re(l, u)
1926
+ }, v = ne(_.forw, _.bakw, "c");
1927
+ this.centroid = {
1928
+ forw: v,
1929
+ bakw: ie(v)
1930
+ };
1931
+ const T = this.vertexMode === ht.VERTEX_BIRDEYE ? this.calculateBirdeyeVertices(y, _, i, n, r, a, f) : this.calculatePlainVertices(y, _, i, n, r, a, f), I = { forw: [], bakw: [] };
1932
+ for (let N = 0; N < T.length; N++) {
1933
+ const V = T[N].forw, z = T[N].bakw, G = ne(V, z, `b${N}`), tt = ie(G);
1934
+ s.forw.push(G), s.bakw.push(tt), I.forw.push(G), I.bakw.push(tt);
1935
+ }
1936
+ this.pointsSet = {
1937
+ forw: Ot(s.forw),
1938
+ bakw: Ot(s.bakw),
1939
+ edges: []
1940
+ }, this.tins = {
1941
+ forw: ve(te(this.pointsSet.forw, s.edges, "target"))
1942
+ }, (e === ht.MODE_STRICT || e === ht.MODE_AUTO) && this.calcurateStrictTin(), (e === ht.MODE_LOOSE || e === ht.MODE_AUTO && this.strict_status === ht.STATUS_ERROR) && (this.tins.bakw = ve(
1943
+ te(this.pointsSet.bakw, s.edges, "target")
1944
+ ), delete this.kinks, this.strict_status = ht.STATUS_LOOSE), this.vertices_params = {
1945
+ forw: Fe(I.forw, this.centroid.forw),
1946
+ bakw: Fe(I.bakw, this.centroid.bakw)
1947
+ }, this.addIndexedTin(), this.calculatePointsWeight();
1948
+ }
1949
+ /**
1950
+ * 通常の頂点を計算
1951
+ */
1952
+ calculatePlainVertices(e, s, i, n, r, a, f) {
1953
+ const c = Object.keys(e).reduce((y, g) => {
1954
+ const b = e[g], w = b.forw, S = b.bakw, _ = {
1955
+ forw: [w[0] - s.forw[0], w[1] - s.forw[1]],
1956
+ bakw: [S[0] - s.bakw[0], S[1] - s.bakw[1]]
1957
+ }, v = _.forw[0] === 0 ? 1 / 0 : ((_.forw[0] < 0 ? n : r) - s.forw[0]) / _.forw[0], T = _.forw[1] === 0 ? 1 / 0 : ((_.forw[1] < 0 ? a : f) - s.forw[1]) / _.forw[1];
1958
+ if (Math.abs(v) / Math.abs(T) < 1.1) {
1959
+ const I = {
1960
+ forw: [_.forw[0] * v + s.forw[0], _.forw[1] * v + s.forw[1]],
1961
+ bakw: [_.bakw[0] * v + s.bakw[0], _.bakw[1] * v + s.bakw[1]]
1962
+ };
1963
+ _.forw[0] < 0 ? y[3].push(I) : y[1].push(I);
1964
+ }
1965
+ if (Math.abs(T) / Math.abs(v) < 1.1) {
1966
+ const I = {
1967
+ forw: [_.forw[0] * T + s.forw[0], _.forw[1] * T + s.forw[1]],
1968
+ bakw: [_.bakw[0] * T + s.bakw[0], _.bakw[1] * T + s.bakw[1]]
1969
+ };
1970
+ _.forw[1] < 0 ? y[0].push(I) : y[2].push(I);
1971
+ }
1972
+ return y;
1973
+ }, [[], [], [], []]);
1974
+ let h = Object.keys(e).reduce((y, g, b, w) => {
1975
+ const S = e[g], _ = S.forw, v = S.bakw, T = {
1976
+ forw: [_[0] - s.forw[0], _[1] - s.forw[1]],
1977
+ bakw: [v[0] - s.bakw[0], s.bakw[1] - v[1]]
1978
+ };
1979
+ if (T.forw[0] === 0 || T.forw[1] === 0) return y;
1980
+ let I = 0;
1981
+ return T.forw[0] > 0 && (I += 1), T.forw[1] > 0 && (I += 2), y[I].push([T.forw, T.bakw]), b === w.length - 1 ? y.map((N) => N.reduce((V, z, G, tt) => {
1982
+ V || (V = [1 / 0, 0, 0]);
1983
+ let X = Math.sqrt(Math.pow(z[0][0], 2) + Math.pow(z[0][1], 2)) / Math.sqrt(Math.pow(z[1][0], 2) + Math.pow(z[1][1], 2));
1984
+ X = X < V[0] ? X : V[0];
1985
+ const it = Math.atan2(z[0][0], z[0][1]) - Math.atan2(z[1][0], z[1][1]), d = V[1] + Math.cos(it), m = V[2] + Math.sin(it);
1986
+ return G === tt.length - 1 ? [X, Math.atan2(m, d)] : [X, d, m];
1987
+ }, null)) : y;
1988
+ }, [[], [], [], []]);
1989
+ h.length === 1 && (h = [h[0], h[0], h[0], h[0]]);
1990
+ const l = h.map((y, g) => {
1991
+ const b = i[g], w = [b[0] - s.forw[0], b[1] - s.forw[1]], _ = Math.sqrt(Math.pow(w[0], 2) + Math.pow(w[1], 2)) / y[0], v = Math.atan2(w[0], w[1]) - y[1], T = [
1992
+ s.bakw[0] + _ * Math.sin(v),
1993
+ s.bakw[1] - _ * Math.cos(v)
1994
+ ];
1995
+ return { forw: b, bakw: T };
1996
+ }), p = l[2];
1997
+ return l[2] = l[3], l[3] = p, this.checkAndAdjustVertices(l, c, s), l;
1998
+ }
1999
+ /**
2000
+ * 鳥瞰図モードの頂点を計算
2001
+ */
2002
+ calculateBirdeyeVertices(e, s, i, n, r, a, f) {
2003
+ return this.calculatePlainVertices(e, s, i, n, r, a, f);
2004
+ }
2005
+ /**
2006
+ * 頂点の位置を調整
2007
+ */
2008
+ checkAndAdjustVertices(e, s, i) {
2009
+ const n = [1, 1, 1, 1];
2010
+ for (let r = 0; r < 4; r++) {
2011
+ const a = (r + 1) % 4, f = xe([e[r].bakw, e[a].bakw]);
2012
+ s[r].map((c) => {
2013
+ const u = xe([i.bakw, c.bakw]), h = es(f, u);
2014
+ if (h.features.length > 0 && h.features[0].geometry) {
2015
+ const l = h.features[0], p = Math.sqrt(
2016
+ Math.pow(c.bakw[0] - i.bakw[0], 2) + Math.pow(c.bakw[1] - i.bakw[1], 2)
2017
+ ), y = Math.sqrt(
2018
+ Math.pow(l.geometry.coordinates[0] - i.bakw[0], 2) + Math.pow(l.geometry.coordinates[1] - i.bakw[1], 2)
2019
+ ), g = p / y;
2020
+ g > n[r] && (n[r] = g), g > n[a] && (n[a] = g);
2021
+ }
2022
+ });
2023
+ }
2024
+ e.forEach((r, a) => {
2025
+ const f = n[a], c = [
2026
+ (r.bakw[0] - i.bakw[0]) * f + i.bakw[0],
2027
+ (r.bakw[1] - i.bakw[1]) * f + i.bakw[1]
2028
+ ];
2029
+ r.bakw = c;
2030
+ });
2031
+ }
2032
+ /**
2033
+ * 点の重み付けを計算します
2034
+ */
2035
+ calculatePointsWeight() {
2036
+ const e = ["forw"];
2037
+ this.strict_status === ht.STATUS_LOOSE && e.push("bakw");
2038
+ const s = {};
2039
+ e.forEach((n) => {
2040
+ s[n] = {};
2041
+ const r = {};
2042
+ this.tins[n].features.map((a) => {
2043
+ const f = ["a", "b", "c"];
2044
+ for (let c = 0; c < 3; c++) {
2045
+ const u = (c + 1) % 3, h = f[c], l = f[u], p = a.properties[h].index, y = a.properties[l].index, g = [p, y].sort().join("-");
2046
+ if (!r[g]) {
2047
+ const b = a.geometry.coordinates[0][c], w = a.geometry.coordinates[0][u], S = a.properties[h].geom, _ = a.properties[l].geom;
2048
+ r[g] = 1;
2049
+ const v = Math.sqrt(
2050
+ Math.pow(S[0] - _[0], 2) + Math.pow(S[1] - _[1], 2)
2051
+ ) / Math.sqrt(
2052
+ Math.pow(b[0] - w[0], 2) + Math.pow(b[1] - w[1], 2)
2053
+ );
2054
+ s[n] || (s[n] = {});
2055
+ const T = s[n];
2056
+ T[`${p}:${g}`] = v, T[`${y}:${g}`] = v;
2057
+ }
2058
+ }
2059
+ });
2060
+ });
2061
+ const i = {};
2062
+ e.map((n) => {
2063
+ i[n] = {}, this.strict_status === ht.STATUS_STRICT && (i.bakw = {});
2064
+ const r = s[n], a = {};
2065
+ Object.keys(r).forEach((c) => {
2066
+ const [u] = c.split(":");
2067
+ a[u] || (a[u] = []), a[u].push(r[c]);
2068
+ }), Object.keys(a).forEach((c) => {
2069
+ const u = a[c], h = u.reduce((l, p) => l + p, 0) / u.length;
2070
+ i[n] || (i[n] = {}), i[n][c] = h, this.strict_status === ht.STATUS_STRICT && (i.bakw || (i.bakw = {}), i.bakw[c] = 1 / h);
2071
+ });
2072
+ let f = 0;
2073
+ for (let c = 0; c < 4; c++) {
2074
+ const u = `b${c}`, h = i[n][u] || 0;
2075
+ f += h;
2076
+ }
2077
+ i[n].c = f / 4, this.strict_status === ht.STATUS_STRICT && i.bakw && (i.bakw.c = 1 / i[n].c);
2078
+ }), this.pointsWeightBuffer = i;
2079
+ }
2080
+ }
2081
+ export {
2082
+ ht as Tin,
2083
+ te as constrainedTin,
2084
+ ie as counterPoint,
2085
+ ne as createPoint,
2086
+ Ns as findIntersections,
2087
+ oe as format_version,
2088
+ nn as insertSearchIndex,
2089
+ Fe as vertexCalc
2090
+ };