UNPKG

@maplat/tin

Version:

JavaScript library which performs homeomorphic conversion mutually between the coordinate systems of two planes based on the control points.

1,174 lines 83 kB
var Qe = Object.defineProperty; var Ze = (o, t, e) => t in o ? Qe(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e; var rt = (o, t, e) => Ze(o, typeof t != "symbol" ? t + "" : t, e); import ts from "@turf/boolean-point-in-polygon"; import es from "@turf/centroid"; import ke from "@turf/convex"; import { featureCollection as Ot, polygon as me, point as Jt, lineString as xe } from "@turf/helpers"; import ss from "@turf/line-intersect"; import ns from "delaunator"; var is = Object.defineProperty, rs = (o, t, e) => t in o ? is(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, nt = (o, t, e) => rs(o, typeof t != "symbol" ? t + "" : t, e); const Tt = 11102230246251565e-32, lt = 134217729, os = (3 + 8 * Tt) * Tt; function ae(o, t, e, s, i) { let n, r, a, f, c = t[0], u = s[0], h = 0, l = 0; u > c == u > -c ? (n = c, c = t[++h]) : (n = u, u = s[++l]); let p = 0; if (h < o && l < e) for (u > c == u > -c ? (r = c + n, a = n - (r - c), c = t[++h]) : (r = u + n, a = n - (r - u), u = s[++l]), n = r, a !== 0 && (i[p++] = a); h < o && l < e; ) u > c == u > -c ? (r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h]) : (r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l]), n = r, a !== 0 && (i[p++] = a); for (; h < o; ) r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h], n = r, a !== 0 && (i[p++] = a); for (; l < e; ) r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l], n = r, a !== 0 && (i[p++] = a); return (n !== 0 || p === 0) && (i[p++] = n), p; } function as(o, t) { let e = t[0]; for (let s = 1; s < o; s++) e += t[s]; return e; } function Ht(o) { return new Float64Array(o); } const hs = (3 + 16 * Tt) * Tt, cs = (2 + 12 * Tt) * Tt, fs = (9 + 64 * Tt) * Tt * Tt, Vt = Ht(4), _e = Ht(8), Me = Ht(12), Se = Ht(16), gt = Ht(4); function us(o, t, e, s, i, n, r) { let a, f, c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V; const z = o - i, G = e - i, tt = t - n, X = s - n; v = z * X, l = lt * z, p = l - (l - z), y = z - p, l = lt * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = tt * G, l = lt * tt, p = l - (l - tt), y = tt - p, l = lt * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, Vt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, Vt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, Vt[2] = S - (V - h) + (w - h), Vt[3] = V; let it = as(4, Vt), d = cs * r; if (it >= d || -it >= d || (h = o - z, a = o - (z + h) + (h - i), h = e - G, c = e - (G + h) + (h - i), h = t - tt, f = t - (tt + h) + (h - n), h = s - X, u = s - (X + h) + (h - n), a === 0 && f === 0 && c === 0 && u === 0) || (d = fs * r + os * Math.abs(it), it += z * u + X * a - (tt * c + G * f), it >= d || -it >= d)) return it; v = a * X, l = lt * a, p = l - (l - a), y = a - p, l = lt * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = f * G, l = lt * f, p = l - (l - f), y = f - p, l = lt * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V; const m = ae(4, Vt, 4, gt, _e); v = z * u, l = lt * z, p = l - (l - z), y = z - p, l = lt * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = tt * c, l = lt * tt, p = l - (l - tt), y = tt - p, l = lt * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V; const x = ae(m, _e, 4, gt, Me); v = a * u, l = lt * a, p = l - (l - a), y = a - p, l = lt * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = f * c, l = lt * f, p = l - (l - f), y = f - p, l = lt * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, gt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, gt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, gt[2] = S - (V - h) + (w - h), gt[3] = V; const A = ae(x, Me, 4, gt, Se); return Se[A - 1]; } function ls(o, t, e, s, i, n) { const r = (t - n) * (e - i), a = (o - i) * (s - n), f = r - a, c = Math.abs(r + a); return Math.abs(f) >= hs * c ? f : -us(o, t, e, s, i, n, c); } function ds(o, t) { var e, s, i = 0, n, r, a, f, c, u, h, l = o[0], p = o[1], y = t.length; for (e = 0; e < y; e++) { s = 0; var g = t[e], b = g.length - 1; if (u = g[0], u[0] !== g[b][0] && u[1] !== g[b][1]) throw new Error("First and last coordinates in a ring must be the same"); for (r = u[0] - l, a = u[1] - p, s; s < b; s++) { if (h = g[s + 1], f = h[0] - l, c = h[1] - p, a === 0 && c === 0) { if (f <= 0 && r >= 0 || r <= 0 && f >= 0) return 0; } else if (c >= 0 && a <= 0 || c <= 0 && a >= 0) { if (n = ls(r, f, a, c, 0, 0), n === 0) return 0; (n > 0 && c > 0 && a <= 0 || n < 0 && c <= 0 && a > 0) && i++; } u = h, a = c, r = f; } } return i % 2 !== 0; } function Le(o, t, e = {}) { const s = { type: "Feature" }; return (e.id === 0 || e.id) && (s.id = e.id), e.bbox && (s.bbox = e.bbox), s.properties = t || {}, s.geometry = o, s; } function Yt(o, t, e = {}) { if (!o) throw new Error("coordinates is required"); if (!Array.isArray(o)) throw new Error("coordinates must be an Array"); if (o.length < 2) throw new Error("coordinates must be at least 2 numbers long"); if (!Ae(o[0]) || !Ae(o[1])) throw new Error("coordinates must contain numbers"); return Le({ type: "Point", coordinates: o }, t, e); } function Ve(o, t, e = {}) { for (const s of o) { if (s.length < 4) throw new Error( "Each LinearRing of a Polygon must have 4 or more Positions." ); if (s[s.length - 1].length !== s[0].length) throw new Error("First and last Position are not equivalent."); for (let i = 0; i < s[s.length - 1].length; i++) if (s[s.length - 1][i] !== s[0][i]) throw new Error("First and last Position are not equivalent."); } return Le({ type: "Polygon", coordinates: o }, t, e); } function Lt(o, t = {}) { const e = { type: "FeatureCollection" }; return t.id && (e.id = t.id), t.bbox && (e.bbox = t.bbox), e.features = o, e; } function Ae(o) { return !isNaN(o) && o !== null && !Array.isArray(o); } function gs(o) { if (!o) throw new Error("coord is required"); if (!Array.isArray(o)) { if (o.type === "Feature" && o.geometry !== null && o.geometry.type === "Point") return [...o.geometry.coordinates]; if (o.type === "Point") return [...o.coordinates]; } if (Array.isArray(o) && o.length >= 2 && !Array.isArray(o[0]) && !Array.isArray(o[1])) return [...o]; throw new Error("coord must be GeoJSON Point or an Array of numbers"); } function Ee(o) { if (Array.isArray(o)) return o; if (o.type === "Feature") { if (o.geometry !== null) return o.geometry.coordinates; } else if (o.coordinates) return o.coordinates; throw new Error( "coords must be GeoJSON Feature, Geometry Object or an Array" ); } function ps(o) { return o.type === "Feature" ? o.geometry : o; } function ws(o, t, e = {}) { if (!o) throw new Error("point is required"); if (!t) throw new Error("polygon is required"); const s = gs(o), i = ps(t), n = i.type, r = t.bbox; let a = i.coordinates; if (r && ms(s, r) === !1) return !1; n === "Polygon" && (a = [a]); let f = !1; for (var c = 0; c < a.length; ++c) { const u = ds(s, a[c]); if (u === 0) return !e.ignoreBoundary; u && (f = !0); } return f; } function ms(o, t) { return t[0] <= o[0] && t[1] <= o[1] && t[2] >= o[0] && t[3] >= o[1]; } var pe = ws; function ve(o) { const t = o.features; for (let e = 0; e < t.length; e++) { const s = t[e]; `${s.properties.a.index}`.substring(0, 1) === "b" && `${s.properties.b.index}`.substring(0, 1) === "b" ? t[e] = { geometry: { type: "Polygon", coordinates: [ [ s.geometry.coordinates[0][2], s.geometry.coordinates[0][0], s.geometry.coordinates[0][1], s.geometry.coordinates[0][2] ] ] }, properties: { a: { geom: s.properties.c.geom, index: s.properties.c.index }, b: { geom: s.properties.a.geom, index: s.properties.a.index }, c: { geom: s.properties.b.geom, index: s.properties.b.index } }, type: "Feature" } : `${s.properties.c.index}`.substring(0, 1) === "b" && `${s.properties.a.index}`.substring(0, 1) === "b" && (t[e] = { geometry: { type: "Polygon", coordinates: [ [ s.geometry.coordinates[0][1], s.geometry.coordinates[0][2], s.geometry.coordinates[0][0], s.geometry.coordinates[0][1] ] ] }, properties: { a: { geom: s.properties.b.geom, index: s.properties.b.index }, b: { geom: s.properties.c.geom, index: s.properties.c.index }, c: { geom: s.properties.a.geom, index: s.properties.a.index } }, type: "Feature" }); } return o; } function bs(o) { const t = ["a", "b", "c", "a"].map( (n) => o.properties[n].geom ), e = o.geometry.coordinates[0], s = o.properties, i = { a: { geom: e[0], index: s.a.index }, b: { geom: e[1], index: s.b.index }, c: { geom: e[2], index: s.c.index } }; return Ve([t], i); } function ys(o) { const t = [0, 1, 2, 0].map((s) => o[s][0][0]), e = { a: { geom: o[0][0][1], index: o[0][1] }, b: { geom: o[1][0][1], index: o[1][1] }, c: { geom: o[2][0][1], index: o[2][1] } }; return Ve([t], e); } function Gt(o, t, e, s, i, n = !1, r) { const a = o.map( (f) => { (!r || r < 2.00703) && (f = We(f)); const c = isFinite(f) ? t[f] : f === "c" ? s : f === "b0" ? i[0] : f === "b1" ? i[1] : f === "b2" ? i[2] : f === "b3" ? i[3] : function() { const u = f.match(/e(\d+)/); if (u) { const h = parseInt(u[1]); return e[h]; } throw "Bad index value for indexesToTri"; }(); return n ? [[c[1], c[0]], f] : [[c[0], c[1]], f]; } ); return ys(a); } function We(o) { return typeof o == "number" ? o : o.replace(/^(c|e|b)(?:ent|dgeNode|box)(\d+)?$/, "$1$2"); } function ze(o, t) { return t && t >= 2.00703 || Array.isArray(o[0]) ? o : o.map((e) => [ e.illstNodes, e.mercNodes, e.startEnd ]); } function Oe(o, t) { for (let e = 0; e < t.features.length; e++) if (pe(o, t.features[e])) return t.features[e]; } function Xe(o, t, e) { const s = t.geometry.coordinates[0][0], i = t.geometry.coordinates[0][1], n = t.geometry.coordinates[0][2], r = o.geometry.coordinates, a = t.properties.a.geom, f = t.properties.b.geom, c = t.properties.c.geom, u = [i[0] - s[0], i[1] - s[1]], h = [n[0] - s[0], n[1] - s[1]], l = [r[0] - s[0], r[1] - s[1]], p = [f[0] - a[0], f[1] - a[1]], y = [c[0] - a[0], c[1] - a[1]]; let g = (h[1] * l[0] - h[0] * l[1]) / (u[0] * h[1] - u[1] * h[0]), b = (u[0] * l[1] - u[1] * l[0]) / (u[0] * h[1] - u[1] * h[0]); if (e) { const w = e[t.properties.a.index], S = e[t.properties.b.index], _ = e[t.properties.c.index]; let v; if (g < 0 || b < 0 || 1 - g - b < 0) { const T = g / (g + b), I = b / (g + b); v = g / S / (T / S + I / _), b = b / _ / (T / S + I / _); } else v = g / S / (g / S + b / _ + (1 - g - b) / w), b = b / _ / (g / S + b / _ + (1 - g - b) / w); g = v; } return [ g * p[0] + b * y[0] + a[0], g * p[1] + b * y[1] + a[1] ]; } function ks(o, t, e, s) { const i = o.geometry.coordinates, n = e.geometry.coordinates, r = Math.atan2(i[0] - n[0], i[1] - n[1]), a = xs(r, t[0]); if (a === void 0) throw new Error("Unable to determine vertex index"); const f = t[1][a]; return Xe(o, f.features[0], s); } function re(o, t, e, s, i, n, r, a) { let f; if (r && (f = Oe(o, Lt([r]))), !f) { if (e) { const c = o.geometry.coordinates, u = e.gridNum, h = e.xOrigin, l = e.yOrigin, p = e.xUnit, y = e.yUnit, g = e.gridCache, b = At(c[0], h, p, u), w = At(c[1], l, y, u), S = g[b] ? g[b][w] ? g[b][w] : [] : []; t = Lt(S.map((_) => t.features[_])); } f = Oe(o, t); } return a && a(f), f ? Xe(o, f, n) : ks(o, s, i, n); } function At(o, t, e, s) { let i = Math.floor((o - t) / e); return i >= s && (i = s - 1), i; } function xs(o, t) { let e = Te(o - t[0]), s = Math.PI * 2, i; for (let n = 0; n < t.length; n++) { const r = (n + 1) % t.length, a = Te(o - t[r]), f = Math.min(Math.abs(e), Math.abs(a)); e * a <= 0 && f < s && (s = f, i = n), e = a; } return i; } function Te(o, t = !1) { const e = t ? function(s) { return !(s >= 0 && s < Math.PI * 2); } : function(s) { return !(s > -1 * Math.PI && s <= Math.PI); }; for (; e(o); ) o = o + 2 * Math.PI * (o > 0 ? -1 : 1); return o; } const we = 2.00703, kt = class xt { constructor() { nt(this, "points", []), nt(this, "pointsWeightBuffer"), nt(this, "strict_status"), nt(this, "vertices_params"), nt(this, "centroid"), nt(this, "edgeNodes"), nt(this, "edges"), nt(this, "tins"), nt(this, "kinks"), nt(this, "yaxisMode", xt.YAXIS_INVERT), nt(this, "strictMode", xt.MODE_AUTO), nt(this, "vertexMode", xt.VERTEX_PLAIN), nt(this, "bounds"), nt(this, "boundsPolygon"), nt(this, "wh"), nt(this, "xy"), nt(this, "indexedTins"), nt(this, "stateFull", !1), nt(this, "stateTriangle"), nt(this, "stateBackward"); } /** * コンパイルされた設定を適用します * * @param compiled - コンパイルされた設定オブジェクト * @returns 変換に必要な主要なオブジェクトのセット * * 以下の処理を行います: * 1. バージョンに応じた設定の解釈 * 2. 各種パラメータの復元 * 3. TINネットワークの再構築 * 4. インデックスの作成 */ setCompiled(t) { if (t.version || !t.tins && t.points && t.tins_points) { this.points = t.points, this.pointsWeightBuffer = !t.version || t.version < 2.00703 ? ["forw", "bakw"].reduce((s, i) => { const n = t.weight_buffer[i]; return n && (s[i] = Object.keys(n).reduce((r, a) => { const f = We(a); return r[f] = n[a], r; }, {})), s; }, {}) : t.weight_buffer, t.strict_status ? this.strict_status = t.strict_status : t.kinks_points ? this.strict_status = xt.STATUS_ERROR : t.tins_points.length == 2 ? this.strict_status = xt.STATUS_LOOSE : this.strict_status = xt.STATUS_STRICT, this.vertices_params = { forw: [t.vertices_params[0]], bakw: [t.vertices_params[1]] }, this.vertices_params.forw[1] = [0, 1, 2, 3].map((s) => { const i = (s + 1) % 4, n = Gt( ["c", `b${s}`, `b${i}`], t.points, t.edgeNodes || [], t.centroid_point, t.vertices_points, !1, we ); return Lt([n]); }), this.vertices_params.bakw[1] = [0, 1, 2, 3].map((s) => { const i = (s + 1) % 4, n = Gt( ["c", `b${s}`, `b${i}`], t.points, t.edgeNodes || [], t.centroid_point, t.vertices_points, !0, we ); return Lt([n]); }), this.centroid = { forw: Yt(t.centroid_point[0], { target: { geom: t.centroid_point[1], index: "c" } }), bakw: Yt(t.centroid_point[1], { target: { geom: t.centroid_point[0], index: "c" } }) }, this.edges = ze(t.edges || []), this.edgeNodes = t.edgeNodes || []; const e = t.tins_points.length == 1 ? 0 : 1; this.tins = { forw: Lt( t.tins_points[0].map( (s) => Gt( s, t.points, t.edgeNodes || [], t.centroid_point, t.vertices_points, !1, t.version ) ) ), bakw: Lt( t.tins_points[e].map( (s) => Gt( s, t.points, t.edgeNodes || [], t.centroid_point, t.vertices_points, !0, t.version ) ) ) }, this.addIndexedTin(), t.kinks_points && (this.kinks = { bakw: Lt( t.kinks_points.map((s) => Yt(s)) ) }), t.yaxisMode ? this.yaxisMode = t.yaxisMode : this.yaxisMode = xt.YAXIS_INVERT, t.vertexMode && (this.vertexMode = t.vertexMode), t.strictMode && (this.strictMode = t.strictMode), t.bounds ? (this.bounds = t.bounds, this.boundsPolygon = t.boundsPolygon, this.xy = t.xy, this.wh = t.wh) : (this.xy = [0, 0], t.wh && (this.wh = t.wh), this.bounds = void 0, this.boundsPolygon = void 0); } else { t = JSON.parse( JSON.stringify(t).replace('"cent"', '"c"').replace(/"bbox(\d+)"/g, '"b$1"') ), 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; const e = []; for (let s = 0; s < this.tins.forw.features.length; s++) { const i = this.tins.forw.features[s]; ["a", "b", "c"].map((n, r) => { const a = i.geometry.coordinates[0][r], f = i.properties[n].geom, c = i.properties[n].index; typeof c == "number" && (e[c] = [a, f]); }); } this.points = e; } } /** * TINネットワークのインデックスを作成します * * インデックスは変換処理を高速化するために使用されます。 * グリッド形式のインデックスを作成し、各グリッドに * 含まれる三角形を記録します。 */ addIndexedTin() { const t = this.tins, e = t.forw, s = t.bakw, i = Math.ceil(Math.sqrt(e.features.length)); if (i < 3) { this.indexedTins = void 0; return; } let n = [], r = []; const a = e.features.map((g) => { let b = []; return Ee(g)[0].map((w) => { n.length === 0 ? n = [Array.from(w), Array.from(w)] : (w[0] < n[0][0] && (n[0][0] = w[0]), w[0] > n[1][0] && (n[1][0] = w[0]), w[1] < n[0][1] && (n[0][1] = w[1]), w[1] > n[1][1] && (n[1][1] = w[1])), b.length === 0 ? b = [Array.from(w), Array.from(w)] : (w[0] < b[0][0] && (b[0][0] = w[0]), w[0] > b[1][0] && (b[1][0] = w[0]), w[1] < b[0][1] && (b[0][1] = w[1]), w[1] > b[1][1] && (b[1][1] = w[1])); }), b; }), f = (n[1][0] - n[0][0]) / i, c = (n[1][1] - n[0][1]) / i, u = a.reduce( (g, b, w) => { const S = At( b[0][0], n[0][0], f, i ), _ = At( b[1][0], n[0][0], f, i ), v = At( b[0][1], n[0][1], c, i ), T = At( b[1][1], n[0][1], c, i ); for (let I = S; I <= _; I++) { g[I] || (g[I] = []); for (let N = v; N <= T; N++) g[I][N] || (g[I][N] = []), g[I][N].push(w); } return g; }, [] ), h = s.features.map((g) => { let b = []; return Ee(g)[0].map((w) => { r.length === 0 ? r = [Array.from(w), Array.from(w)] : (w[0] < r[0][0] && (r[0][0] = w[0]), w[0] > r[1][0] && (r[1][0] = w[0]), w[1] < r[0][1] && (r[0][1] = w[1]), w[1] > r[1][1] && (r[1][1] = w[1])), b.length === 0 ? b = [Array.from(w), Array.from(w)] : (w[0] < b[0][0] && (b[0][0] = w[0]), w[0] > b[1][0] && (b[1][0] = w[0]), w[1] < b[0][1] && (b[0][1] = w[1]), w[1] > b[1][1] && (b[1][1] = w[1])); }), b; }), l = (r[1][0] - r[0][0]) / i, p = (r[1][1] - r[0][1]) / i, y = h.reduce( (g, b, w) => { const S = At( b[0][0], r[0][0], l, i ), _ = At( b[1][0], r[0][0], l, i ), v = At( b[0][1], r[0][1], p, i ), T = At( b[1][1], r[0][1], p, i ); for (let I = S; I <= _; I++) { g[I] || (g[I] = []); for (let N = v; N <= T; N++) g[I][N] || (g[I][N] = []), g[I][N].push(w); } return g; }, [] ); this.indexedTins = { forw: { gridNum: i, xOrigin: n[0][0], yOrigin: n[0][1], xUnit: f, yUnit: c, gridCache: u }, bakw: { gridNum: i, xOrigin: r[0][0], yOrigin: r[0][1], xUnit: l, yUnit: p, gridCache: y } }; } /** * 座標変換を実行します * * @param apoint - 変換する座標 * @param backward - 逆方向の変換かどうか * @param ignoreBounds - 境界チェックを無視するかどうか * @returns 変換後の座標、または境界外の場合はfalse * * @throws {Error} 逆方向変換が許可されていない状態での逆変換時 */ transform(t, e, s) { if (e && this.strict_status == xt.STATUS_ERROR) throw 'Backward transform is not allowed if strict_status == "strict_error"'; this.yaxisMode == xt.YAXIS_FOLLOW && e && (t = [t[0], -1 * t[1]]); const i = Yt(t); if (this.bounds && !e && !s && !pe(i, this.boundsPolygon)) return !1; const n = e ? this.tins.bakw : this.tins.forw, r = e ? this.indexedTins.bakw : this.indexedTins.forw, a = e ? this.vertices_params.bakw : this.vertices_params.forw, f = e ? this.centroid.bakw : this.centroid.forw, c = e ? this.pointsWeightBuffer.bakw : this.pointsWeightBuffer.forw; let u, h; this.stateFull && (this.stateBackward == e ? u = this.stateTriangle : (this.stateBackward = e, this.stateTriangle = void 0), h = (p) => { this.stateTriangle = p; }); let l = re( i, n, r, a, f, c, u, h ); if (this.bounds && e && !s) { const p = Yt(l); if (!pe(p, this.boundsPolygon)) return !1; } else this.yaxisMode == xt.YAXIS_FOLLOW && !e && (l = [l[0], -1 * l[1]]); return l; } }; nt(kt, "VERTEX_PLAIN", "plain"), nt(kt, "VERTEX_BIRDEYE", "birdeye"), nt(kt, "MODE_STRICT", "strict"), nt(kt, "MODE_AUTO", "auto"), nt(kt, "MODE_LOOSE", "loose"), nt(kt, "STATUS_STRICT", "strict"), nt(kt, "STATUS_ERROR", "strict_error"), nt(kt, "STATUS_LOOSE", "loose"), nt(kt, "YAXIS_FOLLOW", "follow"), nt(kt, "YAXIS_INVERT", "invert"); let _s = kt; const dt = 11102230246251565e-32, $ = 134217729, Ye = (3 + 8 * dt) * dt; function ct(o, t, e, s, i) { let n, r, a, f, c = t[0], u = s[0], h = 0, l = 0; u > c == u > -c ? (n = c, c = t[++h]) : (n = u, u = s[++l]); let p = 0; if (h < o && l < e) for (u > c == u > -c ? (r = c + n, a = n - (r - c), c = t[++h]) : (r = u + n, a = n - (r - u), u = s[++l]), n = r, a !== 0 && (i[p++] = a); h < o && l < e; ) u > c == u > -c ? (r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h]) : (r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l]), n = r, a !== 0 && (i[p++] = a); for (; h < o; ) r = n + c, f = r - n, a = n - (r - f) + (c - f), c = t[++h], n = r, a !== 0 && (i[p++] = a); for (; l < e; ) r = n + u, f = r - n, a = n - (r - f) + (u - f), u = s[++l], n = r, a !== 0 && (i[p++] = a); return (n !== 0 || p === 0) && (i[p++] = n), p; } function yt(o, t, e, s, i, n, r, a) { return ct(ct(o, t, e, s, r), r, i, n, a); } function M(o, t, e, s) { let i, n, r, a, f, c, u, h, l, p, y; u = $ * e, p = u - (u - e), y = e - p; let g = t[0]; i = g * e, u = $ * g, h = u - (u - g), l = g - h, r = l * y - (i - h * p - l * p - h * y); let b = 0; r !== 0 && (s[b++] = r); for (let w = 1; w < o; w++) g = t[w], a = g * e, u = $ * g, h = u - (u - g), l = g - h, f = l * y - (a - h * p - l * p - h * y), n = i + f, c = n - i, r = i - (n - c) + (f - c), r !== 0 && (s[b++] = r), i = a + n, r = n - (i - a), r !== 0 && (s[b++] = r); return (i !== 0 || b === 0) && (s[b++] = i), b; } function Ce(o, t) { let e = t[0]; for (let s = 1; s < o; s++) e += t[s]; return e; } function H(o) { return new Float64Array(o); } const Ms = (3 + 16 * dt) * dt, Ss = (2 + 12 * dt) * dt, As = (9 + 64 * dt) * dt * dt, Wt = H(4), Ie = H(8), Pe = H(12), $e = H(16), pt = H(4); function Es(o, t, e, s, i, n, r) { let a, f, c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V; const z = o - i, G = e - i, tt = t - n, X = s - n; v = z * X, l = $ * z, p = l - (l - z), y = z - p, l = $ * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = tt * G, l = $ * tt, p = l - (l - tt), y = tt - p, l = $ * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, Wt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, Wt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, Wt[2] = S - (V - h) + (w - h), Wt[3] = V; let it = Ce(4, Wt), d = Ss * r; if (it >= d || -it >= d || (h = o - z, a = o - (z + h) + (h - i), h = e - G, c = e - (G + h) + (h - i), h = t - tt, f = t - (tt + h) + (h - n), h = s - X, u = s - (X + h) + (h - n), a === 0 && f === 0 && c === 0 && u === 0) || (d = As * r + Ye * Math.abs(it), it += z * u + X * a - (tt * c + G * f), it >= d || -it >= d)) return it; v = a * X, l = $ * a, p = l - (l - a), y = a - p, l = $ * X, g = l - (l - X), b = X - g, T = y * b - (v - p * g - y * g - p * b), I = f * G, l = $ * f, p = l - (l - f), y = f - p, l = $ * G, g = l - (l - G), b = G - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V; const m = ct(4, Wt, 4, pt, Ie); v = z * u, l = $ * z, p = l - (l - z), y = z - p, l = $ * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = tt * c, l = $ * tt, p = l - (l - tt), y = tt - p, l = $ * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V; const x = ct(m, Ie, 4, pt, Pe); v = a * u, l = $ * a, p = l - (l - a), y = a - p, l = $ * u, g = l - (l - u), b = u - g, T = y * b - (v - p * g - y * g - p * b), I = f * c, l = $ * f, p = l - (l - f), y = f - p, l = $ * c, g = l - (l - c), b = c - g, N = y * b - (I - p * g - y * g - p * b), w = T - N, h = T - w, pt[0] = T - (w + h) + (h - N), S = v + w, h = S - v, _ = v - (S - h) + (w - h), w = _ - I, h = _ - w, pt[1] = _ - (w + h) + (h - I), V = S + w, h = V - S, pt[2] = S - (V - h) + (w - h), pt[3] = V; const A = ct(x, Pe, 4, pt, $e); return $e[A - 1]; } function Ct(o, t, e, s, i, n) { const r = (t - n) * (e - i), a = (o - i) * (s - n), f = r - a, c = Math.abs(r + a); return Math.abs(f) >= Ms * c ? f : -Es(o, t, e, s, i, n, c); } const vs = (10 + 96 * dt) * dt, Os = (4 + 48 * dt) * dt, Ts = (44 + 576 * dt) * dt * dt, It = H(4), Pt = H(4), $t = H(4), _t = H(4), Mt = H(4), St = H(4), wt = H(4), mt = H(4), he = H(8), ce = H(8), fe = H(8), ue = H(8), le = H(8), de = H(8), Kt = H(8), Qt = H(8), Zt = H(8), Bt = H(4), Dt = H(4), Ft = H(4), U = H(8), L = H(16), et = H(16), st = H(16), Z = H(32), Rt = H(32), ot = H(48), bt = H(64); let zt = H(1152), ge = H(1152); function at(o, t, e) { o = ct(o, zt, t, e, ge); const s = zt; return zt = ge, ge = s, o; } function Is(o, t, e, s, i, n, r, a, f) { let c, u, h, l, p, y, g, b, w, S, _, v, T, I, N, V, z, G, tt, X, it, d, m, x, A, E, R, k, O, B, P, D, F, W, j; const Y = o - r, C = e - r, q = i - r, K = t - a, J = s - a, Q = n - a; P = C * Q, m = $ * C, x = m - (m - C), A = C - x, m = $ * Q, E = m - (m - Q), R = Q - E, D = A * R - (P - x * E - A * E - x * R), F = q * J, m = $ * q, x = m - (m - q), A = q - x, m = $ * J, E = m - (m - J), R = J - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, It[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, It[1] = B - (k + d) + (d - F), j = O + k, d = j - O, It[2] = O - (j - d) + (k - d), It[3] = j, P = q * K, m = $ * q, x = m - (m - q), A = q - x, m = $ * K, E = m - (m - K), R = K - E, D = A * R - (P - x * E - A * E - x * R), F = Y * Q, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * Q, E = m - (m - Q), R = Q - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Pt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Pt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Pt[2] = O - (j - d) + (k - d), Pt[3] = j, P = Y * J, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * J, E = m - (m - J), R = J - E, D = A * R - (P - x * E - A * E - x * R), F = C * K, m = $ * C, x = m - (m - C), A = C - x, m = $ * K, E = m - (m - K), R = K - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, $t[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, $t[1] = B - (k + d) + (d - F), j = O + k, d = j - O, $t[2] = O - (j - d) + (k - d), $t[3] = j, c = ct( ct( ct( M(M(4, It, Y, U), U, Y, L), L, M(M(4, It, K, U), U, K, et), et, Z ), Z, ct( M(M(4, Pt, C, U), U, C, L), L, M(M(4, Pt, J, U), U, J, et), et, Rt ), Rt, bt ), bt, ct( M(M(4, $t, q, U), U, q, L), L, M(M(4, $t, Q, U), U, Q, et), et, Z ), Z, zt ); let Ut = Ce(c, zt), Xt = Os * f; if (Ut >= Xt || -Ut >= Xt || (d = o - Y, u = o - (Y + d) + (d - r), d = t - K, p = t - (K + d) + (d - a), d = e - C, h = e - (C + d) + (d - r), d = s - J, y = s - (J + d) + (d - a), d = i - q, l = i - (q + d) + (d - r), d = n - Q, g = n - (Q + d) + (d - a), u === 0 && h === 0 && l === 0 && p === 0 && y === 0 && g === 0) || (Xt = Ts * f + Ye * Math.abs(Ut), Ut += (Y * Y + K * K) * (C * g + Q * h - (J * l + q * y)) + 2 * (Y * u + K * p) * (C * Q - J * q) + ((C * C + J * J) * (q * p + K * l - (Q * u + Y * g)) + 2 * (C * h + J * y) * (q * K - Q * Y)) + ((q * q + Q * Q) * (Y * y + J * u - (K * h + C * p)) + 2 * (q * l + Q * g) * (Y * J - K * C)), Ut >= Xt || -Ut >= Xt)) return Ut; if ((h !== 0 || y !== 0 || l !== 0 || g !== 0) && (P = Y * Y, m = $ * Y, x = m - (m - Y), A = Y - x, D = A * A - (P - x * x - (x + x) * A), F = K * K, m = $ * K, x = m - (m - K), A = K - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, _t[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, _t[1] = B - (k - d) + (F - d), j = O + k, d = j - O, _t[2] = O - (j - d) + (k - d), _t[3] = j), (l !== 0 || g !== 0 || u !== 0 || p !== 0) && (P = C * C, m = $ * C, x = m - (m - C), A = C - x, D = A * A - (P - x * x - (x + x) * A), F = J * J, m = $ * J, x = m - (m - J), A = J - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, Mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, Mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, Mt[2] = O - (j - d) + (k - d), Mt[3] = j), (u !== 0 || p !== 0 || h !== 0 || y !== 0) && (P = q * q, m = $ * q, x = m - (m - q), A = q - x, D = A * A - (P - x * x - (x + x) * A), F = Q * Q, m = $ * Q, x = m - (m - Q), A = Q - x, W = A * A - (F - x * x - (x + x) * A), k = D + W, d = k - D, St[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, St[1] = B - (k - d) + (F - d), j = O + k, d = j - O, St[2] = O - (j - d) + (k - d), St[3] = j), u !== 0 && (b = M(4, It, u, he), c = at(c, yt( M(b, he, 2 * Y, L), L, M(M(4, St, u, U), U, J, et), et, M(M(4, Mt, u, U), U, -Q, st), st, Z, ot ), ot)), p !== 0 && (w = M(4, It, p, ce), c = at(c, yt( M(w, ce, 2 * K, L), L, M(M(4, Mt, p, U), U, q, et), et, M(M(4, St, p, U), U, -C, st), st, Z, ot ), ot)), h !== 0 && (S = M(4, Pt, h, fe), c = at(c, yt( M(S, fe, 2 * C, L), L, M(M(4, _t, h, U), U, Q, et), et, M(M(4, St, h, U), U, -K, st), st, Z, ot ), ot)), y !== 0 && (_ = M(4, Pt, y, ue), c = at(c, yt( M(_, ue, 2 * J, L), L, M(M(4, St, y, U), U, Y, et), et, M(M(4, _t, y, U), U, -q, st), st, Z, ot ), ot)), l !== 0 && (v = M(4, $t, l, le), c = at(c, yt( M(v, le, 2 * q, L), L, M(M(4, Mt, l, U), U, K, et), et, M(M(4, _t, l, U), U, -J, st), st, Z, ot ), ot)), g !== 0 && (T = M(4, $t, g, de), c = at(c, yt( M(T, de, 2 * Q, L), L, M(M(4, _t, g, U), U, C, et), et, M(M(4, Mt, g, U), U, -Y, st), st, Z, ot ), ot)), u !== 0 || p !== 0) { if (h !== 0 || y !== 0 || l !== 0 || g !== 0 ? (P = h * Q, m = $ * h, x = m - (m - h), A = h - x, m = $ * Q, E = m - (m - Q), R = Q - E, D = A * R - (P - x * E - A * E - x * R), F = C * g, m = $ * C, x = m - (m - C), A = C - x, m = $ * g, E = m - (m - g), R = g - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, P = l * -J, m = $ * l, x = m - (m - l), A = l - x, m = $ * -J, E = m - (m - -J), R = -J - E, D = A * R - (P - x * E - A * E - x * R), F = q * -y, m = $ * q, x = m - (m - q), A = q - x, m = $ * -y, E = m - (m - -y), R = -y - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, N = ct(4, wt, 4, mt, Qt), P = h * g, m = $ * h, x = m - (m - h), A = h - x, m = $ * g, E = m - (m - g), R = g - E, D = A * R - (P - x * E - A * E - x * R), F = l * y, m = $ * l, x = m - (m - l), A = l - x, m = $ * y, E = m - (m - y), R = y - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Dt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Dt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Dt[2] = O - (j - d) + (k - d), Dt[3] = j, G = 4) : (Qt[0] = 0, N = 1, Dt[0] = 0, G = 1), u !== 0) { const ft = M(N, Qt, u, st); c = at(c, ct( M(b, he, u, L), L, M(ft, st, 2 * Y, Z), Z, ot ), ot); const ut = M(G, Dt, u, U); c = at(c, yt( M(ut, U, 2 * Y, L), L, M(ut, U, u, et), et, M(ft, st, u, Z), Z, Rt, bt ), bt), y !== 0 && (c = at(c, M(M(4, St, u, U), U, y, L), L)), g !== 0 && (c = at(c, M(M(4, Mt, -u, U), U, g, L), L)); } if (p !== 0) { const ft = M(N, Qt, p, st); c = at(c, ct( M(w, ce, p, L), L, M(ft, st, 2 * K, Z), Z, ot ), ot); const ut = M(G, Dt, p, U); c = at(c, yt( M(ut, U, 2 * K, L), L, M(ut, U, p, et), et, M(ft, st, p, Z), Z, Rt, bt ), bt); } } if (h !== 0 || y !== 0) { if (l !== 0 || g !== 0 || u !== 0 || p !== 0 ? (P = l * K, m = $ * l, x = m - (m - l), A = l - x, m = $ * K, E = m - (m - K), R = K - E, D = A * R - (P - x * E - A * E - x * R), F = q * p, m = $ * q, x = m - (m - q), A = q - x, m = $ * p, E = m - (m - p), R = p - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, X = -Q, it = -g, P = u * X, m = $ * u, x = m - (m - u), A = u - x, m = $ * X, E = m - (m - X), R = X - E, D = A * R - (P - x * E - A * E - x * R), F = Y * it, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * it, E = m - (m - it), R = it - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, V = ct(4, wt, 4, mt, Zt), P = l * p, m = $ * l, x = m - (m - l), A = l - x, m = $ * p, E = m - (m - p), R = p - E, D = A * R - (P - x * E - A * E - x * R), F = u * g, m = $ * u, x = m - (m - u), A = u - x, m = $ * g, E = m - (m - g), R = g - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Ft[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Ft[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Ft[2] = O - (j - d) + (k - d), Ft[3] = j, tt = 4) : (Zt[0] = 0, V = 1, Ft[0] = 0, tt = 1), h !== 0) { const ft = M(V, Zt, h, st); c = at(c, ct( M(S, fe, h, L), L, M(ft, st, 2 * C, Z), Z, ot ), ot); const ut = M(tt, Ft, h, U); c = at(c, yt( M(ut, U, 2 * C, L), L, M(ut, U, h, et), et, M(ft, st, h, Z), Z, Rt, bt ), bt), g !== 0 && (c = at(c, M(M(4, _t, h, U), U, g, L), L)), p !== 0 && (c = at(c, M(M(4, St, -h, U), U, p, L), L)); } if (y !== 0) { const ft = M(V, Zt, y, st); c = at(c, ct( M(_, ue, y, L), L, M(ft, st, 2 * J, Z), Z, ot ), ot); const ut = M(tt, Ft, y, U); c = at(c, yt( M(ut, U, 2 * J, L), L, M(ut, U, y, et), et, M(ft, st, y, Z), Z, Rt, bt ), bt); } } if (l !== 0 || g !== 0) { if (u !== 0 || p !== 0 || h !== 0 || y !== 0 ? (P = u * J, m = $ * u, x = m - (m - u), A = u - x, m = $ * J, E = m - (m - J), R = J - E, D = A * R - (P - x * E - A * E - x * R), F = Y * y, m = $ * Y, x = m - (m - Y), A = Y - x, m = $ * y, E = m - (m - y), R = y - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, wt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, wt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, wt[2] = O - (j - d) + (k - d), wt[3] = j, X = -K, it = -p, P = h * X, m = $ * h, x = m - (m - h), A = h - x, m = $ * X, E = m - (m - X), R = X - E, D = A * R - (P - x * E - A * E - x * R), F = C * it, m = $ * C, x = m - (m - C), A = C - x, m = $ * it, E = m - (m - it), R = it - E, W = A * R - (F - x * E - A * E - x * R), k = D + W, d = k - D, mt[0] = D - (k - d) + (W - d), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B + F, d = k - B, mt[1] = B - (k - d) + (F - d), j = O + k, d = j - O, mt[2] = O - (j - d) + (k - d), mt[3] = j, I = ct(4, wt, 4, mt, Kt), P = u * y, m = $ * u, x = m - (m - u), A = u - x, m = $ * y, E = m - (m - y), R = y - E, D = A * R - (P - x * E - A * E - x * R), F = h * p, m = $ * h, x = m - (m - h), A = h - x, m = $ * p, E = m - (m - p), R = p - E, W = A * R - (F - x * E - A * E - x * R), k = D - W, d = D - k, Bt[0] = D - (k + d) + (d - W), O = P + k, d = O - P, B = P - (O - d) + (k - d), k = B - F, d = B - k, Bt[1] = B - (k + d) + (d - F), j = O + k, d = j - O, Bt[2] = O - (j - d) + (k - d), Bt[3] = j, z = 4) : (Kt[0] = 0, I = 1, Bt[0] = 0, z = 1), l !== 0) { const ft = M(I, Kt, l, st); c = at(c, ct( M(v, le, l, L), L, M(ft, st, 2 * q, Z), Z, ot ), ot); const ut = M(z, Bt, l, U); c = at(c, yt( M(ut, U, 2 * q, L), L, M(ut, U, l, et), et, M(ft, st, l, Z), Z, Rt, bt ), bt), p !== 0 && (c = at(c, M(M(4, Mt, l, U), U, p, L), L)), y !== 0 && (c = at(c, M(M(4, _t, -l, U), U, y, L), L)); } if (g !== 0) { const ft = M(I, Kt, g, st); c = at(c, ct( M(T, de, g, L), L, M(ft, st, 2 * Q, Z), Z, ot ), ot); const ut = M(z, Bt, g, U); c = at(c, yt( M(ut, U, 2 * Q, L), L, M(ut, U, g, et), et, M(ft, st, g, Z), Z, Rt, bt ), bt); } } return zt[c - 1]; } function Ps(o, t, e, s, i, n, r, a) { const f = o - r, c = e - r, u = i - r, h = t - a, l = s - a, p = n - a, y = c * p, g = u * l, b = f * f + h * h, w = u * h, S = f * p, _ = c * c + l * l, v = f * l, T = c * h, I = u * u + p * p, N = b * (y - g) + _ * (w - S) + I * (v - T), V = (Math.abs(y) + Math.abs(g)) * b + (Math.abs(w) + Math.abs(S)) * _ + (Math.abs(v) + Math.abs(T)) * I, z = vs * V; return N > z || -N > z ? N : Is(o, t, e, s, i, n, r, a, V); } class $s { constructor(t, e) { this.W = t, this.bs = e; } /** * Add a number to the set. * * @param idx The number to add. Must be 0 <= idx < len. * @return this. */ add(t) { const e = this.W, s = t / e | 0, i = t % e; return this.bs[s] |= 1 << i, this; } /** * Delete a number from the set. * * @param idx The number to delete. Must be 0 <= idx < len. * @return this. */ delete(t) { const e = this.W, s = t / e | 0, i = t % e; return this.bs[s] &= ~(1 << i), this; } /** * Add or delete a number in the set, depending on the second argument. * * @param idx The number to add or delete. Must be 0 <= idx < len. * @param val If true, add the number, otherwise delete. * @return val. */ set(t, e) { const s = this.W, i = t / s | 0, n = t % s, r = 1 << n; return this.bs[i] ^= (-e ^ this.bs[i]) & r, e; } /** * Whether the number is in the set. * * @param idx The number to test. Must be 0 <= idx < len. * @return True if the number is in the set. */ has(t) { const e = this.W, s = t / e | 0, i = t % e; return !!(this.bs[s] & 1 << i); } /** * Iterate over the numbers that are in the set. The callback is invoked * with each number that is set. It is allowed to change the BitSet during * iteration. If it deletes a number that has not been iterated over, that * number will not show up in a later call. If it adds a number during * iteration, that number may or may not show up in a later call. * * @param fn The function to call for each number. * @return this. */ forEach(t) { const e = this.W, s = this.bs, i = s.length; for (let n = 0; n < i; n++) { let r = 0; for (; s[n] && r < e; ) s[n] & 1 << r && t(n * e + r), r++; } return this; } } class Re extends $s { /** * Create a bit set. * * @param len The length of the bit set, limiting the maximum value that * can be stored in it to len - 1. */ constructor(t) { const e = new Uint8Array(Math.ceil(t / 8)).fill(0); super(8, e); } } function jt(o) { return o % 3 === 2 ? o - 2 : o + 1; } function Et(o) { return o % 3 === 0 ? o + 2 : o - 1; } function qe(o, t, e, s, i, n, r, a) { const f = Ct(o, t, i, n, r, a), c = Ct(e, s, i, n, r, a); if (f > 0 && c > 0 || f < 0 && c < 0) return !1; const u = Ct(i, n, o, t, e, s), h = Ct(r, a, o, t, e, s); return u > 0 && h > 0 || u < 0 && h < 0 ? !1 : f === 0 && c === 0 && u === 0 && h === 0 ? !(Math.max(i, r) < Math.min(o, e) || Math.max(o, e) < Math.min(i, r) || Math.max(n, a) < Math.min(t, s) || Math.max(t, s) < Math.min(n, a)) : !0; } class Rs { constructor(t) { this.del = t; } } const Je = class extends Rs { /** * Make a Constrain. * * @param del The triangulation output from Delaunator. * @param edges If provided, constrain these edges as by constrainAll. */ constructor(t, e) { if (!t || typeof t != "object" || !t.triangles || !t.halfedges || !t.coords) throw new Error("Expected an object with Delaunator output"); if (t.triangles.length % 3 || t.halfedges.length !== t.triangles.length || t.coords.length % 2) throw new Error("Delaunator output appears inconsistent"); if (t.triangles.length < 3) throw new Error("No edges in triangulation"); super(t); const s = 2 ** 32 - 1, i = t.coords.length >> 1, n = t.triangles.length; this.vertMap = new Uint32Array(i).fill(s), this.flips = new Re(n), this.consd = new Re(n); for (let r = 0; r < n; r++) { const a = t.triangles[r]; this.vertMap[a] === s && this.updateVert(r); } e && this.constrainAll(e); } /** * Constrain the triangulation such that there is an edge between p1 and p2. */ constrainOne(t, e) { const { triangles: s, halfedges: i } = this.del, n = this.vertMap[t]; let r = n; do { const c = s[r], u = jt(r); if (c === e) return this.protect(r); const h = Et(r), l = s[h]; if (l === e) return this.protect(u), u; if (this.intersectSegments(t, e, l, c)) { r = h; break; } r = i[u]; } while (r !== -1 && r !== n); let a = r, f = -1; for (; r !== -1; ) { const c = i[r], u = Et(r), h = Et(c), l = jt(c); if (c === -1) throw new Error("Constraining edge exited the hull"); if (this.consd.has(r)) throw new Error("Edge intersects already constrained edge"); if (this.isCollinear(t, e, s[r]) || this.isCollinear(t, e, s[c])) throw new Error("Constraining edge intersects point"); if (!this.intersectSegments( s[r], s[c], s[u], s[h] )) { if (f === -1 && (f = r), s[h] === e) { if (r === f) throw new Error("Infinite loop: non-convex quadrilateral"); r = f, f = -1; continue; } if (this.intersectSegments(t, e, s[h], s[c])) r = h; else if (this.intersectSegments(t, e, s[l], s[h])) r = l; else if (f === r) throw new Error("Infinite loop: no further intersect after non-convex"); continue; } if (this.flipDiagonal(r), this.intersectSegments(t, e, s[u], s[h]) && (f === -1 && (f = u), f === u)) throw new Error("Infinite loop: flipped diagonal still intersects"); s[h] === e ? (a = h, r = f, f = -1) : this.intersectSegments(t, e, s[l], s[h]) && (r = l); } return this.protect(a), this.delaunify(!0), this.findEdge(t, e); } /** * Fix the Delaunay condition. */ delaunify(t = !1) { const { halfedges: e } = this.del, s = this.flips, i = this.consd, n = e.length; do { var r = 0; for (let a = 0; a < n; a++) { if (i.has(a)) continue; s.delete(a); const f = e[a]; f !== -1 && (s.delete(f), this.isDelaunay(a) || (this.flipDiagonal(a), r++)); } } while (t && r > 0); return this; } /** * Call constrainOne on each edge */ constrainAll(t) { const e = t.length; for (let s = 0; s < e; s++) { const i = t[s]; this.constrainOne(i[0], i[1]); } return this; } /** * Whether an edge is constrained */ isConstrained(t) { return this.consd.has(t); } /** * Find the edge that points from p1 -> p2. If there is only an edge from * p2 -> p1 (i.e. it is on the hull), returns the negative id of it. */ findEdge(t, e) { const s = this.vertMap[e], { triangles: i, halfedges: n } = this.del; let r = s, a = -1; do { if (i[r] === t) return r; a = jt(r), r = n[a]; } while (r !== -1 && r !== s); return i[jt(a)] === t ? -a : 1 / 0; } /** * Mark an edge as constrained, i.e. should not be touched by `delaunify`. */ protect(t) { const e = this.del.halfedges[t], s = this.flips, i = this.consd; return s.delete(t), i.add(t), e !== -1 ? (s.delete(e), i.add(e), e) : -t; } /** * Mark an edge as flipped unless constrained. */ markFlip(t) { const e = this.del.halfedges, s = this.flips; if (this.consd.has(t)) return !1; const i = e[t]; return i !== -1 && (s.add(t), s.add(i)), !0; } /** * Flip the edge shared by two triangles. */ flipDiagonal(t) { const { triangles: e, halfedges: s } = this.del, i = this.flips, n = this.consd, r = s[t], a = Et(t), f = jt(t), c = Et(r), u = jt(r), h = s[a], l = s[c]; if (n.has(t)) throw new Error("Trying to flip a constrained edge"); return e[t] = e[c], s[t] = l, i.set(t, i.has(c)) || n.set(t, n.has(c)), l !== -1 && (s[l] = t), s[a] = c, e[r] = e[a], s[r] = h, i.set(r, i.has(a)) || n.set(r, n.has(a)), h !== -1 && (s[h] = r), s[c] = a, this.markFlip(t), this.markFlip(f), this.markFlip(r), this.markFlip(u), i.add(a), n.delete(a), i.add(c), n.delete(c), this.updateVert(t), this.updateVert(f), this.updateVert(r), this.updateVert(u), a; } /** * Whether point p1, p2, and p are collinear */ isCollinear(t, e, s) { const i = this.del.coords; return Ct( i[t * 2], i[t * 2 + 1], i[e * 2], i[e * 2 + 1], i[s * 2], i[s * 2 + 1] ) === 0; } /** * Whether px is in the circumcircle of the triangle formed by p1, p2, p3 */ inCircle(t, e, s, i) { const n = this.del.coords; return Ps( n[t * 2], n[t * 2 + 1], n[e * 2], n[e * 2 + 1], n[s * 2], n[s * 2 + 1], n[i * 2], n[i * 2 + 1] ) < 0; } /** * Whether the triangles sharing edg conform to the Delaunay condition */ isDelaunay(t) { const { triangles: e, halfedges: s } = this.del, i = s[t]; if (i === -1) return !0; const n = e[Et(t)], r = e[t], a = e[jt(t)], f = e[Et(i)]; return !this.inCircle(n, r, a, f); } /** * Update the vertex -> incoming edge map */ updateVert(t) { const { triangles: e, halfedges: s } = this.del, i