@maplat/tin 0.9.4 → 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.
@@ -0,0 +1,3291 @@
1
+ var Kn = Object.defineProperty;
2
+ var Qn = (r, t, e) => t in r ? Kn(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var at = (r, t, e) => Qn(r, typeof t != "symbol" ? t + "" : t, e);
4
+ const Yt = 11102230246251565e-32, pt = 134217729, Zn = (3 + 8 * Yt) * Yt;
5
+ function Oe(r, t, e, n, s) {
6
+ let i, o, a, c, l = t[0], u = n[0], h = 0, f = 0;
7
+ u > l == u > -l ? (i = l, l = t[++h]) : (i = u, u = n[++f]);
8
+ let g = 0;
9
+ if (h < r && f < e)
10
+ for (u > l == u > -l ? (o = l + i, a = i - (o - l), l = t[++h]) : (o = u + i, a = i - (o - u), u = n[++f]), i = o, a !== 0 && (s[g++] = a); h < r && f < e; )
11
+ u > l == u > -l ? (o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h]) : (o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f]), i = o, a !== 0 && (s[g++] = a);
12
+ for (; h < r; )
13
+ o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h], i = o, a !== 0 && (s[g++] = a);
14
+ for (; f < e; )
15
+ o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f], i = o, a !== 0 && (s[g++] = a);
16
+ return (i !== 0 || g === 0) && (s[g++] = i), g;
17
+ }
18
+ function tr(r, t) {
19
+ let e = t[0];
20
+ for (let n = 1; n < r; n++) e += t[n];
21
+ return e;
22
+ }
23
+ function oe(r) {
24
+ return new Float64Array(r);
25
+ }
26
+ const er = (3 + 16 * Yt) * Yt, nr = (2 + 12 * Yt) * Yt, rr = (9 + 64 * Yt) * Yt * Yt, Wt = oe(4), Ke = oe(8), Qe = oe(12), Ze = oe(16), wt = oe(4);
27
+ function ir(r, t, e, n, s, i, o) {
28
+ let a, c, l, u, h, f, g, _, d, y, v, p, w, x, E, A, T, S;
29
+ const B = r - s, O = e - s, I = t - i, C = n - i;
30
+ x = B * C, f = pt * B, g = f - (f - B), _ = B - g, f = pt * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * O, f = pt * I, g = f - (f - I), _ = I - g, f = pt * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, Wt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, Wt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, Wt[2] = p - (S - h) + (v - h), Wt[3] = S;
31
+ let N = tr(4, Wt), m = nr * o;
32
+ if (N >= m || -N >= m || (h = r - B, a = r - (B + h) + (h - s), h = e - O, l = e - (O + h) + (h - s), h = t - I, c = t - (I + h) + (h - i), h = n - C, u = n - (C + h) + (h - i), a === 0 && c === 0 && l === 0 && u === 0) || (m = rr * o + Zn * Math.abs(N), N += B * u + C * a - (I * l + O * c), N >= m || -N >= m)) return N;
33
+ x = a * C, f = pt * a, g = f - (f - a), _ = a - g, f = pt * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * O, f = pt * c, g = f - (f - c), _ = c - g, f = pt * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, wt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, wt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, wt[2] = p - (S - h) + (v - h), wt[3] = S;
34
+ const M = Oe(4, Wt, 4, wt, Ke);
35
+ x = B * u, f = pt * B, g = f - (f - B), _ = B - g, f = pt * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * l, f = pt * I, g = f - (f - I), _ = I - g, f = pt * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, wt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, wt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, wt[2] = p - (S - h) + (v - h), wt[3] = S;
36
+ const k = Oe(M, Ke, 4, wt, Qe);
37
+ x = a * u, f = pt * a, g = f - (f - a), _ = a - g, f = pt * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * l, f = pt * c, g = f - (f - c), _ = c - g, f = pt * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, wt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, wt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, wt[2] = p - (S - h) + (v - h), wt[3] = S;
38
+ const P = Oe(k, Qe, 4, wt, Ze);
39
+ return Ze[P - 1];
40
+ }
41
+ function ne(r, t, e, n, s, i) {
42
+ const o = (t - i) * (e - s), a = (r - s) * (n - i), c = o - a, l = Math.abs(o + a);
43
+ return Math.abs(c) >= er * l ? c : -ir(r, t, e, n, s, i, l);
44
+ }
45
+ function sr(r, t) {
46
+ var e, n, s = 0, i, o, a, c, l, u, h, f = r[0], g = r[1], _ = t.length;
47
+ for (e = 0; e < _; e++) {
48
+ n = 0;
49
+ var d = t[e], y = d.length - 1;
50
+ if (u = d[0], u[0] !== d[y][0] && u[1] !== d[y][1])
51
+ throw new Error("First and last coordinates in a ring must be the same");
52
+ for (o = u[0] - f, a = u[1] - g, n; n < y; n++) {
53
+ if (h = d[n + 1], c = h[0] - f, l = h[1] - g, a === 0 && l === 0) {
54
+ if (c <= 0 && o >= 0 || o <= 0 && c >= 0)
55
+ return 0;
56
+ } else if (l >= 0 && a <= 0 || l <= 0 && a >= 0) {
57
+ if (i = ne(o, c, a, l, 0, 0), i === 0)
58
+ return 0;
59
+ (i > 0 && l > 0 && a <= 0 || i < 0 && l <= 0 && a > 0) && s++;
60
+ }
61
+ u = h, a = l, o = c;
62
+ }
63
+ }
64
+ return s % 2 !== 0;
65
+ }
66
+ function se(r, t, e = {}) {
67
+ const n = { type: "Feature" };
68
+ return (e.id === 0 || e.id) && (n.id = e.id), e.bbox && (n.bbox = e.bbox), n.properties = t || {}, n.geometry = r, n;
69
+ }
70
+ function Vt(r, t, e = {}) {
71
+ if (!r)
72
+ throw new Error("coordinates is required");
73
+ if (!Array.isArray(r))
74
+ throw new Error("coordinates must be an Array");
75
+ if (r.length < 2)
76
+ throw new Error("coordinates must be at least 2 numbers long");
77
+ if (!en(r[0]) || !en(r[1]))
78
+ throw new Error("coordinates must contain numbers");
79
+ return se({
80
+ type: "Point",
81
+ coordinates: r
82
+ }, t, e);
83
+ }
84
+ function ke(r, t, e = {}) {
85
+ for (const s of r) {
86
+ if (s.length < 4)
87
+ throw new Error(
88
+ "Each LinearRing of a Polygon must have 4 or more Positions."
89
+ );
90
+ if (s[s.length - 1].length !== s[0].length)
91
+ throw new Error("First and last Position are not equivalent.");
92
+ for (let i = 0; i < s[s.length - 1].length; i++)
93
+ if (s[s.length - 1][i] !== s[0][i])
94
+ throw new Error("First and last Position are not equivalent.");
95
+ }
96
+ return se({
97
+ type: "Polygon",
98
+ coordinates: r
99
+ }, t, e);
100
+ }
101
+ function tn(r, t, e = {}) {
102
+ if (r.length < 2)
103
+ throw new Error("coordinates must be an array of two or more positions");
104
+ return se({
105
+ type: "LineString",
106
+ coordinates: r
107
+ }, t, e);
108
+ }
109
+ function Xt(r, t = {}) {
110
+ const e = { type: "FeatureCollection" };
111
+ return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = r, e;
112
+ }
113
+ function en(r) {
114
+ return !isNaN(r) && r !== null && !Array.isArray(r);
115
+ }
116
+ function or(r) {
117
+ if (!r)
118
+ throw new Error("coord is required");
119
+ if (!Array.isArray(r)) {
120
+ if (r.type === "Feature" && r.geometry !== null && r.geometry.type === "Point")
121
+ return [...r.geometry.coordinates];
122
+ if (r.type === "Point")
123
+ return [...r.coordinates];
124
+ }
125
+ if (Array.isArray(r) && r.length >= 2 && !Array.isArray(r[0]) && !Array.isArray(r[1]))
126
+ return [...r];
127
+ throw new Error("coord must be GeoJSON Point or an Array of numbers");
128
+ }
129
+ function ar(r) {
130
+ return r.type === "Feature" ? r.geometry : r;
131
+ }
132
+ function hr(r, t, e = {}) {
133
+ if (!r)
134
+ throw new Error("point is required");
135
+ if (!t)
136
+ throw new Error("polygon is required");
137
+ const n = or(r), s = ar(t), i = s.type, o = t.bbox;
138
+ let a = s.coordinates;
139
+ if (o && cr(n, o) === !1)
140
+ return !1;
141
+ i === "Polygon" && (a = [a]);
142
+ let c = !1;
143
+ for (var l = 0; l < a.length; ++l) {
144
+ const u = sr(n, a[l]);
145
+ if (u === 0) return !e.ignoreBoundary;
146
+ u && (c = !0);
147
+ }
148
+ return c;
149
+ }
150
+ function cr(r, t) {
151
+ return t[0] <= r[0] && t[1] <= r[1] && t[2] >= r[0] && t[3] >= r[1];
152
+ }
153
+ var lr = hr;
154
+ function ze(r, t, e) {
155
+ if (r !== null)
156
+ for (var n, s, i, o, a, c, l, u = 0, h = 0, f, g = r.type, _ = g === "FeatureCollection", d = g === "Feature", y = _ ? r.features.length : 1, v = 0; v < y; v++) {
157
+ l = _ ? r.features[v].geometry : d ? r.geometry : r, f = l ? l.type === "GeometryCollection" : !1, a = f ? l.geometries.length : 1;
158
+ for (var p = 0; p < a; p++) {
159
+ var w = 0, x = 0;
160
+ if (o = f ? l.geometries[p] : l, o !== null) {
161
+ c = o.coordinates;
162
+ var E = o.type;
163
+ switch (u = e && (E === "Polygon" || E === "MultiPolygon") ? 1 : 0, E) {
164
+ case null:
165
+ break;
166
+ case "Point":
167
+ if (t(
168
+ c,
169
+ h,
170
+ v,
171
+ w,
172
+ x
173
+ ) === !1)
174
+ return !1;
175
+ h++, w++;
176
+ break;
177
+ case "LineString":
178
+ case "MultiPoint":
179
+ for (n = 0; n < c.length; n++) {
180
+ if (t(
181
+ c[n],
182
+ h,
183
+ v,
184
+ w,
185
+ x
186
+ ) === !1)
187
+ return !1;
188
+ h++, E === "MultiPoint" && w++;
189
+ }
190
+ E === "LineString" && w++;
191
+ break;
192
+ case "Polygon":
193
+ case "MultiLineString":
194
+ for (n = 0; n < c.length; n++) {
195
+ for (s = 0; s < c[n].length - u; s++) {
196
+ if (t(
197
+ c[n][s],
198
+ h,
199
+ v,
200
+ w,
201
+ x
202
+ ) === !1)
203
+ return !1;
204
+ h++;
205
+ }
206
+ E === "MultiLineString" && w++, E === "Polygon" && x++;
207
+ }
208
+ E === "Polygon" && w++;
209
+ break;
210
+ case "MultiPolygon":
211
+ for (n = 0; n < c.length; n++) {
212
+ for (x = 0, s = 0; s < c[n].length; s++) {
213
+ for (i = 0; i < c[n][s].length - u; i++) {
214
+ if (t(
215
+ c[n][s][i],
216
+ h,
217
+ v,
218
+ w,
219
+ x
220
+ ) === !1)
221
+ return !1;
222
+ h++;
223
+ }
224
+ x++;
225
+ }
226
+ w++;
227
+ }
228
+ break;
229
+ case "GeometryCollection":
230
+ for (n = 0; n < o.geometries.length; n++)
231
+ if (ze(o.geometries[n], t, e) === !1)
232
+ return !1;
233
+ break;
234
+ default:
235
+ throw new Error("Unknown Geometry Type");
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
241
+ function fr(r, t = {}) {
242
+ let e = 0, n = 0, s = 0;
243
+ return ze(
244
+ r,
245
+ function(i) {
246
+ e += i[0], n += i[1], s++;
247
+ },
248
+ !0
249
+ ), Vt([e / s, n / s], t.properties);
250
+ }
251
+ var ur = fr, Pn = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
252
+ function dr(r) {
253
+ return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
254
+ }
255
+ function pr(r) {
256
+ if (r.__esModule) return r;
257
+ var t = r.default;
258
+ if (typeof t == "function") {
259
+ var e = function n() {
260
+ return this instanceof n ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
261
+ };
262
+ e.prototype = t.prototype;
263
+ } else e = {};
264
+ return Object.defineProperty(e, "__esModule", { value: !0 }), Object.keys(r).forEach(function(n) {
265
+ var s = Object.getOwnPropertyDescriptor(r, n);
266
+ Object.defineProperty(e, n, s.get ? s : {
267
+ enumerable: !0,
268
+ get: function() {
269
+ return r[n];
270
+ }
271
+ });
272
+ }), e;
273
+ }
274
+ var qe = { exports: {} }, On = { exports: {} };
275
+ (function(r, t) {
276
+ (function(e, n) {
277
+ r.exports = n();
278
+ })(Pn, function() {
279
+ function e(p, w, x, E, A) {
280
+ (function T(S, B, O, I, C) {
281
+ for (; I > O; ) {
282
+ if (I - O > 600) {
283
+ var N = I - O + 1, m = B - O + 1, M = Math.log(N), k = 0.5 * Math.exp(2 * M / 3), P = 0.5 * Math.sqrt(M * k * (N - k) / N) * (m - N / 2 < 0 ? -1 : 1), X = Math.max(O, Math.floor(B - m * k / N + P)), R = Math.min(I, Math.floor(B + (N - m) * k / N + P));
284
+ T(S, B, X, R, C);
285
+ }
286
+ var b = S[B], Y = O, D = I;
287
+ for (n(S, O, B), C(S[I], b) > 0 && n(S, O, I); Y < D; ) {
288
+ for (n(S, Y, D), Y++, D--; C(S[Y], b) < 0; ) Y++;
289
+ for (; C(S[D], b) > 0; ) D--;
290
+ }
291
+ C(S[O], b) === 0 ? n(S, O, D) : n(S, ++D, I), D <= B && (O = D + 1), B <= D && (I = D - 1);
292
+ }
293
+ })(p, w, x || 0, E || p.length - 1, A || s);
294
+ }
295
+ function n(p, w, x) {
296
+ var E = p[w];
297
+ p[w] = p[x], p[x] = E;
298
+ }
299
+ function s(p, w) {
300
+ return p < w ? -1 : p > w ? 1 : 0;
301
+ }
302
+ var i = function(p) {
303
+ p === void 0 && (p = 9), this._maxEntries = Math.max(4, p), this._minEntries = Math.max(2, Math.ceil(0.4 * this._maxEntries)), this.clear();
304
+ };
305
+ function o(p, w, x) {
306
+ if (!x) return w.indexOf(p);
307
+ for (var E = 0; E < w.length; E++) if (x(p, w[E])) return E;
308
+ return -1;
309
+ }
310
+ function a(p, w) {
311
+ c(p, 0, p.children.length, w, p);
312
+ }
313
+ function c(p, w, x, E, A) {
314
+ A || (A = y(null)), A.minX = 1 / 0, A.minY = 1 / 0, A.maxX = -1 / 0, A.maxY = -1 / 0;
315
+ for (var T = w; T < x; T++) {
316
+ var S = p.children[T];
317
+ l(A, p.leaf ? E(S) : S);
318
+ }
319
+ return A;
320
+ }
321
+ function l(p, w) {
322
+ return p.minX = Math.min(p.minX, w.minX), p.minY = Math.min(p.minY, w.minY), p.maxX = Math.max(p.maxX, w.maxX), p.maxY = Math.max(p.maxY, w.maxY), p;
323
+ }
324
+ function u(p, w) {
325
+ return p.minX - w.minX;
326
+ }
327
+ function h(p, w) {
328
+ return p.minY - w.minY;
329
+ }
330
+ function f(p) {
331
+ return (p.maxX - p.minX) * (p.maxY - p.minY);
332
+ }
333
+ function g(p) {
334
+ return p.maxX - p.minX + (p.maxY - p.minY);
335
+ }
336
+ function _(p, w) {
337
+ return p.minX <= w.minX && p.minY <= w.minY && w.maxX <= p.maxX && w.maxY <= p.maxY;
338
+ }
339
+ function d(p, w) {
340
+ return w.minX <= p.maxX && w.minY <= p.maxY && w.maxX >= p.minX && w.maxY >= p.minY;
341
+ }
342
+ function y(p) {
343
+ return { children: p, height: 1, leaf: !0, minX: 1 / 0, minY: 1 / 0, maxX: -1 / 0, maxY: -1 / 0 };
344
+ }
345
+ function v(p, w, x, E, A) {
346
+ for (var T = [w, x]; T.length; ) if (!((x = T.pop()) - (w = T.pop()) <= E)) {
347
+ var S = w + Math.ceil((x - w) / E / 2) * E;
348
+ e(p, S, w, x, A), T.push(w, S, S, x);
349
+ }
350
+ }
351
+ return i.prototype.all = function() {
352
+ return this._all(this.data, []);
353
+ }, i.prototype.search = function(p) {
354
+ var w = this.data, x = [];
355
+ if (!d(p, w)) return x;
356
+ for (var E = this.toBBox, A = []; w; ) {
357
+ for (var T = 0; T < w.children.length; T++) {
358
+ var S = w.children[T], B = w.leaf ? E(S) : S;
359
+ d(p, B) && (w.leaf ? x.push(S) : _(p, B) ? this._all(S, x) : A.push(S));
360
+ }
361
+ w = A.pop();
362
+ }
363
+ return x;
364
+ }, i.prototype.collides = function(p) {
365
+ var w = this.data;
366
+ if (!d(p, w)) return !1;
367
+ for (var x = []; w; ) {
368
+ for (var E = 0; E < w.children.length; E++) {
369
+ var A = w.children[E], T = w.leaf ? this.toBBox(A) : A;
370
+ if (d(p, T)) {
371
+ if (w.leaf || _(p, T)) return !0;
372
+ x.push(A);
373
+ }
374
+ }
375
+ w = x.pop();
376
+ }
377
+ return !1;
378
+ }, i.prototype.load = function(p) {
379
+ if (!p || !p.length) return this;
380
+ if (p.length < this._minEntries) {
381
+ for (var w = 0; w < p.length; w++) this.insert(p[w]);
382
+ return this;
383
+ }
384
+ var x = this._build(p.slice(), 0, p.length - 1, 0);
385
+ if (this.data.children.length) if (this.data.height === x.height) this._splitRoot(this.data, x);
386
+ else {
387
+ if (this.data.height < x.height) {
388
+ var E = this.data;
389
+ this.data = x, x = E;
390
+ }
391
+ this._insert(x, this.data.height - x.height - 1, !0);
392
+ }
393
+ else this.data = x;
394
+ return this;
395
+ }, i.prototype.insert = function(p) {
396
+ return p && this._insert(p, this.data.height - 1), this;
397
+ }, i.prototype.clear = function() {
398
+ return this.data = y([]), this;
399
+ }, i.prototype.remove = function(p, w) {
400
+ if (!p) return this;
401
+ for (var x, E, A, T = this.data, S = this.toBBox(p), B = [], O = []; T || B.length; ) {
402
+ if (T || (T = B.pop(), E = B[B.length - 1], x = O.pop(), A = !0), T.leaf) {
403
+ var I = o(p, T.children, w);
404
+ if (I !== -1) return T.children.splice(I, 1), B.push(T), this._condense(B), this;
405
+ }
406
+ A || T.leaf || !_(T, S) ? E ? (x++, T = E.children[x], A = !1) : T = null : (B.push(T), O.push(x), x = 0, E = T, T = T.children[0]);
407
+ }
408
+ return this;
409
+ }, i.prototype.toBBox = function(p) {
410
+ return p;
411
+ }, i.prototype.compareMinX = function(p, w) {
412
+ return p.minX - w.minX;
413
+ }, i.prototype.compareMinY = function(p, w) {
414
+ return p.minY - w.minY;
415
+ }, i.prototype.toJSON = function() {
416
+ return this.data;
417
+ }, i.prototype.fromJSON = function(p) {
418
+ return this.data = p, this;
419
+ }, i.prototype._all = function(p, w) {
420
+ for (var x = []; p; ) p.leaf ? w.push.apply(w, p.children) : x.push.apply(x, p.children), p = x.pop();
421
+ return w;
422
+ }, i.prototype._build = function(p, w, x, E) {
423
+ var A, T = x - w + 1, S = this._maxEntries;
424
+ if (T <= S) return a(A = y(p.slice(w, x + 1)), this.toBBox), A;
425
+ E || (E = Math.ceil(Math.log(T) / Math.log(S)), S = Math.ceil(T / Math.pow(S, E - 1))), (A = y([])).leaf = !1, A.height = E;
426
+ var B = Math.ceil(T / S), O = B * Math.ceil(Math.sqrt(S));
427
+ v(p, w, x, O, this.compareMinX);
428
+ for (var I = w; I <= x; I += O) {
429
+ var C = Math.min(I + O - 1, x);
430
+ v(p, I, C, B, this.compareMinY);
431
+ for (var N = I; N <= C; N += B) {
432
+ var m = Math.min(N + B - 1, C);
433
+ A.children.push(this._build(p, N, m, E - 1));
434
+ }
435
+ }
436
+ return a(A, this.toBBox), A;
437
+ }, i.prototype._chooseSubtree = function(p, w, x, E) {
438
+ for (; E.push(w), !w.leaf && E.length - 1 !== x; ) {
439
+ for (var A = 1 / 0, T = 1 / 0, S = void 0, B = 0; B < w.children.length; B++) {
440
+ var O = w.children[B], I = f(O), C = (N = p, m = O, (Math.max(m.maxX, N.maxX) - Math.min(m.minX, N.minX)) * (Math.max(m.maxY, N.maxY) - Math.min(m.minY, N.minY)) - I);
441
+ C < T ? (T = C, A = I < A ? I : A, S = O) : C === T && I < A && (A = I, S = O);
442
+ }
443
+ w = S || w.children[0];
444
+ }
445
+ var N, m;
446
+ return w;
447
+ }, i.prototype._insert = function(p, w, x) {
448
+ var E = x ? p : this.toBBox(p), A = [], T = this._chooseSubtree(E, this.data, w, A);
449
+ for (T.children.push(p), l(T, E); w >= 0 && A[w].children.length > this._maxEntries; ) this._split(A, w), w--;
450
+ this._adjustParentBBoxes(E, A, w);
451
+ }, i.prototype._split = function(p, w) {
452
+ var x = p[w], E = x.children.length, A = this._minEntries;
453
+ this._chooseSplitAxis(x, A, E);
454
+ var T = this._chooseSplitIndex(x, A, E), S = y(x.children.splice(T, x.children.length - T));
455
+ S.height = x.height, S.leaf = x.leaf, a(x, this.toBBox), a(S, this.toBBox), w ? p[w - 1].children.push(S) : this._splitRoot(x, S);
456
+ }, i.prototype._splitRoot = function(p, w) {
457
+ this.data = y([p, w]), this.data.height = p.height + 1, this.data.leaf = !1, a(this.data, this.toBBox);
458
+ }, i.prototype._chooseSplitIndex = function(p, w, x) {
459
+ for (var E, A, T, S, B, O, I, C = 1 / 0, N = 1 / 0, m = w; m <= x - w; m++) {
460
+ var M = c(p, 0, m, this.toBBox), k = c(p, m, x, this.toBBox), P = (A = M, T = k, S = void 0, B = void 0, O = void 0, I = void 0, S = Math.max(A.minX, T.minX), B = Math.max(A.minY, T.minY), O = Math.min(A.maxX, T.maxX), I = Math.min(A.maxY, T.maxY), Math.max(0, O - S) * Math.max(0, I - B)), X = f(M) + f(k);
461
+ P < C ? (C = P, E = m, N = X < N ? X : N) : P === C && X < N && (N = X, E = m);
462
+ }
463
+ return E || x - w;
464
+ }, i.prototype._chooseSplitAxis = function(p, w, x) {
465
+ var E = p.leaf ? this.compareMinX : u, A = p.leaf ? this.compareMinY : h;
466
+ this._allDistMargin(p, w, x, E) < this._allDistMargin(p, w, x, A) && p.children.sort(E);
467
+ }, i.prototype._allDistMargin = function(p, w, x, E) {
468
+ p.children.sort(E);
469
+ for (var A = this.toBBox, T = c(p, 0, w, A), S = c(p, x - w, x, A), B = g(T) + g(S), O = w; O < x - w; O++) {
470
+ var I = p.children[O];
471
+ l(T, p.leaf ? A(I) : I), B += g(T);
472
+ }
473
+ for (var C = x - w - 1; C >= w; C--) {
474
+ var N = p.children[C];
475
+ l(S, p.leaf ? A(N) : N), B += g(S);
476
+ }
477
+ return B;
478
+ }, i.prototype._adjustParentBBoxes = function(p, w, x) {
479
+ for (var E = x; E >= 0; E--) l(w[E], p);
480
+ }, i.prototype._condense = function(p) {
481
+ for (var w = p.length - 1, x = void 0; w >= 0; w--) p[w].children.length === 0 ? w > 0 ? (x = p[w - 1].children).splice(x.indexOf(p[w]), 1) : this.clear() : a(p[w], this.toBBox);
482
+ }, i;
483
+ });
484
+ })(On);
485
+ var gr = On.exports;
486
+ let mr = class {
487
+ constructor(t = [], e = wr) {
488
+ if (this.data = t, this.length = this.data.length, this.compare = e, this.length > 0)
489
+ for (let n = (this.length >> 1) - 1; n >= 0; n--) this._down(n);
490
+ }
491
+ push(t) {
492
+ this.data.push(t), this.length++, this._up(this.length - 1);
493
+ }
494
+ pop() {
495
+ if (this.length === 0) return;
496
+ const t = this.data[0], e = this.data.pop();
497
+ return this.length--, this.length > 0 && (this.data[0] = e, this._down(0)), t;
498
+ }
499
+ peek() {
500
+ return this.data[0];
501
+ }
502
+ _up(t) {
503
+ const { data: e, compare: n } = this, s = e[t];
504
+ for (; t > 0; ) {
505
+ const i = t - 1 >> 1, o = e[i];
506
+ if (n(s, o) >= 0) break;
507
+ e[t] = o, t = i;
508
+ }
509
+ e[t] = s;
510
+ }
511
+ _down(t) {
512
+ const { data: e, compare: n } = this, s = this.length >> 1, i = e[t];
513
+ for (; t < s; ) {
514
+ let o = (t << 1) + 1, a = e[o];
515
+ const c = o + 1;
516
+ if (c < this.length && n(e[c], a) < 0 && (o = c, a = e[c]), n(a, i) >= 0) break;
517
+ e[t] = a, t = o;
518
+ }
519
+ e[t] = i;
520
+ }
521
+ };
522
+ function wr(r, t) {
523
+ return r < t ? -1 : r > t ? 1 : 0;
524
+ }
525
+ const yr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
526
+ __proto__: null,
527
+ default: mr
528
+ }, Symbol.toStringTag, { value: "Module" })), vr = /* @__PURE__ */ pr(yr);
529
+ var Ae = { exports: {} }, _r = function(t, e, n, s) {
530
+ var i = t[0], o = t[1], a = !1;
531
+ n === void 0 && (n = 0), s === void 0 && (s = e.length);
532
+ for (var c = (s - n) / 2, l = 0, u = c - 1; l < c; u = l++) {
533
+ var h = e[n + l * 2 + 0], f = e[n + l * 2 + 1], g = e[n + u * 2 + 0], _ = e[n + u * 2 + 1], d = f > o != _ > o && i < (g - h) * (o - f) / (_ - f) + h;
534
+ d && (a = !a);
535
+ }
536
+ return a;
537
+ }, xr = function(t, e, n, s) {
538
+ var i = t[0], o = t[1], a = !1;
539
+ n === void 0 && (n = 0), s === void 0 && (s = e.length);
540
+ for (var c = s - n, l = 0, u = c - 1; l < c; u = l++) {
541
+ var h = e[l + n][0], f = e[l + n][1], g = e[u + n][0], _ = e[u + n][1], d = f > o != _ > o && i < (g - h) * (o - f) / (_ - f) + h;
542
+ d && (a = !a);
543
+ }
544
+ return a;
545
+ }, Tn = _r, Bn = xr;
546
+ Ae.exports = function(t, e, n, s) {
547
+ return e.length > 0 && Array.isArray(e[0]) ? Bn(t, e, n, s) : Tn(t, e, n, s);
548
+ };
549
+ Ae.exports.nested = Bn;
550
+ Ae.exports.flat = Tn;
551
+ var br = Ae.exports, Ue = { exports: {} };
552
+ (function(r, t) {
553
+ (function(e, n) {
554
+ n(t);
555
+ })(Pn, function(e) {
556
+ const s = 33306690738754706e-32;
557
+ function i(d, y, v, p, w) {
558
+ let x, E, A, T, S = y[0], B = p[0], O = 0, I = 0;
559
+ B > S == B > -S ? (x = S, S = y[++O]) : (x = B, B = p[++I]);
560
+ let C = 0;
561
+ if (O < d && I < v) for (B > S == B > -S ? (A = x - ((E = S + x) - S), S = y[++O]) : (A = x - ((E = B + x) - B), B = p[++I]), x = E, A !== 0 && (w[C++] = A); O < d && I < v; ) B > S == B > -S ? (A = x - ((E = x + S) - (T = E - x)) + (S - T), S = y[++O]) : (A = x - ((E = x + B) - (T = E - x)) + (B - T), B = p[++I]), x = E, A !== 0 && (w[C++] = A);
562
+ for (; O < d; ) A = x - ((E = x + S) - (T = E - x)) + (S - T), S = y[++O], x = E, A !== 0 && (w[C++] = A);
563
+ for (; I < v; ) A = x - ((E = x + B) - (T = E - x)) + (B - T), B = p[++I], x = E, A !== 0 && (w[C++] = A);
564
+ return x === 0 && C !== 0 || (w[C++] = x), C;
565
+ }
566
+ function o(d) {
567
+ return new Float64Array(d);
568
+ }
569
+ const a = 33306690738754716e-32, c = 22204460492503146e-32, l = 11093356479670487e-47, u = o(4), h = o(8), f = o(12), g = o(16), _ = o(4);
570
+ e.orient2d = function(d, y, v, p, w, x) {
571
+ const E = (y - x) * (v - w), A = (d - w) * (p - x), T = E - A;
572
+ if (E === 0 || A === 0 || E > 0 != A > 0) return T;
573
+ const S = Math.abs(E + A);
574
+ return Math.abs(T) >= a * S ? T : -function(B, O, I, C, N, m, M) {
575
+ let k, P, X, R, b, Y, D, L, F, z, j, U, J, W, H, K, Z, Q;
576
+ const ut = B - N, dt = I - N, st = O - m, ot = C - m;
577
+ b = (H = (L = ut - (D = (Y = 134217729 * ut) - (Y - ut))) * (z = ot - (F = (Y = 134217729 * ot) - (Y - ot))) - ((W = ut * ot) - D * F - L * F - D * z)) - (j = H - (Z = (L = st - (D = (Y = 134217729 * st) - (Y - st))) * (z = dt - (F = (Y = 134217729 * dt) - (Y - dt))) - ((K = st * dt) - D * F - L * F - D * z))), u[0] = H - (j + b) + (b - Z), b = (J = W - ((U = W + j) - (b = U - W)) + (j - b)) - (j = J - K), u[1] = J - (j + b) + (b - K), b = (Q = U + j) - U, u[2] = U - (Q - b) + (j - b), u[3] = Q;
578
+ let Ct = function(Hn, Je) {
579
+ let He = Je[0];
580
+ for (let Pe = 1; Pe < Hn; Pe++) He += Je[Pe];
581
+ return He;
582
+ }(4, u), Zt = c * M;
583
+ if (Ct >= Zt || -Ct >= Zt || (k = B - (ut + (b = B - ut)) + (b - N), X = I - (dt + (b = I - dt)) + (b - N), P = O - (st + (b = O - st)) + (b - m), R = C - (ot + (b = C - ot)) + (b - m), k === 0 && P === 0 && X === 0 && R === 0) || (Zt = l * M + s * Math.abs(Ct), (Ct += ut * R + ot * k - (st * X + dt * P)) >= Zt || -Ct >= Zt)) return Ct;
584
+ b = (H = (L = k - (D = (Y = 134217729 * k) - (Y - k))) * (z = ot - (F = (Y = 134217729 * ot) - (Y - ot))) - ((W = k * ot) - D * F - L * F - D * z)) - (j = H - (Z = (L = P - (D = (Y = 134217729 * P) - (Y - P))) * (z = dt - (F = (Y = 134217729 * dt) - (Y - dt))) - ((K = P * dt) - D * F - L * F - D * z))), _[0] = H - (j + b) + (b - Z), b = (J = W - ((U = W + j) - (b = U - W)) + (j - b)) - (j = J - K), _[1] = J - (j + b) + (b - K), b = (Q = U + j) - U, _[2] = U - (Q - b) + (j - b), _[3] = Q;
585
+ const Wn = i(4, u, 4, _, h);
586
+ b = (H = (L = ut - (D = (Y = 134217729 * ut) - (Y - ut))) * (z = R - (F = (Y = 134217729 * R) - (Y - R))) - ((W = ut * R) - D * F - L * F - D * z)) - (j = H - (Z = (L = st - (D = (Y = 134217729 * st) - (Y - st))) * (z = X - (F = (Y = 134217729 * X) - (Y - X))) - ((K = st * X) - D * F - L * F - D * z))), _[0] = H - (j + b) + (b - Z), b = (J = W - ((U = W + j) - (b = U - W)) + (j - b)) - (j = J - K), _[1] = J - (j + b) + (b - K), b = (Q = U + j) - U, _[2] = U - (Q - b) + (j - b), _[3] = Q;
587
+ const Gn = i(Wn, h, 4, _, f);
588
+ b = (H = (L = k - (D = (Y = 134217729 * k) - (Y - k))) * (z = R - (F = (Y = 134217729 * R) - (Y - R))) - ((W = k * R) - D * F - L * F - D * z)) - (j = H - (Z = (L = P - (D = (Y = 134217729 * P) - (Y - P))) * (z = X - (F = (Y = 134217729 * X) - (Y - X))) - ((K = P * X) - D * F - L * F - D * z))), _[0] = H - (j + b) + (b - Z), b = (J = W - ((U = W + j) - (b = U - W)) + (j - b)) - (j = J - K), _[1] = J - (j + b) + (b - K), b = (Q = U + j) - U, _[2] = U - (Q - b) + (j - b), _[3] = Q;
589
+ const Jn = i(Gn, f, 4, _, g);
590
+ return g[Jn - 1];
591
+ }(d, y, v, p, w, x, S);
592
+ }, e.orient2dfast = function(d, y, v, p, w, x) {
593
+ return (y - x) * (v - w) - (d - w) * (p - x);
594
+ }, Object.defineProperty(e, "__esModule", { value: !0 });
595
+ });
596
+ })(Ue, Ue.exports);
597
+ var Mr = Ue.exports, nn = gr, be = vr, Sr = br, Er = Mr.orient2d;
598
+ be.default && (be = be.default);
599
+ qe.exports = Xn;
600
+ qe.exports.default = Xn;
601
+ function Xn(r, t, e) {
602
+ t = Math.max(0, t === void 0 ? 2 : t), e = e || 0;
603
+ var n = Tr(r), s = new nn(16);
604
+ s.toBBox = function(p) {
605
+ return {
606
+ minX: p[0],
607
+ minY: p[1],
608
+ maxX: p[0],
609
+ maxY: p[1]
610
+ };
611
+ }, s.compareMinX = function(p, w) {
612
+ return p[0] - w[0];
613
+ }, s.compareMinY = function(p, w) {
614
+ return p[1] - w[1];
615
+ }, s.load(r);
616
+ for (var i = [], o = 0, a; o < n.length; o++) {
617
+ var c = n[o];
618
+ s.remove(c), a = on(c, a), i.push(a);
619
+ }
620
+ var l = new nn(16);
621
+ for (o = 0; o < i.length; o++) l.insert(Te(i[o]));
622
+ for (var u = t * t, h = e * e; i.length; ) {
623
+ var f = i.shift(), g = f.p, _ = f.next.p, d = Be(g, _);
624
+ if (!(d < h)) {
625
+ var y = d / u;
626
+ c = kr(s, f.prev.p, g, _, f.next.next.p, y, l), c && Math.min(Be(c, g), Be(c, _)) <= y && (i.push(f), i.push(on(c, f)), s.remove(c), l.remove(f), l.insert(Te(f)), l.insert(Te(f.next)));
627
+ }
628
+ }
629
+ f = a;
630
+ var v = [];
631
+ do
632
+ v.push(f.p), f = f.next;
633
+ while (f !== a);
634
+ return v.push(f.p), v;
635
+ }
636
+ function kr(r, t, e, n, s, i, o) {
637
+ for (var a = new be([], Ar), c = r.data; c; ) {
638
+ for (var l = 0; l < c.children.length; l++) {
639
+ var u = c.children[l], h = c.leaf ? Xe(u, e, n) : Pr(e, n, u);
640
+ h > i || a.push({
641
+ node: u,
642
+ dist: h
643
+ });
644
+ }
645
+ for (; a.length && !a.peek().node.children; ) {
646
+ var f = a.pop(), g = f.node, _ = Xe(g, t, e), d = Xe(g, n, s);
647
+ if (f.dist < _ && f.dist < d && sn(e, g, o) && sn(n, g, o)) return g;
648
+ }
649
+ c = a.pop(), c && (c = c.node);
650
+ }
651
+ return null;
652
+ }
653
+ function Ar(r, t) {
654
+ return r.dist - t.dist;
655
+ }
656
+ function Pr(r, t, e) {
657
+ if (rn(r, e) || rn(t, e)) return 0;
658
+ var n = he(r[0], r[1], t[0], t[1], e.minX, e.minY, e.maxX, e.minY);
659
+ if (n === 0) return 0;
660
+ var s = he(r[0], r[1], t[0], t[1], e.minX, e.minY, e.minX, e.maxY);
661
+ if (s === 0) return 0;
662
+ var i = he(r[0], r[1], t[0], t[1], e.maxX, e.minY, e.maxX, e.maxY);
663
+ if (i === 0) return 0;
664
+ var o = he(r[0], r[1], t[0], t[1], e.minX, e.maxY, e.maxX, e.maxY);
665
+ return o === 0 ? 0 : Math.min(n, s, i, o);
666
+ }
667
+ function rn(r, t) {
668
+ return r[0] >= t.minX && r[0] <= t.maxX && r[1] >= t.minY && r[1] <= t.maxY;
669
+ }
670
+ function sn(r, t, e) {
671
+ for (var n = Math.min(r[0], t[0]), s = Math.min(r[1], t[1]), i = Math.max(r[0], t[0]), o = Math.max(r[1], t[1]), a = e.search({ minX: n, minY: s, maxX: i, maxY: o }), c = 0; c < a.length; c++)
672
+ if (Or(a[c].p, a[c].next.p, r, t)) return !1;
673
+ return !0;
674
+ }
675
+ function Ht(r, t, e) {
676
+ return Er(r[0], r[1], t[0], t[1], e[0], e[1]);
677
+ }
678
+ function Or(r, t, e, n) {
679
+ return r !== n && t !== e && Ht(r, t, e) > 0 != Ht(r, t, n) > 0 && Ht(e, n, r) > 0 != Ht(e, n, t) > 0;
680
+ }
681
+ function Te(r) {
682
+ var t = r.p, e = r.next.p;
683
+ return r.minX = Math.min(t[0], e[0]), r.minY = Math.min(t[1], e[1]), r.maxX = Math.max(t[0], e[0]), r.maxY = Math.max(t[1], e[1]), r;
684
+ }
685
+ function Tr(r) {
686
+ for (var t = r[0], e = r[0], n = r[0], s = r[0], i = 0; i < r.length; i++) {
687
+ var o = r[i];
688
+ o[0] < t[0] && (t = o), o[0] > n[0] && (n = o), o[1] < e[1] && (e = o), o[1] > s[1] && (s = o);
689
+ }
690
+ var a = [t, e, n, s], c = a.slice();
691
+ for (i = 0; i < r.length; i++)
692
+ Sr(r[i], a) || c.push(r[i]);
693
+ return Xr(c);
694
+ }
695
+ function on(r, t) {
696
+ var e = {
697
+ p: r,
698
+ prev: null,
699
+ next: null,
700
+ minX: 0,
701
+ minY: 0,
702
+ maxX: 0,
703
+ maxY: 0
704
+ };
705
+ return t ? (e.next = t.next, e.prev = t, t.next.prev = e, t.next = e) : (e.prev = e, e.next = e), e;
706
+ }
707
+ function Be(r, t) {
708
+ var e = r[0] - t[0], n = r[1] - t[1];
709
+ return e * e + n * n;
710
+ }
711
+ function Xe(r, t, e) {
712
+ var n = t[0], s = t[1], i = e[0] - n, o = e[1] - s;
713
+ if (i !== 0 || o !== 0) {
714
+ var a = ((r[0] - n) * i + (r[1] - s) * o) / (i * i + o * o);
715
+ a > 1 ? (n = e[0], s = e[1]) : a > 0 && (n += i * a, s += o * a);
716
+ }
717
+ return i = r[0] - n, o = r[1] - s, i * i + o * o;
718
+ }
719
+ function he(r, t, e, n, s, i, o, a) {
720
+ var c = e - r, l = n - t, u = o - s, h = a - i, f = r - s, g = t - i, _ = c * c + l * l, d = c * u + l * h, y = u * u + h * h, v = c * f + l * g, p = u * f + h * g, w = _ * y - d * d, x, E, A, T, S = w, B = w;
721
+ w === 0 ? (E = 0, S = 1, T = p, B = y) : (E = d * p - y * v, T = _ * p - d * v, E < 0 ? (E = 0, T = p, B = y) : E > S && (E = S, T = p + d, B = y)), T < 0 ? (T = 0, -v < 0 ? E = 0 : -v > _ ? E = S : (E = -v, S = _)) : T > B && (T = B, -v + d < 0 ? E = 0 : -v + d > _ ? E = S : (E = -v + d, S = _)), x = E === 0 ? 0 : E / S, A = T === 0 ? 0 : T / B;
722
+ var O = (1 - x) * r + x * e, I = (1 - x) * t + x * n, C = (1 - A) * s + A * o, N = (1 - A) * i + A * a, m = C - O, M = N - I;
723
+ return m * m + M * M;
724
+ }
725
+ function Br(r, t) {
726
+ return r[0] === t[0] ? r[1] - t[1] : r[0] - t[0];
727
+ }
728
+ function Xr(r) {
729
+ r.sort(Br);
730
+ for (var t = [], e = 0; e < r.length; e++) {
731
+ for (; t.length >= 2 && Ht(t[t.length - 2], t[t.length - 1], r[e]) <= 0; )
732
+ t.pop();
733
+ t.push(r[e]);
734
+ }
735
+ for (var n = [], s = r.length - 1; s >= 0; s--) {
736
+ for (; n.length >= 2 && Ht(n[n.length - 2], n[n.length - 1], r[s]) <= 0; )
737
+ n.pop();
738
+ n.push(r[s]);
739
+ }
740
+ return n.pop(), t.pop(), t.concat(n);
741
+ }
742
+ var Yr = qe.exports;
743
+ const Ir = /* @__PURE__ */ dr(Yr);
744
+ function Cr(r, t = {}) {
745
+ t.concavity = t.concavity || 1 / 0;
746
+ const e = [];
747
+ if (ze(r, (s) => {
748
+ e.push([s[0], s[1]]);
749
+ }), !e.length)
750
+ return null;
751
+ const n = Ir(e, t.concavity);
752
+ return n.length > 3 ? ke([n]) : null;
753
+ }
754
+ var an = Cr;
755
+ class Yn {
756
+ constructor(t = [], e = Nr) {
757
+ if (this.data = t, this.length = this.data.length, this.compare = e, this.length > 0)
758
+ for (let n = (this.length >> 1) - 1; n >= 0; n--) this._down(n);
759
+ }
760
+ push(t) {
761
+ this.data.push(t), this.length++, this._up(this.length - 1);
762
+ }
763
+ pop() {
764
+ if (this.length === 0) return;
765
+ const t = this.data[0], e = this.data.pop();
766
+ return this.length--, this.length > 0 && (this.data[0] = e, this._down(0)), t;
767
+ }
768
+ peek() {
769
+ return this.data[0];
770
+ }
771
+ _up(t) {
772
+ const { data: e, compare: n } = this, s = e[t];
773
+ for (; t > 0; ) {
774
+ const i = t - 1 >> 1, o = e[i];
775
+ if (n(s, o) >= 0) break;
776
+ e[t] = o, t = i;
777
+ }
778
+ e[t] = s;
779
+ }
780
+ _down(t) {
781
+ const { data: e, compare: n } = this, s = this.length >> 1, i = e[t];
782
+ for (; t < s; ) {
783
+ let o = (t << 1) + 1, a = e[o];
784
+ const c = o + 1;
785
+ if (c < this.length && n(e[c], a) < 0 && (o = c, a = e[c]), n(a, i) >= 0) break;
786
+ e[t] = a, t = o;
787
+ }
788
+ e[t] = i;
789
+ }
790
+ }
791
+ function Nr(r, t) {
792
+ return r < t ? -1 : r > t ? 1 : 0;
793
+ }
794
+ function In(r, t) {
795
+ return r.p.x > t.p.x ? 1 : r.p.x < t.p.x ? -1 : r.p.y !== t.p.y ? r.p.y > t.p.y ? 1 : -1 : 1;
796
+ }
797
+ function $r(r, t) {
798
+ return r.rightSweepEvent.p.x > t.rightSweepEvent.p.x ? 1 : r.rightSweepEvent.p.x < t.rightSweepEvent.p.x ? -1 : r.rightSweepEvent.p.y !== t.rightSweepEvent.p.y ? r.rightSweepEvent.p.y < t.rightSweepEvent.p.y ? 1 : -1 : 1;
799
+ }
800
+ class hn {
801
+ constructor(t, e, n, s) {
802
+ this.p = {
803
+ x: t[0],
804
+ y: t[1]
805
+ }, this.featureId = e, this.ringId = n, this.eventId = s, this.otherEvent = null, this.isLeftEndpoint = null;
806
+ }
807
+ isSamePoint(t) {
808
+ return this.p.x === t.p.x && this.p.y === t.p.y;
809
+ }
810
+ }
811
+ function Dr(r, t) {
812
+ if (r.type === "FeatureCollection") {
813
+ const e = r.features;
814
+ for (let n = 0; n < e.length; n++)
815
+ cn(e[n], t);
816
+ } else
817
+ cn(r, t);
818
+ }
819
+ let ce = 0, le = 0, fe = 0;
820
+ function cn(r, t) {
821
+ const e = r.type === "Feature" ? r.geometry : r;
822
+ let n = e.coordinates;
823
+ (e.type === "Polygon" || e.type === "MultiLineString") && (n = [n]), e.type === "LineString" && (n = [[n]]);
824
+ for (let s = 0; s < n.length; s++)
825
+ for (let i = 0; i < n[s].length; i++) {
826
+ let o = n[s][i][0], a = null;
827
+ le = le + 1;
828
+ for (let c = 0; c < n[s][i].length - 1; c++) {
829
+ a = n[s][i][c + 1];
830
+ const l = new hn(o, ce, le, fe), u = new hn(a, ce, le, fe + 1);
831
+ l.otherEvent = u, u.otherEvent = l, In(l, u) > 0 ? (u.isLeftEndpoint = !0, l.isLeftEndpoint = !1) : (l.isLeftEndpoint = !0, u.isLeftEndpoint = !1), t.push(l), t.push(u), o = a, fe = fe + 1;
832
+ }
833
+ }
834
+ ce = ce + 1;
835
+ }
836
+ class Rr {
837
+ constructor(t) {
838
+ this.leftSweepEvent = t, this.rightSweepEvent = t.otherEvent;
839
+ }
840
+ }
841
+ function Lr(r, t) {
842
+ if (r === null || t === null || r.leftSweepEvent.ringId === t.leftSweepEvent.ringId && (r.rightSweepEvent.isSamePoint(t.leftSweepEvent) || r.rightSweepEvent.isSamePoint(t.leftSweepEvent) || r.rightSweepEvent.isSamePoint(t.rightSweepEvent) || r.leftSweepEvent.isSamePoint(t.leftSweepEvent) || r.leftSweepEvent.isSamePoint(t.rightSweepEvent))) return !1;
843
+ const e = r.leftSweepEvent.p.x, n = r.leftSweepEvent.p.y, s = r.rightSweepEvent.p.x, i = r.rightSweepEvent.p.y, o = t.leftSweepEvent.p.x, a = t.leftSweepEvent.p.y, c = t.rightSweepEvent.p.x, l = t.rightSweepEvent.p.y, u = (l - a) * (s - e) - (c - o) * (i - n), h = (c - o) * (n - a) - (l - a) * (e - o), f = (s - e) * (n - a) - (i - n) * (e - o);
844
+ if (u === 0)
845
+ return !1;
846
+ const g = h / u, _ = f / u;
847
+ if (g >= 0 && g <= 1 && _ >= 0 && _ <= 1) {
848
+ const d = e + g * (s - e), y = n + g * (i - n);
849
+ return [d, y];
850
+ }
851
+ return !1;
852
+ }
853
+ function Fr(r, t) {
854
+ t = t || !1;
855
+ const e = [], n = new Yn([], $r);
856
+ for (; r.length; ) {
857
+ const s = r.pop();
858
+ if (s.isLeftEndpoint) {
859
+ const i = new Rr(s);
860
+ for (let o = 0; o < n.data.length; o++) {
861
+ const a = n.data[o];
862
+ if (t && a.leftSweepEvent.featureId === s.featureId)
863
+ continue;
864
+ const c = Lr(i, a);
865
+ c !== !1 && e.push(c);
866
+ }
867
+ n.push(i);
868
+ } else s.isLeftEndpoint === !1 && n.pop();
869
+ }
870
+ return e;
871
+ }
872
+ function Ur(r, t) {
873
+ const e = new Yn([], In);
874
+ return Dr(r, e), Fr(e, t);
875
+ }
876
+ var jr = Ur;
877
+ function zr(r, t, e = {}) {
878
+ const { removeDuplicates: n = !0, ignoreSelfIntersections: s = !0 } = e;
879
+ let i = [];
880
+ r.type === "FeatureCollection" ? i = i.concat(r.features) : r.type === "Feature" ? i.push(r) : (r.type === "LineString" || r.type === "Polygon" || r.type === "MultiLineString" || r.type === "MultiPolygon") && i.push(se(r)), t.type === "FeatureCollection" ? i = i.concat(t.features) : t.type === "Feature" ? i.push(t) : (t.type === "LineString" || t.type === "Polygon" || t.type === "MultiLineString" || t.type === "MultiPolygon") && i.push(se(t));
881
+ const o = jr(
882
+ Xt(i),
883
+ s
884
+ );
885
+ let a = [];
886
+ if (n) {
887
+ const c = {};
888
+ o.forEach((l) => {
889
+ const u = l.join(",");
890
+ c[u] || (c[u] = !0, a.push(l));
891
+ });
892
+ } else
893
+ a = o;
894
+ return Xt(a.map((c) => Vt(c)));
895
+ }
896
+ var qr = zr;
897
+ function Vr(r) {
898
+ const e = new Wr(r).findSegmentIntersections();
899
+ return $n(e).reduce(
900
+ (n, s, i, o) => (n || (n = {}), n[`${s.x}:${s.y}`] = s, i != o.length - 1 ? n : Object.keys(n).map((a) => Vt([n[a].x, n[a].y]))),
901
+ []
902
+ );
903
+ }
904
+ class Wr {
905
+ /**
906
+ * 線分群からArcCollectionを初期化
907
+ * @param coords - 線分群の座標配列
908
+ */
909
+ constructor(t) {
910
+ /**
911
+ * 座標データの配列
912
+ * _xx, _yy: Float64Array形式で座標を保持
913
+ * _ii: 各線分の開始インデックス
914
+ * _nn: 各線分の頂点数
915
+ */
916
+ at(this, "_xx");
917
+ at(this, "_yy");
918
+ // coordinates data
919
+ at(this, "_ii");
920
+ at(this, "_nn");
921
+ // indexes, sizes
922
+ at(this, "_zz");
923
+ at(this, "_zlimit", 0);
924
+ // simplification
925
+ at(this, "_bb");
926
+ at(this, "_allBounds");
927
+ // bounding boxes
928
+ at(this, "_arcIter");
929
+ at(this, "_filteredArcIter");
930
+ // path iterators
931
+ at(this, "buf");
932
+ this.initArcs(t);
933
+ }
934
+ initArcs(t) {
935
+ const e = [], n = [], s = t.map((i) => {
936
+ const o = i ? i.length : 0;
937
+ for (let a = 0; a < o; a++)
938
+ e.push(i[a][0]), n.push(i[a][1]);
939
+ return o;
940
+ });
941
+ this.initXYData(s, e, n);
942
+ }
943
+ initXYData(t, e, n) {
944
+ const s = t.length;
945
+ this._xx = new Float64Array(e), this._yy = new Float64Array(n), this._nn = new Uint32Array(t), this._zz = null, this._zlimit = 0, this._filteredArcIter = null, this._ii = new Uint32Array(s);
946
+ let i = 0;
947
+ for (let o = 0; o < s; o++)
948
+ this._ii[o] = i, i += t[o];
949
+ (i != this._xx.length || this._xx.length != this._yy.length) && Ve("ArcCollection#initXYData() Counting error"), this.initBounds(), this._arcIter = new di(this._xx, this._yy);
950
+ }
951
+ initBounds() {
952
+ const t = this.calcArcBounds_(this._xx, this._yy, this._nn);
953
+ this._bb = t.bb, this._allBounds = t.bounds;
954
+ }
955
+ /**
956
+ * データの境界を計算
957
+ * @returns バウンディングボックス情報
958
+ */
959
+ calcArcBounds_(t, e, n) {
960
+ const s = n.length, i = new Float64Array(s * 4), o = new Se();
961
+ let a = 0, c, l, u;
962
+ for (let h = 0; h < s; h++)
963
+ c = n[h], c > 0 && (l = h * 4, u = pi(t, e, a, c), i[l++] = u[0], i[l++] = u[1], i[l++] = u[2], i[l] = u[3], a += c, o.mergeBounds(u));
964
+ return {
965
+ bb: i,
966
+ bounds: o
967
+ };
968
+ }
969
+ getBounds() {
970
+ return this._allBounds.clone();
971
+ }
972
+ // @cb function(i, j, xx, yy)
973
+ forEachSegment(t) {
974
+ let e = 0;
975
+ for (let n = 0, s = this.size(); n < s; n++)
976
+ e += this.forEachArcSegment(n, t);
977
+ return e;
978
+ }
979
+ size() {
980
+ return this._ii && this._ii.length || 0;
981
+ }
982
+ // @cb function(i, j, xx, yy)
983
+ forEachArcSegment(t, e) {
984
+ const n = t >= 0, s = n ? t : ~t, i = this.getRetainedInterval(), o = this._nn[s], a = n ? 1 : -1;
985
+ let c = n ? this._ii[s] : this._ii[s] + o - 1, l = c, u = 0;
986
+ for (let h = 1; h < o; h++)
987
+ l += a, (i === 0 || this._zz[l] >= i) && (e(c, l, this._xx, this._yy), c = l, u++);
988
+ return u;
989
+ }
990
+ getRetainedInterval() {
991
+ return this._zlimit;
992
+ }
993
+ // Give access to raw data arrays...
994
+ getVertexData() {
995
+ return {
996
+ xx: this._xx,
997
+ yy: this._yy,
998
+ zz: this._zz,
999
+ bb: this._bb,
1000
+ nn: this._nn,
1001
+ ii: this._ii
1002
+ };
1003
+ }
1004
+ getUint32Array(t) {
1005
+ const e = t * 4;
1006
+ return (!this.buf || this.buf.byteLength < e) && (this.buf = new ArrayBuffer(e)), new Uint32Array(this.buf, 0, t);
1007
+ }
1008
+ // Return average magnitudes of dx, dy (with simplification)
1009
+ getAvgSegment2() {
1010
+ let t = 0, e = 0;
1011
+ const n = this.forEachSegment(
1012
+ (s, i, o, a) => {
1013
+ t += Math.abs(o[s] - o[i]), e += Math.abs(a[s] - a[i]);
1014
+ }
1015
+ );
1016
+ return [t / n || 0, e / n || 0];
1017
+ }
1018
+ /**
1019
+ * 交差判定のためのストライプ数を計算
1020
+ * 線分の平均長さに基づいて最適な分割数を決定
1021
+ */
1022
+ calcSegmentIntersectionStripeCount() {
1023
+ const t = this.getBounds().height(), e = this.getAvgSegment2()[1];
1024
+ let n = 1;
1025
+ return e > 0 && t > 0 && (n = Math.ceil(t / e / 20)), n || 1;
1026
+ }
1027
+ /**
1028
+ * 線分の交差を検出
1029
+ * ストライプ分割による効率的な判定を実装
1030
+ *
1031
+ * @returns 検出された交差点の配列
1032
+ */
1033
+ findSegmentIntersections() {
1034
+ const t = this.getBounds(), e = t.ymin, n = t.ymax - e, s = this.calcSegmentIntersectionStripeCount(), i = new Uint32Array(s), o = s > 1 ? (d) => Math.floor((s - 1) * (d - e) / n) : () => 0;
1035
+ let a, c;
1036
+ this.forEachSegment(
1037
+ (d, y, v, p) => {
1038
+ let w = o(p[d]);
1039
+ const x = o(p[y]);
1040
+ for (; i[w] = i[w] + 2, w != x; )
1041
+ w += x > w ? 1 : -1;
1042
+ }
1043
+ );
1044
+ const l = this.getUint32Array(Hr(i));
1045
+ let u = 0;
1046
+ const h = [];
1047
+ Kr(i, (d) => {
1048
+ const y = u;
1049
+ u += d, h.push(l.subarray(y, u));
1050
+ }), Qr(i, 0), this.forEachSegment(
1051
+ (d, y, v, p) => {
1052
+ let w = o(p[d]);
1053
+ const x = o(p[y]);
1054
+ let E, A;
1055
+ for (; E = i[w], i[w] = E + 2, A = h[w], A[E] = d, A[E + 1] = y, w != x; )
1056
+ w += x > w ? 1 : -1;
1057
+ }
1058
+ );
1059
+ const f = this.getVertexData(), g = [];
1060
+ let _;
1061
+ for (a = 0; a < s; a++)
1062
+ for (_ = Zr(h[a], f.xx, f.yy), c = 0; c < _.length; c++)
1063
+ g.push(_[c]);
1064
+ return $n(g);
1065
+ }
1066
+ }
1067
+ function Ve(...r) {
1068
+ const t = r.join(" ");
1069
+ throw new Error(t);
1070
+ }
1071
+ function We(r) {
1072
+ return r ? Jr(r) ? !0 : Gr(r) ? !1 : r.length === 0 ? !0 : r.length > 0 : !1;
1073
+ }
1074
+ function Gr(r) {
1075
+ return r != null && r.toString === String.prototype.toString;
1076
+ }
1077
+ function Jr(r) {
1078
+ return Array.isArray(r);
1079
+ }
1080
+ function Hr(r, t) {
1081
+ We(r) || Ve("utils.sum() expects an array, received:", r);
1082
+ let e = 0, n;
1083
+ for (let s = 0, i = r.length; s < i; s++)
1084
+ n = r[s], n && (e += n);
1085
+ return e;
1086
+ }
1087
+ function Kr(r, t, e) {
1088
+ if (!We(r))
1089
+ throw new Error(`#forEach() takes an array-like argument. ${r}`);
1090
+ for (let n = 0, s = r.length; n < s; n++)
1091
+ t.call(e, r[n], n);
1092
+ }
1093
+ function Qr(r, t) {
1094
+ for (let e = 0, n = r.length; e < n; e++)
1095
+ r[e] = t;
1096
+ return r;
1097
+ }
1098
+ function Zr(r, t, e) {
1099
+ const n = r.length - 2, s = [];
1100
+ let i, o, a, c, l, u, h, f, g, _, d, y, v, p, w, x, E;
1101
+ for (ci(t, r), x = 0; x < n; ) {
1102
+ for (i = r[x], o = r[x + 1], l = t[i], u = t[o], g = e[i], _ = e[o], E = x; E < n && (E += 2, a = r[E], h = t[a], !(u < h)); ) {
1103
+ if (d = e[a], c = r[E + 1], f = t[c], y = e[c], g >= d) {
1104
+ if (g > y && _ > d && _ > y) continue;
1105
+ } else if (g < y && _ < d && _ < y) continue;
1106
+ i == a || i == c || o == a || o == c || (v = ti(
1107
+ l,
1108
+ g,
1109
+ u,
1110
+ _,
1111
+ h,
1112
+ d,
1113
+ f,
1114
+ y
1115
+ ), v && (p = [i, o], w = [a, c], s.push(fn(v, p, w, t, e)), v.length == 4 && s.push(
1116
+ fn(v.slice(2), p, w, t, e)
1117
+ )));
1118
+ }
1119
+ x += 2;
1120
+ }
1121
+ return s;
1122
+ }
1123
+ function ti(r, t, e, n, s, i, o, a) {
1124
+ const c = ei(r, t, e, n, s, i, o, a);
1125
+ let l = null;
1126
+ return c && (l = ni(r, t, e, n, s, i, o, a), l ? hi(r, t, e, n, s, i, o, a) && (l = null) : l = ai(r, t, e, n, s, i, o, a)), l;
1127
+ }
1128
+ function ei(r, t, e, n, s, i, o, a) {
1129
+ return re(r, t, e, n, s, i) * re(r, t, e, n, o, a) <= 0 && re(s, i, o, a, r, t) * re(s, i, o, a, e, n) <= 0;
1130
+ }
1131
+ function re(r, t, e, n, s, i) {
1132
+ return Cn(r - s, t - i, e - s, n - i);
1133
+ }
1134
+ function Cn(r, t, e, n) {
1135
+ return r * n - t * e;
1136
+ }
1137
+ function ni(r, t, e, n, s, i, o, a) {
1138
+ let c = ue(r, t, e, n, s, i, o, a), l;
1139
+ return c && (l = ii(c[0], c[1], r, t, e, n, s, i, o, a), l == 1 ? c = ue(e, n, r, t, s, i, o, a) : l == 2 ? c = ue(s, i, o, a, r, t, e, n) : l == 3 && (c = ue(o, a, s, i, r, t, e, n))), c && oi(c, r, t, e, n, s, i, o, a), c;
1140
+ }
1141
+ function ue(r, t, e, n, s, i, o, a) {
1142
+ const c = Cn(e - r, n - t, o - s, a - i), l = 1e-18;
1143
+ let u;
1144
+ if (c === 0) return null;
1145
+ const h = re(s, i, o, a, r, t) / c;
1146
+ return c <= l && c >= -l ? u = ri(r, t, e, n, s, i, o, a) : u = [r + h * (e - r), t + h * (n - t)], u;
1147
+ }
1148
+ function ri(r, t, e, n, s, i, o, a) {
1149
+ let c = null;
1150
+ return !Bt(r, s, o) && !Bt(t, i, a) ? c = [r, t] : !Bt(e, s, o) && !Bt(n, i, a) ? c = [e, n] : !Bt(s, r, e) && !Bt(i, t, n) ? c = [s, i] : !Bt(o, r, e) && !Bt(a, t, n) && (c = [o, a]), c;
1151
+ }
1152
+ function Bt(r, t, e) {
1153
+ let n;
1154
+ return t < e ? n = r < t || r > e : t > e ? n = r > t || r < e : n = r != t, n;
1155
+ }
1156
+ function ii(r, t, ...e) {
1157
+ let n = -1, s = 1 / 0, i;
1158
+ for (let o = 0, a = 0, c = e.length; a < c; o++, a += 2)
1159
+ i = si(r, t, e[a], e[a + 1]), i < s && (s = i, n = o);
1160
+ return n;
1161
+ }
1162
+ function si(r, t, e, n) {
1163
+ const s = r - e, i = t - n;
1164
+ return s * s + i * i;
1165
+ }
1166
+ function oi(r, t, e, n, s, i, o, a, c) {
1167
+ let l = r[0], u = r[1];
1168
+ l = de(l, t, n), l = de(l, i, a), u = de(u, e, s), u = de(u, o, c), r[0] = l, r[1] = u;
1169
+ }
1170
+ function de(r, t, e) {
1171
+ let n;
1172
+ return Bt(r, t, e) && (n = Math.abs(r - t) < Math.abs(r - e) ? t : e, r = n), r;
1173
+ }
1174
+ function ai(r, t, e, n, s, i, o, a) {
1175
+ const c = Math.min(r, e, s, o), l = Math.max(r, e, s, o), u = Math.min(t, n, i, a), h = Math.max(t, n, i, a), f = h - u > l - c;
1176
+ let g = [];
1177
+ return (f ? Nt(t, u, h) : Nt(r, c, l)) && g.push(r, t), (f ? Nt(n, u, h) : Nt(e, c, l)) && g.push(e, n), (f ? Nt(i, u, h) : Nt(s, c, l)) && g.push(s, i), (f ? Nt(a, u, h) : Nt(o, c, l)) && g.push(o, a), (g.length != 2 && g.length != 4 || g.length == 4 && g[0] == g[2] && g[1] == g[3]) && (g = null), g;
1178
+ }
1179
+ function hi(r, t, e, n, s, i, o, a) {
1180
+ return r == s && t == i || r == o && t == a || e == s && n == i || e == o && n == a;
1181
+ }
1182
+ function Nt(r, t, e) {
1183
+ return r > t && r < e;
1184
+ }
1185
+ function ci(r, t) {
1186
+ li(r, t), Nn(r, t, 0, t.length - 2);
1187
+ }
1188
+ function li(r, t) {
1189
+ for (let e = 0, n = t.length; e < n; e += 2)
1190
+ r[t[e]] > r[t[e + 1]] && fi(t, e, e + 1);
1191
+ }
1192
+ function fi(r, t, e) {
1193
+ const n = r[t];
1194
+ r[t] = r[e], r[e] = n;
1195
+ }
1196
+ function Nn(r, t, e, n) {
1197
+ let s = e, i = n, o, a;
1198
+ for (; s < n; ) {
1199
+ for (o = r[t[e + n >> 2 << 1]]; s <= i; ) {
1200
+ for (; r[t[s]] < o; ) s += 2;
1201
+ for (; r[t[i]] > o; ) i -= 2;
1202
+ s <= i && (a = t[s], t[s] = t[i], t[i] = a, a = t[s + 1], t[s + 1] = t[i + 1], t[i + 1] = a, s += 2, i -= 2);
1203
+ }
1204
+ if (i - e < 40 ? ln(r, t, e, i) : Nn(r, t, e, i), n - s < 40) {
1205
+ ln(r, t, s, n);
1206
+ return;
1207
+ }
1208
+ e = s, i = n;
1209
+ }
1210
+ }
1211
+ function ln(r, t, e, n) {
1212
+ let s, i;
1213
+ for (let o = e + 2; o <= n; o += 2) {
1214
+ s = t[o], i = t[o + 1];
1215
+ let a;
1216
+ for (a = o - 2; a >= e && r[s] < r[t[a]]; a -= 2)
1217
+ t[a + 2] = t[a], t[a + 3] = t[a + 1];
1218
+ t[a + 2] = s, t[a + 3] = i;
1219
+ }
1220
+ }
1221
+ function fn(r, t, e, n, s) {
1222
+ const i = r[0], o = r[1];
1223
+ t = un(i, o, t[0], t[1], n, s), e = un(i, o, e[0], e[1], n, s);
1224
+ const a = t[0] < e[0] ? t : e, c = a == t ? e : t;
1225
+ return { x: i, y: o, a, b: c };
1226
+ }
1227
+ function un(r, t, e, n, s, i) {
1228
+ let o = e < n ? e : n, a = o === e ? n : e;
1229
+ return s[o] == r && i[o] == t ? a = o : s[a] == r && i[a] == t && (o = a), [o, a];
1230
+ }
1231
+ function $n(r) {
1232
+ const t = {};
1233
+ return r.filter((e) => {
1234
+ const n = ui(e);
1235
+ return n in t ? !1 : (t[n] = !0, !0);
1236
+ });
1237
+ }
1238
+ function ui(r) {
1239
+ return `${r.a.join(",")};${r.b.join(",")}`;
1240
+ }
1241
+ class di {
1242
+ constructor(t, e) {
1243
+ at(this, "_i", 0);
1244
+ at(this, "_n", 0);
1245
+ at(this, "_inc", 1);
1246
+ at(this, "_xx");
1247
+ at(this, "_yy");
1248
+ at(this, "i", 0);
1249
+ at(this, "x", 0);
1250
+ at(this, "y", 0);
1251
+ this._xx = t, this._yy = e;
1252
+ }
1253
+ }
1254
+ function pi(r, t, e, n) {
1255
+ let s = e | 0;
1256
+ const i = isNaN(n) ? r.length - s : n + s;
1257
+ let o, a, c, l, u, h;
1258
+ if (i > 0)
1259
+ c = u = r[s], l = h = t[s];
1260
+ else return [void 0, void 0, void 0, void 0];
1261
+ for (s++; s < i; s++)
1262
+ o = r[s], a = t[s], o < c && (c = o), o > u && (u = o), a < l && (l = a), a > h && (h = a);
1263
+ return [c, l, u, h];
1264
+ }
1265
+ class Se {
1266
+ constructor(...t) {
1267
+ at(this, "xmin");
1268
+ at(this, "ymin");
1269
+ at(this, "xmax");
1270
+ at(this, "ymax");
1271
+ t.length > 0 && this.setBounds(t);
1272
+ }
1273
+ // Return a bounding box with the same extent as this one.
1274
+ cloneBounds() {
1275
+ return this.clone();
1276
+ }
1277
+ clone() {
1278
+ return new Se(this.xmin, this.ymin, this.xmax, this.ymax);
1279
+ }
1280
+ width() {
1281
+ return this.xmax - this.xmin || 0;
1282
+ }
1283
+ height() {
1284
+ return this.ymax - this.ymin || 0;
1285
+ }
1286
+ setBounds(t, e, n, s) {
1287
+ return arguments.length == 1 && (We(t) ? (e = t[1], n = t[2], s = t[3], t = t[0]) : (e = t.ymin, n = t.xmax, s = t.ymax, t = t.xmin)), this.xmin = t, this.ymin = e, this.xmax = n, this.ymax = s, (t > n || e > s) && this.update(), this;
1288
+ }
1289
+ update() {
1290
+ let t;
1291
+ 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);
1292
+ }
1293
+ mergeBounds(t, ...e) {
1294
+ let n, s, i, o;
1295
+ return t instanceof Se ? (n = t.xmin, s = t.ymin, i = t.xmax, o = t.ymax) : e.length == 3 ? (n = t, s = e[0], i = e[1], o = e[2]) : t.length == 4 ? (n = t[0], s = t[1], i = t[2], o = t[3]) : Ve("Bounds#mergeBounds() invalid argument:", t), this.xmin === void 0 ? this.setBounds(n, s, i, o) : (n < this.xmin && (this.xmin = n), s < this.ymin && (this.ymin = s), i > this.xmax && (this.xmax = i), o > this.ymax && (this.ymax = o)), this;
1296
+ }
1297
+ }
1298
+ const dn = Math.pow(2, -52), pe = new Uint32Array(512);
1299
+ class Ge {
1300
+ static from(t, e = vi, n = _i) {
1301
+ const s = t.length, i = new Float64Array(s * 2);
1302
+ for (let o = 0; o < s; o++) {
1303
+ const a = t[o];
1304
+ i[2 * o] = e(a), i[2 * o + 1] = n(a);
1305
+ }
1306
+ return new Ge(i);
1307
+ }
1308
+ constructor(t) {
1309
+ const e = t.length >> 1;
1310
+ if (e > 0 && typeof t[0] != "number") throw new Error("Expected coords to contain numbers.");
1311
+ this.coords = t;
1312
+ const n = Math.max(2 * e - 5, 0);
1313
+ this._triangles = new Uint32Array(n * 3), this._halfedges = new Int32Array(n * 3), this._hashSize = Math.ceil(Math.sqrt(e)), this._hullPrev = new Uint32Array(e), this._hullNext = new Uint32Array(e), this._hullTri = new Uint32Array(e), this._hullHash = new Int32Array(this._hashSize).fill(-1), this._ids = new Uint32Array(e), this._dists = new Float64Array(e), this.update();
1314
+ }
1315
+ update() {
1316
+ const { coords: t, _hullPrev: e, _hullNext: n, _hullTri: s, _hullHash: i } = this, o = t.length >> 1;
1317
+ let a = 1 / 0, c = 1 / 0, l = -1 / 0, u = -1 / 0;
1318
+ for (let O = 0; O < o; O++) {
1319
+ const I = t[2 * O], C = t[2 * O + 1];
1320
+ I < a && (a = I), C < c && (c = C), I > l && (l = I), C > u && (u = C), this._ids[O] = O;
1321
+ }
1322
+ const h = (a + l) / 2, f = (c + u) / 2;
1323
+ let g = 1 / 0, _, d, y;
1324
+ for (let O = 0; O < o; O++) {
1325
+ const I = Ye(h, f, t[2 * O], t[2 * O + 1]);
1326
+ I < g && (_ = O, g = I);
1327
+ }
1328
+ const v = t[2 * _], p = t[2 * _ + 1];
1329
+ g = 1 / 0;
1330
+ for (let O = 0; O < o; O++) {
1331
+ if (O === _) continue;
1332
+ const I = Ye(v, p, t[2 * O], t[2 * O + 1]);
1333
+ I < g && I > 0 && (d = O, g = I);
1334
+ }
1335
+ let w = t[2 * d], x = t[2 * d + 1], E = 1 / 0;
1336
+ for (let O = 0; O < o; O++) {
1337
+ if (O === _ || O === d) continue;
1338
+ const I = wi(v, p, w, x, t[2 * O], t[2 * O + 1]);
1339
+ I < E && (y = O, E = I);
1340
+ }
1341
+ let A = t[2 * y], T = t[2 * y + 1];
1342
+ if (E === 1 / 0) {
1343
+ for (let C = 0; C < o; C++)
1344
+ this._dists[C] = t[2 * C] - t[0] || t[2 * C + 1] - t[1];
1345
+ Kt(this._ids, this._dists, 0, o - 1);
1346
+ const O = new Uint32Array(o);
1347
+ let I = 0;
1348
+ for (let C = 0, N = -1 / 0; C < o; C++) {
1349
+ const m = this._ids[C];
1350
+ this._dists[m] > N && (O[I++] = m, N = this._dists[m]);
1351
+ }
1352
+ this.hull = O.subarray(0, I), this.triangles = new Uint32Array(0), this.halfedges = new Uint32Array(0);
1353
+ return;
1354
+ }
1355
+ if (ne(v, p, w, x, A, T) < 0) {
1356
+ const O = d, I = w, C = x;
1357
+ d = y, w = A, x = T, y = O, A = I, T = C;
1358
+ }
1359
+ const S = yi(v, p, w, x, A, T);
1360
+ this._cx = S.x, this._cy = S.y;
1361
+ for (let O = 0; O < o; O++)
1362
+ this._dists[O] = Ye(t[2 * O], t[2 * O + 1], S.x, S.y);
1363
+ Kt(this._ids, this._dists, 0, o - 1), this._hullStart = _;
1364
+ let B = 3;
1365
+ n[_] = e[y] = d, n[d] = e[_] = y, n[y] = e[d] = _, s[_] = 0, s[d] = 1, s[y] = 2, i.fill(-1), i[this._hashKey(v, p)] = _, i[this._hashKey(w, x)] = d, i[this._hashKey(A, T)] = y, this.trianglesLen = 0, this._addTriangle(_, d, y, -1, -1, -1);
1366
+ for (let O = 0, I, C; O < this._ids.length; O++) {
1367
+ const N = this._ids[O], m = t[2 * N], M = t[2 * N + 1];
1368
+ if (O > 0 && Math.abs(m - I) <= dn && Math.abs(M - C) <= dn || (I = m, C = M, N === _ || N === d || N === y)) continue;
1369
+ let k = 0;
1370
+ for (let Y = 0, D = this._hashKey(m, M); Y < this._hashSize && (k = i[(D + Y) % this._hashSize], !(k !== -1 && k !== n[k])); Y++)
1371
+ ;
1372
+ k = e[k];
1373
+ let P = k, X;
1374
+ for (; X = n[P], ne(m, M, t[2 * P], t[2 * P + 1], t[2 * X], t[2 * X + 1]) >= 0; )
1375
+ if (P = X, P === k) {
1376
+ P = -1;
1377
+ break;
1378
+ }
1379
+ if (P === -1) continue;
1380
+ let R = this._addTriangle(P, N, n[P], -1, -1, s[P]);
1381
+ s[N] = this._legalize(R + 2), s[P] = R, B++;
1382
+ let b = n[P];
1383
+ for (; X = n[b], ne(m, M, t[2 * b], t[2 * b + 1], t[2 * X], t[2 * X + 1]) < 0; )
1384
+ R = this._addTriangle(b, N, X, s[N], -1, s[b]), s[N] = this._legalize(R + 2), n[b] = b, B--, b = X;
1385
+ if (P === k)
1386
+ for (; X = e[P], ne(m, M, t[2 * X], t[2 * X + 1], t[2 * P], t[2 * P + 1]) < 0; )
1387
+ R = this._addTriangle(X, N, P, -1, s[P], s[X]), this._legalize(R + 2), s[X] = R, n[P] = P, B--, P = X;
1388
+ this._hullStart = e[N] = P, n[P] = e[b] = N, n[N] = b, i[this._hashKey(m, M)] = N, i[this._hashKey(t[2 * P], t[2 * P + 1])] = P;
1389
+ }
1390
+ this.hull = new Uint32Array(B);
1391
+ for (let O = 0, I = this._hullStart; O < B; O++)
1392
+ this.hull[O] = I, I = n[I];
1393
+ this.triangles = this._triangles.subarray(0, this.trianglesLen), this.halfedges = this._halfedges.subarray(0, this.trianglesLen);
1394
+ }
1395
+ _hashKey(t, e) {
1396
+ return Math.floor(gi(t - this._cx, e - this._cy) * this._hashSize) % this._hashSize;
1397
+ }
1398
+ _legalize(t) {
1399
+ const { _triangles: e, _halfedges: n, coords: s } = this;
1400
+ let i = 0, o = 0;
1401
+ for (; ; ) {
1402
+ const a = n[t], c = t - t % 3;
1403
+ if (o = c + (t + 2) % 3, a === -1) {
1404
+ if (i === 0) break;
1405
+ t = pe[--i];
1406
+ continue;
1407
+ }
1408
+ const l = a - a % 3, u = c + (t + 1) % 3, h = l + (a + 2) % 3, f = e[o], g = e[t], _ = e[u], d = e[h];
1409
+ if (mi(
1410
+ s[2 * f],
1411
+ s[2 * f + 1],
1412
+ s[2 * g],
1413
+ s[2 * g + 1],
1414
+ s[2 * _],
1415
+ s[2 * _ + 1],
1416
+ s[2 * d],
1417
+ s[2 * d + 1]
1418
+ )) {
1419
+ e[t] = d, e[a] = f;
1420
+ const v = n[h];
1421
+ if (v === -1) {
1422
+ let w = this._hullStart;
1423
+ do {
1424
+ if (this._hullTri[w] === h) {
1425
+ this._hullTri[w] = t;
1426
+ break;
1427
+ }
1428
+ w = this._hullPrev[w];
1429
+ } while (w !== this._hullStart);
1430
+ }
1431
+ this._link(t, v), this._link(a, n[o]), this._link(o, h);
1432
+ const p = l + (a + 1) % 3;
1433
+ i < pe.length && (pe[i++] = p);
1434
+ } else {
1435
+ if (i === 0) break;
1436
+ t = pe[--i];
1437
+ }
1438
+ }
1439
+ return o;
1440
+ }
1441
+ _link(t, e) {
1442
+ this._halfedges[t] = e, e !== -1 && (this._halfedges[e] = t);
1443
+ }
1444
+ // add a new triangle given vertex indices and adjacent half-edge ids
1445
+ _addTriangle(t, e, n, s, i, o) {
1446
+ const a = this.trianglesLen;
1447
+ return this._triangles[a] = t, this._triangles[a + 1] = e, this._triangles[a + 2] = n, this._link(a, s), this._link(a + 1, i), this._link(a + 2, o), this.trianglesLen += 3, a;
1448
+ }
1449
+ }
1450
+ function gi(r, t) {
1451
+ const e = r / (Math.abs(r) + Math.abs(t));
1452
+ return (t > 0 ? 3 - e : 1 + e) / 4;
1453
+ }
1454
+ function Ye(r, t, e, n) {
1455
+ const s = r - e, i = t - n;
1456
+ return s * s + i * i;
1457
+ }
1458
+ function mi(r, t, e, n, s, i, o, a) {
1459
+ const c = r - o, l = t - a, u = e - o, h = n - a, f = s - o, g = i - a, _ = c * c + l * l, d = u * u + h * h, y = f * f + g * g;
1460
+ return c * (h * y - d * g) - l * (u * y - d * f) + _ * (u * g - h * f) < 0;
1461
+ }
1462
+ function wi(r, t, e, n, s, i) {
1463
+ const o = e - r, a = n - t, c = s - r, l = i - t, u = o * o + a * a, h = c * c + l * l, f = 0.5 / (o * l - a * c), g = (l * u - a * h) * f, _ = (o * h - c * u) * f;
1464
+ return g * g + _ * _;
1465
+ }
1466
+ function yi(r, t, e, n, s, i) {
1467
+ const o = e - r, a = n - t, c = s - r, l = i - t, u = o * o + a * a, h = c * c + l * l, f = 0.5 / (o * l - a * c), g = r + (l * u - a * h) * f, _ = t + (o * h - c * u) * f;
1468
+ return { x: g, y: _ };
1469
+ }
1470
+ function Kt(r, t, e, n) {
1471
+ if (n - e <= 20)
1472
+ for (let s = e + 1; s <= n; s++) {
1473
+ const i = r[s], o = t[i];
1474
+ let a = s - 1;
1475
+ for (; a >= e && t[r[a]] > o; ) r[a + 1] = r[a--];
1476
+ r[a + 1] = i;
1477
+ }
1478
+ else {
1479
+ const s = e + n >> 1;
1480
+ let i = e + 1, o = n;
1481
+ te(r, s, i), t[r[e]] > t[r[n]] && te(r, e, n), t[r[i]] > t[r[n]] && te(r, i, n), t[r[e]] > t[r[i]] && te(r, e, i);
1482
+ const a = r[i], c = t[a];
1483
+ for (; ; ) {
1484
+ do
1485
+ i++;
1486
+ while (t[r[i]] < c);
1487
+ do
1488
+ o--;
1489
+ while (t[r[o]] > c);
1490
+ if (o < i) break;
1491
+ te(r, i, o);
1492
+ }
1493
+ r[e + 1] = r[o], r[o] = a, n - i + 1 >= o - e ? (Kt(r, t, i, n), Kt(r, t, e, o - 1)) : (Kt(r, t, e, o - 1), Kt(r, t, i, n));
1494
+ }
1495
+ }
1496
+ function te(r, t, e) {
1497
+ const n = r[t];
1498
+ r[t] = r[e], r[e] = n;
1499
+ }
1500
+ function vi(r) {
1501
+ return r[0];
1502
+ }
1503
+ function _i(r) {
1504
+ return r[1];
1505
+ }
1506
+ const mt = 11102230246251565e-32, q = 134217729, Dn = (3 + 8 * mt) * mt;
1507
+ function ft(r, t, e, n, s) {
1508
+ let i, o, a, c, l = t[0], u = n[0], h = 0, f = 0;
1509
+ u > l == u > -l ? (i = l, l = t[++h]) : (i = u, u = n[++f]);
1510
+ let g = 0;
1511
+ if (h < r && f < e)
1512
+ for (u > l == u > -l ? (o = l + i, a = i - (o - l), l = t[++h]) : (o = u + i, a = i - (o - u), u = n[++f]), i = o, a !== 0 && (s[g++] = a); h < r && f < e; )
1513
+ u > l == u > -l ? (o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h]) : (o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f]), i = o, a !== 0 && (s[g++] = a);
1514
+ for (; h < r; )
1515
+ o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h], i = o, a !== 0 && (s[g++] = a);
1516
+ for (; f < e; )
1517
+ o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f], i = o, a !== 0 && (s[g++] = a);
1518
+ return (i !== 0 || g === 0) && (s[g++] = i), g;
1519
+ }
1520
+ function Mt(r, t, e, n, s, i, o, a) {
1521
+ return ft(ft(r, t, e, n, o), o, s, i, a);
1522
+ }
1523
+ function $(r, t, e, n) {
1524
+ let s, i, o, a, c, l, u, h, f, g, _;
1525
+ u = q * e, g = u - (u - e), _ = e - g;
1526
+ let d = t[0];
1527
+ s = d * e, u = q * d, h = u - (u - d), f = d - h, o = f * _ - (s - h * g - f * g - h * _);
1528
+ let y = 0;
1529
+ o !== 0 && (n[y++] = o);
1530
+ for (let v = 1; v < r; v++)
1531
+ d = t[v], a = d * e, u = q * d, h = u - (u - d), f = d - h, c = f * _ - (a - h * g - f * g - h * _), i = s + c, l = i - s, o = s - (i - l) + (c - l), o !== 0 && (n[y++] = o), s = a + i, o = i - (s - a), o !== 0 && (n[y++] = o);
1532
+ return (s !== 0 || y === 0) && (n[y++] = s), y;
1533
+ }
1534
+ function Rn(r, t) {
1535
+ let e = t[0];
1536
+ for (let n = 1; n < r; n++) e += t[n];
1537
+ return e;
1538
+ }
1539
+ function tt(r) {
1540
+ return new Float64Array(r);
1541
+ }
1542
+ const xi = (3 + 16 * mt) * mt, bi = (2 + 12 * mt) * mt, Mi = (9 + 64 * mt) * mt * mt, Gt = tt(4), pn = tt(8), gn = tt(12), mn = tt(16), yt = tt(4);
1543
+ function Si(r, t, e, n, s, i, o) {
1544
+ let a, c, l, u, h, f, g, _, d, y, v, p, w, x, E, A, T, S;
1545
+ const B = r - s, O = e - s, I = t - i, C = n - i;
1546
+ x = B * C, f = q * B, g = f - (f - B), _ = B - g, f = q * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * O, f = q * I, g = f - (f - I), _ = I - g, f = q * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, Gt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, Gt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, Gt[2] = p - (S - h) + (v - h), Gt[3] = S;
1547
+ let N = Rn(4, Gt), m = bi * o;
1548
+ if (N >= m || -N >= m || (h = r - B, a = r - (B + h) + (h - s), h = e - O, l = e - (O + h) + (h - s), h = t - I, c = t - (I + h) + (h - i), h = n - C, u = n - (C + h) + (h - i), a === 0 && c === 0 && l === 0 && u === 0) || (m = Mi * o + Dn * Math.abs(N), N += B * u + C * a - (I * l + O * c), N >= m || -N >= m)) return N;
1549
+ x = a * C, f = q * a, g = f - (f - a), _ = a - g, f = q * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * O, f = q * c, g = f - (f - c), _ = c - g, f = q * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, yt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, yt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, yt[2] = p - (S - h) + (v - h), yt[3] = S;
1550
+ const M = ft(4, Gt, 4, yt, pn);
1551
+ x = B * u, f = q * B, g = f - (f - B), _ = B - g, f = q * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * l, f = q * I, g = f - (f - I), _ = I - g, f = q * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, yt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, yt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, yt[2] = p - (S - h) + (v - h), yt[3] = S;
1552
+ const k = ft(M, pn, 4, yt, gn);
1553
+ x = a * u, f = q * a, g = f - (f - a), _ = a - g, f = q * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * l, f = q * c, g = f - (f - c), _ = c - g, f = q * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, yt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, yt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, yt[2] = p - (S - h) + (v - h), yt[3] = S;
1554
+ const P = ft(k, gn, 4, yt, mn);
1555
+ return mn[P - 1];
1556
+ }
1557
+ function ie(r, t, e, n, s, i) {
1558
+ const o = (t - i) * (e - s), a = (r - s) * (n - i), c = o - a, l = Math.abs(o + a);
1559
+ return Math.abs(c) >= xi * l ? c : -Si(r, t, e, n, s, i, l);
1560
+ }
1561
+ const Ei = (10 + 96 * mt) * mt, ki = (4 + 48 * mt) * mt, Ai = (44 + 576 * mt) * mt * mt, $t = tt(4), Dt = tt(4), Rt = tt(4), kt = tt(4), At = tt(4), Pt = tt(4), vt = tt(4), _t = tt(4), Ie = tt(8), Ce = tt(8), Ne = tt(8), $e = tt(8), De = tt(8), Re = tt(8), ge = tt(8), me = tt(8), we = tt(8), Ft = tt(4), Ut = tt(4), jt = tt(4), V = tt(8), G = tt(16), nt = tt(16), rt = tt(16), et = tt(32), Lt = tt(32), ct = tt(48), bt = tt(64);
1562
+ let Qt = tt(1152), Le = tt(1152);
1563
+ function lt(r, t, e) {
1564
+ r = ft(r, Qt, t, e, Le);
1565
+ const n = Qt;
1566
+ return Qt = Le, Le = n, r;
1567
+ }
1568
+ function Pi(r, t, e, n, s, i, o, a, c) {
1569
+ let l, u, h, f, g, _, d, y, v, p, w, x, E, A, T, S, B, O, I, C, N, m, M, k, P, X, R, b, Y, D, L, F, z, j, U;
1570
+ const J = r - o, W = e - o, H = s - o, K = t - a, Z = n - a, Q = i - a;
1571
+ L = W * Q, M = q * W, k = M - (M - W), P = W - k, M = q * Q, X = M - (M - Q), R = Q - X, F = P * R - (L - k * X - P * X - k * R), z = H * Z, M = q * H, k = M - (M - H), P = H - k, M = q * Z, X = M - (M - Z), R = Z - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, $t[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, $t[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, $t[2] = Y - (U - m) + (b - m), $t[3] = U, L = H * K, M = q * H, k = M - (M - H), P = H - k, M = q * K, X = M - (M - K), R = K - X, F = P * R - (L - k * X - P * X - k * R), z = J * Q, M = q * J, k = M - (M - J), P = J - k, M = q * Q, X = M - (M - Q), R = Q - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, Dt[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, Dt[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, Dt[2] = Y - (U - m) + (b - m), Dt[3] = U, L = J * Z, M = q * J, k = M - (M - J), P = J - k, M = q * Z, X = M - (M - Z), R = Z - X, F = P * R - (L - k * X - P * X - k * R), z = W * K, M = q * W, k = M - (M - W), P = W - k, M = q * K, X = M - (M - K), R = K - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, Rt[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, Rt[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, Rt[2] = Y - (U - m) + (b - m), Rt[3] = U, l = ft(
1572
+ ft(
1573
+ ft(
1574
+ $($(4, $t, J, V), V, J, G),
1575
+ G,
1576
+ $($(4, $t, K, V), V, K, nt),
1577
+ nt,
1578
+ et
1579
+ ),
1580
+ et,
1581
+ ft(
1582
+ $($(4, Dt, W, V), V, W, G),
1583
+ G,
1584
+ $($(4, Dt, Z, V), V, Z, nt),
1585
+ nt,
1586
+ Lt
1587
+ ),
1588
+ Lt,
1589
+ bt
1590
+ ),
1591
+ bt,
1592
+ ft(
1593
+ $($(4, Rt, H, V), V, H, G),
1594
+ G,
1595
+ $($(4, Rt, Q, V), V, Q, nt),
1596
+ nt,
1597
+ et
1598
+ ),
1599
+ et,
1600
+ Qt
1601
+ );
1602
+ let ut = Rn(l, Qt), dt = ki * c;
1603
+ if (ut >= dt || -ut >= dt || (m = r - J, u = r - (J + m) + (m - o), m = t - K, g = t - (K + m) + (m - a), m = e - W, h = e - (W + m) + (m - o), m = n - Z, _ = n - (Z + m) + (m - a), m = s - H, f = s - (H + m) + (m - o), m = i - Q, d = i - (Q + m) + (m - a), u === 0 && h === 0 && f === 0 && g === 0 && _ === 0 && d === 0) || (dt = Ai * c + Dn * Math.abs(ut), ut += (J * J + K * K) * (W * d + Q * h - (Z * f + H * _)) + 2 * (J * u + K * g) * (W * Q - Z * H) + ((W * W + Z * Z) * (H * g + K * f - (Q * u + J * d)) + 2 * (W * h + Z * _) * (H * K - Q * J)) + ((H * H + Q * Q) * (J * _ + Z * u - (K * h + W * g)) + 2 * (H * f + Q * d) * (J * Z - K * W)), ut >= dt || -ut >= dt))
1604
+ return ut;
1605
+ if ((h !== 0 || _ !== 0 || f !== 0 || d !== 0) && (L = J * J, M = q * J, k = M - (M - J), P = J - k, F = P * P - (L - k * k - (k + k) * P), z = K * K, M = q * K, k = M - (M - K), P = K - k, j = P * P - (z - k * k - (k + k) * P), b = F + j, m = b - F, kt[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, kt[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, kt[2] = Y - (U - m) + (b - m), kt[3] = U), (f !== 0 || d !== 0 || u !== 0 || g !== 0) && (L = W * W, M = q * W, k = M - (M - W), P = W - k, F = P * P - (L - k * k - (k + k) * P), z = Z * Z, M = q * Z, k = M - (M - Z), P = Z - k, j = P * P - (z - k * k - (k + k) * P), b = F + j, m = b - F, At[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, At[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, At[2] = Y - (U - m) + (b - m), At[3] = U), (u !== 0 || g !== 0 || h !== 0 || _ !== 0) && (L = H * H, M = q * H, k = M - (M - H), P = H - k, F = P * P - (L - k * k - (k + k) * P), z = Q * Q, M = q * Q, k = M - (M - Q), P = Q - k, j = P * P - (z - k * k - (k + k) * P), b = F + j, m = b - F, Pt[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, Pt[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, Pt[2] = Y - (U - m) + (b - m), Pt[3] = U), u !== 0 && (y = $(4, $t, u, Ie), l = lt(l, Mt(
1606
+ $(y, Ie, 2 * J, G),
1607
+ G,
1608
+ $($(4, Pt, u, V), V, Z, nt),
1609
+ nt,
1610
+ $($(4, At, u, V), V, -Q, rt),
1611
+ rt,
1612
+ et,
1613
+ ct
1614
+ ), ct)), g !== 0 && (v = $(4, $t, g, Ce), l = lt(l, Mt(
1615
+ $(v, Ce, 2 * K, G),
1616
+ G,
1617
+ $($(4, At, g, V), V, H, nt),
1618
+ nt,
1619
+ $($(4, Pt, g, V), V, -W, rt),
1620
+ rt,
1621
+ et,
1622
+ ct
1623
+ ), ct)), h !== 0 && (p = $(4, Dt, h, Ne), l = lt(l, Mt(
1624
+ $(p, Ne, 2 * W, G),
1625
+ G,
1626
+ $($(4, kt, h, V), V, Q, nt),
1627
+ nt,
1628
+ $($(4, Pt, h, V), V, -K, rt),
1629
+ rt,
1630
+ et,
1631
+ ct
1632
+ ), ct)), _ !== 0 && (w = $(4, Dt, _, $e), l = lt(l, Mt(
1633
+ $(w, $e, 2 * Z, G),
1634
+ G,
1635
+ $($(4, Pt, _, V), V, J, nt),
1636
+ nt,
1637
+ $($(4, kt, _, V), V, -H, rt),
1638
+ rt,
1639
+ et,
1640
+ ct
1641
+ ), ct)), f !== 0 && (x = $(4, Rt, f, De), l = lt(l, Mt(
1642
+ $(x, De, 2 * H, G),
1643
+ G,
1644
+ $($(4, At, f, V), V, K, nt),
1645
+ nt,
1646
+ $($(4, kt, f, V), V, -Z, rt),
1647
+ rt,
1648
+ et,
1649
+ ct
1650
+ ), ct)), d !== 0 && (E = $(4, Rt, d, Re), l = lt(l, Mt(
1651
+ $(E, Re, 2 * Q, G),
1652
+ G,
1653
+ $($(4, kt, d, V), V, W, nt),
1654
+ nt,
1655
+ $($(4, At, d, V), V, -J, rt),
1656
+ rt,
1657
+ et,
1658
+ ct
1659
+ ), ct)), u !== 0 || g !== 0) {
1660
+ if (h !== 0 || _ !== 0 || f !== 0 || d !== 0 ? (L = h * Q, M = q * h, k = M - (M - h), P = h - k, M = q * Q, X = M - (M - Q), R = Q - X, F = P * R - (L - k * X - P * X - k * R), z = W * d, M = q * W, k = M - (M - W), P = W - k, M = q * d, X = M - (M - d), R = d - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, vt[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, vt[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, vt[2] = Y - (U - m) + (b - m), vt[3] = U, L = f * -Z, M = q * f, k = M - (M - f), P = f - k, M = q * -Z, X = M - (M - -Z), R = -Z - X, F = P * R - (L - k * X - P * X - k * R), z = H * -_, M = q * H, k = M - (M - H), P = H - k, M = q * -_, X = M - (M - -_), R = -_ - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, _t[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, _t[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, _t[2] = Y - (U - m) + (b - m), _t[3] = U, T = ft(4, vt, 4, _t, me), L = h * d, M = q * h, k = M - (M - h), P = h - k, M = q * d, X = M - (M - d), R = d - X, F = P * R - (L - k * X - P * X - k * R), z = f * _, M = q * f, k = M - (M - f), P = f - k, M = q * _, X = M - (M - _), R = _ - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, Ut[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, Ut[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, Ut[2] = Y - (U - m) + (b - m), Ut[3] = U, O = 4) : (me[0] = 0, T = 1, Ut[0] = 0, O = 1), u !== 0) {
1661
+ const st = $(T, me, u, rt);
1662
+ l = lt(l, ft(
1663
+ $(y, Ie, u, G),
1664
+ G,
1665
+ $(st, rt, 2 * J, et),
1666
+ et,
1667
+ ct
1668
+ ), ct);
1669
+ const ot = $(O, Ut, u, V);
1670
+ l = lt(l, Mt(
1671
+ $(ot, V, 2 * J, G),
1672
+ G,
1673
+ $(ot, V, u, nt),
1674
+ nt,
1675
+ $(st, rt, u, et),
1676
+ et,
1677
+ Lt,
1678
+ bt
1679
+ ), bt), _ !== 0 && (l = lt(l, $($(4, Pt, u, V), V, _, G), G)), d !== 0 && (l = lt(l, $($(4, At, -u, V), V, d, G), G));
1680
+ }
1681
+ if (g !== 0) {
1682
+ const st = $(T, me, g, rt);
1683
+ l = lt(l, ft(
1684
+ $(v, Ce, g, G),
1685
+ G,
1686
+ $(st, rt, 2 * K, et),
1687
+ et,
1688
+ ct
1689
+ ), ct);
1690
+ const ot = $(O, Ut, g, V);
1691
+ l = lt(l, Mt(
1692
+ $(ot, V, 2 * K, G),
1693
+ G,
1694
+ $(ot, V, g, nt),
1695
+ nt,
1696
+ $(st, rt, g, et),
1697
+ et,
1698
+ Lt,
1699
+ bt
1700
+ ), bt);
1701
+ }
1702
+ }
1703
+ if (h !== 0 || _ !== 0) {
1704
+ if (f !== 0 || d !== 0 || u !== 0 || g !== 0 ? (L = f * K, M = q * f, k = M - (M - f), P = f - k, M = q * K, X = M - (M - K), R = K - X, F = P * R - (L - k * X - P * X - k * R), z = H * g, M = q * H, k = M - (M - H), P = H - k, M = q * g, X = M - (M - g), R = g - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, vt[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, vt[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, vt[2] = Y - (U - m) + (b - m), vt[3] = U, C = -Q, N = -d, L = u * C, M = q * u, k = M - (M - u), P = u - k, M = q * C, X = M - (M - C), R = C - X, F = P * R - (L - k * X - P * X - k * R), z = J * N, M = q * J, k = M - (M - J), P = J - k, M = q * N, X = M - (M - N), R = N - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, _t[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, _t[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, _t[2] = Y - (U - m) + (b - m), _t[3] = U, S = ft(4, vt, 4, _t, we), L = f * g, M = q * f, k = M - (M - f), P = f - k, M = q * g, X = M - (M - g), R = g - X, F = P * R - (L - k * X - P * X - k * R), z = u * d, M = q * u, k = M - (M - u), P = u - k, M = q * d, X = M - (M - d), R = d - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, jt[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, jt[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, jt[2] = Y - (U - m) + (b - m), jt[3] = U, I = 4) : (we[0] = 0, S = 1, jt[0] = 0, I = 1), h !== 0) {
1705
+ const st = $(S, we, h, rt);
1706
+ l = lt(l, ft(
1707
+ $(p, Ne, h, G),
1708
+ G,
1709
+ $(st, rt, 2 * W, et),
1710
+ et,
1711
+ ct
1712
+ ), ct);
1713
+ const ot = $(I, jt, h, V);
1714
+ l = lt(l, Mt(
1715
+ $(ot, V, 2 * W, G),
1716
+ G,
1717
+ $(ot, V, h, nt),
1718
+ nt,
1719
+ $(st, rt, h, et),
1720
+ et,
1721
+ Lt,
1722
+ bt
1723
+ ), bt), d !== 0 && (l = lt(l, $($(4, kt, h, V), V, d, G), G)), g !== 0 && (l = lt(l, $($(4, Pt, -h, V), V, g, G), G));
1724
+ }
1725
+ if (_ !== 0) {
1726
+ const st = $(S, we, _, rt);
1727
+ l = lt(l, ft(
1728
+ $(w, $e, _, G),
1729
+ G,
1730
+ $(st, rt, 2 * Z, et),
1731
+ et,
1732
+ ct
1733
+ ), ct);
1734
+ const ot = $(I, jt, _, V);
1735
+ l = lt(l, Mt(
1736
+ $(ot, V, 2 * Z, G),
1737
+ G,
1738
+ $(ot, V, _, nt),
1739
+ nt,
1740
+ $(st, rt, _, et),
1741
+ et,
1742
+ Lt,
1743
+ bt
1744
+ ), bt);
1745
+ }
1746
+ }
1747
+ if (f !== 0 || d !== 0) {
1748
+ if (u !== 0 || g !== 0 || h !== 0 || _ !== 0 ? (L = u * Z, M = q * u, k = M - (M - u), P = u - k, M = q * Z, X = M - (M - Z), R = Z - X, F = P * R - (L - k * X - P * X - k * R), z = J * _, M = q * J, k = M - (M - J), P = J - k, M = q * _, X = M - (M - _), R = _ - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, vt[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, vt[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, vt[2] = Y - (U - m) + (b - m), vt[3] = U, C = -K, N = -g, L = h * C, M = q * h, k = M - (M - h), P = h - k, M = q * C, X = M - (M - C), R = C - X, F = P * R - (L - k * X - P * X - k * R), z = W * N, M = q * W, k = M - (M - W), P = W - k, M = q * N, X = M - (M - N), R = N - X, j = P * R - (z - k * X - P * X - k * R), b = F + j, m = b - F, _t[0] = F - (b - m) + (j - m), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D + z, m = b - D, _t[1] = D - (b - m) + (z - m), U = Y + b, m = U - Y, _t[2] = Y - (U - m) + (b - m), _t[3] = U, A = ft(4, vt, 4, _t, ge), L = u * _, M = q * u, k = M - (M - u), P = u - k, M = q * _, X = M - (M - _), R = _ - X, F = P * R - (L - k * X - P * X - k * R), z = h * g, M = q * h, k = M - (M - h), P = h - k, M = q * g, X = M - (M - g), R = g - X, j = P * R - (z - k * X - P * X - k * R), b = F - j, m = F - b, Ft[0] = F - (b + m) + (m - j), Y = L + b, m = Y - L, D = L - (Y - m) + (b - m), b = D - z, m = D - b, Ft[1] = D - (b + m) + (m - z), U = Y + b, m = U - Y, Ft[2] = Y - (U - m) + (b - m), Ft[3] = U, B = 4) : (ge[0] = 0, A = 1, Ft[0] = 0, B = 1), f !== 0) {
1749
+ const st = $(A, ge, f, rt);
1750
+ l = lt(l, ft(
1751
+ $(x, De, f, G),
1752
+ G,
1753
+ $(st, rt, 2 * H, et),
1754
+ et,
1755
+ ct
1756
+ ), ct);
1757
+ const ot = $(B, Ft, f, V);
1758
+ l = lt(l, Mt(
1759
+ $(ot, V, 2 * H, G),
1760
+ G,
1761
+ $(ot, V, f, nt),
1762
+ nt,
1763
+ $(st, rt, f, et),
1764
+ et,
1765
+ Lt,
1766
+ bt
1767
+ ), bt), g !== 0 && (l = lt(l, $($(4, At, f, V), V, g, G), G)), _ !== 0 && (l = lt(l, $($(4, kt, -f, V), V, _, G), G));
1768
+ }
1769
+ if (d !== 0) {
1770
+ const st = $(A, ge, d, rt);
1771
+ l = lt(l, ft(
1772
+ $(E, Re, d, G),
1773
+ G,
1774
+ $(st, rt, 2 * Q, et),
1775
+ et,
1776
+ ct
1777
+ ), ct);
1778
+ const ot = $(B, Ft, d, V);
1779
+ l = lt(l, Mt(
1780
+ $(ot, V, 2 * Q, G),
1781
+ G,
1782
+ $(ot, V, d, nt),
1783
+ nt,
1784
+ $(st, rt, d, et),
1785
+ et,
1786
+ Lt,
1787
+ bt
1788
+ ), bt);
1789
+ }
1790
+ }
1791
+ return Qt[l - 1];
1792
+ }
1793
+ function Oi(r, t, e, n, s, i, o, a) {
1794
+ const c = r - o, l = e - o, u = s - o, h = t - a, f = n - a, g = i - a, _ = l * g, d = u * f, y = c * c + h * h, v = u * h, p = c * g, w = l * l + f * f, x = c * f, E = l * h, A = u * u + g * g, T = y * (_ - d) + w * (v - p) + A * (x - E), S = (Math.abs(_) + Math.abs(d)) * y + (Math.abs(v) + Math.abs(p)) * w + (Math.abs(x) + Math.abs(E)) * A, B = Ei * S;
1795
+ return T > B || -T > B ? T : Pi(r, t, e, n, s, i, o, a, S);
1796
+ }
1797
+ class Ti {
1798
+ constructor(t, e) {
1799
+ this.W = t, this.bs = e;
1800
+ }
1801
+ /**
1802
+ * Add a number to the set.
1803
+ *
1804
+ * @param idx The number to add. Must be 0 <= idx < len.
1805
+ * @return this.
1806
+ */
1807
+ add(t) {
1808
+ const e = this.W, n = t / e | 0, s = t % e;
1809
+ return this.bs[n] |= 1 << s, this;
1810
+ }
1811
+ /**
1812
+ * Delete a number from the set.
1813
+ *
1814
+ * @param idx The number to delete. Must be 0 <= idx < len.
1815
+ * @return this.
1816
+ */
1817
+ delete(t) {
1818
+ const e = this.W, n = t / e | 0, s = t % e;
1819
+ return this.bs[n] &= ~(1 << s), this;
1820
+ }
1821
+ /**
1822
+ * Add or delete a number in the set, depending on the second argument.
1823
+ *
1824
+ * @param idx The number to add or delete. Must be 0 <= idx < len.
1825
+ * @param val If true, add the number, otherwise delete.
1826
+ * @return val.
1827
+ */
1828
+ set(t, e) {
1829
+ const n = this.W, s = t / n | 0, i = t % n, o = 1 << i;
1830
+ return this.bs[s] ^= (-e ^ this.bs[s]) & o, e;
1831
+ }
1832
+ /**
1833
+ * Whether the number is in the set.
1834
+ *
1835
+ * @param idx The number to test. Must be 0 <= idx < len.
1836
+ * @return True if the number is in the set.
1837
+ */
1838
+ has(t) {
1839
+ const e = this.W, n = t / e | 0, s = t % e;
1840
+ return !!(this.bs[n] & 1 << s);
1841
+ }
1842
+ /**
1843
+ * Iterate over the numbers that are in the set. The callback is invoked
1844
+ * with each number that is set. It is allowed to change the BitSet during
1845
+ * iteration. If it deletes a number that has not been iterated over, that
1846
+ * number will not show up in a later call. If it adds a number during
1847
+ * iteration, that number may or may not show up in a later call.
1848
+ *
1849
+ * @param fn The function to call for each number.
1850
+ * @return this.
1851
+ */
1852
+ forEach(t) {
1853
+ const e = this.W, n = this.bs, s = n.length;
1854
+ for (let i = 0; i < s; i++) {
1855
+ let o = 0;
1856
+ for (; n[i] && o < e; )
1857
+ n[i] & 1 << o && t(i * e + o), o++;
1858
+ }
1859
+ return this;
1860
+ }
1861
+ }
1862
+ class wn extends Ti {
1863
+ /**
1864
+ * Create a bit set.
1865
+ *
1866
+ * @param len The length of the bit set, limiting the maximum value that
1867
+ * can be stored in it to len - 1.
1868
+ */
1869
+ constructor(t) {
1870
+ const e = new Uint8Array(Math.ceil(t / 8)).fill(0);
1871
+ super(8, e);
1872
+ }
1873
+ }
1874
+ function zt(r) {
1875
+ return r % 3 === 2 ? r - 2 : r + 1;
1876
+ }
1877
+ function Tt(r) {
1878
+ return r % 3 === 0 ? r + 2 : r - 1;
1879
+ }
1880
+ function Ln(r, t, e, n, s, i, o, a) {
1881
+ const c = ie(r, t, s, i, o, a), l = ie(e, n, s, i, o, a);
1882
+ if (c > 0 && l > 0 || c < 0 && l < 0)
1883
+ return !1;
1884
+ const u = ie(s, i, r, t, e, n), h = ie(o, a, r, t, e, n);
1885
+ return u > 0 && h > 0 || u < 0 && h < 0 ? !1 : c === 0 && l === 0 && u === 0 && h === 0 ? !(Math.max(s, o) < Math.min(r, e) || Math.max(r, e) < Math.min(s, o) || Math.max(i, a) < Math.min(t, n) || Math.max(t, n) < Math.min(i, a)) : !0;
1886
+ }
1887
+ class Bi {
1888
+ constructor(t) {
1889
+ this.del = t;
1890
+ }
1891
+ }
1892
+ const Fn = class extends Bi {
1893
+ /**
1894
+ * Make a Constrain.
1895
+ *
1896
+ * @param del The triangulation output from Delaunator.
1897
+ * @param edges If provided, constrain these edges as by constrainAll.
1898
+ */
1899
+ constructor(t, e) {
1900
+ if (!t || typeof t != "object" || !t.triangles || !t.halfedges || !t.coords)
1901
+ throw new Error("Expected an object with Delaunator output");
1902
+ if (t.triangles.length % 3 || t.halfedges.length !== t.triangles.length || t.coords.length % 2)
1903
+ throw new Error("Delaunator output appears inconsistent");
1904
+ if (t.triangles.length < 3)
1905
+ throw new Error("No edges in triangulation");
1906
+ super(t);
1907
+ const n = 2 ** 32 - 1, s = t.coords.length >> 1, i = t.triangles.length;
1908
+ this.vertMap = new Uint32Array(s).fill(n), this.flips = new wn(i), this.consd = new wn(i);
1909
+ for (let o = 0; o < i; o++) {
1910
+ const a = t.triangles[o];
1911
+ this.vertMap[a] === n && this.updateVert(o);
1912
+ }
1913
+ e && this.constrainAll(e);
1914
+ }
1915
+ /**
1916
+ * Constrain the triangulation such that there is an edge between p1 and p2.
1917
+ */
1918
+ constrainOne(t, e) {
1919
+ const { triangles: n, halfedges: s } = this.del, i = this.vertMap[t];
1920
+ let o = i;
1921
+ do {
1922
+ const l = n[o], u = zt(o);
1923
+ if (l === e)
1924
+ return this.protect(o);
1925
+ const h = Tt(o), f = n[h];
1926
+ if (f === e)
1927
+ return this.protect(u), u;
1928
+ if (this.intersectSegments(t, e, f, l)) {
1929
+ o = h;
1930
+ break;
1931
+ }
1932
+ o = s[u];
1933
+ } while (o !== -1 && o !== i);
1934
+ let a = o, c = -1;
1935
+ for (; o !== -1; ) {
1936
+ const l = s[o], u = Tt(o), h = Tt(l), f = zt(l);
1937
+ if (l === -1)
1938
+ throw new Error("Constraining edge exited the hull");
1939
+ if (this.consd.has(o))
1940
+ throw new Error("Edge intersects already constrained edge");
1941
+ if (this.isCollinear(t, e, n[o]) || this.isCollinear(t, e, n[l]))
1942
+ throw new Error("Constraining edge intersects point");
1943
+ if (!this.intersectSegments(
1944
+ n[o],
1945
+ n[l],
1946
+ n[u],
1947
+ n[h]
1948
+ )) {
1949
+ if (c === -1 && (c = o), n[h] === e) {
1950
+ if (o === c)
1951
+ throw new Error("Infinite loop: non-convex quadrilateral");
1952
+ o = c, c = -1;
1953
+ continue;
1954
+ }
1955
+ if (this.intersectSegments(t, e, n[h], n[l]))
1956
+ o = h;
1957
+ else if (this.intersectSegments(t, e, n[f], n[h]))
1958
+ o = f;
1959
+ else if (c === o)
1960
+ throw new Error("Infinite loop: no further intersect after non-convex");
1961
+ continue;
1962
+ }
1963
+ if (this.flipDiagonal(o), this.intersectSegments(t, e, n[u], n[h]) && (c === -1 && (c = u), c === u))
1964
+ throw new Error("Infinite loop: flipped diagonal still intersects");
1965
+ n[h] === e ? (a = h, o = c, c = -1) : this.intersectSegments(t, e, n[f], n[h]) && (o = f);
1966
+ }
1967
+ return this.protect(a), this.delaunify(!0), this.findEdge(t, e);
1968
+ }
1969
+ /**
1970
+ * Fix the Delaunay condition.
1971
+ */
1972
+ delaunify(t = !1) {
1973
+ const { halfedges: e } = this.del, n = this.flips, s = this.consd, i = e.length;
1974
+ do {
1975
+ var o = 0;
1976
+ for (let a = 0; a < i; a++) {
1977
+ if (s.has(a))
1978
+ continue;
1979
+ n.delete(a);
1980
+ const c = e[a];
1981
+ c !== -1 && (n.delete(c), this.isDelaunay(a) || (this.flipDiagonal(a), o++));
1982
+ }
1983
+ } while (t && o > 0);
1984
+ return this;
1985
+ }
1986
+ /**
1987
+ * Call constrainOne on each edge
1988
+ */
1989
+ constrainAll(t) {
1990
+ const e = t.length;
1991
+ for (let n = 0; n < e; n++) {
1992
+ const s = t[n];
1993
+ this.constrainOne(s[0], s[1]);
1994
+ }
1995
+ return this;
1996
+ }
1997
+ /**
1998
+ * Whether an edge is constrained
1999
+ */
2000
+ isConstrained(t) {
2001
+ return this.consd.has(t);
2002
+ }
2003
+ /**
2004
+ * Find the edge that points from p1 -> p2. If there is only an edge from
2005
+ * p2 -> p1 (i.e. it is on the hull), returns the negative id of it.
2006
+ */
2007
+ findEdge(t, e) {
2008
+ const n = this.vertMap[e], { triangles: s, halfedges: i } = this.del;
2009
+ let o = n, a = -1;
2010
+ do {
2011
+ if (s[o] === t)
2012
+ return o;
2013
+ a = zt(o), o = i[a];
2014
+ } while (o !== -1 && o !== n);
2015
+ return s[zt(a)] === t ? -a : 1 / 0;
2016
+ }
2017
+ /**
2018
+ * Mark an edge as constrained, i.e. should not be touched by `delaunify`.
2019
+ */
2020
+ protect(t) {
2021
+ const e = this.del.halfedges[t], n = this.flips, s = this.consd;
2022
+ return n.delete(t), s.add(t), e !== -1 ? (n.delete(e), s.add(e), e) : -t;
2023
+ }
2024
+ /**
2025
+ * Mark an edge as flipped unless constrained.
2026
+ */
2027
+ markFlip(t) {
2028
+ const e = this.del.halfedges, n = this.flips;
2029
+ if (this.consd.has(t))
2030
+ return !1;
2031
+ const s = e[t];
2032
+ return s !== -1 && (n.add(t), n.add(s)), !0;
2033
+ }
2034
+ /**
2035
+ * Flip the edge shared by two triangles.
2036
+ */
2037
+ flipDiagonal(t) {
2038
+ const { triangles: e, halfedges: n } = this.del, s = this.flips, i = this.consd, o = n[t], a = Tt(t), c = zt(t), l = Tt(o), u = zt(o), h = n[a], f = n[l];
2039
+ if (i.has(t))
2040
+ throw new Error("Trying to flip a constrained edge");
2041
+ return e[t] = e[l], n[t] = f, s.set(t, s.has(l)) || i.set(t, i.has(l)), f !== -1 && (n[f] = t), n[a] = l, e[o] = e[a], n[o] = h, s.set(o, s.has(a)) || i.set(o, i.has(a)), h !== -1 && (n[h] = o), n[l] = a, this.markFlip(t), this.markFlip(c), this.markFlip(o), this.markFlip(u), s.add(a), i.delete(a), s.add(l), i.delete(l), this.updateVert(t), this.updateVert(c), this.updateVert(o), this.updateVert(u), a;
2042
+ }
2043
+ /**
2044
+ * Whether point p1, p2, and p are collinear
2045
+ */
2046
+ isCollinear(t, e, n) {
2047
+ const s = this.del.coords;
2048
+ return ie(
2049
+ s[t * 2],
2050
+ s[t * 2 + 1],
2051
+ s[e * 2],
2052
+ s[e * 2 + 1],
2053
+ s[n * 2],
2054
+ s[n * 2 + 1]
2055
+ ) === 0;
2056
+ }
2057
+ /**
2058
+ * Whether px is in the circumcircle of the triangle formed by p1, p2, p3
2059
+ */
2060
+ inCircle(t, e, n, s) {
2061
+ const i = this.del.coords;
2062
+ return Oi(
2063
+ i[t * 2],
2064
+ i[t * 2 + 1],
2065
+ i[e * 2],
2066
+ i[e * 2 + 1],
2067
+ i[n * 2],
2068
+ i[n * 2 + 1],
2069
+ i[s * 2],
2070
+ i[s * 2 + 1]
2071
+ ) < 0;
2072
+ }
2073
+ /**
2074
+ * Whether the triangles sharing edg conform to the Delaunay condition
2075
+ */
2076
+ isDelaunay(t) {
2077
+ const { triangles: e, halfedges: n } = this.del, s = n[t];
2078
+ if (s === -1)
2079
+ return !0;
2080
+ const i = e[Tt(t)], o = e[t], a = e[zt(t)], c = e[Tt(s)];
2081
+ return !this.inCircle(i, o, a, c);
2082
+ }
2083
+ /**
2084
+ * Update the vertex -> incoming edge map
2085
+ */
2086
+ updateVert(t) {
2087
+ const { triangles: e, halfedges: n } = this.del, s = this.vertMap, i = e[t];
2088
+ let o = Tt(t), a = n[o];
2089
+ for (; a !== -1 && a !== t; )
2090
+ o = Tt(a), a = n[o];
2091
+ return s[i] = o, o;
2092
+ }
2093
+ /**
2094
+ * Whether the segments between vertices intersect
2095
+ */
2096
+ intersectSegments(t, e, n, s) {
2097
+ const i = this.del.coords;
2098
+ return t === n || t === s || e === n || e === s ? !1 : Ln(
2099
+ i[t * 2],
2100
+ i[t * 2 + 1],
2101
+ i[e * 2],
2102
+ i[e * 2 + 1],
2103
+ i[n * 2],
2104
+ i[n * 2 + 1],
2105
+ i[s * 2],
2106
+ i[s * 2 + 1]
2107
+ );
2108
+ }
2109
+ };
2110
+ Fn.intersectSegments = Ln;
2111
+ let Xi = Fn;
2112
+ function ye(r, t, e) {
2113
+ if (t || (t = []), typeof r != "object" || r.type !== "FeatureCollection")
2114
+ throw "Argument points must be FeatureCollection";
2115
+ if (!Array.isArray(t)) throw "Argument points must be Array of Array";
2116
+ const n = r.features.map(
2117
+ (c) => c.geometry.coordinates
2118
+ ), s = Ge.from(n);
2119
+ let i;
2120
+ const o = [];
2121
+ s.triangles.length !== 0 && t.length !== 0 && (i = new Xi(s), i.constrainAll(t));
2122
+ for (let c = 0; c < s.triangles.length; c += 3)
2123
+ o.push([s.triangles[c], s.triangles[c + 1], s.triangles[c + 2]]);
2124
+ const a = ["a", "b", "c"];
2125
+ return Xt(
2126
+ o.map((c) => {
2127
+ const l = {}, u = c.map((h, f) => {
2128
+ const g = r.features[h], _ = g.geometry.coordinates, d = [_[0], _[1]];
2129
+ return _.length === 3 ? d[2] = _[2] : l[a[f]] = g.properties[e], d;
2130
+ });
2131
+ return u[3] = u[0], ke([u], l);
2132
+ })
2133
+ );
2134
+ }
2135
+ var Yi = Object.defineProperty, Ii = (r, t, e) => t in r ? Yi(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, it = (r, t, e) => Ii(r, typeof t != "symbol" ? t + "" : t, e);
2136
+ const It = 11102230246251565e-32, gt = 134217729, Ci = (3 + 8 * It) * It;
2137
+ function Fe(r, t, e, n, s) {
2138
+ let i, o, a, c, l = t[0], u = n[0], h = 0, f = 0;
2139
+ u > l == u > -l ? (i = l, l = t[++h]) : (i = u, u = n[++f]);
2140
+ let g = 0;
2141
+ if (h < r && f < e)
2142
+ for (u > l == u > -l ? (o = l + i, a = i - (o - l), l = t[++h]) : (o = u + i, a = i - (o - u), u = n[++f]), i = o, a !== 0 && (s[g++] = a); h < r && f < e; )
2143
+ u > l == u > -l ? (o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h]) : (o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f]), i = o, a !== 0 && (s[g++] = a);
2144
+ for (; h < r; )
2145
+ o = i + l, c = o - i, a = i - (o - c) + (l - c), l = t[++h], i = o, a !== 0 && (s[g++] = a);
2146
+ for (; f < e; )
2147
+ o = i + u, c = o - i, a = i - (o - c) + (u - c), u = n[++f], i = o, a !== 0 && (s[g++] = a);
2148
+ return (i !== 0 || g === 0) && (s[g++] = i), g;
2149
+ }
2150
+ function Ni(r, t) {
2151
+ let e = t[0];
2152
+ for (let n = 1; n < r; n++) e += t[n];
2153
+ return e;
2154
+ }
2155
+ function ae(r) {
2156
+ return new Float64Array(r);
2157
+ }
2158
+ const $i = (3 + 16 * It) * It, Di = (2 + 12 * It) * It, Ri = (9 + 64 * It) * It * It, Jt = ae(4), yn = ae(8), vn = ae(12), _n = ae(16), xt = ae(4);
2159
+ function Li(r, t, e, n, s, i, o) {
2160
+ let a, c, l, u, h, f, g, _, d, y, v, p, w, x, E, A, T, S;
2161
+ const B = r - s, O = e - s, I = t - i, C = n - i;
2162
+ x = B * C, f = gt * B, g = f - (f - B), _ = B - g, f = gt * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * O, f = gt * I, g = f - (f - I), _ = I - g, f = gt * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, Jt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, Jt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, Jt[2] = p - (S - h) + (v - h), Jt[3] = S;
2163
+ let N = Ni(4, Jt), m = Di * o;
2164
+ if (N >= m || -N >= m || (h = r - B, a = r - (B + h) + (h - s), h = e - O, l = e - (O + h) + (h - s), h = t - I, c = t - (I + h) + (h - i), h = n - C, u = n - (C + h) + (h - i), a === 0 && c === 0 && l === 0 && u === 0) || (m = Ri * o + Ci * Math.abs(N), N += B * u + C * a - (I * l + O * c), N >= m || -N >= m)) return N;
2165
+ x = a * C, f = gt * a, g = f - (f - a), _ = a - g, f = gt * C, d = f - (f - C), y = C - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * O, f = gt * c, g = f - (f - c), _ = c - g, f = gt * O, d = f - (f - O), y = O - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, xt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, xt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, xt[2] = p - (S - h) + (v - h), xt[3] = S;
2166
+ const M = Fe(4, Jt, 4, xt, yn);
2167
+ x = B * u, f = gt * B, g = f - (f - B), _ = B - g, f = gt * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = I * l, f = gt * I, g = f - (f - I), _ = I - g, f = gt * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, xt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, xt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, xt[2] = p - (S - h) + (v - h), xt[3] = S;
2168
+ const k = Fe(M, yn, 4, xt, vn);
2169
+ x = a * u, f = gt * a, g = f - (f - a), _ = a - g, f = gt * u, d = f - (f - u), y = u - d, E = _ * y - (x - g * d - _ * d - g * y), A = c * l, f = gt * c, g = f - (f - c), _ = c - g, f = gt * l, d = f - (f - l), y = l - d, T = _ * y - (A - g * d - _ * d - g * y), v = E - T, h = E - v, xt[0] = E - (v + h) + (h - T), p = x + v, h = p - x, w = x - (p - h) + (v - h), v = w - A, h = w - v, xt[1] = w - (v + h) + (h - A), S = p + v, h = S - p, xt[2] = p - (S - h) + (v - h), xt[3] = S;
2170
+ const P = Fe(k, vn, 4, xt, _n);
2171
+ return _n[P - 1];
2172
+ }
2173
+ function Fi(r, t, e, n, s, i) {
2174
+ const o = (t - i) * (e - s), a = (r - s) * (n - i), c = o - a, l = Math.abs(o + a);
2175
+ return Math.abs(c) >= $i * l ? c : -Li(r, t, e, n, s, i, l);
2176
+ }
2177
+ function Ui(r, t) {
2178
+ var e, n, s = 0, i, o, a, c, l, u, h, f = r[0], g = r[1], _ = t.length;
2179
+ for (e = 0; e < _; e++) {
2180
+ n = 0;
2181
+ var d = t[e], y = d.length - 1;
2182
+ if (u = d[0], u[0] !== d[y][0] && u[1] !== d[y][1])
2183
+ throw new Error("First and last coordinates in a ring must be the same");
2184
+ for (o = u[0] - f, a = u[1] - g, n; n < y; n++) {
2185
+ if (h = d[n + 1], c = h[0] - f, l = h[1] - g, a === 0 && l === 0) {
2186
+ if (c <= 0 && o >= 0 || o <= 0 && c >= 0)
2187
+ return 0;
2188
+ } else if (l >= 0 && a <= 0 || l <= 0 && a >= 0) {
2189
+ if (i = Fi(o, c, a, l, 0, 0), i === 0)
2190
+ return 0;
2191
+ (i > 0 && l > 0 && a <= 0 || i < 0 && l <= 0 && a > 0) && s++;
2192
+ }
2193
+ u = h, a = l, o = c;
2194
+ }
2195
+ }
2196
+ return s % 2 !== 0;
2197
+ }
2198
+ function Un(r, t, e = {}) {
2199
+ const n = { type: "Feature" };
2200
+ return (e.id === 0 || e.id) && (n.id = e.id), e.bbox && (n.bbox = e.bbox), n.properties = t || {}, n.geometry = r, n;
2201
+ }
2202
+ function ee(r, t, e = {}) {
2203
+ if (!r)
2204
+ throw new Error("coordinates is required");
2205
+ if (!Array.isArray(r))
2206
+ throw new Error("coordinates must be an Array");
2207
+ if (r.length < 2)
2208
+ throw new Error("coordinates must be at least 2 numbers long");
2209
+ if (!xn(r[0]) || !xn(r[1]))
2210
+ throw new Error("coordinates must contain numbers");
2211
+ return Un({
2212
+ type: "Point",
2213
+ coordinates: r
2214
+ }, t, e);
2215
+ }
2216
+ function jn(r, t, e = {}) {
2217
+ for (const n of r) {
2218
+ if (n.length < 4)
2219
+ throw new Error(
2220
+ "Each LinearRing of a Polygon must have 4 or more Positions."
2221
+ );
2222
+ if (n[n.length - 1].length !== n[0].length)
2223
+ throw new Error("First and last Position are not equivalent.");
2224
+ for (let s = 0; s < n[n.length - 1].length; s++)
2225
+ if (n[n.length - 1][s] !== n[0][s])
2226
+ throw new Error("First and last Position are not equivalent.");
2227
+ }
2228
+ return Un({
2229
+ type: "Polygon",
2230
+ coordinates: r
2231
+ }, t, e);
2232
+ }
2233
+ function qt(r, t = {}) {
2234
+ const e = { type: "FeatureCollection" };
2235
+ return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = r, e;
2236
+ }
2237
+ function xn(r) {
2238
+ return !isNaN(r) && r !== null && !Array.isArray(r);
2239
+ }
2240
+ function ji(r) {
2241
+ if (!r)
2242
+ throw new Error("coord is required");
2243
+ if (!Array.isArray(r)) {
2244
+ if (r.type === "Feature" && r.geometry !== null && r.geometry.type === "Point")
2245
+ return [...r.geometry.coordinates];
2246
+ if (r.type === "Point")
2247
+ return [...r.coordinates];
2248
+ }
2249
+ if (Array.isArray(r) && r.length >= 2 && !Array.isArray(r[0]) && !Array.isArray(r[1]))
2250
+ return [...r];
2251
+ throw new Error("coord must be GeoJSON Point or an Array of numbers");
2252
+ }
2253
+ function bn(r) {
2254
+ if (Array.isArray(r))
2255
+ return r;
2256
+ if (r.type === "Feature") {
2257
+ if (r.geometry !== null)
2258
+ return r.geometry.coordinates;
2259
+ } else if (r.coordinates)
2260
+ return r.coordinates;
2261
+ throw new Error(
2262
+ "coords must be GeoJSON Feature, Geometry Object or an Array"
2263
+ );
2264
+ }
2265
+ function zi(r) {
2266
+ return r.type === "Feature" ? r.geometry : r;
2267
+ }
2268
+ function qi(r, t, e = {}) {
2269
+ if (!r)
2270
+ throw new Error("point is required");
2271
+ if (!t)
2272
+ throw new Error("polygon is required");
2273
+ const n = ji(r), s = zi(t), i = s.type, o = t.bbox;
2274
+ let a = s.coordinates;
2275
+ if (o && Vi(n, o) === !1)
2276
+ return !1;
2277
+ i === "Polygon" && (a = [a]);
2278
+ let c = !1;
2279
+ for (var l = 0; l < a.length; ++l) {
2280
+ const u = Ui(n, a[l]);
2281
+ if (u === 0) return !e.ignoreBoundary;
2282
+ u && (c = !0);
2283
+ }
2284
+ return c;
2285
+ }
2286
+ function Vi(r, t) {
2287
+ return t[0] <= r[0] && t[1] <= r[1] && t[2] >= r[0] && t[3] >= r[1];
2288
+ }
2289
+ var je = qi;
2290
+ function Mn(r) {
2291
+ const t = r.features;
2292
+ for (let e = 0; e < t.length; e++) {
2293
+ const n = t[e];
2294
+ `${n.properties.a.index}`.substring(0, 1) === "b" && `${n.properties.b.index}`.substring(0, 1) === "b" ? t[e] = {
2295
+ geometry: {
2296
+ type: "Polygon",
2297
+ coordinates: [
2298
+ [
2299
+ n.geometry.coordinates[0][2],
2300
+ n.geometry.coordinates[0][0],
2301
+ n.geometry.coordinates[0][1],
2302
+ n.geometry.coordinates[0][2]
2303
+ ]
2304
+ ]
2305
+ },
2306
+ properties: {
2307
+ a: {
2308
+ geom: n.properties.c.geom,
2309
+ index: n.properties.c.index
2310
+ },
2311
+ b: {
2312
+ geom: n.properties.a.geom,
2313
+ index: n.properties.a.index
2314
+ },
2315
+ c: {
2316
+ geom: n.properties.b.geom,
2317
+ index: n.properties.b.index
2318
+ }
2319
+ },
2320
+ type: "Feature"
2321
+ } : `${n.properties.c.index}`.substring(0, 1) === "b" && `${n.properties.a.index}`.substring(0, 1) === "b" && (t[e] = {
2322
+ geometry: {
2323
+ type: "Polygon",
2324
+ coordinates: [
2325
+ [
2326
+ n.geometry.coordinates[0][1],
2327
+ n.geometry.coordinates[0][2],
2328
+ n.geometry.coordinates[0][0],
2329
+ n.geometry.coordinates[0][1]
2330
+ ]
2331
+ ]
2332
+ },
2333
+ properties: {
2334
+ a: {
2335
+ geom: n.properties.b.geom,
2336
+ index: n.properties.b.index
2337
+ },
2338
+ b: {
2339
+ geom: n.properties.c.geom,
2340
+ index: n.properties.c.index
2341
+ },
2342
+ c: {
2343
+ geom: n.properties.a.geom,
2344
+ index: n.properties.a.index
2345
+ }
2346
+ },
2347
+ type: "Feature"
2348
+ });
2349
+ }
2350
+ return r;
2351
+ }
2352
+ function Wi(r) {
2353
+ const t = ["a", "b", "c", "a"].map(
2354
+ (i) => r.properties[i].geom
2355
+ ), e = r.geometry.coordinates[0], n = r.properties, s = {
2356
+ a: { geom: e[0], index: n.a.index },
2357
+ b: { geom: e[1], index: n.b.index },
2358
+ c: { geom: e[2], index: n.c.index }
2359
+ };
2360
+ return jn([t], s);
2361
+ }
2362
+ function Gi(r) {
2363
+ const t = [0, 1, 2, 0].map((n) => r[n][0][0]), e = {
2364
+ a: { geom: r[0][0][1], index: r[0][1] },
2365
+ b: { geom: r[1][0][1], index: r[1][1] },
2366
+ c: { geom: r[2][0][1], index: r[2][1] }
2367
+ };
2368
+ return jn([t], e);
2369
+ }
2370
+ function ve(r, t, e, n, s, i = !1, o) {
2371
+ const a = r.map(
2372
+ (c) => {
2373
+ (!o || o < 2.00703) && (c = zn(c));
2374
+ const l = isFinite(c) ? t[c] : c === "c" ? n : c === "b0" ? s[0] : c === "b1" ? s[1] : c === "b2" ? s[2] : c === "b3" ? s[3] : function() {
2375
+ const u = c.match(/e(\d+)/);
2376
+ if (u) {
2377
+ const h = parseInt(u[1]);
2378
+ return e[h];
2379
+ }
2380
+ throw "Bad index value for indexesToTri";
2381
+ }();
2382
+ return i ? [[l[1], l[0]], c] : [[l[0], l[1]], c];
2383
+ }
2384
+ );
2385
+ return Gi(a);
2386
+ }
2387
+ function zn(r) {
2388
+ return typeof r == "number" ? r : r.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2");
2389
+ }
2390
+ function qn(r, t) {
2391
+ return t && t >= 2.00703 || Array.isArray(r[0]) ? r : r.map((e) => [
2392
+ e.illstNodes,
2393
+ e.mercNodes,
2394
+ e.startEnd
2395
+ ]);
2396
+ }
2397
+ function Sn(r, t) {
2398
+ for (let e = 0; e < t.features.length; e++)
2399
+ if (je(r, t.features[e]))
2400
+ return t.features[e];
2401
+ }
2402
+ function Vn(r, t, e) {
2403
+ const n = t.geometry.coordinates[0][0], s = t.geometry.coordinates[0][1], i = t.geometry.coordinates[0][2], o = r.geometry.coordinates, a = t.properties.a.geom, c = t.properties.b.geom, l = t.properties.c.geom, u = [s[0] - n[0], s[1] - n[1]], h = [i[0] - n[0], i[1] - n[1]], f = [o[0] - n[0], o[1] - n[1]], g = [c[0] - a[0], c[1] - a[1]], _ = [l[0] - a[0], l[1] - a[1]];
2404
+ let d = (h[1] * f[0] - h[0] * f[1]) / (u[0] * h[1] - u[1] * h[0]), y = (u[0] * f[1] - u[1] * f[0]) / (u[0] * h[1] - u[1] * h[0]);
2405
+ if (e) {
2406
+ const v = e[t.properties.a.index], p = e[t.properties.b.index], w = e[t.properties.c.index];
2407
+ let x;
2408
+ if (d < 0 || y < 0 || 1 - d - y < 0) {
2409
+ const E = d / (d + y), A = y / (d + y);
2410
+ x = d / p / (E / p + A / w), y = y / w / (E / p + A / w);
2411
+ } else
2412
+ x = d / p / (d / p + y / w + (1 - d - y) / v), y = y / w / (d / p + y / w + (1 - d - y) / v);
2413
+ d = x;
2414
+ }
2415
+ return [
2416
+ d * g[0] + y * _[0] + a[0],
2417
+ d * g[1] + y * _[1] + a[1]
2418
+ ];
2419
+ }
2420
+ function Ji(r, t, e, n) {
2421
+ const s = r.geometry.coordinates, i = e.geometry.coordinates, o = Math.atan2(s[0] - i[0], s[1] - i[1]), a = Hi(o, t[0]), c = t[1][a];
2422
+ return Vn(r, c.features[0], n);
2423
+ }
2424
+ function Me(r, t, e, n, s, i, o, a) {
2425
+ let c;
2426
+ if (o && (c = Sn(r, qt([o]))), !c) {
2427
+ if (e) {
2428
+ const l = r.geometry.coordinates, u = e.gridNum, h = e.xOrigin, f = e.yOrigin, g = e.xUnit, _ = e.yUnit, d = e.gridCache, y = Ot(l[0], h, g, u), v = Ot(l[1], f, _, u), p = d[y] ? d[y][v] ? d[y][v] : [] : [];
2429
+ t = qt(p.map((w) => t.features[w]));
2430
+ }
2431
+ c = Sn(r, t);
2432
+ }
2433
+ return a && a(c), c ? Vn(r, c, i) : Ji(r, n, s, i);
2434
+ }
2435
+ function Ot(r, t, e, n) {
2436
+ let s = Math.floor((r - t) / e);
2437
+ return s >= n && (s = n - 1), s;
2438
+ }
2439
+ function Hi(r, t) {
2440
+ let e = En(r - t[0]), n = Math.PI * 2, s;
2441
+ for (let i = 0; i < t.length; i++) {
2442
+ const o = (i + 1) % t.length, a = En(r - t[o]), c = Math.min(Math.abs(e), Math.abs(a));
2443
+ e * a <= 0 && c < n && (n = c, s = i), e = a;
2444
+ }
2445
+ return s;
2446
+ }
2447
+ function En(r, t = !1) {
2448
+ const e = t ? function(n) {
2449
+ return !(n >= 0 && n < Math.PI * 2);
2450
+ } : function(n) {
2451
+ return !(n > -1 * Math.PI && n <= Math.PI);
2452
+ };
2453
+ for (; e(r); )
2454
+ r = r + 2 * Math.PI * (r > 0 ? -1 : 1);
2455
+ return r;
2456
+ }
2457
+ const Ee = 2.00703, St = class Et {
2458
+ constructor() {
2459
+ it(this, "points", []), it(this, "pointsWeightBuffer"), it(this, "strict_status"), it(this, "vertices_params"), it(this, "centroid"), it(this, "edgeNodes"), it(this, "edges"), it(this, "tins"), it(this, "kinks"), it(this, "yaxisMode", Et.YAXIS_INVERT), it(this, "strictMode", Et.MODE_AUTO), it(this, "vertexMode", Et.VERTEX_PLAIN), it(this, "bounds"), it(this, "boundsPolygon"), it(this, "wh"), it(this, "xy"), it(this, "indexedTins"), it(this, "stateFull", !1), it(this, "stateTriangle"), it(this, "stateBackward");
2460
+ }
2461
+ /**
2462
+ * コンパイルされた設定を適用します
2463
+ *
2464
+ * @param compiled - コンパイルされた設定オブジェクト
2465
+ * @returns 変換に必要な主要なオブジェクトのセット
2466
+ *
2467
+ * 以下の処理を行います:
2468
+ * 1. バージョンに応じた設定の解釈
2469
+ * 2. 各種パラメータの復元
2470
+ * 3. TINネットワークの再構築
2471
+ * 4. インデックスの作成
2472
+ */
2473
+ setCompiled(t) {
2474
+ if (t.version || !t.tins && t.points && t.tins_points) {
2475
+ this.points = t.points, this.pointsWeightBuffer = !t.version || t.version < 2.00703 ? ["forw", "bakw"].reduce((n, s) => {
2476
+ const i = t.weight_buffer[s];
2477
+ return i && (n[s] = Object.keys(i).reduce((o, a) => {
2478
+ const c = zn(a);
2479
+ return o[c] = i[a], o;
2480
+ }, {})), n;
2481
+ }, {}) : t.weight_buffer, t.strict_status ? this.strict_status = t.strict_status : t.kinks_points ? this.strict_status = Et.STATUS_ERROR : t.tins_points.length == 2 ? this.strict_status = Et.STATUS_LOOSE : this.strict_status = Et.STATUS_STRICT, this.vertices_params = {
2482
+ forw: [t.vertices_params[0]],
2483
+ bakw: [t.vertices_params[1]]
2484
+ }, this.vertices_params.forw[1] = [0, 1, 2, 3].map((n) => {
2485
+ const s = (n + 1) % 4, i = ve(
2486
+ ["c", `b${n}`, `b${s}`],
2487
+ t.points,
2488
+ t.edgeNodes || [],
2489
+ t.centroid_point,
2490
+ t.vertices_points,
2491
+ !1,
2492
+ Ee
2493
+ );
2494
+ return qt([i]);
2495
+ }), this.vertices_params.bakw[1] = [0, 1, 2, 3].map((n) => {
2496
+ const s = (n + 1) % 4, i = ve(
2497
+ ["c", `b${n}`, `b${s}`],
2498
+ t.points,
2499
+ t.edgeNodes || [],
2500
+ t.centroid_point,
2501
+ t.vertices_points,
2502
+ !0,
2503
+ Ee
2504
+ );
2505
+ return qt([i]);
2506
+ }), this.centroid = {
2507
+ forw: ee(t.centroid_point[0], {
2508
+ target: {
2509
+ geom: t.centroid_point[1],
2510
+ index: "c"
2511
+ }
2512
+ }),
2513
+ bakw: ee(t.centroid_point[1], {
2514
+ target: {
2515
+ geom: t.centroid_point[0],
2516
+ index: "c"
2517
+ }
2518
+ })
2519
+ }, this.edges = qn(t.edges || []), this.edgeNodes = t.edgeNodes || [];
2520
+ const e = t.tins_points.length == 1 ? 0 : 1;
2521
+ this.tins = {
2522
+ forw: qt(
2523
+ t.tins_points[0].map(
2524
+ (n) => ve(
2525
+ n,
2526
+ t.points,
2527
+ t.edgeNodes || [],
2528
+ t.centroid_point,
2529
+ t.vertices_points,
2530
+ !1,
2531
+ t.version
2532
+ )
2533
+ )
2534
+ ),
2535
+ bakw: qt(
2536
+ t.tins_points[e].map(
2537
+ (n) => ve(
2538
+ n,
2539
+ t.points,
2540
+ t.edgeNodes || [],
2541
+ t.centroid_point,
2542
+ t.vertices_points,
2543
+ !0,
2544
+ t.version
2545
+ )
2546
+ )
2547
+ )
2548
+ }, this.addIndexedTin(), t.kinks_points && (this.kinks = {
2549
+ bakw: qt(
2550
+ t.kinks_points.map((n) => ee(n))
2551
+ )
2552
+ }), t.yaxisMode ? this.yaxisMode = t.yaxisMode : this.yaxisMode = Et.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);
2553
+ } else {
2554
+ t = JSON.parse(
2555
+ JSON.stringify(t).replace('"cent"', '"c"').replace(/"bbox(\d+)"/g, '"b$1"')
2556
+ ), 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;
2557
+ const e = [];
2558
+ for (let n = 0; n < this.tins.forw.features.length; n++) {
2559
+ const s = this.tins.forw.features[n];
2560
+ ["a", "b", "c"].map((i, o) => {
2561
+ const a = s.geometry.coordinates[0][o], c = s.properties[i].geom, l = s.properties[i].index;
2562
+ e[l] = [a, c];
2563
+ });
2564
+ }
2565
+ this.points = e;
2566
+ }
2567
+ return {
2568
+ tins: this.tins,
2569
+ strict_status: this.strict_status,
2570
+ weight_buffer: this.pointsWeightBuffer,
2571
+ vertices_params: this.vertices_params,
2572
+ centroid: this.centroid,
2573
+ kinks: this.kinks
2574
+ };
2575
+ }
2576
+ /**
2577
+ * TINネットワークのインデックスを作成します
2578
+ *
2579
+ * インデックスは変換処理を高速化するために使用されます。
2580
+ * グリッド形式のインデックスを作成し、各グリッドに
2581
+ * 含まれる三角形を記録します。
2582
+ */
2583
+ addIndexedTin() {
2584
+ const t = this.tins, e = t.forw, n = t.bakw, s = Math.ceil(Math.sqrt(e.features.length));
2585
+ if (s < 3) {
2586
+ this.indexedTins = void 0;
2587
+ return;
2588
+ }
2589
+ let i = [], o = [];
2590
+ const a = e.features.map((d) => {
2591
+ let y = [];
2592
+ return bn(d)[0].map((v) => {
2593
+ i.length === 0 ? i = [Array.from(v), Array.from(v)] : (v[0] < i[0][0] && (i[0][0] = v[0]), v[0] > i[1][0] && (i[1][0] = v[0]), v[1] < i[0][1] && (i[0][1] = v[1]), v[1] > i[1][1] && (i[1][1] = v[1])), y.length === 0 ? y = [Array.from(v), Array.from(v)] : (v[0] < y[0][0] && (y[0][0] = v[0]), v[0] > y[1][0] && (y[1][0] = v[0]), v[1] < y[0][1] && (y[0][1] = v[1]), v[1] > y[1][1] && (y[1][1] = v[1]));
2594
+ }), y;
2595
+ }), c = (i[1][0] - i[0][0]) / s, l = (i[1][1] - i[0][1]) / s, u = a.reduce(
2596
+ (d, y, v) => {
2597
+ const p = Ot(
2598
+ y[0][0],
2599
+ i[0][0],
2600
+ c,
2601
+ s
2602
+ ), w = Ot(
2603
+ y[1][0],
2604
+ i[0][0],
2605
+ c,
2606
+ s
2607
+ ), x = Ot(
2608
+ y[0][1],
2609
+ i[0][1],
2610
+ l,
2611
+ s
2612
+ ), E = Ot(
2613
+ y[1][1],
2614
+ i[0][1],
2615
+ l,
2616
+ s
2617
+ );
2618
+ for (let A = p; A <= w; A++) {
2619
+ d[A] || (d[A] = []);
2620
+ for (let T = x; T <= E; T++)
2621
+ d[A][T] || (d[A][T] = []), d[A][T].push(v);
2622
+ }
2623
+ return d;
2624
+ },
2625
+ []
2626
+ ), h = n.features.map((d) => {
2627
+ let y = [];
2628
+ return bn(d)[0].map((v) => {
2629
+ o.length === 0 ? o = [Array.from(v), Array.from(v)] : (v[0] < o[0][0] && (o[0][0] = v[0]), v[0] > o[1][0] && (o[1][0] = v[0]), v[1] < o[0][1] && (o[0][1] = v[1]), v[1] > o[1][1] && (o[1][1] = v[1])), y.length === 0 ? y = [Array.from(v), Array.from(v)] : (v[0] < y[0][0] && (y[0][0] = v[0]), v[0] > y[1][0] && (y[1][0] = v[0]), v[1] < y[0][1] && (y[0][1] = v[1]), v[1] > y[1][1] && (y[1][1] = v[1]));
2630
+ }), y;
2631
+ }), f = (o[1][0] - o[0][0]) / s, g = (o[1][1] - o[0][1]) / s, _ = h.reduce(
2632
+ (d, y, v) => {
2633
+ const p = Ot(
2634
+ y[0][0],
2635
+ o[0][0],
2636
+ f,
2637
+ s
2638
+ ), w = Ot(
2639
+ y[1][0],
2640
+ o[0][0],
2641
+ f,
2642
+ s
2643
+ ), x = Ot(
2644
+ y[0][1],
2645
+ o[0][1],
2646
+ g,
2647
+ s
2648
+ ), E = Ot(
2649
+ y[1][1],
2650
+ o[0][1],
2651
+ g,
2652
+ s
2653
+ );
2654
+ for (let A = p; A <= w; A++) {
2655
+ d[A] || (d[A] = []);
2656
+ for (let T = x; T <= E; T++)
2657
+ d[A][T] || (d[A][T] = []), d[A][T].push(v);
2658
+ }
2659
+ return d;
2660
+ },
2661
+ []
2662
+ );
2663
+ this.indexedTins = {
2664
+ forw: {
2665
+ gridNum: s,
2666
+ xOrigin: i[0][0],
2667
+ yOrigin: i[0][1],
2668
+ xUnit: c,
2669
+ yUnit: l,
2670
+ gridCache: u
2671
+ },
2672
+ bakw: {
2673
+ gridNum: s,
2674
+ xOrigin: o[0][0],
2675
+ yOrigin: o[0][1],
2676
+ xUnit: f,
2677
+ yUnit: g,
2678
+ gridCache: _
2679
+ }
2680
+ };
2681
+ }
2682
+ /**
2683
+ * 座標変換を実行します
2684
+ *
2685
+ * @param apoint - 変換する座標
2686
+ * @param backward - 逆方向の変換かどうか
2687
+ * @param ignoreBounds - 境界チェックを無視するかどうか
2688
+ * @returns 変換後の座標、または境界外の場合はfalse
2689
+ *
2690
+ * @throws {Error} 逆方向変換が許可されていない状態での逆変換時
2691
+ */
2692
+ transform(t, e, n) {
2693
+ if (e && this.strict_status == Et.STATUS_ERROR)
2694
+ throw 'Backward transform is not allowed if strict_status == "strict_error"';
2695
+ this.yaxisMode == Et.YAXIS_FOLLOW && e && (t = [t[0], -1 * t[1]]);
2696
+ const s = ee(t);
2697
+ if (this.bounds && !e && !n && !je(s, this.boundsPolygon))
2698
+ return !1;
2699
+ const i = e ? this.tins.bakw : this.tins.forw, o = e ? this.indexedTins.bakw : this.indexedTins.forw, a = e ? this.vertices_params.bakw : this.vertices_params.forw, c = e ? this.centroid.bakw : this.centroid.forw, l = e ? this.pointsWeightBuffer.bakw : this.pointsWeightBuffer.forw;
2700
+ let u, h;
2701
+ this.stateFull && (this.stateBackward == e ? u = this.stateTriangle : (this.stateBackward = e, this.stateTriangle = void 0), h = (g) => {
2702
+ this.stateTriangle = g;
2703
+ });
2704
+ let f = Me(
2705
+ s,
2706
+ i,
2707
+ o,
2708
+ a,
2709
+ c,
2710
+ l,
2711
+ u,
2712
+ h
2713
+ );
2714
+ if (this.bounds && e && !n) {
2715
+ const g = ee(f);
2716
+ if (!je(g, this.boundsPolygon)) return !1;
2717
+ } else this.yaxisMode == Et.YAXIS_FOLLOW && !e && (f = [f[0], -1 * f[1]]);
2718
+ return f;
2719
+ }
2720
+ };
2721
+ it(St, "VERTEX_PLAIN", "plain"), it(St, "VERTEX_BIRDEYE", "birdeye"), it(St, "MODE_STRICT", "strict"), it(St, "MODE_AUTO", "auto"), it(St, "MODE_LOOSE", "loose"), it(St, "STATUS_STRICT", "strict"), it(St, "STATUS_ERROR", "strict_error"), it(St, "STATUS_LOOSE", "loose"), it(St, "YAXIS_FOLLOW", "follow"), it(St, "YAXIS_INVERT", "invert");
2722
+ let Ki = St;
2723
+ function _e(r, t, e) {
2724
+ return Vt(r, { target: { geom: t, index: e } });
2725
+ }
2726
+ function xe(r) {
2727
+ return Vt(r.properties.target.geom, {
2728
+ target: {
2729
+ geom: r.geometry.coordinates,
2730
+ index: r.properties.target.index
2731
+ }
2732
+ });
2733
+ }
2734
+ function kn(r, t) {
2735
+ const e = t.geometry.coordinates;
2736
+ return [0, 1, 2, 3].map((n) => {
2737
+ const s = (n + 1) % 4, i = r[n], o = r[s], a = i.geometry.coordinates, c = Math.atan2(
2738
+ a[0] - e[0],
2739
+ a[1] - e[1]
2740
+ ), l = [t, i, o, t].map(
2741
+ (f) => f.geometry.coordinates
2742
+ ), u = {
2743
+ a: {
2744
+ geom: t.properties.target.geom,
2745
+ index: t.properties.target.index
2746
+ },
2747
+ b: {
2748
+ geom: i.properties.target.geom,
2749
+ index: i.properties.target.index
2750
+ },
2751
+ c: {
2752
+ geom: o.properties.target.geom,
2753
+ index: o.properties.target.index
2754
+ }
2755
+ }, h = Xt([ke([l], u)]);
2756
+ return [c, h];
2757
+ }).reduce(
2758
+ (n, s) => (n[0].push(s[0]), n[1].push(s[1]), n),
2759
+ [[], []]
2760
+ );
2761
+ }
2762
+ function An(r) {
2763
+ const t = ["a", "b", "c"].map(
2764
+ (e) => r.properties[e].index
2765
+ );
2766
+ return [
2767
+ [0, 1],
2768
+ [0, 2],
2769
+ [1, 2],
2770
+ [0, 1, 2]
2771
+ ].map(
2772
+ (e) => e.map((n) => t[n]).sort().join("-")
2773
+ ).sort();
2774
+ }
2775
+ function Qi(r, t, e) {
2776
+ const n = An(t.forw), s = An(t.bakw);
2777
+ if (JSON.stringify(n) != JSON.stringify(s))
2778
+ throw `${JSON.stringify(t, null, 2)}
2779
+ ${JSON.stringify(
2780
+ n
2781
+ )}
2782
+ ${JSON.stringify(s)}`;
2783
+ for (let i = 0; i < n.length; i++) {
2784
+ const o = n[i];
2785
+ r[o] || (r[o] = []), r[o].push(t);
2786
+ }
2787
+ }
2788
+ class ht extends Ki {
2789
+ /**
2790
+ * Tinクラスのインスタンスを生成します
2791
+ *
2792
+ * @param {Partial<Options>} options - 初期化オプション
2793
+ * bounds または wh のどちらかが必須です
2794
+ */
2795
+ constructor(e = {}) {
2796
+ super();
2797
+ at(this, "importance");
2798
+ at(this, "priority");
2799
+ at(this, "pointsSet");
2800
+ 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);
2801
+ }
2802
+ /**
2803
+ * フォーマットバージョンを取得します
2804
+ *
2805
+ * @returns {number} 現在のフォーマットバージョン
2806
+ */
2807
+ getFormatVersion() {
2808
+ return Ee;
2809
+ }
2810
+ /**
2811
+ * 制御点(GCP: Ground Control Points)を設定します
2812
+ *
2813
+ * @param points - 制御点の配列。各要素は [ソース座標, ターゲット座標] の形式
2814
+ *
2815
+ * 注意:この操作によりTINネットワークはリセットされ、
2816
+ * 再度updateTin()を呼び出す必要があります。
2817
+ */
2818
+ setPoints(e) {
2819
+ this.yaxisMode == ht.YAXIS_FOLLOW && (e = e.map((n) => [n[0], [n[1][0], -1 * n[1][1]]])), this.points = e, this.tins = void 0, this.indexedTins = void 0;
2820
+ }
2821
+ /**
2822
+ * エッジ(制約線)を設定します
2823
+ *
2824
+ * @param edges - エッジの配列。新規フォーマットまたはレガシーフォーマットに対応
2825
+ *
2826
+ * 注意:この操作によりTINネットワークはリセットされ、
2827
+ * 再度updateTin()を呼び出す必要があります。
2828
+ */
2829
+ setEdges(e = []) {
2830
+ this.edges = qn(e), this.edgeNodes = void 0, this.tins = void 0, this.indexedTins = void 0;
2831
+ }
2832
+ /**
2833
+ * 境界ポリゴンを設定します
2834
+ *
2835
+ * @param bounds - 境界を定義する頂点座標の配列
2836
+ *
2837
+ * - 境界ポリゴンの計算
2838
+ * - バウンディングボックスの計算
2839
+ * - 内部状態の更新
2840
+ */
2841
+ setBounds(e) {
2842
+ this.bounds = e;
2843
+ let n = e[0][0], s = n, i = e[0][1], o = i;
2844
+ const a = [e[0]];
2845
+ for (let c = 1; c < e.length; c++) {
2846
+ const l = e[c];
2847
+ l[0] < n && (n = l[0]), l[0] > s && (s = l[0]), l[1] < i && (i = l[1]), l[1] > o && (o = l[1]), a.push(l);
2848
+ }
2849
+ a.push(e[0]), this.boundsPolygon = ke([a]), this.xy = [n, i], this.wh = [s - n, o - i], this.vertexMode = ht.VERTEX_PLAIN, this.tins = void 0, this.indexedTins = void 0;
2850
+ }
2851
+ /**
2852
+ * 現在の設定を永続化可能な形式にコンパイルします
2853
+ *
2854
+ * @returns Compiled - コンパイルされた設定オブジェクト
2855
+ *
2856
+ * 以下の情報が含まれます:
2857
+ * - バージョン情報
2858
+ * - 制御点データ
2859
+ * - TINネットワーク情報
2860
+ * - 境界情報
2861
+ * - 各種モード設定
2862
+ */
2863
+ getCompiled() {
2864
+ const e = {};
2865
+ e.version = Ee, e.points = this.points, e.weight_buffer = this.pointsWeightBuffer, e.centroid_point = [
2866
+ this.centroid.forw.geometry.coordinates,
2867
+ this.centroid.forw.properties.target.geom
2868
+ ], e.vertices_params = [
2869
+ this.vertices_params.forw[0],
2870
+ this.vertices_params.bakw[0]
2871
+ ], e.vertices_points = [];
2872
+ const n = this.vertices_params.forw[1];
2873
+ return [0, 1, 2, 3].map((s) => {
2874
+ const i = n[s].features[0], o = i.geometry.coordinates[0][1], a = i.properties.b.geom;
2875
+ e.vertices_points[s] = [o, a];
2876
+ }), e.strict_status = this.strict_status, e.tins_points = [[]], this.tins.forw.features.map((s) => {
2877
+ e.tins_points[0].push(
2878
+ ["a", "b", "c"].map(
2879
+ (i) => s.properties[i].index
2880
+ )
2881
+ );
2882
+ }), this.strict_status == ht.STATUS_LOOSE ? (e.tins_points[1] = [], this.tins.bakw.features.map((s) => {
2883
+ e.tins_points[1].push(
2884
+ ["a", "b", "c"].map(
2885
+ (i) => s.properties[i].index
2886
+ )
2887
+ );
2888
+ })) : this.strict_status == ht.STATUS_ERROR && (e.kinks_points = this.kinks.bakw.features.map(
2889
+ (s) => s.geometry.coordinates
2890
+ )), 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;
2891
+ }
2892
+ /**
2893
+ * 幅と高さを設定します
2894
+ *
2895
+ * @param {number[]} wh - [width, height] の形式で指定
2896
+ * この操作によりTINネットワークはリセットされます
2897
+ */
2898
+ setWh(e) {
2899
+ this.wh = e, this.xy = [0, 0], this.bounds = void 0, this.boundsPolygon = void 0, this.tins = void 0, this.indexedTins = void 0;
2900
+ }
2901
+ /**
2902
+ * 頂点モードを設定します
2903
+ *
2904
+ * @param {VertexMode} mode - "plain" または "birdeye"
2905
+ * この操作によりTINネットワークはリセットされます
2906
+ */
2907
+ setVertexMode(e) {
2908
+ this.vertexMode = e, this.tins = void 0, this.indexedTins = void 0;
2909
+ }
2910
+ /**
2911
+ * 厳密性モードを設定します
2912
+ *
2913
+ * @param {StrictMode} mode - "strict", "auto", または "loose"
2914
+ * この操作によりTINネットワークはリセットされます
2915
+ */
2916
+ setStrictMode(e) {
2917
+ this.strictMode = e, this.tins = void 0, this.indexedTins = void 0;
2918
+ }
2919
+ /**
2920
+ * 厳密なTINを計算します
2921
+ *
2922
+ * - 逆方向の三角形を生成
2923
+ * - 交差チェックを実行
2924
+ * - 結果に基づいてstrict_statusを更新
2925
+ *
2926
+ * strict_statusは以下のいずれかになります:
2927
+ * - STATUS_STRICT: 交差なし
2928
+ * - STATUS_ERROR: 交差あり
2929
+ */
2930
+ calcurateStrictTin() {
2931
+ const e = this.tins.forw.features.map((i) => Wi(i));
2932
+ this.tins.bakw = Xt(e);
2933
+ const n = {};
2934
+ this.tins.forw.features.forEach((i, o) => {
2935
+ const a = this.tins.bakw.features[o];
2936
+ Qi(n, { forw: i, bakw: a });
2937
+ });
2938
+ const s = ["forw", "bakw"].map((i) => {
2939
+ const o = this.tins[i].features.map(
2940
+ (a) => a.geometry.coordinates[0]
2941
+ );
2942
+ return Vr(o);
2943
+ });
2944
+ s[0].length == 0 && s[1].length == 0 ? (this.strict_status = ht.STATUS_STRICT, delete this.kinks) : (this.strict_status = ht.STATUS_ERROR, this.kinks = {}, s[0].length > 0 && (this.kinks.forw = Xt(s[0])), s[1].length > 0 && (this.kinks.bakw = Xt(s[1])));
2945
+ }
2946
+ /**
2947
+ * 点群セットを生成します
2948
+ *
2949
+ * 以下の処理を行います:
2950
+ * 1. 制御点からポイントセットを生成
2951
+ * 2. エッジ節点の生成と追加
2952
+ * 3. エッジの接続関係の構築
2953
+ *
2954
+ * @returns {object} 生成された点群セットと接続情報
2955
+ * @property {FeatureCollection} forw - 順方向の点群
2956
+ * @property {FeatureCollection} bakw - 逆方向の点群
2957
+ * @property {Array} edges - エッジ接続情報
2958
+ */
2959
+ generatePointsSet() {
2960
+ const e = { forw: [], bakw: [] };
2961
+ for (let i = 0; i < this.points.length; i++) {
2962
+ const o = this.points[i][0], a = this.points[i][1], c = _e(o, a, i);
2963
+ e.forw.push(c), e.bakw.push(xe(c));
2964
+ }
2965
+ const n = [];
2966
+ let s = 0;
2967
+ this.edgeNodes = [], this.edges || (this.edges = []);
2968
+ for (let i = 0; i < this.edges.length; i++) {
2969
+ const o = this.edges[i][2], a = Object.assign([], this.edges[i][0]), c = Object.assign([], this.edges[i][1]);
2970
+ if (a.length === 0 && c.length === 0) {
2971
+ n.push(o);
2972
+ continue;
2973
+ }
2974
+ a.unshift(this.points[o[0]][0]), a.push(this.points[o[1]][0]), c.unshift(this.points[o[0]][1]), c.push(this.points[o[1]][1]);
2975
+ const l = [a, c].map((u) => {
2976
+ const h = u.map((g, _, d) => {
2977
+ if (_ === 0) return 0;
2978
+ const y = d[_ - 1];
2979
+ return Math.sqrt(
2980
+ Math.pow(g[0] - y[0], 2) + Math.pow(g[1] - y[1], 2)
2981
+ );
2982
+ }), f = h.reduce(
2983
+ (g, _, d) => d === 0 ? [0] : (g.push(g[d - 1] + _), g),
2984
+ []
2985
+ );
2986
+ return f.map((g, _, d) => {
2987
+ const y = g / d[d.length - 1];
2988
+ return [u[_], h[_], f[_], y];
2989
+ });
2990
+ });
2991
+ l.map((u, h) => {
2992
+ const f = l[h ? 0 : 1];
2993
+ return u.filter(
2994
+ (g, _) => !(_ === 0 || _ === u.length - 1 || g[4] === "handled")
2995
+ ).map((g) => {
2996
+ const _ = g[0], d = g[3], y = f.reduce(
2997
+ (v, p, w, x) => {
2998
+ if (v) return v;
2999
+ const E = x[w + 1];
3000
+ if (p[3] === d)
3001
+ return p[4] = "handled", [p];
3002
+ if (p[3] < d && E[3] > d) return [p, E];
3003
+ },
3004
+ void 0
3005
+ );
3006
+ if (y.length === 1)
3007
+ return h === 0 ? [_, y[0][0], d] : [y[0][0], _, d];
3008
+ {
3009
+ const v = y[0], p = y[1], w = d - v[3], x = p[3] - v[3], E = w / x, A = [
3010
+ (p[0][0] - v[0][0]) * E + v[0][0],
3011
+ (p[0][1] - v[0][1]) * E + v[0][1]
3012
+ ];
3013
+ return h === 0 ? [_, A, d] : [A, _, d];
3014
+ }
3015
+ });
3016
+ }).reduce((u, h) => u.concat(h), []).sort((u, h) => u[2] < h[2] ? -1 : 1).map((u, h, f) => {
3017
+ this.edgeNodes[s] = [u[0], u[1]];
3018
+ const g = _e(u[0], u[1], `e${s}`);
3019
+ s++, e.forw.push(g), e.bakw.push(xe(g)), h === 0 ? n.push([o[0], e.forw.length - 1]) : n.push([
3020
+ e.forw.length - 2,
3021
+ e.forw.length - 1
3022
+ ]), h === f.length - 1 && n.push([e.forw.length - 1, o[1]]);
3023
+ });
3024
+ }
3025
+ return {
3026
+ forw: Xt(e.forw),
3027
+ bakw: Xt(e.bakw),
3028
+ edges: n
3029
+ };
3030
+ }
3031
+ /**
3032
+ * 入力データの検証と初期データの準備
3033
+ * - 境界値のチェック
3034
+ * - バッファー付き境界の計算
3035
+ * - 点群セットの生成
3036
+ * @returns {object} 検証済みの点群セットと境界データ
3037
+ * @throws {Error} "SOME POINTS OUTSIDE" 制御点が境界外にある場合
3038
+ */
3039
+ validateAndPrepareInputs() {
3040
+ const e = this.xy[0] - 0.05 * this.wh[0], n = this.xy[0] + 1.05 * this.wh[0], s = this.xy[1] - 0.05 * this.wh[1], i = this.xy[1] + 1.05 * this.wh[1];
3041
+ if (!this.points.reduce(
3042
+ (l, u) => l && (this.bounds ? lr(u[0], this.boundsPolygon) : u[0][0] >= e && u[0][0] <= n && u[0][1] >= s && u[0][1] <= i),
3043
+ !0
3044
+ ))
3045
+ throw "SOME POINTS OUTSIDE";
3046
+ let a = [];
3047
+ return this.wh && (a = [
3048
+ [e, s],
3049
+ [n, s],
3050
+ [e, i],
3051
+ [n, i]
3052
+ ]), { pointsSet: this.generatePointsSet(), bbox: a, minx: e, maxx: n, miny: s, maxy: i };
3053
+ }
3054
+ /**
3055
+ * TINネットワークを更新し、座標変換の準備を行います
3056
+ *
3057
+ * このメソッドは以下の処理を実行します:
3058
+ * 1. 入力データの検証
3059
+ * 2. 制御点のTIN生成
3060
+ * 3. Convex Hull(凸包)の計算
3061
+ * 4. 境界の調整
3062
+ * 5. 変換パラメータの計算
3063
+ *
3064
+ * @throws {Error} "TOO LINEAR1" - 制御点が直線的すぎる場合
3065
+ * @throws {Error} "TOO LINEAR2" - 変換後の点が直線的すぎる場合
3066
+ * @throws {Error} "SOME POINTS OUTSIDE" - 制御点が境界外にある場合
3067
+ */
3068
+ updateTin() {
3069
+ let e = this.strictMode;
3070
+ e != ht.MODE_STRICT && e != ht.MODE_LOOSE && (e = ht.MODE_AUTO);
3071
+ const { pointsSet: n, bbox: s, minx: i, maxx: o, miny: a, maxy: c } = this.validateAndPrepareInputs(), l = ye(n.forw, n.edges, "target"), u = ye(n.bakw, n.edges, "target"), h = ur(n.forw);
3072
+ if (l.features.length == 0 || u.features.length == 0)
3073
+ throw "TOO LINEAR1";
3074
+ const f = {}, g = an(n.forw).geometry.coordinates[0];
3075
+ let _;
3076
+ try {
3077
+ _ = g.map((S) => ({
3078
+ forw: S,
3079
+ bakw: Me(Vt(S), l)
3080
+ })), _.forEach((S) => {
3081
+ f[`${S.forw[0]}:${S.forw[1]}`] = S;
3082
+ });
3083
+ } catch {
3084
+ throw "TOO LINEAR2";
3085
+ }
3086
+ const d = an(n.bakw).geometry.coordinates[0];
3087
+ try {
3088
+ _ = d.map((S) => ({
3089
+ bakw: S,
3090
+ forw: Me(Vt(S), u)
3091
+ })), _.forEach((S) => {
3092
+ f[`${S.forw[0]}:${S.forw[1]}`] = S;
3093
+ });
3094
+ } catch {
3095
+ throw "TOO LINEAR2";
3096
+ }
3097
+ const y = {
3098
+ forw: h.geometry.coordinates,
3099
+ bakw: Me(h, l)
3100
+ }, v = _e(y.forw, y.bakw, "c");
3101
+ this.centroid = { forw: v, bakw: xe(v) };
3102
+ const p = Object.keys(f).reduce(
3103
+ (S, B, O, I) => {
3104
+ const C = f[B].forw, N = f[B].bakw, m = {
3105
+ forw: [
3106
+ C[0] - y.forw[0],
3107
+ C[1] - y.forw[1]
3108
+ ]
3109
+ };
3110
+ m.bakw = [
3111
+ N[0] - y.bakw[0],
3112
+ N[1] - y.bakw[1]
3113
+ ];
3114
+ const M = m.forw[0] == 0 ? 1 / 0 : ((m.forw[0] < 0 ? i : o) - y.forw[0]) / m.forw[0], k = m.forw[1] == 0 ? 1 / 0 : ((m.forw[1] < 0 ? a : c) - y.forw[1]) / m.forw[1];
3115
+ if (Math.abs(M) / Math.abs(k) < 1.1) {
3116
+ const P = {
3117
+ forw: [
3118
+ m.forw[0] * M + y.forw[0],
3119
+ m.forw[1] * M + y.forw[1]
3120
+ ],
3121
+ bakw: [
3122
+ m.bakw[0] * M + y.bakw[0],
3123
+ m.bakw[1] * M + y.bakw[1]
3124
+ ]
3125
+ };
3126
+ m.forw[0] < 0 ? S[3].push(P) : S[1].push(P);
3127
+ }
3128
+ if (Math.abs(k) / Math.abs(M) < 1.1) {
3129
+ const P = {
3130
+ forw: [
3131
+ m.forw[0] * k + y.forw[0],
3132
+ m.forw[1] * k + y.forw[1]
3133
+ ],
3134
+ bakw: [
3135
+ m.bakw[0] * k + y.bakw[0],
3136
+ m.bakw[1] * k + y.bakw[1]
3137
+ ]
3138
+ };
3139
+ m.forw[1] < 0 ? S[0].push(P) : S[2].push(P);
3140
+ }
3141
+ return S;
3142
+ },
3143
+ [[], [], [], []]
3144
+ );
3145
+ let w = Object.keys(f).reduce(
3146
+ (S, B, O, I) => {
3147
+ const C = f[B].forw, N = f[B].bakw, m = {
3148
+ forw: [
3149
+ C[0] - y.forw[0],
3150
+ C[1] - y.forw[1]
3151
+ ]
3152
+ };
3153
+ if (m.bakw = [
3154
+ N[0] - y.bakw[0],
3155
+ y.bakw[1] - N[1]
3156
+ ], m.forw[0] == 0 || m.forw[1] == 0)
3157
+ return S;
3158
+ let M = 0;
3159
+ return m.forw[0] > 0 && (M += 1), m.forw[1] > 0 && (M += 2), S[M].push([
3160
+ m.forw,
3161
+ m.bakw
3162
+ ]), O == I.length - 1 ? S.length == S.filter((k) => k.length > 0).length && this.vertexMode == ht.VERTEX_BIRDEYE ? S : S.reduce((k, P) => [k[0].concat(P)], [[]]) : S;
3163
+ },
3164
+ [[], [], [], []]
3165
+ ).map(
3166
+ (S) => (
3167
+ // Finalize calcuration of Average scaling factors and rotation factors
3168
+ S.reduce(
3169
+ (B, O, I, C) => {
3170
+ B || (B = [1 / 0, 0, 0]);
3171
+ let N = Math.sqrt(Math.pow(O[0][0], 2) + Math.pow(O[0][1], 2)) / Math.sqrt(Math.pow(O[1][0], 2) + Math.pow(O[1][1], 2));
3172
+ N = N < B[0] ? N : B[0];
3173
+ const m = Math.atan2(O[0][0], O[0][1]) - Math.atan2(O[1][0], O[1][1]), M = B[1] + Math.cos(m), k = B[2] + Math.sin(m);
3174
+ return I == C.length - 1 ? [N, Math.atan2(k, M)] : [N, M, k];
3175
+ },
3176
+ null
3177
+ )
3178
+ )
3179
+ );
3180
+ w.length == 1 && (w = [w[0], w[0], w[0], w[0]]);
3181
+ let x = w.map((S, B) => {
3182
+ const O = s[B], I = [
3183
+ O[0] - y.forw[0],
3184
+ O[1] - y.forw[1]
3185
+ ], N = Math.sqrt(
3186
+ Math.pow(I[0], 2) + Math.pow(I[1], 2)
3187
+ ) / S[0], M = Math.atan2(I[0], I[1]) - S[1], k = [
3188
+ y.bakw[0] + N * Math.sin(M),
3189
+ y.bakw[1] - N * Math.cos(M)
3190
+ ];
3191
+ return { forw: O, bakw: k };
3192
+ });
3193
+ const E = x[2];
3194
+ x[2] = x[3], x[3] = E;
3195
+ const A = [1, 1, 1, 1];
3196
+ for (let S = 0; S < 4; S++) {
3197
+ const B = (S + 1) % 4, O = tn([x[S].bakw, x[B].bakw]);
3198
+ p[S].map((C) => {
3199
+ const N = tn([y.bakw, C.bakw]), m = qr(O, N);
3200
+ if (m.features.length > 0 && m.features[0].geometry) {
3201
+ const M = m.features[0], k = Math.sqrt(
3202
+ Math.pow(C.bakw[0] - y.bakw[0], 2) + Math.pow(C.bakw[1] - y.bakw[1], 2)
3203
+ ), P = Math.sqrt(
3204
+ Math.pow(
3205
+ M.geometry.coordinates[0] - y.bakw[0],
3206
+ 2
3207
+ ) + Math.pow(
3208
+ M.geometry.coordinates[1] - y.bakw[1],
3209
+ 2
3210
+ )
3211
+ ), X = k / P;
3212
+ X > A[S] && (A[S] = X), X > A[B] && (A[B] = X);
3213
+ }
3214
+ });
3215
+ }
3216
+ x = x.map((S, B) => {
3217
+ const O = A[B], I = [
3218
+ (S.bakw[0] - y.bakw[0]) * O + y.bakw[0],
3219
+ (S.bakw[1] - y.bakw[1]) * O + y.bakw[1]
3220
+ ];
3221
+ return { forw: S.forw, bakw: I };
3222
+ });
3223
+ const T = { forw: [], bakw: [] };
3224
+ for (let S = 0; S < x.length; S++) {
3225
+ const B = x[S].forw, O = x[S].bakw, I = _e(B, O, `b${S}`), C = xe(I);
3226
+ n.forw.features.push(I), n.bakw.features.push(C), T.forw.push(I), T.bakw.push(C);
3227
+ }
3228
+ this.pointsSet = n, this.tins = {
3229
+ forw: Mn(
3230
+ ye(n.forw, n.edges, "target")
3231
+ )
3232
+ }, (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 = Mn(
3233
+ ye(n.bakw, n.edges, "target")
3234
+ ), delete this.kinks, this.strict_status = ht.STATUS_LOOSE), this.vertices_params = {
3235
+ forw: kn(T.forw, this.centroid.forw),
3236
+ bakw: kn(T.bakw, this.centroid.bakw)
3237
+ }, this.addIndexedTin(), this.calculatePointsWeight();
3238
+ }
3239
+ /**
3240
+ * 点の重み付けを計算します
3241
+ *
3242
+ * - 各点について周辺の三角形から重みを計算
3243
+ * - 順方向と逆方向(必要な場合)の重みを計算
3244
+ * - 重心点の重みも計算
3245
+ *
3246
+ * 重みは変換の精度と安定性に影響を与えます
3247
+ */
3248
+ calculatePointsWeight() {
3249
+ const e = ["forw"];
3250
+ this.strict_status == ht.STATUS_LOOSE && e.push("bakw");
3251
+ const n = {};
3252
+ e.forEach((i) => {
3253
+ n[i] = {};
3254
+ const o = {};
3255
+ this.tins[i].features.map((c) => {
3256
+ const l = ["a", "b", "c"];
3257
+ for (let u = 0; u < 3; u++) {
3258
+ const h = (u + 1) % 3, f = l[u], g = l[h], _ = c.properties[f].index, d = c.properties[g].index, y = [_, d].sort().join("-");
3259
+ if (!o[y]) {
3260
+ const v = c.geometry.coordinates[0][u], p = c.geometry.coordinates[0][h], w = c.properties[f].geom, x = c.properties[g].geom;
3261
+ o[y] = 1;
3262
+ const E = Math.sqrt(
3263
+ Math.pow(w[0] - x[0], 2) + Math.pow(w[1] - x[1], 2)
3264
+ ) / Math.sqrt(
3265
+ Math.pow(v[0] - p[0], 2) + Math.pow(v[1] - p[1], 2)
3266
+ );
3267
+ n[i][_] || (n[i][_] = {}), n[i][d] || (n[i][d] = {}), n[i][_][y] = E, n[i][d][y] = E;
3268
+ }
3269
+ }
3270
+ });
3271
+ });
3272
+ const s = {};
3273
+ e.map((i) => {
3274
+ s[i] = {}, this.strict_status == ht.STATUS_STRICT && (s.bakw = {}), Object.keys(n[i]).map((o) => {
3275
+ s[i][o] = Object.keys(
3276
+ n[i][o]
3277
+ ).reduce((a, c, l, u) => (a = a + n[i][o][c], l == u.length - 1 ? a / u.length : a), 0), this.strict_status == ht.STATUS_STRICT && (s.bakw[o] = 1 / s[i][o]);
3278
+ }), s[i].c = [0, 1, 2, 3].reduce(
3279
+ (o, a) => {
3280
+ const c = `b${a}`;
3281
+ return o = o + s[i][c], a == 3 ? o / 4 : o;
3282
+ },
3283
+ 0
3284
+ ), this.strict_status == ht.STATUS_STRICT && (s.bakw.c = 1 / s[i].c);
3285
+ }), this.pointsWeightBuffer = s;
3286
+ }
3287
+ }
3288
+ typeof window < "u" ? window.Tin = ht : typeof global < "u" && (global.Tin = ht);
3289
+ export {
3290
+ ht as default
3291
+ };