pantograph2d 0.9.1 → 0.10.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.
@@ -1,31 +1,31 @@
1
- var tn = Object.defineProperty;
2
- var nn = (t, n, e) => n in t ? tn(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
3
- var C = (t, n, e) => nn(t, typeof n != "symbol" ? n + "" : n, e);
4
- import { b as k, d as en, e as Ot, a as q, s as V, n as sn, p as Tt, r as U, A as S, g, u as Lt, E as M, T as on, v as rn, Q as A, w as $, C as I, c as ln, x as cn, L as y, y as zt, F as lt, z as N, G as un, l as an, o as fn, H as dt, B as hn } from "./QuadraticBezier-DxieHk9z.js";
5
- function pn(t, n) {
6
- const e = k(n, t.firstPoint), s = en(e, t.V) / t.squareLength;
1
+ var nn = Object.defineProperty;
2
+ var en = (t, n, e) => n in t ? nn(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
3
+ var C = (t, n, e) => en(t, typeof n != "symbol" ? n + "" : n, e);
4
+ import { b as k, d as sn, e as Tt, a as z, s as V, n as on, p as Lt, r as U, A as S, g as P, u as qt, E as M, T as rn, v as ln, Q as I, w as $, C as A, c as un, x as cn, L as b, y as zt, F as ut, z as N, G as an, l as fn, o as hn, H as mt, B as pn } from "./QuadraticBezier-DxieHk9z.js";
5
+ function dn(t, n) {
6
+ const e = k(n, t.firstPoint), s = sn(e, t.V) / t.squareLength;
7
7
  return t.paramPoint(s);
8
8
  }
9
- function J(t, n, e) {
10
- const s = e || t.precision, i = pn(t, n.center), o = Ot(i, n.center);
9
+ function K(t, n, e) {
10
+ const s = e || t.precision, i = dn(t, n.center), o = Tt(i, n.center);
11
11
  if (o > n.radius + s) return [];
12
12
  if (Math.abs(o - n.radius) < s) {
13
- const u = i;
14
- return t.isOnSegment(u) && n.isOnSegment(u) ? [u] : [];
13
+ const c = i;
14
+ return t.isOnSegment(c) && n.isOnSegment(c) ? [c] : [];
15
15
  }
16
- const r = [], l = Math.sqrt(
16
+ const l = [], r = Math.sqrt(
17
17
  n.radius * n.radius - o * o
18
- ), c = t.tangentAtFirstPoint, a = q(i, V(c, l));
19
- t.isOnSegment(a) && n.isOnSegment(a) && r.push(a);
20
- const f = q(i, V(c, -l));
21
- return t.isOnSegment(f) && n.isOnSegment(f) && r.push(f), r;
18
+ ), u = t.tangentAtFirstPoint, a = z(i, V(u, r));
19
+ t.isOnSegment(a) && n.isOnSegment(a) && l.push(a);
20
+ const f = z(i, V(u, -r));
21
+ return t.isOnSegment(f) && n.isOnSegment(f) && l.push(f), l;
22
22
  }
23
- const dn = (t) => {
23
+ const mn = (t) => {
24
24
  const { firstPoint: n, lastPoint: e, center: s, clockwise: i } = t;
25
25
  return new S(e, n, s, i, {
26
26
  ignoreChecks: !0
27
27
  });
28
- }, mn = (t, n) => {
28
+ }, gn = (t, n) => {
29
29
  if (t.isSame(n))
30
30
  return [t];
31
31
  const e = U(
@@ -41,9 +41,9 @@ const dn = (t) => {
41
41
  if (e.length === 0) return [];
42
42
  if (e.length === 1) return [];
43
43
  if (e.length === 2)
44
- return t.isSame(dn(n)) ? [] : [new S(e[0], e[1], t.center, t.clockwise)];
44
+ return t.isSame(mn(n)) ? [] : [new S(e[0], e[1], t.center, t.clockwise)];
45
45
  if (e.length === 3) {
46
- const s = g(e[0], n.lastPoint) || g(e[0], n.firstPoint) ? 1 : 0;
46
+ const s = P(e[0], n.lastPoint) || P(e[0], n.firstPoint) ? 1 : 0;
47
47
  return [
48
48
  new S(
49
49
  e[0 + s],
@@ -59,101 +59,101 @@ const dn = (t) => {
59
59
  ];
60
60
  throw new Error("Bug in the arc arc overlap algorithm");
61
61
  };
62
- function qt(t, n, e = !1, s) {
63
- const i = s || t.precision, o = Ot(t.center, n.center), r = t.radius + n.radius;
64
- if (o > r + i)
62
+ function Dt(t, n, e = !1, s) {
63
+ const i = s || t.precision, o = Tt(t.center, n.center), l = t.radius + n.radius;
64
+ if (o > l + i)
65
65
  return [];
66
- const l = Math.abs(t.radius - n.radius);
67
- if (o < l - i)
66
+ const r = Math.abs(t.radius - n.radius);
67
+ if (o < r - i)
68
68
  return [];
69
69
  if (o < i)
70
- return l > i ? [] : e ? mn(t, n) : [];
71
- const c = sn(k(n.center, t.center)), a = o > r - i;
70
+ return r > i ? [] : e ? gn(t, n) : [];
71
+ const u = on(k(n.center, t.center)), a = o > l - i;
72
72
  if (
73
73
  // circles are outside each other
74
74
  a || // circles are inside each other
75
- Math.abs(o - l) < i
75
+ Math.abs(o - r) < i
76
76
  ) {
77
- const w = a || t.radius > n.radius ? 1 : -1, x = q(
77
+ const g = a || t.radius > n.radius ? 1 : -1, w = z(
78
78
  t.center,
79
- V(c, w * t.radius)
79
+ V(u, g * t.radius)
80
80
  );
81
- return t.isOnSegment(x) && n.isOnSegment(x) ? [x] : [];
81
+ return t.isOnSegment(w) && n.isOnSegment(w) ? [w] : [];
82
82
  }
83
- const f = t.radius * t.radius / (2 * o) - n.radius * n.radius / (2 * o) + o / 2, u = q(
83
+ const f = t.radius * t.radius / (2 * o) - n.radius * n.radius / (2 * o) + o / 2, c = z(
84
84
  t.center,
85
- V(c, f)
85
+ V(u, f)
86
86
  ), h = Math.sqrt(
87
87
  t.radius * t.radius - f * f
88
- ), p = Tt(c), d = q(u, V(p, h)), m = q(u, V(p, -h)), P = [];
89
- return t.isOnSegment(d) && n.isOnSegment(d) && P.push(d), t.isOnSegment(m) && n.isOnSegment(m) && P.push(m), P;
88
+ ), p = Lt(u), d = z(c, V(p, h)), m = z(c, V(p, -h)), x = [];
89
+ return t.isOnSegment(d) && n.isOnSegment(d) && x.push(d), t.isOnSegment(m) && n.isOnSegment(m) && x.push(m), x;
90
90
  }
91
- function et(t, n, e = 1e-9) {
92
- const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope, o = s.yIntercept, r = n.majorRadius * n.majorRadius, l = n.minorRadius * n.minorRadius, c = n.majorRadius * n.minorRadius, a = s.slope * s.slope, f = s.yIntercept * s.yIntercept, u = (w) => w.map(
93
- (x) => n.reverseEllipseReferenceFrameTransform.transform(x)
94
- ).filter((x) => t.isOnSegment(x) && n.isOnSegment(x));
91
+ function st(t, n, e = 1e-9) {
92
+ const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope, o = s.yIntercept, l = n.majorRadius * n.majorRadius, r = n.minorRadius * n.minorRadius, u = n.majorRadius * n.minorRadius, a = s.slope * s.slope, f = s.yIntercept * s.yIntercept, c = (g) => g.map(
93
+ (w) => n.reverseEllipseReferenceFrameTransform.transform(w)
94
+ ).filter((w) => t.isOnSegment(w) && n.isOnSegment(w));
95
95
  if (!Number.isFinite(i)) {
96
- const w = s.firstPoint[0];
97
- if (Math.abs(w) - n.majorRadius > e) return [];
98
- if (Math.abs(Math.abs(w) - n.majorRadius) < e)
99
- return u([[w, 0]]);
100
- const x = n.minorRadius * Math.sqrt(1 - w * w / r), F = [w, x], b = [w, -x];
101
- return u([F, b]);
102
- }
103
- const h = r * a + l - f;
96
+ const g = s.firstPoint[0];
97
+ if (Math.abs(g) - n.majorRadius > e) return [];
98
+ if (Math.abs(Math.abs(g) - n.majorRadius) < e)
99
+ return c([[g, 0]]);
100
+ const w = n.minorRadius * Math.sqrt(1 - g * g / l), F = [g, w], y = [g, -w];
101
+ return c([F, y]);
102
+ }
103
+ const h = l * a + r - f;
104
104
  if (h < -e)
105
105
  return [];
106
- const p = r * a + l;
106
+ const p = l * a + r;
107
107
  if (Math.abs(h) < e) {
108
- const w = -(r * i * o) / p, x = l * o / p;
109
- return u([[w, x]]);
108
+ const g = -(l * i * o) / p, w = r * o / p;
109
+ return c([[g, w]]);
110
110
  }
111
111
  const d = Math.sqrt(h), m = [
112
- -(r * i * o + c * d) / p,
113
- (l * o - c * i * d) / p
114
- ], P = [
115
- -(r * i * o - c * d) / p,
116
- (l * o + c * i * d) / p
112
+ -(l * i * o + u * d) / p,
113
+ (r * o - u * i * d) / p
114
+ ], x = [
115
+ -(l * i * o - u * d) / p,
116
+ (r * o + u * i * d) / p
117
117
  ];
118
- return u([m, P]);
119
- }
120
- function Dt(t, n) {
121
- const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2, o = s.xy, r = s.y2, l = s.x, c = s.y, a = s.c, f = n.coefficients, u = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, P = f.c, w = {
122
- z0: a * i * d * d + i * i * P * P - l * i * d * P + u * u * a * a - 2 * i * P * u * a - l * d * u * a + u * l * l * P,
123
- z1: m * l * l * u - P * d * i * o - 2 * i * P * u * c - a * u * h * l + 2 * d * h * i * a + 2 * m * P * i * i + d * d * i * c - m * d * i * l - 2 * i * m * u * a - a * u * d * o + 2 * a * c * u * u - P * h * i * l - c * u * d * l + 2 * P * o * u * l,
124
- z2: m * m * i * i + 2 * p * P * i * i - c * u * d * o + P * u * o * o - c * u * h * l - P * h * i * o - 2 * i * m * u * c + 2 * d * h * i * c - p * d * i * l - 2 * i * p * u * a + h * h * i * a + 2 * m * o * u * l + c * c * u * u - r * u * d * l - m * h * i * l + 2 * a * r * u * u - a * u * h * o + p * l * l * u + d * d * i * r - m * d * i * o - 2 * i * P * u * r,
125
- z3: -2 * i * u * r * m + m * u * o * o + 2 * p * o * u * l - r * u * h * l + h * h * i * c - m * h * i * o - 2 * i * p * u * c - c * u * h * o - p * h * i * l + 2 * m * p * i * i + 2 * c * r * u * u - r * u * d * o + 2 * d * h * i * r - p * d * i * o,
126
- z4: i * i * p * p - 2 * i * p * u * r + u * u * r * r - o * i * h * p - o * h * u * r + o * o * u * p + r * i * h * h
127
- }, F = Lt(
128
- [w.z0, w.z1, w.z2, w.z3, w.z4],
118
+ return c([m, x]);
119
+ }
120
+ function Rt(t, n) {
121
+ const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2, o = s.xy, l = s.y2, r = s.x, u = s.y, a = s.c, f = n.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, x = f.c, g = {
122
+ z0: a * i * d * d + i * i * x * x - r * i * d * x + c * c * a * a - 2 * i * x * c * a - r * d * c * a + c * r * r * x,
123
+ z1: m * r * r * c - x * d * i * o - 2 * i * x * c * u - a * c * h * r + 2 * d * h * i * a + 2 * m * x * i * i + d * d * i * u - m * d * i * r - 2 * i * m * c * a - a * c * d * o + 2 * a * u * c * c - x * h * i * r - u * c * d * r + 2 * x * o * c * r,
124
+ z2: m * m * i * i + 2 * p * x * i * i - u * c * d * o + x * c * o * o - u * c * h * r - x * h * i * o - 2 * i * m * c * u + 2 * d * h * i * u - p * d * i * r - 2 * i * p * c * a + h * h * i * a + 2 * m * o * c * r + u * u * c * c - l * c * d * r - m * h * i * r + 2 * a * l * c * c - a * c * h * o + p * r * r * c + d * d * i * l - m * d * i * o - 2 * i * x * c * l,
125
+ z3: -2 * i * c * l * m + m * c * o * o + 2 * p * o * c * r - l * c * h * r + h * h * i * u - m * h * i * o - 2 * i * p * c * u - u * c * h * o - p * h * i * r + 2 * m * p * i * i + 2 * u * l * c * c - l * c * d * o + 2 * d * h * i * l - p * d * i * o,
126
+ z4: i * i * p * p - 2 * i * p * c * l + c * c * l * l - o * i * h * p - o * h * c * l + o * o * c * p + l * i * h * h
127
+ }, F = qt(
128
+ [g.z0, g.z1, g.z2, g.z3, g.z4],
129
129
  e
130
- ).flatMap((b) => {
131
- const R = i * h * b + i * d - u * o * b - u * l;
130
+ ).flatMap((y) => {
131
+ const R = i * h * y + i * d - c * o * y - c * r;
132
132
  if (R)
133
- return [[-(i * P + i * p * b * b - u * r * b * b + i * m * b - u * c * b - u * a) / R, b]];
134
- const T = o * b + l, L = -T / (2 * i), j = r * b * b + c * b + a, z = T * T / (4 * i * i) - j / i;
135
- if (Math.abs(z) < e)
136
- return [[L, b]];
137
- if (z > 0) {
138
- const H = Math.sqrt(z);
139
- return [[L + H, b], [L - H, b]];
133
+ return [[-(i * x + i * p * y * y - c * l * y * y + i * m * y - c * u * y - c * a) / R, y]];
134
+ const T = o * y + r, L = -T / (2 * i), j = l * y * y + u * y + a, q = T * T / (4 * i * i) - j / i;
135
+ if (Math.abs(q) < e)
136
+ return [[L, y]];
137
+ if (q > 0) {
138
+ const H = Math.sqrt(q);
139
+ return [[L + H, y], [L - H, y]];
140
140
  }
141
141
  return [];
142
142
  });
143
143
  return U(F, e);
144
144
  }
145
- function mt(t, n) {
146
- return Dt(t, n).filter((s) => t.isOnSegment(s) && n.isOnSegment(s));
145
+ function gt(t, n) {
146
+ return Rt(t, n).filter((s) => t.isOnSegment(s) && n.isOnSegment(s));
147
147
  }
148
- const gn = (t) => {
148
+ const Pn = (t) => {
149
149
  const {
150
150
  firstPoint: n,
151
151
  lastPoint: e,
152
152
  center: s,
153
153
  majorRadius: i,
154
154
  minorRadius: o,
155
- tiltAngle: r,
156
- clockwise: l
155
+ tiltAngle: l,
156
+ clockwise: r
157
157
  } = t;
158
158
  return new M(
159
159
  e,
@@ -161,14 +161,14 @@ const gn = (t) => {
161
161
  s,
162
162
  i,
163
163
  o,
164
- r,
165
164
  l,
165
+ r,
166
166
  {
167
167
  ignoreChecks: !0,
168
168
  angleUnits: "rad"
169
169
  }
170
170
  );
171
- }, Pn = (t, n) => {
171
+ }, wn = (t, n) => {
172
172
  if (t.isSame(n))
173
173
  return [t];
174
174
  const e = (i, o) => new M(
@@ -193,50 +193,50 @@ const gn = (t) => {
193
193
  if (s.length === 0) return [];
194
194
  if (s.length === 1) return [];
195
195
  if (s.length === 2)
196
- return t.isSame(gn(n)) ? [] : [e(s[0], s[1])];
196
+ return t.isSame(Pn(n)) ? [] : [e(s[0], s[1])];
197
197
  if (s.length === 3) {
198
- const i = g(s[0], n.lastPoint) || g(s[0], n.firstPoint) ? 1 : 0;
198
+ const i = P(s[0], n.lastPoint) || P(s[0], n.firstPoint) ? 1 : 0;
199
199
  return [e(s[0 + i], s[1 + i])];
200
200
  } else if (s.length === 4)
201
201
  return [e(s[0], s[1]), e(s[2], s[3])];
202
202
  throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm");
203
203
  };
204
- function wn(t, n, e = !1) {
204
+ function xn(t, n, e = !1) {
205
205
  const s = Math.max(t.precision, n.precision);
206
- return g(t.center, n.center) && Math.abs(t.majorRadius - n.majorRadius) < s && Math.abs(t.minorRadius - n.minorRadius) < s && (Math.abs(t.tiltAngle - n.tiltAngle) < s || Math.abs(Math.abs(t.tiltAngle - n.tiltAngle) - Math.PI) < s) ? e ? Pn(t, n) : [] : Dt(t, n).filter((r) => t.isOnSegment(r) && n.isOnSegment(r));
206
+ return P(t.center, n.center) && Math.abs(t.majorRadius - n.majorRadius) < s && Math.abs(t.minorRadius - n.minorRadius) < s && (Math.abs(t.tiltAngle - n.tiltAngle) < s || Math.abs(Math.abs(t.tiltAngle - n.tiltAngle) - Math.PI) < s) ? e ? wn(t, n) : [] : Rt(t, n).filter((l) => t.isOnSegment(l) && n.isOnSegment(l));
207
207
  }
208
- function gt(t, n) {
209
- const [e, s] = t.firstPoint, [i, o] = t.lastPoint, r = new on().translate(-e, -s).rotate(-Math.atan2(o - s, i - e)), l = r.clone().inverse(), c = n.transform(r);
210
- return c.paramsAtY(0).map((a) => c.paramPoint(a)).map((a) => l.transform(a)).filter((a) => t.isOnSegment(a));
208
+ function Pt(t, n) {
209
+ const [e, s] = t.firstPoint, [i, o] = t.lastPoint, l = new rn().translate(-e, -s).rotate(-Math.atan2(o - s, i - e)), r = l.clone().inverse(), u = n.transform(l);
210
+ return u.paramsAtY(0).map((a) => u.paramPoint(a)).map((a) => r.transform(a)).filter((a) => t.isOnSegment(a));
211
211
  }
212
- const xn = (t, n = 1e-9) => {
212
+ const Sn = (t, n = 1e-9) => {
213
213
  let e = t;
214
214
  return Math.abs(t) < n && (e = 0), e.toFixed(-Math.log10(n));
215
215
  };
216
- function Rt(t, n = 1e-9) {
216
+ function Vt(t, n = 1e-9) {
217
217
  return Array.from(
218
- new Map(t.map((e) => [xn(e, n), e])).values()
218
+ new Map(t.map((e) => [Sn(e, n), e])).values()
219
219
  );
220
220
  }
221
- const Sn = (t, n) => {
222
- const [[e, s, i, o], [r, l, c, a]] = n.polynomialCoefficients, f = t.coefficients, u = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, P = f.c, w = e * e, x = s * s, F = i * i, b = o * o, R = r * r, T = l * l, L = c * c, j = a * a, z = P + d * e + u * w + m * r + h * e * r + p * R, H = d * s + 2 * u * e * s + h * s * r + m * l + h * e * l + 2 * p * r * l, Qt = u * x + d * i + 2 * u * e * i + h * i * r + h * s * l + p * T + m * c + h * e * c + 2 * p * r * c, Wt = 2 * u * s * i + d * o + 2 * u * e * o + h * o * r + h * i * l + h * s * c + 2 * p * l * c + m * a + h * e * a + 2 * p * r * a, Jt = u * F + 2 * u * s * o + h * o * l + h * i * c + p * L + h * s * a + 2 * p * l * a, Kt = 2 * u * i * o + h * o * c + h * i * a + 2 * p * c * a, Zt = u * b + h * o * a + p * j;
223
- return [z, H, Qt, Wt, Jt, Kt, Zt];
224
- };
225
- function Pt(t, n) {
226
- const e = Math.max(t.precision, n.precision), s = Sn(t, n), i = Lt(s, e).filter((o) => o >= -n.precision && o <= 1 + n.precision);
227
- return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
228
- }
229
221
  const yn = (t, n) => {
230
- const [[e, s, i], [o, r, l]] = n.polynomialCoefficients, c = t.coefficients, a = c.x2, f = c.xy, u = c.y2, h = c.x, p = c.y, d = c.c, m = e * e, P = s * s, w = i * i, x = o * o, F = r * r, b = l * l, R = a * m + f * e * o + u * x + h * e + p * o + d, T = 2 * a * e * s + f * e * r + f * s * o + 2 * u * o * r + h * s + p * r, L = 2 * a * e * i + a * P + f * e * l + f * s * r + f * i * o + 2 * u * o * l + u * F + h * i + p * l, j = 2 * a * s * i + f * s * l + f * i * r + 2 * u * r * l, z = a * w + f * i * l + u * b;
231
- return [R, T, L, j, z];
222
+ const [[e, s, i, o], [l, r, u, a]] = n.polynomialCoefficients, f = t.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, x = f.c, g = e * e, w = s * s, F = i * i, y = o * o, R = l * l, T = r * r, L = u * u, j = a * a, q = x + d * e + c * g + m * l + h * e * l + p * R, H = d * s + 2 * c * e * s + h * s * l + m * r + h * e * r + 2 * p * l * r, Wt = c * w + d * i + 2 * c * e * i + h * i * l + h * s * r + p * T + m * u + h * e * u + 2 * p * l * u, Jt = 2 * c * s * i + d * o + 2 * c * e * o + h * o * l + h * i * r + h * s * u + 2 * p * r * u + m * a + h * e * a + 2 * p * l * a, Kt = c * F + 2 * c * s * o + h * o * r + h * i * u + p * L + h * s * a + 2 * p * r * a, Zt = 2 * c * i * o + h * o * u + h * i * a + 2 * p * u * a, tn = c * y + h * o * a + p * j;
223
+ return [q, H, Wt, Jt, Kt, Zt, tn];
232
224
  };
233
225
  function wt(t, n) {
234
- const e = Math.max(t.precision, n.precision), s = yn(t, n), i = rn(...s).filter((o) => o >= -n.precision && o <= 1 + n.precision);
235
- return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
226
+ const e = Math.max(t.precision, n.precision), s = yn(t, n), i = qt(s, e).filter((o) => o >= -n.precision && o <= 1 + n.precision);
227
+ return Vt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
228
+ }
229
+ const bn = (t, n) => {
230
+ const [[e, s, i], [o, l, r]] = n.polynomialCoefficients, u = t.coefficients, a = u.x2, f = u.xy, c = u.y2, h = u.x, p = u.y, d = u.c, m = e * e, x = s * s, g = i * i, w = o * o, F = l * l, y = r * r, R = a * m + f * e * o + c * w + h * e + p * o + d, T = 2 * a * e * s + f * e * l + f * s * o + 2 * c * o * l + h * s + p * l, L = 2 * a * e * i + a * x + f * e * r + f * s * l + f * i * o + 2 * c * o * r + c * F + h * i + p * r, j = 2 * a * s * i + f * s * r + f * i * l + 2 * c * l * r, q = a * g + f * i * r + c * y;
231
+ return [R, T, L, j, q];
232
+ };
233
+ function xt(t, n) {
234
+ const e = Math.max(t.precision, n.precision), s = bn(t, n), i = ln(...s).filter((o) => o >= -n.precision && o <= 1 + n.precision);
235
+ return Vt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
236
236
  }
237
237
  function E(t, { firstPoint: n, lastPoint: e }, s = 1e-9) {
238
238
  const i = k(e, n);
239
- return Math.abs(i[0]) < s ? i[1] > 0 ? n[0] - t[0] : t[0] - n[0] : Math.abs(i[1]) < s ? i[0] > 0 ? t[1] - n[1] : n[1] - t[1] : ln(i, k(t, n)) / cn(i);
239
+ return Math.abs(i[0]) < s ? i[1] > 0 ? n[0] - t[0] : t[0] - n[0] : Math.abs(i[1]) < s ? i[0] > 0 ? t[1] - n[1] : n[1] - t[1] : un(i, k(t, n)) / cn(i);
240
240
  }
241
241
  class ct {
242
242
  constructor(n, e, s, i) {
@@ -246,9 +246,9 @@ class ct {
246
246
  return this.positiveThickness - this.negativeThickness;
247
247
  }
248
248
  }
249
- const bn = 3 / 4, Cn = 4 / 9;
250
- function Mn(t) {
251
- const n = E(t.firstControlPoint, t), e = E(t.lastControlPoint, t), s = n * e > 0 ? bn : Cn;
249
+ const Cn = 3 / 4, Mn = 4 / 9;
250
+ function In(t) {
251
+ const n = E(t.firstControlPoint, t), e = E(t.lastControlPoint, t), s = n * e > 0 ? Cn : Mn;
252
252
  return new ct(
253
253
  t.firstPoint,
254
254
  t.lastPoint,
@@ -265,32 +265,32 @@ function An(t) {
265
265
  Math.max(0, n / 2)
266
266
  );
267
267
  }
268
- function In(t) {
269
- if (t instanceof I)
270
- return Mn(t);
268
+ function En(t) {
271
269
  if (t instanceof A)
270
+ return In(t);
271
+ if (t instanceof I)
272
272
  return An(t);
273
273
  throw new Error("Not implemented");
274
274
  }
275
- function En(t) {
276
- const n = t.paramPoint(0.5), e = Tt(k(n, t.firstPoint)), s = q(n, e), i = {
275
+ function Fn(t) {
276
+ const n = t.paramPoint(0.5), e = Lt(k(n, t.firstPoint)), s = z(n, e), i = {
277
277
  firstPoint: n,
278
278
  lastPoint: s
279
279
  }, o = [
280
280
  E(t.firstPoint, i),
281
281
  E(t.lastPoint, i)
282
282
  ];
283
- return t instanceof I ? o.push(
283
+ return t instanceof A ? o.push(
284
284
  E(t.firstControlPoint, i),
285
285
  E(t.lastControlPoint, i)
286
- ) : t instanceof A && o.push(E(t.controlPoint, i)), new ct(
286
+ ) : t instanceof I && o.push(E(t.controlPoint, i)), new ct(
287
287
  n,
288
288
  s,
289
289
  Math.min(...o),
290
290
  Math.max(...o)
291
291
  );
292
292
  }
293
- function xt(t, n) {
293
+ function St(t, n) {
294
294
  const e = [];
295
295
  for (let s = 1; s < t.length; s++) {
296
296
  const i = t[s];
@@ -298,8 +298,8 @@ function xt(t, n) {
298
298
  e.push(i[0]);
299
299
  continue;
300
300
  }
301
- const o = t[s - 1], r = n - o[1], l = n - i[1];
302
- if (r * l < 0) {
301
+ const o = t[s - 1], l = n - o[1], r = n - i[1];
302
+ if (l * r < 0) {
303
303
  e.push(
304
304
  o[0] + (n - o[1]) * (i[0] - o[0]) / (i[1] - o[1])
305
305
  );
@@ -319,29 +319,29 @@ class Y {
319
319
  return this.from === "start" ? this.to === "end" ? n : n.splitAtParameters([this.to])[0] : this.to === "end" ? n.splitAtParameters([this.from])[1] : n.splitAtParameters([this.from, this.to])[1];
320
320
  }
321
321
  }
322
- function Fn(t, n) {
323
- if (t instanceof I)
324
- return new Bn([
322
+ function vn(t, n) {
323
+ if (t instanceof A)
324
+ return new kn([
325
325
  E(t.firstPoint, n),
326
326
  E(t.firstControlPoint, n),
327
327
  E(t.lastControlPoint, n),
328
328
  E(t.lastPoint, n)
329
329
  ]);
330
- if (t instanceof A)
331
- return new vn([
330
+ if (t instanceof I)
331
+ return new Bn([
332
332
  E(t.firstPoint, n),
333
333
  E(t.controlPoint, n),
334
334
  E(t.lastPoint, n)
335
335
  ]);
336
336
  throw new Error("Not implemented");
337
337
  }
338
- class vn {
338
+ class Bn {
339
339
  constructor(n) {
340
340
  C(this, "topHull", []);
341
341
  C(this, "bottomHull", []);
342
342
  this.distances = n;
343
- const [e, s, i] = n, o = [0, e], r = [1 / 2, s], l = [1, i], c = i - e, a = e;
344
- s - (c * (1 / 2) + a) > 0 ? (this.topHull = [o, r, l], this.bottomHull = [o, l]) : (this.topHull = [o, l], this.bottomHull = [o, r, l]);
343
+ const [e, s, i] = n, o = [0, e], l = [1 / 2, s], r = [1, i], u = i - e, a = e;
344
+ s - (u * (1 / 2) + a) > 0 ? (this.topHull = [o, l, r], this.bottomHull = [o, r]) : (this.topHull = [o, r], this.bottomHull = [o, l, r]);
345
345
  }
346
346
  get startDistance() {
347
347
  return this.distances[0];
@@ -350,18 +350,18 @@ class vn {
350
350
  return this.distances[2];
351
351
  }
352
352
  }
353
- class Bn {
353
+ class kn {
354
354
  constructor(n) {
355
355
  C(this, "topHull", []);
356
356
  C(this, "bottomHull", []);
357
357
  this.distances = n;
358
- const [e, s, i, o] = n, r = [0, e], l = [1 / 3, s], c = [2 / 3, i], a = [1, o], f = o - e, u = e, h = s - (f * (1 / 3) + u), p = i - (f * (2 / 3) + u);
358
+ const [e, s, i, o] = n, l = [0, e], r = [1 / 3, s], u = [2 / 3, i], a = [1, o], f = o - e, c = e, h = s - (f * (1 / 3) + c), p = i - (f * (2 / 3) + c);
359
359
  let d = null, m = null;
360
360
  if (h * p < 0)
361
- d = [r, l, a], m = [r, c, a];
361
+ d = [l, r, a], m = [l, u, a];
362
362
  else {
363
- const w = h / p;
364
- w >= 2 ? (d = [r, l, a], m = [r, a]) : w <= 0.5 ? (d = [r, c, a], m = [r, a]) : (d = [r, l, c, a], m = [r, a]);
363
+ const g = h / p;
364
+ g >= 2 ? (d = [l, r, a], m = [l, a]) : g <= 0.5 ? (d = [l, u, a], m = [l, a]) : (d = [l, r, u, a], m = [l, a]);
365
365
  }
366
366
  h < 0 && ([d, m] = [m, d]), this.topHull = d, this.bottomHull = m;
367
367
  }
@@ -372,11 +372,11 @@ class Bn {
372
372
  return this.distances[3];
373
373
  }
374
374
  }
375
- function St(t, n) {
376
- const e = Fn(n, t), s = xt(
375
+ function yt(t, n) {
376
+ const e = vn(n, t), s = St(
377
377
  e.topHull,
378
378
  t.negativeThickness
379
- ), i = xt(
379
+ ), i = St(
380
380
  e.bottomHull,
381
381
  t.positiveThickness
382
382
  ), o = e.endDistance >= t.negativeThickness && e.endDistance <= t.positiveThickness;
@@ -388,39 +388,39 @@ function St(t, n) {
388
388
  throw new Error(
389
389
  "Bug in the clipping algorithm, unexpected number of crossing points"
390
390
  );
391
- const r = s.length ? s : i;
392
- return r.length === 2 ? new Y(r[0], r[1]) : o ? new Y(r[0], "end") : new Y("start", r[0]);
391
+ const l = s.length ? s : i;
392
+ return l.length === 2 ? new Y(l[0], l[1]) : o ? new Y(l[0], "end") : new Y("start", l[0]);
393
393
  }
394
- function yt(t, n) {
395
- const e = In(t), s = St(e, n);
394
+ function bt(t, n) {
395
+ const e = En(t), s = yt(e, n);
396
396
  if (!s)
397
397
  return null;
398
- const i = En(t), o = St(
398
+ const i = Fn(t), o = yt(
399
399
  i,
400
400
  n
401
401
  );
402
402
  return o ? s.size > o.size ? o.clipCurve(n) : s.clipCurve(n) : null;
403
403
  }
404
- const W = (t) => t instanceof A ? $(k(t.controlPoint, t.firstPoint)) + $(k(t.controlPoint, t.lastPoint)) : $(k(t.firstControlPoint, t.firstPoint)) + $(k(t.lastControlPoint, t.firstControlPoint)) + $(k(t.lastControlPoint, t.lastPoint));
404
+ const W = (t) => t instanceof I ? $(k(t.controlPoint, t.firstPoint)) + $(k(t.controlPoint, t.lastPoint)) : $(k(t.firstControlPoint, t.firstPoint)) + $(k(t.lastControlPoint, t.firstControlPoint)) + $(k(t.lastControlPoint, t.lastPoint));
405
405
  function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
406
406
  const i = Math.max(e * e, Number.EPSILON * 10);
407
- let o = t, r = n, l = W(o), c = W(r);
407
+ let o = t, l = n, r = W(o), u = W(l);
408
408
  for (let a = 0; a < s; a++) {
409
- const f = l > i ? yt(r, o) : o;
409
+ const f = r > i ? bt(l, o) : o;
410
410
  if (!f) return [];
411
- const u = W(f), h = c > i ? yt(f, r) : r;
411
+ const c = W(f), h = u > i ? bt(f, l) : l;
412
412
  if (!h) return [];
413
413
  const p = W(h);
414
- if (u <= i && p <= i)
414
+ if (c <= i && p <= i)
415
415
  return [
416
416
  f.boundingBox.intersection(h.boundingBox).center
417
417
  ];
418
- if (g(f.firstPoint, f.lastPoint) && h.isOnSegment(f.firstPoint))
418
+ if (P(f.firstPoint, f.lastPoint) && h.isOnSegment(f.firstPoint))
419
419
  return [f.firstPoint];
420
- if (g(h.firstPoint, h.lastPoint) && f.isOnSegment(h.firstPoint))
420
+ if (P(h.firstPoint, h.lastPoint) && f.isOnSegment(h.firstPoint))
421
421
  return [h.firstPoint];
422
- if (u > 0.8 * l && p > 0.8 * c)
423
- if (u / l > p / c) {
422
+ if (c > 0.8 * r && p > 0.8 * u)
423
+ if (c / r > p / u) {
424
424
  const [d, m] = f.splitAtParameters([
425
425
  0.5
426
426
  ]);
@@ -451,11 +451,11 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
451
451
  e
452
452
  );
453
453
  }
454
- o = f, r = h, l = u, c = p;
454
+ o = f, l = h, r = c, u = p;
455
455
  }
456
456
  throw new Error("Bézier clip: Maximum number of iterations reached");
457
457
  }
458
- function kn(t, n) {
458
+ function On(t, n) {
459
459
  const e = [];
460
460
  if ([
461
461
  [t.firstPoint, n],
@@ -469,20 +469,20 @@ function kn(t, n) {
469
469
  if (e.length === 2)
470
470
  return [t.splitAt(e)[1]];
471
471
  if (e.length === 3)
472
- return g(e[0], t.firstPoint) && g(e[1], t.lastPoint) ? [t] : [n];
472
+ return P(e[0], t.firstPoint) && P(e[1], t.lastPoint) ? [t] : [n];
473
473
  if (e.length === 4)
474
474
  return [t];
475
475
  }
476
476
  function _n(t, n, e = !1) {
477
477
  const s = Math.max(t.precision, n.precision);
478
478
  if (e) {
479
- const i = kn(t, n);
479
+ const i = On(t, n);
480
480
  if (i)
481
481
  return i;
482
482
  }
483
483
  return D(t, n, s);
484
484
  }
485
- function On(t, n) {
485
+ function Tn(t, n) {
486
486
  const e = [];
487
487
  if ([
488
488
  [t.firstPoint, n],
@@ -496,21 +496,21 @@ function On(t, n) {
496
496
  if (e.length === 2)
497
497
  return [t.splitAt(e)[1]];
498
498
  if (e.length === 3)
499
- return g(e[0], t.firstPoint) && g(e[1], t.lastPoint) ? [t] : [n];
499
+ return P(e[0], t.firstPoint) && P(e[1], t.lastPoint) ? [t] : [n];
500
500
  if (e.length === 4)
501
501
  return [t];
502
502
  }
503
- function Tn(t, n, e = !1) {
503
+ function Ln(t, n, e = !1) {
504
504
  const s = Math.max(t.precision, n.precision);
505
505
  if (e) {
506
- const i = On(t, n);
506
+ const i = Tn(t, n);
507
507
  if (i)
508
508
  return i;
509
509
  }
510
510
  return D(t, n, s);
511
511
  }
512
- function ae(t, n, e) {
513
- if (t instanceof y && n instanceof y) {
512
+ function de(t, n, e) {
513
+ if (t instanceof b && n instanceof b) {
514
514
  const s = zt(
515
515
  t,
516
516
  n,
@@ -519,36 +519,36 @@ function ae(t, n, e) {
519
519
  );
520
520
  return s === null ? [] : [s];
521
521
  }
522
- if (t instanceof y && n instanceof S)
523
- return J(t, n, e);
524
- if (t instanceof S && n instanceof y)
525
- return J(n, t, e);
522
+ if (t instanceof b && n instanceof S)
523
+ return K(t, n, e);
524
+ if (t instanceof S && n instanceof b)
525
+ return K(n, t, e);
526
526
  if (t instanceof S && n instanceof S)
527
- return qt(t, n, !1, e);
527
+ return Dt(t, n, !1, e);
528
528
  throw new Error("Not implemented");
529
529
  }
530
- function K(t, n, e) {
531
- if (t instanceof y && n instanceof y) {
530
+ function Z(t, n, e) {
531
+ if (t instanceof b && n instanceof b) {
532
532
  const s = zt(
533
533
  t,
534
534
  n,
535
535
  !0,
536
536
  e
537
537
  );
538
- return s === null ? { intersections: [], overlaps: [], count: 0 } : s instanceof y ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
538
+ return s === null ? { intersections: [], overlaps: [], count: 0 } : s instanceof b ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
539
539
  }
540
540
  if (!t.boundingBox.overlaps(n.boundingBox))
541
541
  return { intersections: [], overlaps: [], count: 0 };
542
- if (t instanceof y && n instanceof S) {
543
- const s = J(t, n, e);
542
+ if (t instanceof b && n instanceof S) {
543
+ const s = K(t, n, e);
544
544
  return { intersections: s, overlaps: [], count: s.length };
545
545
  }
546
- if (t instanceof S && n instanceof y) {
547
- const s = J(n, t, e);
546
+ if (t instanceof S && n instanceof b) {
547
+ const s = K(n, t, e);
548
548
  return { intersections: s, overlaps: [], count: s.length };
549
549
  }
550
550
  if (t instanceof S && n instanceof S) {
551
- const s = qt(
551
+ const s = Dt(
552
552
  t,
553
553
  n,
554
554
  !0,
@@ -564,16 +564,16 @@ function K(t, n, e) {
564
564
  count: s.length
565
565
  } : { intersections: [], overlaps: [], count: 0 };
566
566
  }
567
- if (t instanceof y && n instanceof M) {
568
- const s = et(
567
+ if (t instanceof b && n instanceof M) {
568
+ const s = st(
569
569
  t,
570
570
  n,
571
571
  e
572
572
  );
573
573
  return { intersections: s, overlaps: [], count: s.length };
574
574
  }
575
- if (n instanceof y && t instanceof M) {
576
- const s = et(
575
+ if (n instanceof b && t instanceof M) {
576
+ const s = st(
577
577
  n,
578
578
  t,
579
579
  e
@@ -581,15 +581,15 @@ function K(t, n, e) {
581
581
  return { intersections: s, overlaps: [], count: s.length };
582
582
  }
583
583
  if (t instanceof S && n instanceof M) {
584
- const s = mt(t, n);
584
+ const s = gt(t, n);
585
585
  return { intersections: s, overlaps: [], count: s.length };
586
586
  }
587
587
  if (n instanceof S && t instanceof M) {
588
- const s = mt(n, t);
588
+ const s = gt(n, t);
589
589
  return { intersections: s, overlaps: [], count: s.length };
590
590
  }
591
591
  if (t instanceof M && n instanceof M) {
592
- const s = wn(
592
+ const s = xn(
593
593
  t,
594
594
  n,
595
595
  !0
@@ -604,36 +604,36 @@ function K(t, n, e) {
604
604
  count: s.length
605
605
  } : { intersections: [], overlaps: [], count: 0 };
606
606
  }
607
- if (t instanceof y && (n instanceof I || n instanceof A)) {
608
- const s = gt(t, n);
607
+ if (t instanceof b && (n instanceof A || n instanceof I)) {
608
+ const s = Pt(t, n);
609
609
  return { intersections: s, overlaps: [], count: s.length };
610
610
  }
611
- if (n instanceof y && (t instanceof I || t instanceof A)) {
612
- const s = gt(n, t);
611
+ if (n instanceof b && (t instanceof A || t instanceof I)) {
612
+ const s = Pt(n, t);
613
613
  return { intersections: s, overlaps: [], count: s.length };
614
614
  }
615
- if ((t instanceof S || t instanceof M) && n instanceof A) {
616
- const s = wt(t, n);
615
+ if ((t instanceof S || t instanceof M) && n instanceof I) {
616
+ const s = xt(t, n);
617
617
  return { intersections: s, overlaps: [], count: s.length };
618
618
  }
619
- if ((n instanceof S || n instanceof M) && t instanceof A) {
620
- const s = wt(n, t);
619
+ if ((n instanceof S || n instanceof M) && t instanceof I) {
620
+ const s = xt(n, t);
621
621
  return { intersections: s, overlaps: [], count: s.length };
622
622
  }
623
- if ((t instanceof S || t instanceof M) && n instanceof I) {
624
- const s = Pt(t, n);
623
+ if ((t instanceof S || t instanceof M) && n instanceof A) {
624
+ const s = wt(t, n);
625
625
  return { intersections: s, overlaps: [], count: s.length };
626
626
  }
627
- if ((n instanceof S || n instanceof M) && t instanceof I) {
628
- const s = Pt(n, t);
627
+ if ((n instanceof S || n instanceof M) && t instanceof A) {
628
+ const s = wt(n, t);
629
629
  return { intersections: s, overlaps: [], count: s.length };
630
630
  }
631
- if (t instanceof A && n instanceof A) {
632
- const s = Tn(
631
+ if (t instanceof I && n instanceof I) {
632
+ const s = Ln(
633
633
  t,
634
634
  n
635
635
  );
636
- return s.length ? s[0] instanceof A ? {
636
+ return s.length ? s[0] instanceof I ? {
637
637
  intersections: [],
638
638
  overlaps: s,
639
639
  count: s.length
@@ -643,16 +643,16 @@ function K(t, n, e) {
643
643
  count: s.length
644
644
  } : { intersections: [], overlaps: [], count: 0 };
645
645
  }
646
- if (t instanceof A && n instanceof I || n instanceof A && t instanceof I) {
646
+ if (t instanceof I && n instanceof A || n instanceof I && t instanceof A) {
647
647
  const s = D(t, n);
648
648
  return { intersections: s, overlaps: [], count: s.length };
649
649
  }
650
- if (t instanceof I && n instanceof I) {
650
+ if (t instanceof A && n instanceof A) {
651
651
  const s = _n(
652
652
  t,
653
653
  n
654
654
  );
655
- return s.length ? s[0] instanceof I ? {
655
+ return s.length ? s[0] instanceof A ? {
656
656
  intersections: [],
657
657
  overlaps: s,
658
658
  count: s.length
@@ -664,23 +664,23 @@ function K(t, n, e) {
664
664
  }
665
665
  throw new Error("Not implemented");
666
666
  }
667
- function Vt(t) {
667
+ function Nt(t) {
668
668
  const n = [];
669
669
  for (let e = 0; e < t; e++)
670
670
  for (let s = 0; s <= e; s++)
671
671
  n.push([e, s]);
672
672
  return n;
673
673
  }
674
- function* st(t) {
675
- for (const [n, e] of Vt(t.length))
674
+ function* it(t) {
675
+ for (const [n, e] of Nt(t.length))
676
676
  n !== e && (yield [t[n], t[e]]);
677
677
  }
678
- class Nt extends lt {
678
+ class Ut extends ut {
679
679
  constructor(e, { ignoreChecks: s = !1 } = {}) {
680
680
  super();
681
681
  C(this, "segments");
682
682
  C(this, "_boundingBox", null);
683
- s || Ut(e), this.segments = e;
683
+ s || jt(e), this.segments = e;
684
684
  }
685
685
  get repr() {
686
686
  return this.segments.map((e) => e.repr).join(`
@@ -705,12 +705,12 @@ class Nt extends lt {
705
705
  intersects(e) {
706
706
  return this.boundingBox.overlaps(e.boundingBox) ? this.segments.some(
707
707
  (s) => e.segments.some(
708
- (i) => K(s, i).count > 0
708
+ (i) => Z(s, i).count > 0
709
709
  )
710
710
  ) : !1;
711
711
  }
712
712
  overlappingSegments(e) {
713
- return this.segments.flatMap((s) => e.segments.flatMap((i) => s.boundingBox.overlaps(i.boundingBox) ? K(s, i).overlaps : []));
713
+ return this.segments.flatMap((s) => e.segments.flatMap((i) => s.boundingBox.overlaps(i.boundingBox) ? Z(s, i).overlaps : []));
714
714
  }
715
715
  get boundingBox() {
716
716
  if (this._boundingBox === null) {
@@ -725,61 +725,61 @@ class Nt extends lt {
725
725
  return this.repr;
726
726
  }
727
727
  }
728
- function Ln(t, n = "Stroke") {
729
- Vt(t.length).forEach(
728
+ function qn(t, n = "Stroke") {
729
+ Nt(t.length).forEach(
730
730
  ([e, s]) => {
731
731
  if (e === s) return;
732
- const i = t[e], o = t[s], r = K(i, o), l = Math.max(i.precision, o.precision);
733
- if (r.count !== 0) {
734
- if (r.count === 1 && !r.overlaps.length) {
735
- const c = e - s, a = r.intersections[0];
736
- if (c === 1 && g(i.firstPoint, a, l) || c === -1 && g(i.lastPoint, a, l) || c === t.length - 1 && g(i.lastPoint, a, l) && g(o.firstPoint, a, l) || -c === t.length - 1 && g(i.firstPoint, a, l) && g(o.lastPoint, a, l))
732
+ const i = t[e], o = t[s], l = Z(i, o), r = Math.max(i.precision, o.precision);
733
+ if (l.count !== 0) {
734
+ if (l.count === 1 && !l.overlaps.length) {
735
+ const u = e - s, a = l.intersections[0];
736
+ if (u === 1 && P(i.firstPoint, a, r) || u === -1 && P(i.lastPoint, a, r) || u === t.length - 1 && P(i.lastPoint, a, r) && P(o.firstPoint, a, r) || -u === t.length - 1 && P(i.firstPoint, a, r) && P(o.lastPoint, a, r))
737
737
  return;
738
738
  }
739
- if (!(r.count === 2 && t.length === 2 && (g(
739
+ if (!(l.count === 2 && t.length === 2 && (P(
740
740
  i.firstPoint,
741
- r.intersections[0],
742
- l
743
- ) && g(
741
+ l.intersections[0],
742
+ r
743
+ ) && P(
744
744
  i.lastPoint,
745
- r.intersections[1],
746
- l
747
- ) || g(
745
+ l.intersections[1],
746
+ r
747
+ ) || P(
748
748
  i.firstPoint,
749
- r.intersections[1],
750
- l
751
- ) && g(
749
+ l.intersections[1],
750
+ r
751
+ ) && P(
752
752
  i.lastPoint,
753
- r.intersections[0],
754
- l
753
+ l.intersections[0],
754
+ r
755
755
  ))))
756
756
  throw new Error(
757
757
  `${n} segments must not intersect, but segments ${i.info} and ${o.info} do at ${JSON.stringify(
758
- r.intersections
758
+ l.intersections
759
759
  )}`
760
760
  );
761
761
  }
762
762
  }
763
763
  );
764
764
  }
765
- function Ut(t, n = "Stroke") {
765
+ function jt(t, n = "Stroke") {
766
766
  if (t.length === 0)
767
767
  throw new Error(`${n} must have at least one segment`);
768
768
  N([t.slice(0, -1), t.slice(1)]).forEach(
769
769
  ([e, s]) => {
770
- if (!g(e.lastPoint, s.firstPoint))
770
+ if (!P(e.lastPoint, s.firstPoint))
771
771
  throw new Error(
772
772
  `${n} segments must be connected, but ${e.info} and ${s.info} are not`
773
773
  );
774
774
  }
775
- ), Ln(t, n);
776
- }
777
- function bt(t, n) {
778
- return !!(t instanceof y && n instanceof y && un(t.V, n.V) || t instanceof S && n instanceof S && g(t.center, n.center) && t.radius - n.radius < t.precision);
775
+ ), qn(t, n);
779
776
  }
780
777
  function Ct(t, n) {
781
- if (t instanceof y && n instanceof y)
782
- return new y(t.firstPoint, n.lastPoint);
778
+ return !!(t instanceof b && n instanceof b && an(t.V, n.V) || t instanceof S && n instanceof S && P(t.center, n.center) && t.radius - n.radius < t.precision);
779
+ }
780
+ function Mt(t, n) {
781
+ if (t instanceof b && n instanceof b)
782
+ return new b(t.firstPoint, n.lastPoint);
783
783
  if (t instanceof S && n instanceof S)
784
784
  return new S(
785
785
  t.firstPoint,
@@ -789,7 +789,7 @@ function Ct(t, n) {
789
789
  );
790
790
  throw new Error("Not implemented");
791
791
  }
792
- function jt(t) {
792
+ function Ht(t) {
793
793
  let n = !1;
794
794
  const e = [];
795
795
  for (const s of t.segments) {
@@ -798,19 +798,19 @@ function jt(t) {
798
798
  continue;
799
799
  }
800
800
  const i = e[e.length - 1];
801
- bt(i, s) ? (n = !0, e.pop(), e.push(Ct(i, s))) : e.push(s);
801
+ Ct(i, s) ? (n = !0, e.pop(), e.push(Mt(i, s))) : e.push(s);
802
802
  }
803
- if (g(t.firstPoint, t.lastPoint) && bt(
803
+ if (P(t.firstPoint, t.lastPoint) && Ct(
804
804
  e[0],
805
805
  e[e.length - 1]
806
806
  )) {
807
807
  n = !0;
808
808
  const s = e.pop();
809
- e[0] = Ct(s, e[0]);
809
+ e[0] = Mt(s, e[0]);
810
810
  }
811
811
  return n ? e : null;
812
812
  }
813
- class B extends Nt {
813
+ class B extends Ut {
814
814
  constructor() {
815
815
  super(...arguments);
816
816
  C(this, "strokeType", "STRAND");
@@ -826,12 +826,12 @@ class B extends Nt {
826
826
  );
827
827
  }
828
828
  extend(e) {
829
- if (!g(this.lastPoint, e.firstPoint))
829
+ if (!P(this.lastPoint, e.firstPoint))
830
830
  throw console.error(this.repr, e.repr), new Error("Cannot extend strand: connection point is not the same");
831
831
  return new B([...this.segments, ...e.segments]);
832
832
  }
833
833
  simplify() {
834
- const e = jt(this);
834
+ const e = Ht(this);
835
835
  return e ? new B(e, { ignoreChecks: !0 }) : this;
836
836
  }
837
837
  transform(e) {
@@ -842,7 +842,7 @@ class B extends Nt {
842
842
  }
843
843
  }
844
844
  const zn = (t, n) => {
845
- const e = an(n, {
845
+ const e = fn(n, {
846
846
  V: [1, 0],
847
847
  firstPoint: t,
848
848
  precision: n.precision
@@ -857,38 +857,38 @@ const zn = (t, n) => {
857
857
  }
858
858
  return 1;
859
859
  };
860
- class ut {
860
+ class at {
861
861
  constructor(n) {
862
862
  C(this, "_count", 0);
863
863
  C(this, "segment");
864
864
  this.segment = n;
865
865
  }
866
866
  update(n, e = !1) {
867
- !e && !this.segment.isOnSegment(n) || (g(n, this.segment.firstPoint) ? this._count += this.segment.tangentAtFirstPoint[1] > 0 ? 1 : 0 : g(n, this.segment.lastPoint) ? this._count += this.segment.tangentAtLastPoint[1] > 0 ? 0 : 1 : this._count += 1);
867
+ !e && !this.segment.isOnSegment(n) || (P(n, this.segment.firstPoint) ? this._count += this.segment.tangentAtFirstPoint[1] > 0 ? 1 : 0 : P(n, this.segment.lastPoint) ? this._count += this.segment.tangentAtLastPoint[1] > 0 ? 0 : 1 : this._count += 1);
868
868
  }
869
869
  get count() {
870
870
  return this._count;
871
871
  }
872
872
  }
873
- const qn = (t, n) => {
873
+ const Dn = (t, n) => {
874
874
  const e = n.precision, s = Math.abs(t[1] - n.center[1]);
875
875
  if (s > n.radius + e) return 0;
876
- const i = fn(t, n.center), o = n.radius * n.radius, r = e * e;
877
- if (Math.abs(i - o) < r && n.isOnSegment(t))
876
+ const i = hn(t, n.center), o = n.radius * n.radius, l = e * e;
877
+ if (Math.abs(i - o) < l && n.isOnSegment(t))
878
878
  return 0;
879
- const l = i - o > r;
880
- if (l && n.center[0] < t[0]) return 0;
881
- const c = Math.sqrt(
879
+ const r = i - o > l;
880
+ if (r && n.center[0] < t[0]) return 0;
881
+ const u = Math.sqrt(
882
882
  n.radius * n.radius - s * s
883
- ), a = new ut(n);
884
- return a.update([n.center[0] + c, t[1]]), l && a.update([n.center[0] - c, t[1]]), a.count;
885
- }, Dn = (t, n) => {
886
- const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new y(t, [e, t[1]]), i = new ut(n);
887
- return et(s, n).forEach((o) => {
883
+ ), a = new at(n);
884
+ return a.update([n.center[0] + u, t[1]]), r && a.update([n.center[0] - u, t[1]]), a.count;
885
+ }, Rn = (t, n) => {
886
+ const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new b(t, [e, t[1]]), i = new at(n);
887
+ return st(s, n).forEach((o) => {
888
888
  i.update(o, !0);
889
889
  }), i.count;
890
- }, Rn = (t, n) => {
891
- const e = new ut(n);
890
+ }, Vn = (t, n) => {
891
+ const e = new at(n);
892
892
  return n.paramsAtY(t[1]).map((s) => {
893
893
  try {
894
894
  return n.paramPoint(s);
@@ -902,74 +902,74 @@ const qn = (t, n) => {
902
902
  e.update(s, !0);
903
903
  }), e.count;
904
904
  };
905
- function Vn(t, n) {
906
- if (n instanceof y)
905
+ function Nn(t, n) {
906
+ if (n instanceof b)
907
907
  return zn(t, n);
908
908
  if (n instanceof S)
909
- return qn(t, n);
910
- if (n instanceof M)
911
909
  return Dn(t, n);
912
- if (n instanceof I || n instanceof A)
910
+ if (n instanceof M)
913
911
  return Rn(t, n);
912
+ if (n instanceof A || n instanceof I)
913
+ return Vn(t, n);
914
914
  throw new Error("Not implemented");
915
915
  }
916
- class O extends Nt {
916
+ class _ extends Ut {
917
917
  constructor(e, { ignoreChecks: s = !1 } = {}) {
918
918
  super(e, { ignoreChecks: !0 });
919
919
  C(this, "strokeType", "LOOP");
920
920
  C(this, "_clockwise", null);
921
- s || Nn(e);
921
+ s || Un(e);
922
922
  }
923
923
  get clockwise() {
924
924
  if (this._clockwise === null) {
925
- const e = this.segments.flatMap((i) => i instanceof y ? [i.firstPoint] : [i.firstPoint, i.paramPoint(0.5)]), s = e.map((i, o) => {
926
- const r = e[(o + 1) % e.length];
927
- return (r[0] - i[0]) * (r[1] + i[1]);
925
+ const e = this.segments.flatMap((i) => i instanceof b ? [i.firstPoint] : [i.firstPoint, i.paramPoint(0.5)]), s = e.map((i, o) => {
926
+ const l = e[(o + 1) % e.length];
927
+ return (l[0] - i[0]) * (l[1] + i[1]);
928
928
  }).reduce((i, o) => i + o, 0);
929
929
  this._clockwise = s > 0;
930
930
  }
931
931
  return this._clockwise;
932
932
  }
933
933
  clone() {
934
- return new O(
934
+ return new _(
935
935
  this.segments.map((e) => e.clone()),
936
936
  { ignoreChecks: !0 }
937
937
  );
938
938
  }
939
939
  reverse() {
940
940
  const e = this.segments.map((s) => s.reverse());
941
- return e.reverse(), new O(e, { ignoreChecks: !0 });
941
+ return e.reverse(), new _(e, { ignoreChecks: !0 });
942
942
  }
943
943
  transform(e) {
944
- return new O(
944
+ return new _(
945
945
  this.segments.map((s) => s.transform(e)),
946
946
  { ignoreChecks: !0 }
947
947
  );
948
948
  }
949
- contains(e) {
950
- return this.onStroke(e) || !this.boundingBox.contains(e) ? !1 : this.segments.reduce((i, o) => i + Vn(e, o), 0) % 2 === 1;
949
+ contains(e, { strokeIsInside: s = !1 } = {}) {
950
+ return this.onStroke(e) ? s : this.boundingBox.contains(e) ? this.segments.reduce((o, l) => o + Nn(e, l), 0) % 2 === 1 : !1;
951
951
  }
952
952
  simplify() {
953
- const e = jt(this);
954
- return e ? new O(e, { ignoreChecks: !0 }) : this;
953
+ const e = Ht(this);
954
+ return e ? new _(e, { ignoreChecks: !0 }) : this;
955
955
  }
956
956
  }
957
- function Nn(t) {
958
- if (Ut(t, "Loop"), !g(t[0].firstPoint, t[t.length - 1].lastPoint))
957
+ function Un(t) {
958
+ if (jt(t, "Loop"), !P(t[0].firstPoint, t[t.length - 1].lastPoint))
959
959
  throw new Error("Loop segment must be closed");
960
960
  }
961
- const Un = [
962
- y,
961
+ const jn = [
962
+ b,
963
963
  S,
964
964
  M,
965
- A,
966
- I
965
+ I,
966
+ A
967
967
  ];
968
- function jn(t) {
969
- return Un.some((n) => t instanceof n);
968
+ function Hn(t) {
969
+ return jn.some((n) => t instanceof n);
970
970
  }
971
- function Ht(t) {
972
- if (t instanceof y)
971
+ function $t(t) {
972
+ if (t instanceof b)
973
973
  return {
974
974
  type: t.segmentType,
975
975
  firstPoint: t.firstPoint,
@@ -994,14 +994,14 @@ function Ht(t) {
994
994
  minorRadius: t.minorRadius,
995
995
  tiltAngle: t.tiltAngle
996
996
  };
997
- if (t instanceof A)
997
+ if (t instanceof I)
998
998
  return {
999
999
  type: t.segmentType,
1000
1000
  firstPoint: t.firstPoint,
1001
1001
  lastPoint: t.lastPoint,
1002
1002
  controlPoint: t.controlPoint
1003
1003
  };
1004
- if (t instanceof I)
1004
+ if (t instanceof A)
1005
1005
  return {
1006
1006
  type: t.segmentType,
1007
1007
  firstPoint: t.firstPoint,
@@ -1011,37 +1011,37 @@ function Ht(t) {
1011
1011
  };
1012
1012
  throw new Error("Unknown segment type");
1013
1013
  }
1014
- function it(t) {
1014
+ function ot(t) {
1015
1015
  return {
1016
1016
  type: "LOOP",
1017
- segments: t.segments.map(Ht)
1017
+ segments: t.segments.map($t)
1018
1018
  };
1019
1019
  }
1020
- function $t(t) {
1020
+ function Yt(t) {
1021
1021
  return {
1022
1022
  type: "FIGURE",
1023
- contour: it(t.contour),
1024
- holes: t.holes.map(it)
1023
+ contour: ot(t.contour),
1024
+ holes: t.holes.map(ot)
1025
1025
  };
1026
1026
  }
1027
- function Hn(t) {
1027
+ function $n(t) {
1028
1028
  return {
1029
1029
  type: "DIAGRAM",
1030
- figures: t.figures.map($t)
1030
+ figures: t.figures.map(Yt)
1031
1031
  };
1032
1032
  }
1033
- function Mt(t) {
1034
- if (t instanceof _)
1035
- return Hn(t);
1033
+ function It(t) {
1034
+ if (t instanceof O)
1035
+ return $n(t);
1036
1036
  if (t instanceof v)
1037
+ return Yt(t);
1038
+ if (t instanceof _)
1039
+ return ot(t);
1040
+ if (Hn(t))
1037
1041
  return $t(t);
1038
- if (t instanceof O)
1039
- return it(t);
1040
- if (jn(t))
1041
- return Ht(t);
1042
1042
  throw new Error("Unknown shape type");
1043
1043
  }
1044
- class $n {
1044
+ class Yn {
1045
1045
  constructor() {
1046
1046
  this.ids = [], this.values = [], this.length = 0;
1047
1047
  }
@@ -1064,12 +1064,12 @@ class $n {
1064
1064
  const e = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], i = this.length >> 1;
1065
1065
  let o = 0;
1066
1066
  for (; o < i; ) {
1067
- let r = (o << 1) + 1;
1068
- const l = r + 1;
1069
- let c = this.ids[r], a = this.values[r];
1070
- const f = this.values[l];
1071
- if (l < this.length && f < a && (r = l, c = this.ids[l], a = f), a >= s) break;
1072
- this.ids[o] = c, this.values[o] = a, o = r;
1067
+ let l = (o << 1) + 1;
1068
+ const r = l + 1;
1069
+ let u = this.ids[l], a = this.values[l];
1070
+ const f = this.values[r];
1071
+ if (r < this.length && f < a && (l = r, u = this.ids[r], a = f), a >= s) break;
1072
+ this.ids[o] = u, this.values[o] = a, o = l;
1073
1073
  }
1074
1074
  this.ids[o] = e, this.values[o] = s;
1075
1075
  }
@@ -1087,8 +1087,8 @@ class $n {
1087
1087
  this.ids.length = this.values.length = this.length;
1088
1088
  }
1089
1089
  }
1090
- const At = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array], nt = 3;
1091
- class at {
1090
+ const At = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array], et = 3;
1091
+ class ft {
1092
1092
  /**
1093
1093
  * Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
1094
1094
  * @param {ArrayBuffer | SharedArrayBuffer} data
@@ -1104,13 +1104,13 @@ class at {
1104
1104
  if (s !== 251)
1105
1105
  throw new Error("Data does not appear to be in a Flatbush format.");
1106
1106
  const o = i >> 4;
1107
- if (o !== nt)
1108
- throw new Error(`Got v${o} data when expected v${nt}.`);
1109
- const r = At[i & 15];
1110
- if (!r)
1107
+ if (o !== et)
1108
+ throw new Error(`Got v${o} data when expected v${et}.`);
1109
+ const l = At[i & 15];
1110
+ if (!l)
1111
1111
  throw new Error("Unrecognized array type.");
1112
- const [l] = new Uint16Array(n, e + 2, 1), [c] = new Uint32Array(n, e + 4, 1);
1113
- return new at(c, l, r, void 0, n, e);
1112
+ const [r] = new Uint16Array(n, e + 2, 1), [u] = new Uint32Array(n, e + 4, 1);
1113
+ return new ft(u, r, l, void 0, n, e);
1114
1114
  }
1115
1115
  /**
1116
1116
  * Create a Flatbush index that will hold a given number of items.
@@ -1121,20 +1121,20 @@ class at {
1121
1121
  * @param {ArrayBuffer | SharedArrayBuffer} [data] (Only used internally)
1122
1122
  * @param {number} [byteOffset=0] (Only used internally)
1123
1123
  */
1124
- constructor(n, e = 16, s = Float64Array, i = ArrayBuffer, o, r = 0) {
1124
+ constructor(n, e = 16, s = Float64Array, i = ArrayBuffer, o, l = 0) {
1125
1125
  if (n === void 0) throw new Error("Missing required argument: numItems.");
1126
1126
  if (isNaN(n) || n <= 0) throw new Error(`Unexpected numItems value: ${n}.`);
1127
- this.numItems = +n, this.nodeSize = Math.min(Math.max(+e, 2), 65535), this.byteOffset = r;
1128
- let l = n, c = l;
1129
- this._levelBounds = [l * 4];
1127
+ this.numItems = +n, this.nodeSize = Math.min(Math.max(+e, 2), 65535), this.byteOffset = l;
1128
+ let r = n, u = r;
1129
+ this._levelBounds = [r * 4];
1130
1130
  do
1131
- l = Math.ceil(l / this.nodeSize), c += l, this._levelBounds.push(c * 4);
1132
- while (l !== 1);
1133
- this.ArrayType = s, this.IndexArrayType = c < 16384 ? Uint16Array : Uint32Array;
1134
- const a = At.indexOf(this.ArrayType), f = c * 4 * this.ArrayType.BYTES_PER_ELEMENT;
1131
+ r = Math.ceil(r / this.nodeSize), u += r, this._levelBounds.push(u * 4);
1132
+ while (r !== 1);
1133
+ this.ArrayType = s, this.IndexArrayType = u < 16384 ? Uint16Array : Uint32Array;
1134
+ const a = At.indexOf(this.ArrayType), f = u * 4 * this.ArrayType.BYTES_PER_ELEMENT;
1135
1135
  if (a < 0)
1136
1136
  throw new Error(`Unexpected typed array class: ${s}.`);
1137
- o && o.byteLength !== void 0 && !o.buffer ? (this.data = o, this._boxes = new this.ArrayType(this.data, r + 8, c * 4), this._indices = new this.IndexArrayType(this.data, r + 8 + f, c), this._pos = c * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1]) : (this.data = new i(8 + f + c * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, c * 4), this._indices = new this.IndexArrayType(this.data, 8 + f, c), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(this.data, 0, 2).set([251, (nt << 4) + a]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = n), this._queue = new $n();
1137
+ o && o.byteLength !== void 0 && !o.buffer ? (this.data = o, this._boxes = new this.ArrayType(this.data, l + 8, u * 4), this._indices = new this.IndexArrayType(this.data, l + 8 + f, u), this._pos = u * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1]) : (this.data = new i(8 + f + u * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, u * 4), this._indices = new this.IndexArrayType(this.data, 8 + f, u), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(this.data, 0, 2).set([251, (et << 4) + a]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = n), this._queue = new Yn();
1138
1138
  }
1139
1139
  /**
1140
1140
  * Add a given rectangle to the index.
@@ -1145,8 +1145,8 @@ class at {
1145
1145
  * @returns {number} A zero-based, incremental number that represents the newly added rectangle.
1146
1146
  */
1147
1147
  add(n, e, s = n, i = e) {
1148
- const o = this._pos >> 2, r = this._boxes;
1149
- return this._indices[o] = o, r[this._pos++] = n, r[this._pos++] = e, r[this._pos++] = s, r[this._pos++] = i, n < this.minX && (this.minX = n), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), o;
1148
+ const o = this._pos >> 2, l = this._boxes;
1149
+ return this._indices[o] = o, l[this._pos++] = n, l[this._pos++] = e, l[this._pos++] = s, l[this._pos++] = i, n < this.minX && (this.minX = n), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), o;
1150
1150
  }
1151
1151
  /** Perform indexing of the added rectangles. */
1152
1152
  finish() {
@@ -1158,19 +1158,19 @@ class at {
1158
1158
  return;
1159
1159
  }
1160
1160
  const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), o = 65535;
1161
- for (let r = 0, l = 0; r < this.numItems; r++) {
1162
- const c = n[l++], a = n[l++], f = n[l++], u = n[l++], h = Math.floor(o * ((c + f) / 2 - this.minX) / e), p = Math.floor(o * ((a + u) / 2 - this.minY) / s);
1163
- i[r] = Xn(h, p);
1161
+ for (let l = 0, r = 0; l < this.numItems; l++) {
1162
+ const u = n[r++], a = n[r++], f = n[r++], c = n[r++], h = Math.floor(o * ((u + f) / 2 - this.minX) / e), p = Math.floor(o * ((a + c) / 2 - this.minY) / s);
1163
+ i[l] = Gn(h, p);
1164
1164
  }
1165
- ot(i, n, this._indices, 0, this.numItems - 1, this.nodeSize);
1166
- for (let r = 0, l = 0; r < this._levelBounds.length - 1; r++) {
1167
- const c = this._levelBounds[r];
1168
- for (; l < c; ) {
1169
- const a = l;
1170
- let f = n[l++], u = n[l++], h = n[l++], p = n[l++];
1171
- for (let d = 1; d < this.nodeSize && l < c; d++)
1172
- f = Math.min(f, n[l++]), u = Math.min(u, n[l++]), h = Math.max(h, n[l++]), p = Math.max(p, n[l++]);
1173
- this._indices[this._pos >> 2] = a, n[this._pos++] = f, n[this._pos++] = u, n[this._pos++] = h, n[this._pos++] = p;
1165
+ rt(i, n, this._indices, 0, this.numItems - 1, this.nodeSize);
1166
+ for (let l = 0, r = 0; l < this._levelBounds.length - 1; l++) {
1167
+ const u = this._levelBounds[l];
1168
+ for (; r < u; ) {
1169
+ const a = r;
1170
+ let f = n[r++], c = n[r++], h = n[r++], p = n[r++];
1171
+ for (let d = 1; d < this.nodeSize && r < u; d++)
1172
+ f = Math.min(f, n[r++]), c = Math.min(c, n[r++]), h = Math.max(h, n[r++]), p = Math.max(p, n[r++]);
1173
+ this._indices[this._pos >> 2] = a, n[this._pos++] = f, n[this._pos++] = c, n[this._pos++] = h, n[this._pos++] = p;
1174
1174
  }
1175
1175
  }
1176
1176
  }
@@ -1186,18 +1186,18 @@ class at {
1186
1186
  search(n, e, s, i, o) {
1187
1187
  if (this._pos !== this._boxes.length)
1188
1188
  throw new Error("Data not yet indexed - call index.finish().");
1189
- let r = this._boxes.length - 4;
1190
- const l = [], c = [];
1191
- for (; r !== void 0; ) {
1192
- const a = Math.min(r + this.nodeSize * 4, Et(r, this._levelBounds));
1193
- for (let f = r; f < a; f += 4) {
1189
+ let l = this._boxes.length - 4;
1190
+ const r = [], u = [];
1191
+ for (; l !== void 0; ) {
1192
+ const a = Math.min(l + this.nodeSize * 4, Ft(l, this._levelBounds));
1193
+ for (let f = l; f < a; f += 4) {
1194
1194
  if (s < this._boxes[f] || i < this._boxes[f + 1] || n > this._boxes[f + 2] || e > this._boxes[f + 3]) continue;
1195
- const u = this._indices[f >> 2] | 0;
1196
- r >= this.numItems * 4 ? l.push(u) : (o === void 0 || o(u)) && c.push(u);
1195
+ const c = this._indices[f >> 2] | 0;
1196
+ l >= this.numItems * 4 ? r.push(c) : (o === void 0 || o(c)) && u.push(c);
1197
1197
  }
1198
- r = l.pop();
1198
+ l = r.pop();
1199
1199
  }
1200
- return c;
1200
+ return u;
1201
1201
  }
1202
1202
  /**
1203
1203
  * Search items in order of distance from the given point.
@@ -1211,25 +1211,25 @@ class at {
1211
1211
  neighbors(n, e, s = 1 / 0, i = 1 / 0, o) {
1212
1212
  if (this._pos !== this._boxes.length)
1213
1213
  throw new Error("Data not yet indexed - call index.finish().");
1214
- let r = this._boxes.length - 4;
1215
- const l = this._queue, c = [], a = i * i;
1216
- t: for (; r !== void 0; ) {
1217
- const f = Math.min(r + this.nodeSize * 4, Et(r, this._levelBounds));
1218
- for (let u = r; u < f; u += 4) {
1219
- const h = this._indices[u >> 2] | 0, p = It(n, this._boxes[u], this._boxes[u + 2]), d = It(e, this._boxes[u + 1], this._boxes[u + 3]), m = p * p + d * d;
1220
- m > a || (r >= this.numItems * 4 ? l.push(h << 1, m) : (o === void 0 || o(h)) && l.push((h << 1) + 1, m));
1214
+ let l = this._boxes.length - 4;
1215
+ const r = this._queue, u = [], a = i * i;
1216
+ t: for (; l !== void 0; ) {
1217
+ const f = Math.min(l + this.nodeSize * 4, Ft(l, this._levelBounds));
1218
+ for (let c = l; c < f; c += 4) {
1219
+ const h = this._indices[c >> 2] | 0, p = Et(n, this._boxes[c], this._boxes[c + 2]), d = Et(e, this._boxes[c + 1], this._boxes[c + 3]), m = p * p + d * d;
1220
+ m > a || (l >= this.numItems * 4 ? r.push(h << 1, m) : (o === void 0 || o(h)) && r.push((h << 1) + 1, m));
1221
1221
  }
1222
- for (; l.length && l.peek() & 1; )
1223
- if (l.peekValue() > a || (c.push(l.pop() >> 1), c.length === s)) break t;
1224
- r = l.length ? l.pop() >> 1 : void 0;
1222
+ for (; r.length && r.peek() & 1; )
1223
+ if (r.peekValue() > a || (u.push(r.pop() >> 1), u.length === s)) break t;
1224
+ l = r.length ? r.pop() >> 1 : void 0;
1225
1225
  }
1226
- return l.clear(), c;
1226
+ return r.clear(), u;
1227
1227
  }
1228
1228
  }
1229
- function It(t, n, e) {
1229
+ function Et(t, n, e) {
1230
1230
  return t < n ? n - t : t <= e ? 0 : t - e;
1231
1231
  }
1232
- function Et(t, n) {
1232
+ function Ft(t, n) {
1233
1233
  let e = 0, s = n.length - 1;
1234
1234
  for (; e < s; ) {
1235
1235
  const i = e + s >> 1;
@@ -1237,79 +1237,79 @@ function Et(t, n) {
1237
1237
  }
1238
1238
  return n[e];
1239
1239
  }
1240
- function ot(t, n, e, s, i, o) {
1240
+ function rt(t, n, e, s, i, o) {
1241
1241
  if (Math.floor(s / o) >= Math.floor(i / o)) return;
1242
- const r = t[s + i >> 1];
1243
- let l = s - 1, c = i + 1;
1242
+ const l = t[s + i >> 1];
1243
+ let r = s - 1, u = i + 1;
1244
1244
  for (; ; ) {
1245
1245
  do
1246
- l++;
1247
- while (t[l] < r);
1246
+ r++;
1247
+ while (t[r] < l);
1248
1248
  do
1249
- c--;
1250
- while (t[c] > r);
1251
- if (l >= c) break;
1252
- Yn(t, n, e, l, c);
1249
+ u--;
1250
+ while (t[u] > l);
1251
+ if (r >= u) break;
1252
+ Xn(t, n, e, r, u);
1253
1253
  }
1254
- ot(t, n, e, s, c, o), ot(t, n, e, c + 1, i, o);
1254
+ rt(t, n, e, s, u, o), rt(t, n, e, u + 1, i, o);
1255
1255
  }
1256
- function Yn(t, n, e, s, i) {
1256
+ function Xn(t, n, e, s, i) {
1257
1257
  const o = t[s];
1258
1258
  t[s] = t[i], t[i] = o;
1259
- const r = 4 * s, l = 4 * i, c = n[r], a = n[r + 1], f = n[r + 2], u = n[r + 3];
1260
- n[r] = n[l], n[r + 1] = n[l + 1], n[r + 2] = n[l + 2], n[r + 3] = n[l + 3], n[l] = c, n[l + 1] = a, n[l + 2] = f, n[l + 3] = u;
1259
+ const l = 4 * s, r = 4 * i, u = n[l], a = n[l + 1], f = n[l + 2], c = n[l + 3];
1260
+ n[l] = n[r], n[l + 1] = n[r + 1], n[l + 2] = n[r + 2], n[l + 3] = n[r + 3], n[r] = u, n[r + 1] = a, n[r + 2] = f, n[r + 3] = c;
1261
1261
  const h = e[s];
1262
1262
  e[s] = e[i], e[i] = h;
1263
1263
  }
1264
- function Xn(t, n) {
1265
- let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n), o = t & (n ^ 65535), r = e | s >> 1, l = e >> 1 ^ e, c = i >> 1 ^ s & o >> 1 ^ i, a = e & i >> 1 ^ o >> 1 ^ o;
1266
- e = r, s = l, i = c, o = a, r = e & e >> 2 ^ s & s >> 2, l = e & s >> 2 ^ s & (e ^ s) >> 2, c ^= e & i >> 2 ^ s & o >> 2, a ^= s & i >> 2 ^ (e ^ s) & o >> 2, e = r, s = l, i = c, o = a, r = e & e >> 4 ^ s & s >> 4, l = e & s >> 4 ^ s & (e ^ s) >> 4, c ^= e & i >> 4 ^ s & o >> 4, a ^= s & i >> 4 ^ (e ^ s) & o >> 4, e = r, s = l, i = c, o = a, c ^= e & i >> 8 ^ s & o >> 8, a ^= s & i >> 8 ^ (e ^ s) & o >> 8, e = c ^ c >> 1, s = a ^ a >> 1;
1267
- let f = t ^ n, u = s | 65535 ^ (f | e);
1268
- return f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765, u = (u | u << 8) & 16711935, u = (u | u << 4) & 252645135, u = (u | u << 2) & 858993459, u = (u | u << 1) & 1431655765, (u << 1 | f) >>> 0;
1264
+ function Gn(t, n) {
1265
+ let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n), o = t & (n ^ 65535), l = e | s >> 1, r = e >> 1 ^ e, u = i >> 1 ^ s & o >> 1 ^ i, a = e & i >> 1 ^ o >> 1 ^ o;
1266
+ e = l, s = r, i = u, o = a, l = e & e >> 2 ^ s & s >> 2, r = e & s >> 2 ^ s & (e ^ s) >> 2, u ^= e & i >> 2 ^ s & o >> 2, a ^= s & i >> 2 ^ (e ^ s) & o >> 2, e = l, s = r, i = u, o = a, l = e & e >> 4 ^ s & s >> 4, r = e & s >> 4 ^ s & (e ^ s) >> 4, u ^= e & i >> 4 ^ s & o >> 4, a ^= s & i >> 4 ^ (e ^ s) & o >> 4, e = l, s = r, i = u, o = a, u ^= e & i >> 8 ^ s & o >> 8, a ^= s & i >> 8 ^ (e ^ s) & o >> 8, e = u ^ u >> 1, s = a ^ a >> 1;
1267
+ let f = t ^ n, c = s | 65535 ^ (f | e);
1268
+ return f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765, c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, (c << 1 | f) >>> 0;
1269
1269
  }
1270
- function Yt(t, n = 1e-7) {
1270
+ function Xt(t, n = 1e-7) {
1271
1271
  if (t.length === 0) return [];
1272
1272
  if (t.length === 1) return [t];
1273
- const e = new at(t.length);
1273
+ const e = new ft(t.length);
1274
1274
  t.forEach((o) => {
1275
- const [r, l] = o.firstPoint;
1276
- e.add(r - n, l - n, r + n, l + n);
1275
+ const [l, r] = o.firstPoint;
1276
+ e.add(l - n, r - n, l + n, r + n);
1277
1277
  }), e.finish();
1278
1278
  const s = [], i = /* @__PURE__ */ new Set();
1279
- return t.forEach((o, r) => {
1280
- if (i.has(r)) return;
1281
- const l = [o];
1282
- let c = r;
1283
- i.add(r);
1279
+ return t.forEach((o, l) => {
1280
+ if (i.has(l)) return;
1281
+ const r = [o];
1282
+ let u = l;
1283
+ i.add(l);
1284
1284
  let a = t.length;
1285
1285
  for (; ; ) {
1286
1286
  if (a-- < 0)
1287
1287
  throw new Error("Infinite loop detected");
1288
- const f = l[l.length - 1].lastPoint, [u, h] = f, p = e.search(
1289
- u - n,
1288
+ const f = r[r.length - 1].lastPoint, [c, h] = f, p = e.search(
1289
+ c - n,
1290
1290
  h - n,
1291
- u + n,
1291
+ c + n,
1292
1292
  h + n
1293
- ), d = (x) => Math.abs((c - x) % t.length), m = p.filter((x) => !i.has(x)).map((x) => [
1294
- t[x],
1295
- x,
1296
- d(x)
1297
- ]).sort(([, , x], [, , F]) => d(x) - d(F));
1293
+ ), d = (w) => Math.abs((u - w) % t.length), m = p.filter((w) => !i.has(w)).map((w) => [
1294
+ t[w],
1295
+ w,
1296
+ d(w)
1297
+ ]).sort(([, , w], [, , F]) => d(w) - d(F));
1298
1298
  if (m.length === 0) {
1299
- s.push(l);
1299
+ s.push(r);
1300
1300
  break;
1301
1301
  }
1302
- const [P, w] = m[0];
1303
- l.push(P), i.add(w), c = w;
1302
+ const [x, g] = m[0];
1303
+ r.push(x), i.add(g), u = g;
1304
1304
  }
1305
1305
  }), s;
1306
1306
  }
1307
- class v extends lt {
1307
+ class v extends ut {
1308
1308
  constructor(e, s = [], { ignoreChecks: i = !1 } = {}) {
1309
1309
  super();
1310
1310
  C(this, "contour");
1311
1311
  C(this, "holes");
1312
- i || Gn(e, s), this.contour = e, this.holes = s;
1312
+ i || Qn(e, s), this.contour = e, this.holes = s;
1313
1313
  }
1314
1314
  get boundingBox() {
1315
1315
  return this.contour.boundingBox;
@@ -1332,8 +1332,8 @@ class v extends lt {
1332
1332
  this.holes.map((s) => s.transform(e))
1333
1333
  );
1334
1334
  }
1335
- contains(e) {
1336
- return this.contour.contains(e) && !this.holes.some((s) => s.contains(e));
1335
+ contains(e, { strokeIsInside: s = !1 } = {}) {
1336
+ return this.contour.contains(e, { strokeIsInside: s }) && !this.holes.some((i) => i.contains(e, { strokeIsInside: s }));
1337
1337
  }
1338
1338
  intersects(e) {
1339
1339
  return this.allLoops.some(
@@ -1341,266 +1341,326 @@ class v extends lt {
1341
1341
  );
1342
1342
  }
1343
1343
  overlappingStrands(e) {
1344
- const s = e instanceof v ? e.allLoops : [e], i = this.allLoops.flatMap((o) => s.flatMap((r) => o.overlappingSegments(r)));
1345
- return Yt(i).map((o) => new B(o));
1344
+ const s = e instanceof v ? e.allLoops : [e], i = this.allLoops.flatMap((o) => s.flatMap((l) => o.overlappingSegments(l)));
1345
+ return Xt(i).map((o) => new B(o));
1346
1346
  }
1347
1347
  }
1348
- function Gn(t, n = []) {
1348
+ function Qn(t, n = []) {
1349
1349
  if (!t) throw new Error("Figure must have a contour");
1350
- for (const [e, s] of st([t, ...n]))
1350
+ for (const [e, s] of it([t, ...n]))
1351
1351
  if (e.intersects(s))
1352
1352
  throw new Error("Loops in a figure must not intersect");
1353
1353
  if (n.some(
1354
1354
  (e) => !t.contains(e.firstPoint) && !t.onStroke(e.firstPoint)
1355
1355
  ))
1356
1356
  throw new Error("Holes must be inside the contour");
1357
- for (const [e, s] of st(n))
1357
+ for (const [e, s] of it(n))
1358
1358
  if (e.contains(s.firstPoint))
1359
- throw console.error(Mt(e), Mt(s)), new Error("Holes must not be inside other holes");
1360
- }
1361
- const Qn = (t) => {
1362
- const n = t.map((i, o) => t.slice(o + 1).map((r, l) => [l + o + 1, r]).filter(([, r]) => i.boundingBox.overlaps(r.boundingBox)).map(([r]) => r)), e = [], s = Array(n.length);
1359
+ throw console.error(It(e), It(s)), new Error("Holes must not be inside other holes");
1360
+ }
1361
+ const J = (t, n, e = 1e-7) => Math.abs(t - n) <= e, Wn = (t, n) => {
1362
+ const e = t.boundingBox, s = n.boundingBox;
1363
+ return J(e.xMin, s.xMin) && J(e.yMin, s.yMin) && J(e.xMax, s.xMax) && J(e.yMax, s.yMax);
1364
+ }, Jn = (t, n) => {
1365
+ if (t.segmentsCount !== n.segmentsCount || !Wn(t, n)) return !1;
1366
+ const e = t.segments, s = n.segments, i = e.length, o = (l, r) => {
1367
+ for (let u = 0; u < i; u += 1) {
1368
+ const a = (l + r * u + i) % i;
1369
+ if (!e[u].isSame(s[a])) return !1;
1370
+ }
1371
+ return !0;
1372
+ };
1373
+ for (let l = 0; l < i; l += 1)
1374
+ if (e[0].isSame(s[l]) && (o(l, 1) || o(l, -1)))
1375
+ return !0;
1376
+ return !1;
1377
+ }, Kn = (t) => {
1378
+ const n = [];
1379
+ return t.forEach((e) => {
1380
+ n.some((s) => Jn(e, s)) || n.push(e);
1381
+ }), n;
1382
+ }, Zn = (t) => {
1383
+ const n = t.map((i, o) => t.slice(o + 1).map((l, r) => [r + o + 1, l]).filter(([, l]) => i.boundingBox.overlaps(l.boundingBox)).map(([l]) => l)), e = [], s = Array(n.length);
1363
1384
  return n.forEach((i, o) => {
1364
- let r = s[o];
1365
- r || (r = [], e.push(r)), r.push(t[o]), i.length && i.forEach((l) => {
1366
- s[l] = r;
1385
+ let l = s[o];
1386
+ l || (l = [], e.push(l)), l.push(t[o]), i.length && i.forEach((r) => {
1387
+ s[r] = l;
1367
1388
  });
1368
1389
  }), e;
1369
- }, Xt = (t) => t.map((n, e) => {
1370
- const i = n.segments[0].midPoint, o = t.filter((r, l) => e === l ? !1 : r.contains(i));
1390
+ }, Gt = (t) => t.map((n, e) => {
1391
+ const i = n.segments[0].midPoint, o = t.filter((l, r) => e === r ? !1 : l.contains(i));
1371
1392
  return {
1372
1393
  loop: n,
1373
1394
  isIn: o
1374
1395
  };
1375
- }), Wn = (t, n) => t.flatMap(({ loop: e }) => ft(
1396
+ }), te = (t, n) => t.flatMap(({ loop: e }) => ht(
1376
1397
  n.filter(
1377
1398
  ({ loop: s, isIn: i }) => s === e || i.indexOf(e) !== -1
1378
1399
  )
1379
- )), Jn = (t, n) => {
1380
- const e = n.filter(({ isIn: i }) => i.length <= 1), s = ft(
1381
- Xt(t.map(({ loop: i }) => i))
1400
+ )), ne = (t, n) => {
1401
+ const e = n.filter(({ isIn: i }) => i.length <= 1), s = ht(
1402
+ Gt(t.map(({ loop: i }) => i))
1382
1403
  );
1383
1404
  return [e, ...s];
1384
- }, ft = (t) => {
1405
+ }, ht = (t) => {
1385
1406
  if (!t.length) return [];
1386
1407
  const n = t.filter(({ isIn: s }) => !s.length), e = t.filter(({ isIn: s }) => s.length > 1);
1387
- return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ? Wn(n, t) : Jn(e, t);
1408
+ return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ? te(n, t) : ne(e, t);
1388
1409
  };
1389
1410
  function X(t) {
1390
- return Qn(t).map(Xt).flatMap(ft).map((e) => {
1391
- if (e.length === 1) return new v(e[0].loop);
1392
- e.sort((o, r) => o.isIn.length - r.isIn.length);
1393
- const [s, ...i] = e.map(({ loop: o }) => o);
1394
- return new v(s, i);
1411
+ const n = Kn(t);
1412
+ return Zn(n).map(Gt).flatMap(ht).map((s) => {
1413
+ if (s.length === 1) return new v(s[0].loop);
1414
+ s.sort((l, r) => l.isIn.length - r.isIn.length);
1415
+ const [i, ...o] = s.map(({ loop: l }) => l);
1416
+ return new v(i, o);
1395
1417
  });
1396
1418
  }
1397
- function Kn(t, n) {
1419
+ function ee(t, n) {
1398
1420
  const e = [];
1399
1421
  for (const s of t)
1400
1422
  for (const i of n)
1401
1423
  e.push([s, i]);
1402
1424
  return e;
1403
1425
  }
1404
- function* Ft(t, n, e) {
1405
- const s = (r) => n.some((l) => g(l, r.lastPoint)), i = (r) => e.some((l) => r.isSame(l));
1406
- let o = [];
1426
+ function* vt(t, n, e) {
1427
+ const s = (r) => n.some((u) => P(u, r.lastPoint)), i = (r, u) => r.segmentType !== u.segmentType || !u.isOnSegment(r.firstPoint) || !u.isOnSegment(r.lastPoint) ? !1 : r.segmentType !== "LINE" ? u.isOnSegment(r.midPoint) : !0, o = (r) => e.some((u) => r.isSame(u) || i(r, u));
1428
+ let l = [];
1407
1429
  for (const r of t)
1408
- s(r) ? (o.push(r), yield new B(o, { ignoreChecks: !0 }), o = []) : i(r) ? (o.length && (yield new B(o, { ignoreChecks: !0 }), o = []), yield new B([r], { ignoreChecks: !0 })) : o.push(r);
1409
- o.length && (yield new B(o, { ignoreChecks: !0 }));
1430
+ s(r) ? (l.push(r), yield new B(l, { ignoreChecks: !0 }), l = []) : o(r) ? (l.length && (yield new B(l, { ignoreChecks: !0 }), l = []), yield new B([r], { ignoreChecks: !0 })) : l.push(r);
1431
+ l.length && (yield new B(l, { ignoreChecks: !0 }));
1410
1432
  }
1411
- const vt = (t, n) => {
1412
- const e = t.findIndex((o) => g(n, o.firstPoint)), s = t.slice(0, e);
1433
+ const Bt = (t, n) => {
1434
+ const e = t.findIndex((o) => P(n, o.firstPoint)), s = t.slice(0, e);
1413
1435
  return t.slice(e).concat(s);
1414
- }, Bt = (t, n) => {
1436
+ }, kt = (t, n) => {
1415
1437
  let e = t;
1416
- const s = (l) => g(l.firstPoint, n.firstPoint) && g(l.lastPoint, n.lastPoint);
1438
+ const s = (r) => P(r.firstPoint, n.firstPoint) && P(r.lastPoint, n.lastPoint);
1417
1439
  let i = t.findIndex(s);
1418
1440
  if (i === -1) {
1419
- const l = t.map((c) => c.reverse());
1420
- if (l.reverse(), i = l.findIndex(s), i === -1)
1441
+ const r = t.map((u) => u.reverse());
1442
+ if (r.reverse(), i = r.findIndex(s), i === -1)
1421
1443
  throw console.error(
1422
- l.map((c) => c.repr),
1444
+ r.map((u) => u.repr),
1423
1445
  n.repr
1424
1446
  ), new Error("Failed to rotate to segment start");
1425
- e = l;
1447
+ e = r;
1426
1448
  }
1427
1449
  const o = e.slice(0, i);
1428
1450
  return e.slice(i).concat(o);
1429
1451
  };
1430
- function Zn(t, n, e) {
1452
+ function se(t, n, e) {
1431
1453
  return t.filter((s) => {
1432
- const i = n.filter((l) => g(l.firstPoint, s) || g(l.lastPoint, s));
1454
+ const i = n.filter((r) => P(r.firstPoint, s) || P(r.lastPoint, s));
1433
1455
  if (i.length % 2)
1434
1456
  throw new Error("Bug in the intersection algo on non crossing point");
1435
- const o = i.map((l) => e.contains(l.midPoint));
1436
- return !(o.every((l) => l) || !o.some((l) => l));
1457
+ const o = i.map((r) => e.contains(r.midPoint));
1458
+ return !(o.every((r) => r) || !o.some((r) => r));
1437
1459
  });
1438
1460
  }
1439
- function te(t, n, e) {
1440
- let s = [];
1441
- const i = [], o = new Array(t.segments.length).fill(0).map(() => []), r = new Array(n.segments.length).fill(0).map(() => []);
1442
- if (t.segments.forEach((h, p) => {
1443
- n.segments.forEach((d, m) => {
1444
- const { intersections: P, overlaps: w } = K(
1445
- h,
1446
- d,
1461
+ function ie(t, n, e, s = !1) {
1462
+ let i = [];
1463
+ const o = [], l = new Array(t.segments.length).fill(0).map(() => []), r = new Array(n.segments.length).fill(0).map(() => []);
1464
+ if (t.segments.forEach((p, d) => {
1465
+ n.segments.forEach((m, x) => {
1466
+ const { intersections: g, overlaps: w } = Z(
1467
+ p,
1468
+ m,
1447
1469
  e
1448
1470
  );
1449
- s.push(...P), o[p].push(...P), r[m].push(...P), i.push(...w);
1450
- const x = w.flatMap((F) => [
1451
- F.firstPoint,
1452
- F.lastPoint
1471
+ i.push(...g), l[d].push(...g), r[x].push(...g), o.push(...w);
1472
+ const F = w.flatMap((y) => [
1473
+ y.firstPoint,
1474
+ y.lastPoint
1453
1475
  ]);
1454
- s.push(...x), o[p].push(...x), r[m].push(...x);
1476
+ i.push(...F), l[d].push(...F), r[x].push(...F);
1455
1477
  });
1456
- }), s = U(s, e), !s.length || s.length === 1) return null;
1457
- const l = ([h, p]) => p.length ? h.splitAt(p) : [h];
1458
- let c = N([t.segments, o]).flatMap(l), a = N([n.segments, r]).flatMap(l);
1459
- if (s = Zn(
1460
- s,
1461
- c,
1478
+ }), i = U(i, e), !i.length || i.length === 1) return null;
1479
+ const u = ([p, d]) => d.length ? p.splitAt(d) : [p];
1480
+ let a = N([t.segments, l]).flatMap(u), f = N([n.segments, r]).flatMap(u);
1481
+ if (i = se(
1482
+ i,
1483
+ a,
1462
1484
  n
1463
- ), !s.length && !i.length) return null;
1464
- if (i.length) {
1465
- const h = i[0];
1466
- c = Bt(
1467
- c,
1468
- h
1469
- ), a = Bt(
1485
+ ), !i.length && !o.length) return null;
1486
+ if (o.length) {
1487
+ const p = o[0];
1488
+ a = kt(
1470
1489
  a,
1471
- h
1490
+ p
1491
+ ), f = kt(
1492
+ f,
1493
+ p
1472
1494
  );
1473
1495
  } else {
1474
- const h = s[0];
1475
- c = vt(c, h), a = vt(a, h);
1476
- }
1477
- let f = Array.from(
1478
- Ft(
1479
- c,
1480
- s,
1481
- i
1482
- )
1483
- ), u = Array.from(
1484
- Ft(
1496
+ const p = i[0];
1497
+ a = Bt(a, p), f = Bt(f, p);
1498
+ }
1499
+ let c = Array.from(
1500
+ vt(
1485
1501
  a,
1486
- s,
1487
- i
1502
+ i,
1503
+ o
1504
+ )
1505
+ ), h = Array.from(
1506
+ vt(
1507
+ f,
1508
+ i,
1509
+ o
1488
1510
  )
1489
1511
  );
1490
- return (!g(
1491
- u[0].lastPoint,
1492
- f[0].lastPoint
1493
- ) || i.length > 0 && u[0].segmentsCount !== 1) && (u = u.map((h) => h.reverse()).reverse(), g(u[0].lastPoint, f[0].lastPoint) || (f = f.map((h) => h.reverse()).reverse())), N([f, u]).map(([h, p]) => h.segmentsCount === 1 && i.some((d) => h.segments[0].isSame(d)) ? [h, "same"] : [h, p]);
1512
+ return (!P(
1513
+ h[0].lastPoint,
1514
+ c[0].lastPoint
1515
+ ) || o.length > 0 && h[0].segmentsCount !== 1) && (h = h.map((p) => p.reverse()).reverse(), P(h[0].lastPoint, c[0].lastPoint) || (c = c.map((p) => p.reverse()).reverse())), N([c, h]).map(([p, d]) => {
1516
+ if (s) {
1517
+ if (((x) => x.segments.every(
1518
+ (g) => o.some(
1519
+ (w) => g.isSame(w) || g.segmentType === w.segmentType && w.isOnSegment(g.firstPoint) && w.isOnSegment(g.lastPoint) && (g.segmentType === "LINE" || w.isOnSegment(g.midPoint))
1520
+ )
1521
+ ))(p))
1522
+ return [p, "same"];
1523
+ } else if (p.segmentsCount === 1 && o.some((m) => p.segments[0].isSame(m)))
1524
+ return [p, "same"];
1525
+ return [p, d];
1526
+ });
1494
1527
  }
1495
- function kt(t) {
1528
+ function Ot(t) {
1496
1529
  let n = t[0];
1497
1530
  for (const e of t.slice(1))
1498
1531
  n = n.extend(e);
1499
- if (!g(n.firstPoint, n.lastPoint))
1532
+ if (!P(n.firstPoint, n.lastPoint))
1500
1533
  throw console.error(
1501
- dt(n.firstPoint),
1502
- dt(n.lastPoint)
1534
+ mt(n.firstPoint),
1535
+ mt(n.lastPoint)
1503
1536
  ), new Error("Bug in the intersection algo on non closing strand");
1504
- return new O(n.segments);
1537
+ return new _(n.segments);
1505
1538
  }
1506
- function ne(t, n) {
1539
+ function oe(t, n) {
1507
1540
  const e = N([
1508
1541
  n.slice(0, -1),
1509
1542
  n.slice(1)
1510
- ]).map(([i, o]) => kt(t.slice(i, o)));
1543
+ ]).map(([i, o]) => Ot(t.slice(i, o)));
1511
1544
  let s = t.slice(
1512
1545
  n[n.length - 1]
1513
1546
  );
1514
- return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(kt(s)), e;
1547
+ return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(Ot(s)), e;
1515
1548
  }
1516
- function ee(t) {
1549
+ function re(t) {
1517
1550
  if (!t.length) return [];
1518
1551
  const n = t.map((i) => i.firstPoint);
1519
1552
  let e = t.map((i) => i.lastPoint);
1520
1553
  e = e.slice(-1).concat(e.slice(0, -1));
1521
1554
  const s = N([n, e]).flatMap(
1522
- ([i, o], r) => g(i, o) ? [] : r
1555
+ ([i, o], l) => P(i, o) ? [] : l
1523
1556
  );
1524
1557
  try {
1525
- return ne(t, s);
1558
+ return oe(t, s);
1526
1559
  } catch {
1527
- return Yt(t.flatMap((o) => o.segments)).filter((o) => o.length > 1).filter((o) => g(o[0].firstPoint, o.at(-1).lastPoint)).map((o) => new O(o));
1560
+ return Xt(t.flatMap((o) => o.segments)).filter((o) => o.length > 1).filter((o) => P(o[0].firstPoint, o.at(-1).lastPoint)).map((o) => new _(o));
1528
1561
  }
1529
1562
  }
1530
1563
  const _t = (t, n) => {
1531
1564
  if (t.length === 0) return [n];
1532
1565
  const e = t.at(-1);
1533
- return g(e.lastPoint, n.firstPoint) ? t.slice(0, -1).concat([e.extend(n)]) : g(e.lastPoint, n.lastPoint) ? t.slice(0, -1).concat([e.extend(n.reverse())]) : t.concat([n]);
1534
- }, se = (t, n) => t.length === 0 ? [n] : g(t[0].firstPoint, n.lastPoint) ? [n.extend(t[0])].concat(t.slice(1)) : [n].concat(t);
1535
- function ht(t, n, {
1566
+ return P(e.lastPoint, n.firstPoint) ? t.slice(0, -1).concat([e.extend(n)]) : P(e.lastPoint, n.lastPoint) ? t.slice(0, -1).concat([e.extend(n.reverse())]) : t.concat([n]);
1567
+ }, le = (t, n) => t.length === 0 ? [n] : P(t[0].firstPoint, n.lastPoint) ? [n.extend(t[0])].concat(t.slice(1)) : [n].concat(t);
1568
+ function pt(t, n, {
1536
1569
  firstInside: e,
1537
- secondInside: s
1570
+ secondInside: s,
1571
+ firstBoundaryInside: i = !1,
1572
+ secondBoundaryInside: o = !1
1538
1573
  }) {
1539
- const i = te(t, n);
1540
- if (!i) {
1541
- const c = t.segments[0].midPoint, a = n.contains(c), f = n.segments[0].midPoint, u = t.contains(f);
1574
+ const l = ie(
1575
+ t,
1576
+ n,
1577
+ void 0,
1578
+ i || o
1579
+ );
1580
+ if (!l) {
1581
+ const f = t.segments[0].midPoint, c = n.contains(f, {
1582
+ strokeIsInside: o
1583
+ }), h = n.segments[0].midPoint, p = t.contains(h, {
1584
+ strokeIsInside: i
1585
+ });
1542
1586
  return {
1543
1587
  identical: !1,
1544
- firstCurveInSecond: a,
1545
- secondCurveInFirst: u
1588
+ firstCurveInSecond: c,
1589
+ secondCurveInFirst: p
1546
1590
  };
1547
1591
  }
1548
- if (i.every(([, c]) => c === "same"))
1592
+ if (l.every(([, f]) => f === "same"))
1549
1593
  return { identical: !0 };
1550
- let o = null, r = null;
1551
- const l = i.flatMap(([c, a]) => {
1552
- let f = [], u = 0;
1553
- if (a === "same")
1554
- return r === 1 ? (r = 1, c) : r === 2 || r === 0 ? (r = null, []) : r === null ? (o ? o = o.extend(c) : o = c, []) : (console.error("weird situation"), []);
1555
- const h = c.segments[0].midPoint, p = n.contains(h);
1556
- (e === "keep" && p || e === "remove" && !p) && (u += 1, f = _t(f, c));
1557
- const d = a.segments[0].midPoint, m = t.contains(d);
1558
- if (s === "keep" && m || s === "remove" && !m) {
1559
- const P = a;
1560
- u += 1, u === 2 && f.length ? (f = _t(f, P), o = null) : f = [P];
1594
+ let r = null, u = null;
1595
+ const a = l.flatMap(([f, c]) => {
1596
+ let h = [], p = 0;
1597
+ if (c === "same")
1598
+ return u === 1 ? (u = 1, f) : u === 2 || u === 0 ? (u = null, []) : u === null ? (r ? r = r.extend(f) : r = f, []) : (console.error("weird situation"), []);
1599
+ const d = f.segments[0].midPoint, m = n.contains(d, {
1600
+ strokeIsInside: o
1601
+ });
1602
+ (e === "keep" && m || e === "remove" && !m) && (p += 1, h = _t(h, f));
1603
+ const x = c.segments[0].midPoint, g = t.contains(x, {
1604
+ strokeIsInside: i
1605
+ });
1606
+ if (s === "keep" && g || s === "remove" && !g) {
1607
+ const w = c;
1608
+ p += 1, p === 2 && h.length ? (h = _t(h, w), r = null) : h = [w];
1561
1609
  }
1562
- return r === null && u === 1 && o && (f = se(f, o)), u === 1 && (r = u, o = null), f.length ? f : (o = null, []);
1610
+ return u === null && p === 1 && r && (h = le(h, r)), p === 1 && (u = p, r = null), h.length ? h : (r = null, []);
1563
1611
  });
1564
- return ee(l);
1612
+ return re(a);
1565
1613
  }
1566
- const ie = (t, n) => {
1567
- const e = ht(t, n, {
1614
+ const ue = (t, n, e) => {
1615
+ const s = pt(t, n, {
1568
1616
  firstInside: "remove",
1569
- secondInside: "remove"
1617
+ secondInside: "remove",
1618
+ ...e
1570
1619
  });
1571
- return Array.isArray(e) ? e : e.identical ? [t] : e.firstCurveInSecond ? [n] : e.secondCurveInFirst ? [t] : [t, n];
1572
- }, Z = (t, n) => {
1573
- const e = ht(t, n, {
1620
+ return Array.isArray(s) ? s : s.identical ? [t] : s.firstCurveInSecond ? [n] : s.secondCurveInFirst ? [t] : [t, n];
1621
+ }, tt = (t, n, e) => {
1622
+ const s = pt(t, n, {
1574
1623
  firstInside: "remove",
1575
- secondInside: "keep"
1624
+ secondInside: "keep",
1625
+ ...e
1576
1626
  });
1577
- return Array.isArray(e) ? e : e.identical ? [] : e.firstCurveInSecond ? [] : e.secondCurveInFirst ? [t, n] : [t];
1578
- }, pt = (t, n) => {
1579
- const e = ht(t, n, {
1627
+ return Array.isArray(s) ? s : s.identical ? [] : s.firstCurveInSecond ? [] : s.secondCurveInFirst ? [t, n] : [t];
1628
+ }, dt = (t, n, e) => {
1629
+ const s = (e == null ? void 0 : e.firstBoundaryInside) ?? !1, i = (e == null ? void 0 : e.secondBoundaryInside) ?? !1, o = s || i, l = (u, a, f) => u.segments.every(
1630
+ (c) => a.contains(c.midPoint, { strokeIsInside: f })
1631
+ );
1632
+ if (o) {
1633
+ if (l(t, n, i))
1634
+ return [t];
1635
+ if (l(n, t, s))
1636
+ return [n];
1637
+ }
1638
+ const r = pt(t, n, {
1580
1639
  firstInside: "keep",
1581
- secondInside: "keep"
1640
+ secondInside: "keep",
1641
+ ...e
1582
1642
  });
1583
- return Array.isArray(e) ? e : e.identical ? [t] : e.firstCurveInSecond ? [t] : e.secondCurveInFirst ? [n] : [];
1643
+ return Array.isArray(r) ? r : r.identical ? [t] : r.firstCurveInSecond ? [t] : r.secondCurveInFirst ? [n] : [];
1584
1644
  };
1585
- function oe(t) {
1645
+ function ce(t) {
1586
1646
  const n = /* @__PURE__ */ new Map(), e = [];
1587
1647
  return t.forEach((s, i) => {
1588
1648
  let o;
1589
- n.has(i) ? o = n.get(i) : (o = { current: [s], fusedWith: /* @__PURE__ */ new Set([i]) }, e.push(o)), t.slice(i + 1).forEach((r, l) => {
1590
- const c = o.current, a = i + l + 1;
1649
+ n.has(i) ? o = n.get(i) : (o = { current: [s], fusedWith: /* @__PURE__ */ new Set([i]) }, e.push(o)), t.slice(i + 1).forEach((l, r) => {
1650
+ const u = o.current, a = i + r + 1;
1591
1651
  if (o.fusedWith.has(a)) return;
1592
- let f = [r], u = !1;
1593
- if (n.has(a) && (f = n.get(a).current, u = !0), !c.some(
1652
+ let f = [l], c = !1;
1653
+ if (n.has(a) && (f = n.get(a).current, c = !0), !u.some(
1594
1654
  (d) => f.some((m) => d.intersects(m))
1595
1655
  )) return;
1596
1656
  let p;
1597
- c.length > 1 || f.length > 1 ? p = G(c, f) : p = Gt(c[0], f[0]), o.fusedWith.add(a), o.current = p, u || n.set(a, o);
1657
+ u.length > 1 || f.length > 1 ? p = G(u, f) : p = Qt(u[0], f[0]), o.fusedWith.add(a), o.current = p, c || n.set(a, o);
1598
1658
  });
1599
1659
  }), e.flatMap(({ current: s }) => s);
1600
1660
  }
1601
- function Gt(t, n) {
1602
- const e = ie(t.contour, n.contour), s = n.holes.flatMap((r) => Z(r, t.contour)), i = t.holes.flatMap((r) => Z(r, n.contour)), o = Kn(t.holes, n.holes).flatMap(
1603
- ([r, l]) => pt(r, l)
1661
+ function Qt(t, n) {
1662
+ const e = ue(t.contour, n.contour), s = n.holes.flatMap((l) => tt(l, t.contour)), i = t.holes.flatMap((l) => tt(l, n.contour)), o = ee(t.holes, n.holes).flatMap(
1663
+ ([l, r]) => dt(l, r)
1604
1664
  );
1605
1665
  return X([
1606
1666
  ...e,
@@ -1609,12 +1669,12 @@ function Gt(t, n) {
1609
1669
  ...o
1610
1670
  ]);
1611
1671
  }
1612
- function tt(t, n) {
1672
+ function nt(t, n) {
1613
1673
  if (t.isFull && n.isFull)
1614
- return X(Z(t.contour, n.contour));
1674
+ return X(tt(t.contour, n.contour));
1615
1675
  if (t.isFull) {
1616
- const s = Z(t.contour, n.contour), i = n.holes.flatMap(
1617
- (o) => pt(o, t.contour)
1676
+ const s = tt(t.contour, n.contour), i = n.holes.flatMap(
1677
+ (o) => dt(o, t.contour, { firstBoundaryInside: !0 })
1618
1678
  );
1619
1679
  return X([...s, ...i]);
1620
1680
  } else if (n.isFull && !t.contour.intersects(n.contour))
@@ -1629,13 +1689,13 @@ function tt(t, n) {
1629
1689
  ]);
1630
1690
  } else
1631
1691
  return [t];
1632
- let e = tt(new v(t.contour), n);
1692
+ let e = nt(new v(t.contour), n);
1633
1693
  return t.holes.forEach((s) => {
1634
- e = e.flatMap((i) => tt(i, new v(s)));
1694
+ e = e.flatMap((i) => nt(i, new v(s)));
1635
1695
  }), e;
1636
1696
  }
1637
- function re(t, n) {
1638
- const e = pt(t.contour, n.contour);
1697
+ function ae(t, n) {
1698
+ const e = dt(t.contour, n.contour);
1639
1699
  if (!e.length) return [];
1640
1700
  let s = X(e);
1641
1701
  return s = Q(
@@ -1650,42 +1710,42 @@ function G(t, n) {
1650
1710
  if (!t.length) return n;
1651
1711
  if (!n.length) return t;
1652
1712
  if (t.length === 1 && n.length > 1 || n.length === 1 && t.length > 1)
1653
- return oe([...t, ...n]);
1713
+ return ce([...t, ...n]);
1654
1714
  if (t.length > 1 && n.length > 1) {
1655
1715
  let e = G([t[0]], n);
1656
1716
  return t.slice(1).forEach((s) => {
1657
1717
  e = G([s], e);
1658
1718
  }), e;
1659
1719
  }
1660
- return t.length === 1 && n.length === 1 ? Gt(t[0], n[0]) : [];
1720
+ return t.length === 1 && n.length === 1 ? Qt(t[0], n[0]) : [];
1661
1721
  }
1662
1722
  function Q(t, n) {
1663
1723
  if (!t.length) return [];
1664
1724
  if (!n.length) return t;
1665
1725
  if (t.length === 1 && n.length === 1)
1666
- return tt(t[0], n[0]);
1726
+ return nt(t[0], n[0]);
1667
1727
  if (t.length > 1)
1668
1728
  return t.flatMap((s) => Q([s], n));
1669
- let e = tt(t[0], n[0]);
1729
+ let e = nt(t[0], n[0]);
1670
1730
  return n.slice(1).forEach((s) => {
1671
1731
  e = Q(e, [s]);
1672
1732
  }), e;
1673
1733
  }
1674
- function rt(t, n) {
1675
- return !t.length || !n.length ? [] : t.length === 1 && n.length === 1 ? re(t[0], n[0]) : t.length > 1 ? t.flatMap((e) => rt([e], n)) : n.flatMap((e) => rt(t, [e]));
1734
+ function lt(t, n) {
1735
+ return !t.length || !n.length ? [] : t.length === 1 && n.length === 1 ? ae(t[0], n[0]) : t.length > 1 ? t.flatMap((e) => lt([e], n)) : n.flatMap((e) => lt(t, [e]));
1676
1736
  }
1677
- class _ extends lt {
1737
+ class O extends ut {
1678
1738
  constructor(e = [], { ignoreChecks: s = !1 } = {}) {
1679
1739
  super();
1680
1740
  C(this, "figures");
1681
1741
  C(this, "_boundingBox", null);
1682
- s || le(e), this.figures = e;
1742
+ s || fe(e), this.figures = e;
1683
1743
  }
1684
1744
  get isEmpty() {
1685
1745
  return this.figures.length === 0;
1686
1746
  }
1687
1747
  get boundingBox() {
1688
- if (this.isEmpty) return new hn();
1748
+ if (this.isEmpty) return new pn();
1689
1749
  if (this._boundingBox === null) {
1690
1750
  let e = this.figures[0].boundingBox;
1691
1751
  for (const s of this.figures.slice(1))
@@ -1695,13 +1755,15 @@ class _ extends lt {
1695
1755
  return this._boundingBox;
1696
1756
  }
1697
1757
  clone() {
1698
- return new _(this.figures.map((e) => e.clone()));
1758
+ return new O(this.figures.map((e) => e.clone()));
1699
1759
  }
1700
1760
  transform(e) {
1701
- return new _(this.figures.map((s) => s.transform(e)));
1761
+ return new O(this.figures.map((s) => s.transform(e)));
1702
1762
  }
1703
- contains(e) {
1704
- return this.figures.some((s) => s.contains(e));
1763
+ contains(e, { strokeIsInside: s = !1 } = {}) {
1764
+ return this.figures.some(
1765
+ (i) => i.contains(e, { strokeIsInside: s })
1766
+ );
1705
1767
  }
1706
1768
  intersects(e) {
1707
1769
  return this.figures.some(
@@ -1709,41 +1771,41 @@ class _ extends lt {
1709
1771
  );
1710
1772
  }
1711
1773
  overlappingStrands(e) {
1712
- return this.figures.flatMap((s) => e instanceof _ ? e.figures.flatMap(
1774
+ return this.figures.flatMap((s) => e instanceof O ? e.figures.flatMap(
1713
1775
  (i) => s.overlappingStrands(i)
1714
1776
  ) : s.overlappingStrands(e));
1715
1777
  }
1716
1778
  fuse(e) {
1717
- return new _(G(this.figures, e.figures));
1779
+ return new O(G(this.figures, e.figures));
1718
1780
  }
1719
1781
  cut(e) {
1720
- return new _(Q(this.figures, e.figures));
1782
+ return new O(Q(this.figures, e.figures));
1721
1783
  }
1722
1784
  intersect(e) {
1723
- return new _(rt(this.figures, e.figures));
1785
+ return new O(lt(this.figures, e.figures));
1724
1786
  }
1725
1787
  }
1726
- function le(t) {
1727
- for (const [n, e] of st(t))
1788
+ function fe(t) {
1789
+ for (const [n, e] of it(t))
1728
1790
  if (n.intersects(e))
1729
1791
  throw new Error("Diagram figures must not intersect");
1730
1792
  }
1731
1793
  export {
1732
- _ as D,
1794
+ O as D,
1733
1795
  v as F,
1734
- O as L,
1796
+ _ as L,
1735
1797
  B as S,
1736
- K as a,
1798
+ Z as a,
1737
1799
  G as b,
1738
1800
  Q as c,
1739
- qt as d,
1740
- Yt as e,
1741
- ae as f,
1742
- jn as g,
1743
- Mt as h,
1744
- rt as i,
1745
- J as l,
1746
- pn as p,
1747
- Ft as s
1801
+ Dt as d,
1802
+ Xt as e,
1803
+ de as f,
1804
+ Hn as g,
1805
+ It as h,
1806
+ lt as i,
1807
+ K as l,
1808
+ dn as p,
1809
+ vt as s
1748
1810
  };
1749
- //# sourceMappingURL=models-zEMLdtLw.js.map
1811
+ //# sourceMappingURL=models-DCkOI0hV.js.map