pantograph2d 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -658
- package/dist/QuadraticBezier-BKElJOgn.cjs +9 -0
- package/dist/QuadraticBezier-BKElJOgn.cjs.map +1 -0
- package/dist/QuadraticBezier-PcRS9HZK.js +4773 -0
- package/dist/QuadraticBezier-PcRS9HZK.js.map +1 -0
- package/dist/draw-L71G180-.cjs +2 -0
- package/dist/draw-L71G180-.cjs.map +1 -0
- package/dist/draw-N2ntigsw.js +417 -0
- package/dist/draw-N2ntigsw.js.map +1 -0
- package/dist/models-BXU-Gx3U.cjs +4 -0
- package/dist/models-BXU-Gx3U.cjs.map +1 -0
- package/dist/{Diagram-2450b2e6.js → models-BjaFYsN2.js} +278 -279
- package/dist/models-BjaFYsN2.js.map +1 -0
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.cjs.map +1 -1
- package/dist/pantograph/drawShape.js +12 -14
- package/dist/pantograph/drawShape.js.map +1 -1
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +2 -2
- package/dist/pantograph/svg.cjs +1 -1
- package/dist/pantograph/svg.js +5 -6
- package/dist/pantograph/svg.js.map +1 -1
- package/dist/pantograph.cjs +2 -2
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +432 -400
- package/dist/pantograph.js.map +1 -1
- package/dist/{wrapSVG-02b823ac.cjs → svg-ZTvNxsWu.cjs} +2 -2
- package/dist/svg-ZTvNxsWu.cjs.map +1 -0
- package/dist/{wrapSVG-0ec8a111.js → svg-hNHYuj_r.js} +2 -2
- package/dist/svg-hNHYuj_r.js.map +1 -0
- package/dist/types/examples/importSVG.d.ts +4 -0
- package/dist/{algorithms → types/src/algorithms}/boolean/figureBooleans.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/boolean/loopBooleans.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/boolean/strandBoolean.d.ts +4 -4
- package/dist/{algorithms → types/src/algorithms}/boolean/strandsBetweenIntersections.d.ts +3 -3
- package/dist/types/src/algorithms/conversions/bezierToArcs.d.ts +7 -0
- package/dist/types/src/algorithms/conversions/bezierToSafeBezier.d.ts +12 -0
- package/dist/types/src/algorithms/conversions/ellipseToArcs.d.ts +0 -0
- package/dist/types/src/algorithms/conversions/ellipseToBezier.d.ts +3 -0
- package/dist/types/src/algorithms/conversions/helpers.d.ts +13 -0
- package/dist/{algorithms → types/src/algorithms}/distances/arcArcDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/distances/genericDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/distances/index.d.ts +1 -1
- package/dist/types/src/algorithms/distances/lineArcDistance.d.ts +3 -0
- package/dist/{algorithms → types/src/algorithms}/distances/lineLineDistance.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/filletSegments.d.ts +1 -1
- package/dist/{algorithms → types/src/algorithms}/intersections/arcArcIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/arcEllipseArcIntersection.d.ts +3 -0
- package/dist/types/src/algorithms/intersections/arcsCubicBezierIntersection.d.ts +5 -0
- package/dist/types/src/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +5 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/bezierClip.d.ts +3 -3
- package/dist/{algorithms → types/src/algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +2 -2
- package/dist/{algorithms → types/src/algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
- package/dist/types/src/algorithms/intersections/fullLinesIntersection.d.ts +18 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/index.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/lineArcIntersection.d.ts +4 -0
- package/dist/types/src/algorithms/intersections/lineBezierIntersection.d.ts +5 -0
- package/dist/types/src/algorithms/intersections/lineEllipseArcIntersection.d.ts +4 -0
- package/dist/{algorithms → types/src/algorithms}/intersections/lineLineIntersection.d.ts +4 -4
- package/dist/{algorithms → types/src/algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/rayIntersections.d.ts +3 -0
- package/dist/{algorithms → types/src/algorithms}/offsets/offsetFigure.d.ts +2 -2
- package/dist/types/src/algorithms/offsets/offsetSegment.d.ts +15 -0
- package/dist/types/src/algorithms/offsets/offsetStroke.d.ts +11 -0
- package/dist/{algorithms → types/src/algorithms}/organiseLoops.d.ts +2 -2
- package/dist/types/src/algorithms/simplify.d.ts +3 -0
- package/dist/types/src/algorithms/solvers/findZeroViaNewton.d.ts +1 -0
- package/dist/{algorithms → types/src/algorithms}/stitchSegments.d.ts +1 -1
- package/dist/types/src/api/drawShape.d.ts +2 -0
- package/dist/types/src/api/models.d.ts +1 -0
- package/dist/types/src/api/svg.d.ts +1 -0
- package/dist/{booleanOperations.d.ts → types/src/booleanOperations.d.ts} +5 -5
- package/dist/types/src/conversionOperations.d.ts +8 -0
- package/dist/{draw.d.ts → types/src/draw.d.ts} +4 -4
- package/dist/{drawShape → types/src/drawShape}/drawCircle.d.ts +1 -1
- package/dist/types/src/drawShape/drawEllipse.d.ts +2 -0
- package/dist/{drawShape → types/src/drawShape}/drawRect.d.ts +1 -1
- package/dist/types/src/drawShape/drawSVGPath.d.ts +2 -0
- package/dist/types/src/drawShape/index.d.ts +4 -0
- package/dist/{export → types/src/export}/json/exportJSON.d.ts +94 -94
- package/dist/{export → types/src/export}/json/jsonDiagram.d.ts +31 -31
- package/dist/{export → types/src/export}/json/jsonFigure.d.ts +31 -31
- package/dist/{export → types/src/export}/json/jsonLoop.d.ts +16 -16
- package/dist/{export → types/src/export}/json/jsonSegment.d.ts +16 -16
- package/dist/types/src/export/svg/api.d.ts +6 -0
- package/dist/{export → types/src/export}/svg/exportSVG.d.ts +6 -6
- package/dist/{export → types/src/export}/svg/svgDiagram.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgFigure.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgLoop.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgSegment.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/svgStrand.d.ts +1 -1
- package/dist/{export → types/src/export}/svg/wrapSVG.d.ts +1 -1
- package/dist/types/src/import/json/importJSON.d.ts +9 -0
- package/dist/{main.d.ts → types/src/main.d.ts} +7 -7
- package/dist/{models → types/src/models}/BoundingBox.d.ts +1 -1
- package/dist/{models → types/src/models}/Diagram.d.ts +7 -7
- package/dist/{models → types/src/models}/Figure.d.ts +7 -7
- package/dist/{models → types/src/models}/Loop.d.ts +4 -4
- package/dist/{models → types/src/models}/Strand.d.ts +2 -2
- package/dist/{models → types/src/models}/Stroke.d.ts +5 -5
- package/dist/{models → types/src/models}/TransformationMatrix.d.ts +1 -1
- package/dist/types/src/models/exports.d.ts +15 -0
- package/dist/types/src/models/segments/AbstractSegment.d.ts +25 -0
- package/dist/{models → types/src/models}/segments/Arc.d.ts +5 -4
- package/dist/{models → types/src/models}/segments/CubicBezier.d.ts +11 -4
- package/dist/{models → types/src/models}/segments/EllipseArc.d.ts +5 -5
- package/dist/{models → types/src/models}/segments/Line.d.ts +4 -4
- package/dist/{models → types/src/models}/segments/QuadraticBezier.d.ts +9 -4
- package/dist/{models → types/src/models}/segments/Segment.d.ts +4 -4
- package/dist/{models → types/src/models}/segments/utils/deCasteljau.d.ts +1 -1
- package/dist/types/src/models/segments/utils/isSegment.d.ts +8 -0
- package/dist/{models → types/src/models}/utils/Transformable.d.ts +2 -2
- package/dist/{offsetOperations.d.ts → types/src/offsetOperations.d.ts} +4 -4
- package/dist/types/src/operations.d.ts +2 -0
- package/dist/types/src/utils/applyMixins.d.ts +1 -0
- package/dist/types/src/utils/listOfFigures.d.ts +4 -0
- package/dist/types/src/utils/projectPointOnLine.d.ts +3 -0
- package/dist/{utils → types/src/utils}/removeDuplicatePoints.d.ts +1 -1
- package/dist/{vectorOperations.d.ts → types/src/vectorOperations.d.ts} +1 -1
- package/package.json +4 -4
- package/dist/Diagram-2450b2e6.js.map +0 -1
- package/dist/Diagram-57e17509.cjs +0 -4
- package/dist/Diagram-57e17509.cjs.map +0 -1
- package/dist/QuadraticBezier-e116a2d6.js +0 -3647
- package/dist/QuadraticBezier-e116a2d6.js.map +0 -1
- package/dist/QuadraticBezier-e3d7218b.cjs +0 -9
- package/dist/QuadraticBezier-e3d7218b.cjs.map +0 -1
- package/dist/algorithms/distances/lineArcDistance.d.ts +0 -3
- package/dist/algorithms/intersections/arcEllipseArcIntersection.d.ts +0 -3
- package/dist/algorithms/intersections/arcsCubicBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/ellipseEllipseIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/lineArcIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/lineBezierIntersection.d.ts +0 -5
- package/dist/algorithms/intersections/lineEllipseArcIntersection.d.ts +0 -4
- package/dist/algorithms/intersections/rayIntersections.d.ts +0 -3
- package/dist/algorithms/offsets/offsetSegment.d.ts +0 -12
- package/dist/algorithms/offsets/offsetStroke.d.ts +0 -9
- package/dist/algorithms/simplify.d.ts +0 -3
- package/dist/api/drawShape.d.ts +0 -2
- package/dist/api/models.d.ts +0 -1
- package/dist/api/svg.d.ts +0 -1
- package/dist/draw-27ac6dae.cjs +0 -2
- package/dist/draw-27ac6dae.cjs.map +0 -1
- package/dist/draw-c7b2705c.js +0 -344
- package/dist/draw-c7b2705c.js.map +0 -1
- package/dist/export/svg/api.d.ts +0 -6
- package/dist/import/json/importJSON.d.ts +0 -9
- package/dist/models/exports.d.ts +0 -15
- package/dist/models/segments/utils/isSegment.d.ts +0 -8
- package/dist/operations.d.ts +0 -2
- package/dist/utils/listOfFigures.d.ts +0 -4
- package/dist/utils/projectPointOnLine.d.ts +0 -3
- package/dist/wrapSVG-02b823ac.cjs.map +0 -1
- package/dist/wrapSVG-0ec8a111.js.map +0 -1
- /package/dist/{algorithms → types/src/algorithms}/optimisation/Brent.d.ts +0 -0
- /package/dist/{algorithms → types/src/algorithms}/optimisation/DiRect.d.ts +0 -0
- /package/dist/{algorithms → types/src/algorithms}/solvers/solvePolynomials.d.ts +0 -0
- /package/dist/{definitions.d.ts → types/src/definitions.d.ts} +0 -0
- /package/dist/{utils → types/src/utils}/allCombinations.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/allPairs.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/angularDistance.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/range.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/removeDuplicateValues.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/unitAngle.d.ts +0 -0
- /package/dist/{utils → types/src/utils}/zip.d.ts +0 -0
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
var tn = Object.defineProperty;
|
|
2
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) =>
|
|
4
|
-
import {
|
|
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-PcRS9HZK.js";
|
|
5
5
|
function pn(t, n) {
|
|
6
6
|
const e = k(n, t.firstPoint), s = en(e, t.V) / t.squareLength;
|
|
7
7
|
return t.paramPoint(s);
|
|
8
8
|
}
|
|
9
9
|
function J(t, n, e) {
|
|
10
10
|
const s = e || t.precision, i = pn(t, n.center), o = Ot(i, n.center);
|
|
11
|
-
if (o > n.radius + s)
|
|
12
|
-
return [];
|
|
11
|
+
if (o > n.radius + s) return [];
|
|
13
12
|
if (Math.abs(o - n.radius) < s) {
|
|
14
|
-
const
|
|
15
|
-
return t.isOnSegment(
|
|
13
|
+
const u = i;
|
|
14
|
+
return t.isOnSegment(u) && n.isOnSegment(u) ? [u] : [];
|
|
16
15
|
}
|
|
17
16
|
const r = [], l = Math.sqrt(
|
|
18
17
|
n.radius * n.radius - o * o
|
|
19
|
-
),
|
|
18
|
+
), c = t.tangentAtFirstPoint, a = q(i, V(c, l));
|
|
20
19
|
t.isOnSegment(a) && n.isOnSegment(a) && r.push(a);
|
|
21
|
-
const f = q(i, V(
|
|
20
|
+
const f = q(i, V(c, -l));
|
|
22
21
|
return t.isOnSegment(f) && n.isOnSegment(f) && r.push(f), r;
|
|
23
22
|
}
|
|
24
23
|
const dn = (t) => {
|
|
@@ -39,10 +38,8 @@ const dn = (t) => {
|
|
|
39
38
|
// We sort by the param value of the first arc. This means that the points
|
|
40
39
|
// will be sorted with the same orientation than arc1
|
|
41
40
|
).sort((s, i) => t.pointToParam(s) - t.pointToParam(i));
|
|
42
|
-
if (e.length === 0)
|
|
43
|
-
|
|
44
|
-
if (e.length === 1)
|
|
45
|
-
return [];
|
|
41
|
+
if (e.length === 0) return [];
|
|
42
|
+
if (e.length === 1) return [];
|
|
46
43
|
if (e.length === 2)
|
|
47
44
|
return t.isSame(dn(n)) ? [] : [new S(e[0], e[1], t.center, t.clockwise)];
|
|
48
45
|
if (e.length === 3) {
|
|
@@ -71,7 +68,7 @@ function qt(t, n, e = !1, s) {
|
|
|
71
68
|
return [];
|
|
72
69
|
if (o < i)
|
|
73
70
|
return l > i ? [] : e ? mn(t, n) : [];
|
|
74
|
-
const
|
|
71
|
+
const c = sn(k(n.center, t.center)), a = o > r - i;
|
|
75
72
|
if (
|
|
76
73
|
// circles are outside each other
|
|
77
74
|
a || // circles are inside each other
|
|
@@ -79,30 +76,29 @@ function qt(t, n, e = !1, s) {
|
|
|
79
76
|
) {
|
|
80
77
|
const w = a || t.radius > n.radius ? 1 : -1, x = q(
|
|
81
78
|
t.center,
|
|
82
|
-
V(
|
|
79
|
+
V(c, w * t.radius)
|
|
83
80
|
);
|
|
84
81
|
return t.isOnSegment(x) && n.isOnSegment(x) ? [x] : [];
|
|
85
82
|
}
|
|
86
|
-
const f = t.radius * t.radius / (2 * o) - n.radius * n.radius / (2 * o) + o / 2,
|
|
83
|
+
const f = t.radius * t.radius / (2 * o) - n.radius * n.radius / (2 * o) + o / 2, u = q(
|
|
87
84
|
t.center,
|
|
88
|
-
V(
|
|
85
|
+
V(c, f)
|
|
89
86
|
), h = Math.sqrt(
|
|
90
87
|
t.radius * t.radius - f * f
|
|
91
|
-
), p = Tt(
|
|
88
|
+
), p = Tt(c), d = q(u, V(p, h)), m = q(u, V(p, -h)), P = [];
|
|
92
89
|
return t.isOnSegment(d) && n.isOnSegment(d) && P.push(d), t.isOnSegment(m) && n.isOnSegment(m) && P.push(m), P;
|
|
93
90
|
}
|
|
94
91
|
function et(t, n, e = 1e-9) {
|
|
95
|
-
const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope, o = s.yIntercept, r = n.majorRadius * n.majorRadius, l = n.minorRadius * n.minorRadius,
|
|
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(
|
|
96
93
|
(x) => n.reverseEllipseReferenceFrameTransform.transform(x)
|
|
97
94
|
).filter((x) => t.isOnSegment(x) && n.isOnSegment(x));
|
|
98
95
|
if (!Number.isFinite(i)) {
|
|
99
96
|
const w = s.firstPoint[0];
|
|
100
|
-
if (Math.abs(w) - n.majorRadius > e)
|
|
101
|
-
return [];
|
|
97
|
+
if (Math.abs(w) - n.majorRadius > e) return [];
|
|
102
98
|
if (Math.abs(Math.abs(w) - n.majorRadius) < e)
|
|
103
|
-
return
|
|
104
|
-
const x = n.minorRadius * Math.sqrt(1 - w * w / r),
|
|
105
|
-
return
|
|
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]);
|
|
106
102
|
}
|
|
107
103
|
const h = r * a + l - f;
|
|
108
104
|
if (h < -e)
|
|
@@ -110,41 +106,41 @@ function et(t, n, e = 1e-9) {
|
|
|
110
106
|
const p = r * a + l;
|
|
111
107
|
if (Math.abs(h) < e) {
|
|
112
108
|
const w = -(r * i * o) / p, x = l * o / p;
|
|
113
|
-
return
|
|
109
|
+
return u([[w, x]]);
|
|
114
110
|
}
|
|
115
111
|
const d = Math.sqrt(h), m = [
|
|
116
|
-
-(r * i * o +
|
|
117
|
-
(l * o -
|
|
112
|
+
-(r * i * o + c * d) / p,
|
|
113
|
+
(l * o - c * i * d) / p
|
|
118
114
|
], P = [
|
|
119
|
-
-(r * i * o -
|
|
120
|
-
(l * o +
|
|
115
|
+
-(r * i * o - c * d) / p,
|
|
116
|
+
(l * o + c * i * d) / p
|
|
121
117
|
];
|
|
122
|
-
return
|
|
118
|
+
return u([m, P]);
|
|
123
119
|
}
|
|
124
120
|
function Dt(t, n) {
|
|
125
|
-
const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2, o = s.xy, r = s.y2, l = s.x,
|
|
126
|
-
z0: a * i * d * d + i * i * P * P - l * i * d * P +
|
|
127
|
-
z1: m * l * l *
|
|
128
|
-
z2: m * m * i * i + 2 * p * P * i * i -
|
|
129
|
-
z3: -2 * i *
|
|
130
|
-
z4: i * i * p * p - 2 * i * p *
|
|
131
|
-
},
|
|
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(
|
|
132
128
|
[w.z0, w.z1, w.z2, w.z3, w.z4],
|
|
133
129
|
e
|
|
134
130
|
).flatMap((b) => {
|
|
135
|
-
const R = i * h * b + i * d -
|
|
131
|
+
const R = i * h * b + i * d - u * o * b - u * l;
|
|
136
132
|
if (R)
|
|
137
|
-
return [[-(i * P + i * p * b * b -
|
|
138
|
-
const T = o * b + l, L = -T / (2 * i), j = r * b * b +
|
|
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;
|
|
139
135
|
if (Math.abs(z) < e)
|
|
140
136
|
return [[L, b]];
|
|
141
137
|
if (z > 0) {
|
|
142
|
-
const
|
|
143
|
-
return [[L +
|
|
138
|
+
const H = Math.sqrt(z);
|
|
139
|
+
return [[L + H, b], [L - H, b]];
|
|
144
140
|
}
|
|
145
141
|
return [];
|
|
146
142
|
});
|
|
147
|
-
return U(
|
|
143
|
+
return U(F, e);
|
|
148
144
|
}
|
|
149
145
|
function mt(t, n) {
|
|
150
146
|
return Dt(t, n).filter((s) => t.isOnSegment(s) && n.isOnSegment(s));
|
|
@@ -194,10 +190,8 @@ const gn = (t) => {
|
|
|
194
190
|
// We sort by the param value of the first arc. This means that the points
|
|
195
191
|
// will be sorted with the same orientation than arc1
|
|
196
192
|
).sort((i, o) => t.pointToParam(i) - t.pointToParam(o));
|
|
197
|
-
if (s.length === 0)
|
|
198
|
-
|
|
199
|
-
if (s.length === 1)
|
|
200
|
-
return [];
|
|
193
|
+
if (s.length === 0) return [];
|
|
194
|
+
if (s.length === 1) return [];
|
|
201
195
|
if (s.length === 2)
|
|
202
196
|
return t.isSame(gn(n)) ? [] : [e(s[0], s[1])];
|
|
203
197
|
if (s.length === 3) {
|
|
@@ -212,8 +206,8 @@ function wn(t, n, e = !1) {
|
|
|
212
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));
|
|
213
207
|
}
|
|
214
208
|
function gt(t, n) {
|
|
215
|
-
const [e, s] = t.firstPoint, [i, o] = t.lastPoint, r = new on().rotate(-Math.atan2(o - s, i - e))
|
|
216
|
-
return
|
|
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));
|
|
217
211
|
}
|
|
218
212
|
const xn = (t, n = 1e-9) => {
|
|
219
213
|
let e = t;
|
|
@@ -225,22 +219,22 @@ function Rt(t, n = 1e-9) {
|
|
|
225
219
|
);
|
|
226
220
|
}
|
|
227
221
|
const Sn = (t, n) => {
|
|
228
|
-
const [[e, s, i, o], [r, l,
|
|
229
|
-
return [z,
|
|
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];
|
|
230
224
|
};
|
|
231
225
|
function Pt(t, n) {
|
|
232
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);
|
|
233
227
|
return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
|
|
234
228
|
}
|
|
235
229
|
const yn = (t, n) => {
|
|
236
|
-
const [[e, s, i], [o, r, l]] = n.polynomialCoefficients,
|
|
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;
|
|
237
231
|
return [R, T, L, j, z];
|
|
238
232
|
};
|
|
239
233
|
function wt(t, n) {
|
|
240
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);
|
|
241
235
|
return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
|
|
242
236
|
}
|
|
243
|
-
function
|
|
237
|
+
function E(t, { firstPoint: n, lastPoint: e }, s = 1e-9) {
|
|
244
238
|
const i = k(e, n);
|
|
245
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);
|
|
246
240
|
}
|
|
@@ -254,7 +248,7 @@ class ct {
|
|
|
254
248
|
}
|
|
255
249
|
const bn = 3 / 4, Cn = 4 / 9;
|
|
256
250
|
function Mn(t) {
|
|
257
|
-
const n =
|
|
251
|
+
const n = E(t.firstControlPoint, t), e = E(t.lastControlPoint, t), s = n * e > 0 ? bn : Cn;
|
|
258
252
|
return new ct(
|
|
259
253
|
t.firstPoint,
|
|
260
254
|
t.lastPoint,
|
|
@@ -263,7 +257,7 @@ function Mn(t) {
|
|
|
263
257
|
);
|
|
264
258
|
}
|
|
265
259
|
function An(t) {
|
|
266
|
-
const n =
|
|
260
|
+
const n = E(t.controlPoint, t);
|
|
267
261
|
return new ct(
|
|
268
262
|
t.firstPoint,
|
|
269
263
|
t.lastPoint,
|
|
@@ -278,18 +272,18 @@ function In(t) {
|
|
|
278
272
|
return An(t);
|
|
279
273
|
throw new Error("Not implemented");
|
|
280
274
|
}
|
|
281
|
-
function
|
|
275
|
+
function En(t) {
|
|
282
276
|
const n = t.paramPoint(0.5), e = Tt(k(n, t.firstPoint)), s = q(n, e), i = {
|
|
283
277
|
firstPoint: n,
|
|
284
278
|
lastPoint: s
|
|
285
279
|
}, o = [
|
|
286
|
-
|
|
287
|
-
|
|
280
|
+
E(t.firstPoint, i),
|
|
281
|
+
E(t.lastPoint, i)
|
|
288
282
|
];
|
|
289
283
|
return t instanceof I ? o.push(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
) : t instanceof A && o.push(
|
|
284
|
+
E(t.firstControlPoint, i),
|
|
285
|
+
E(t.lastControlPoint, i)
|
|
286
|
+
) : t instanceof A && o.push(E(t.controlPoint, i)), new ct(
|
|
293
287
|
n,
|
|
294
288
|
s,
|
|
295
289
|
Math.min(...o),
|
|
@@ -314,7 +308,7 @@ function xt(t, n) {
|
|
|
314
308
|
}
|
|
315
309
|
return e;
|
|
316
310
|
}
|
|
317
|
-
class
|
|
311
|
+
class Y {
|
|
318
312
|
constructor(n, e) {
|
|
319
313
|
this.from = n, this.to = e;
|
|
320
314
|
}
|
|
@@ -325,19 +319,19 @@ class H {
|
|
|
325
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];
|
|
326
320
|
}
|
|
327
321
|
}
|
|
328
|
-
function
|
|
322
|
+
function Fn(t, n) {
|
|
329
323
|
if (t instanceof I)
|
|
330
324
|
return new Bn([
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
325
|
+
E(t.firstPoint, n),
|
|
326
|
+
E(t.firstControlPoint, n),
|
|
327
|
+
E(t.lastControlPoint, n),
|
|
328
|
+
E(t.lastPoint, n)
|
|
335
329
|
]);
|
|
336
330
|
if (t instanceof A)
|
|
337
331
|
return new vn([
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
332
|
+
E(t.firstPoint, n),
|
|
333
|
+
E(t.controlPoint, n),
|
|
334
|
+
E(t.lastPoint, n)
|
|
341
335
|
]);
|
|
342
336
|
throw new Error("Not implemented");
|
|
343
337
|
}
|
|
@@ -346,8 +340,8 @@ class vn {
|
|
|
346
340
|
C(this, "topHull", []);
|
|
347
341
|
C(this, "bottomHull", []);
|
|
348
342
|
this.distances = n;
|
|
349
|
-
const [e, s, i] = n, o = [0, e], r = [1 / 2, s], l = [1, i],
|
|
350
|
-
s - (
|
|
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]);
|
|
351
345
|
}
|
|
352
346
|
get startDistance() {
|
|
353
347
|
return this.distances[0];
|
|
@@ -361,13 +355,13 @@ class Bn {
|
|
|
361
355
|
C(this, "topHull", []);
|
|
362
356
|
C(this, "bottomHull", []);
|
|
363
357
|
this.distances = n;
|
|
364
|
-
const [e, s, i, o] = n, r = [0, e], l = [1 / 3, s],
|
|
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);
|
|
365
359
|
let d = null, m = null;
|
|
366
360
|
if (h * p < 0)
|
|
367
|
-
d = [r, l, a], m = [r,
|
|
361
|
+
d = [r, l, a], m = [r, c, a];
|
|
368
362
|
else {
|
|
369
363
|
const w = h / p;
|
|
370
|
-
w >= 2 ? (d = [r, l, a], m = [r, a]) : w <= 0.5 ? (d = [r,
|
|
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]);
|
|
371
365
|
}
|
|
372
366
|
h < 0 && ([d, m] = [m, d]), this.topHull = d, this.bottomHull = m;
|
|
373
367
|
}
|
|
@@ -379,7 +373,7 @@ class Bn {
|
|
|
379
373
|
}
|
|
380
374
|
}
|
|
381
375
|
function St(t, n) {
|
|
382
|
-
const e =
|
|
376
|
+
const e = Fn(n, t), s = xt(
|
|
383
377
|
e.topHull,
|
|
384
378
|
t.negativeThickness
|
|
385
379
|
), i = xt(
|
|
@@ -387,21 +381,21 @@ function St(t, n) {
|
|
|
387
381
|
t.positiveThickness
|
|
388
382
|
), o = e.endDistance >= t.negativeThickness && e.endDistance <= t.positiveThickness;
|
|
389
383
|
if (!s.length && !i.length)
|
|
390
|
-
return o ? new
|
|
384
|
+
return o ? new Y("start", "end") : null;
|
|
391
385
|
if (s.length === 1 && i.length === 1)
|
|
392
|
-
return new
|
|
386
|
+
return new Y(s[0], i[0]);
|
|
393
387
|
if (s.length === 2 && i.length === 2)
|
|
394
388
|
throw new Error(
|
|
395
389
|
"Bug in the clipping algorithm, unexpected number of crossing points"
|
|
396
390
|
);
|
|
397
391
|
const r = s.length ? s : i;
|
|
398
|
-
return r.length === 2 ? new
|
|
392
|
+
return r.length === 2 ? new Y(r[0], r[1]) : o ? new Y(r[0], "end") : new Y("start", r[0]);
|
|
399
393
|
}
|
|
400
394
|
function yt(t, n) {
|
|
401
395
|
const e = In(t), s = St(e, n);
|
|
402
396
|
if (!s)
|
|
403
397
|
return null;
|
|
404
|
-
const i =
|
|
398
|
+
const i = En(t), o = St(
|
|
405
399
|
i,
|
|
406
400
|
n
|
|
407
401
|
);
|
|
@@ -410,16 +404,14 @@ function yt(t, n) {
|
|
|
410
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));
|
|
411
405
|
function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
412
406
|
const i = Math.max(e * e, Number.EPSILON * 10);
|
|
413
|
-
let o = t, r = n, l = W(o),
|
|
407
|
+
let o = t, r = n, l = W(o), c = W(r);
|
|
414
408
|
for (let a = 0; a < s; a++) {
|
|
415
409
|
const f = l > i ? yt(r, o) : o;
|
|
416
|
-
if (!f)
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
if (!h)
|
|
420
|
-
return [];
|
|
410
|
+
if (!f) return [];
|
|
411
|
+
const u = W(f), h = c > i ? yt(f, r) : r;
|
|
412
|
+
if (!h) return [];
|
|
421
413
|
const p = W(h);
|
|
422
|
-
if (
|
|
414
|
+
if (u <= i && p <= i)
|
|
423
415
|
return [
|
|
424
416
|
f.boundingBox.intersection(h.boundingBox).center
|
|
425
417
|
];
|
|
@@ -427,8 +419,8 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
|
427
419
|
return [f.firstPoint];
|
|
428
420
|
if (g(h.firstPoint, h.lastPoint) && f.isOnSegment(h.firstPoint))
|
|
429
421
|
return [h.firstPoint];
|
|
430
|
-
if (
|
|
431
|
-
if (
|
|
422
|
+
if (u > 0.8 * l && p > 0.8 * c)
|
|
423
|
+
if (u / l > p / c) {
|
|
432
424
|
const [d, m] = f.splitAtParameters([
|
|
433
425
|
0.5
|
|
434
426
|
]);
|
|
@@ -459,7 +451,7 @@ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
|
|
|
459
451
|
e
|
|
460
452
|
);
|
|
461
453
|
}
|
|
462
|
-
o = f, r = h, l =
|
|
454
|
+
o = f, r = h, l = u, c = p;
|
|
463
455
|
}
|
|
464
456
|
throw new Error("Bézier clip: Maximum number of iterations reached");
|
|
465
457
|
}
|
|
@@ -736,13 +728,12 @@ class Nt extends lt {
|
|
|
736
728
|
function Ln(t, n = "Stroke") {
|
|
737
729
|
Vt(t.length).forEach(
|
|
738
730
|
([e, s]) => {
|
|
739
|
-
if (e === s)
|
|
740
|
-
return;
|
|
731
|
+
if (e === s) return;
|
|
741
732
|
const i = t[e], o = t[s], r = K(i, o), l = Math.max(i.precision, o.precision);
|
|
742
733
|
if (r.count !== 0) {
|
|
743
734
|
if (r.count === 1 && !r.overlaps.length) {
|
|
744
|
-
const
|
|
745
|
-
if (
|
|
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))
|
|
746
737
|
return;
|
|
747
738
|
}
|
|
748
739
|
if (!(r.count === 2 && t.length === 2 && (g(
|
|
@@ -859,8 +850,7 @@ const zn = (t, n) => {
|
|
|
859
850
|
if (e === "parallel")
|
|
860
851
|
return 0;
|
|
861
852
|
const { intersectionParam1: s, intersectionParam2: i } = e;
|
|
862
|
-
if (!n.isValidParameter(s) || i <= -n.precision)
|
|
863
|
-
return 0;
|
|
853
|
+
if (!n.isValidParameter(s) || i <= -n.precision) return 0;
|
|
864
854
|
if (Math.abs(s) < n.precision || Math.abs(s - 1) < n.precision) {
|
|
865
855
|
const [, o] = n.midPoint;
|
|
866
856
|
return t[1] - o < 0 ? 1 : 0;
|
|
@@ -882,18 +872,16 @@ class ut {
|
|
|
882
872
|
}
|
|
883
873
|
const qn = (t, n) => {
|
|
884
874
|
const e = n.precision, s = Math.abs(t[1] - n.center[1]);
|
|
885
|
-
if (s > n.radius + e)
|
|
886
|
-
return 0;
|
|
875
|
+
if (s > n.radius + e) return 0;
|
|
887
876
|
const i = fn(t, n.center), o = n.radius * n.radius, r = e * e;
|
|
888
877
|
if (Math.abs(i - o) < r && n.isOnSegment(t))
|
|
889
878
|
return 0;
|
|
890
879
|
const l = i - o > r;
|
|
891
|
-
if (l && n.center[0] < t[0])
|
|
892
|
-
|
|
893
|
-
const u = Math.sqrt(
|
|
880
|
+
if (l && n.center[0] < t[0]) return 0;
|
|
881
|
+
const c = Math.sqrt(
|
|
894
882
|
n.radius * n.radius - s * s
|
|
895
883
|
), a = new ut(n);
|
|
896
|
-
return a.update([n.center[0] +
|
|
884
|
+
return a.update([n.center[0] + c, t[1]]), l && a.update([n.center[0] - c, t[1]]), a.count;
|
|
897
885
|
}, Dn = (t, n) => {
|
|
898
886
|
const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new y(t, [e, t[1]]), i = new ut(n);
|
|
899
887
|
return et(s, n).forEach((o) => {
|
|
@@ -980,7 +968,7 @@ const Un = [
|
|
|
980
968
|
function jn(t) {
|
|
981
969
|
return Un.some((n) => t instanceof n);
|
|
982
970
|
}
|
|
983
|
-
function
|
|
971
|
+
function Ht(t) {
|
|
984
972
|
if (t instanceof y)
|
|
985
973
|
return {
|
|
986
974
|
type: t.segmentType,
|
|
@@ -1026,7 +1014,7 @@ function Yt(t) {
|
|
|
1026
1014
|
function it(t) {
|
|
1027
1015
|
return {
|
|
1028
1016
|
type: "LOOP",
|
|
1029
|
-
segments: t.segments.map(
|
|
1017
|
+
segments: t.segments.map(Ht)
|
|
1030
1018
|
};
|
|
1031
1019
|
}
|
|
1032
1020
|
function $t(t) {
|
|
@@ -1036,7 +1024,7 @@ function $t(t) {
|
|
|
1036
1024
|
holes: t.holes.map(it)
|
|
1037
1025
|
};
|
|
1038
1026
|
}
|
|
1039
|
-
function
|
|
1027
|
+
function Hn(t) {
|
|
1040
1028
|
return {
|
|
1041
1029
|
type: "DIAGRAM",
|
|
1042
1030
|
figures: t.figures.map($t)
|
|
@@ -1044,13 +1032,13 @@ function Yn(t) {
|
|
|
1044
1032
|
}
|
|
1045
1033
|
function Mt(t) {
|
|
1046
1034
|
if (t instanceof _)
|
|
1047
|
-
return
|
|
1035
|
+
return Hn(t);
|
|
1048
1036
|
if (t instanceof v)
|
|
1049
1037
|
return $t(t);
|
|
1050
1038
|
if (t instanceof O)
|
|
1051
1039
|
return it(t);
|
|
1052
1040
|
if (jn(t))
|
|
1053
|
-
return
|
|
1041
|
+
return Ht(t);
|
|
1054
1042
|
throw new Error("Unknown shape type");
|
|
1055
1043
|
}
|
|
1056
1044
|
class $n {
|
|
@@ -1064,15 +1052,13 @@ class $n {
|
|
|
1064
1052
|
let s = this.length++;
|
|
1065
1053
|
for (; s > 0; ) {
|
|
1066
1054
|
const i = s - 1 >> 1, o = this.values[i];
|
|
1067
|
-
if (e >= o)
|
|
1068
|
-
break;
|
|
1055
|
+
if (e >= o) break;
|
|
1069
1056
|
this.ids[s] = this.ids[i], this.values[s] = o, s = i;
|
|
1070
1057
|
}
|
|
1071
1058
|
this.ids[s] = n, this.values[s] = e;
|
|
1072
1059
|
}
|
|
1073
1060
|
pop() {
|
|
1074
|
-
if (this.length === 0)
|
|
1075
|
-
return;
|
|
1061
|
+
if (this.length === 0) return;
|
|
1076
1062
|
const n = this.ids[0];
|
|
1077
1063
|
if (this.length--, this.length > 0) {
|
|
1078
1064
|
const e = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], i = this.length >> 1;
|
|
@@ -1080,11 +1066,10 @@ class $n {
|
|
|
1080
1066
|
for (; o < i; ) {
|
|
1081
1067
|
let r = (o << 1) + 1;
|
|
1082
1068
|
const l = r + 1;
|
|
1083
|
-
let
|
|
1069
|
+
let c = this.ids[r], a = this.values[r];
|
|
1084
1070
|
const f = this.values[l];
|
|
1085
|
-
if (l < this.length && f < a && (r = l,
|
|
1086
|
-
|
|
1087
|
-
this.ids[o] = u, this.values[o] = a, o = r;
|
|
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;
|
|
1088
1073
|
}
|
|
1089
1074
|
this.ids[o] = e, this.values[o] = s;
|
|
1090
1075
|
}
|
|
@@ -1102,50 +1087,68 @@ class $n {
|
|
|
1102
1087
|
this.ids.length = this.values.length = this.length;
|
|
1103
1088
|
}
|
|
1104
1089
|
}
|
|
1105
|
-
const At = [
|
|
1106
|
-
Int8Array,
|
|
1107
|
-
Uint8Array,
|
|
1108
|
-
Uint8ClampedArray,
|
|
1109
|
-
Int16Array,
|
|
1110
|
-
Uint16Array,
|
|
1111
|
-
Int32Array,
|
|
1112
|
-
Uint32Array,
|
|
1113
|
-
Float32Array,
|
|
1114
|
-
Float64Array
|
|
1115
|
-
], nt = 3;
|
|
1090
|
+
const At = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array], nt = 3;
|
|
1116
1091
|
class at {
|
|
1117
|
-
|
|
1092
|
+
/**
|
|
1093
|
+
* Recreate a Flatbush index from raw `ArrayBuffer` or `SharedArrayBuffer` data.
|
|
1094
|
+
* @param {ArrayBuffer | SharedArrayBuffer} data
|
|
1095
|
+
* @param {number} [byteOffset=0] byte offset to the start of the Flatbush buffer in the referenced ArrayBuffer.
|
|
1096
|
+
* @returns {Flatbush} index
|
|
1097
|
+
*/
|
|
1098
|
+
static from(n, e = 0) {
|
|
1099
|
+
if (e % 8 !== 0)
|
|
1100
|
+
throw new Error("byteOffset must be 8-byte aligned.");
|
|
1118
1101
|
if (!n || n.byteLength === void 0 || n.buffer)
|
|
1119
1102
|
throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
|
|
1120
|
-
const [
|
|
1121
|
-
if (
|
|
1103
|
+
const [s, i] = new Uint8Array(n, e + 0, 2);
|
|
1104
|
+
if (s !== 251)
|
|
1122
1105
|
throw new Error("Data does not appear to be in a Flatbush format.");
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
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)
|
|
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);
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* Create a Flatbush index that will hold a given number of items.
|
|
1117
|
+
* @param {number} numItems
|
|
1118
|
+
* @param {number} [nodeSize=16] Size of the tree node (16 by default).
|
|
1119
|
+
* @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
|
|
1120
|
+
* @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used to store data (`ArrayBuffer` by default).
|
|
1121
|
+
* @param {ArrayBuffer | SharedArrayBuffer} [data] (Only used internally)
|
|
1122
|
+
* @param {number} [byteOffset=0] (Only used internally)
|
|
1123
|
+
*/
|
|
1124
|
+
constructor(n, e = 16, s = Float64Array, i = ArrayBuffer, o, r = 0) {
|
|
1125
|
+
if (n === void 0) throw new Error("Missing required argument: numItems.");
|
|
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];
|
|
1136
1130
|
do
|
|
1137
|
-
|
|
1138
|
-
while (
|
|
1139
|
-
this.ArrayType = s
|
|
1140
|
-
const
|
|
1141
|
-
if (
|
|
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;
|
|
1135
|
+
if (a < 0)
|
|
1142
1136
|
throw new Error(`Unexpected typed array class: ${s}.`);
|
|
1143
|
-
o && o.byteLength !== void 0 && !o.buffer ? (this.data = o, this._boxes = new this.ArrayType(this.data, 8,
|
|
1144
|
-
}
|
|
1145
|
-
|
|
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();
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Add a given rectangle to the index.
|
|
1141
|
+
* @param {number} minX
|
|
1142
|
+
* @param {number} minY
|
|
1143
|
+
* @param {number} maxX
|
|
1144
|
+
* @param {number} maxY
|
|
1145
|
+
* @returns {number} A zero-based, incremental number that represents the newly added rectangle.
|
|
1146
|
+
*/
|
|
1147
|
+
add(n, e, s = n, i = e) {
|
|
1146
1148
|
const o = this._pos >> 2, r = this._boxes;
|
|
1147
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
1150
|
}
|
|
1151
|
+
/** Perform indexing of the added rectangles. */
|
|
1149
1152
|
finish() {
|
|
1150
1153
|
if (this._pos >> 2 !== this.numItems)
|
|
1151
1154
|
throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
|
|
@@ -1154,63 +1157,79 @@ class at {
|
|
|
1154
1157
|
n[this._pos++] = this.minX, n[this._pos++] = this.minY, n[this._pos++] = this.maxX, n[this._pos++] = this.maxY;
|
|
1155
1158
|
return;
|
|
1156
1159
|
}
|
|
1157
|
-
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), o =
|
|
1160
|
+
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), o = 65535;
|
|
1158
1161
|
for (let r = 0, l = 0; r < this.numItems; r++) {
|
|
1159
|
-
const
|
|
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);
|
|
1160
1163
|
i[r] = Xn(h, p);
|
|
1161
1164
|
}
|
|
1162
1165
|
ot(i, n, this._indices, 0, this.numItems - 1, this.nodeSize);
|
|
1163
1166
|
for (let r = 0, l = 0; r < this._levelBounds.length - 1; r++) {
|
|
1164
|
-
const
|
|
1165
|
-
for (; l <
|
|
1167
|
+
const c = this._levelBounds[r];
|
|
1168
|
+
for (; l < c; ) {
|
|
1166
1169
|
const a = l;
|
|
1167
|
-
let f = n[l++],
|
|
1168
|
-
for (let d = 1; d < this.nodeSize && l <
|
|
1169
|
-
f = Math.min(f, n[l++]),
|
|
1170
|
-
this._indices[this._pos >> 2] = a, n[this._pos++] = f, n[this._pos++] =
|
|
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;
|
|
1171
1174
|
}
|
|
1172
1175
|
}
|
|
1173
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Search the index by a bounding box.
|
|
1179
|
+
* @param {number} minX
|
|
1180
|
+
* @param {number} minY
|
|
1181
|
+
* @param {number} maxX
|
|
1182
|
+
* @param {number} maxY
|
|
1183
|
+
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
1184
|
+
* @returns {number[]} An array of indices of items intersecting or touching the given bounding box.
|
|
1185
|
+
*/
|
|
1174
1186
|
search(n, e, s, i, o) {
|
|
1175
1187
|
if (this._pos !== this._boxes.length)
|
|
1176
1188
|
throw new Error("Data not yet indexed - call index.finish().");
|
|
1177
1189
|
let r = this._boxes.length - 4;
|
|
1178
|
-
const l = [],
|
|
1190
|
+
const l = [], c = [];
|
|
1179
1191
|
for (; r !== void 0; ) {
|
|
1180
|
-
const a = Math.min(r + this.nodeSize * 4,
|
|
1192
|
+
const a = Math.min(r + this.nodeSize * 4, Et(r, this._levelBounds));
|
|
1181
1193
|
for (let f = r; f < a; f += 4) {
|
|
1182
|
-
if (s < this._boxes[f] || i < this._boxes[f + 1] || n > this._boxes[f + 2] || e > this._boxes[f + 3])
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
r >= this.numItems * 4 ? l.push(c) : (o === void 0 || o(c)) && u.push(c);
|
|
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);
|
|
1186
1197
|
}
|
|
1187
1198
|
r = l.pop();
|
|
1188
1199
|
}
|
|
1189
|
-
return
|
|
1190
|
-
}
|
|
1200
|
+
return c;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Search items in order of distance from the given point.
|
|
1204
|
+
* @param {number} x
|
|
1205
|
+
* @param {number} y
|
|
1206
|
+
* @param {number} [maxResults=Infinity]
|
|
1207
|
+
* @param {number} [maxDistance=Infinity]
|
|
1208
|
+
* @param {(index: number) => boolean} [filterFn] An optional function for filtering the results.
|
|
1209
|
+
* @returns {number[]} An array of indices of items found.
|
|
1210
|
+
*/
|
|
1191
1211
|
neighbors(n, e, s = 1 / 0, i = 1 / 0, o) {
|
|
1192
1212
|
if (this._pos !== this._boxes.length)
|
|
1193
1213
|
throw new Error("Data not yet indexed - call index.finish().");
|
|
1194
1214
|
let r = this._boxes.length - 4;
|
|
1195
|
-
const l = this._queue,
|
|
1196
|
-
for (; r !== void 0; ) {
|
|
1197
|
-
const f = Math.min(r + this.nodeSize * 4,
|
|
1198
|
-
for (let
|
|
1199
|
-
const h = this._indices[
|
|
1200
|
-
r >= this.numItems * 4 ? l.push(h << 1, m) : (o === void 0 || o(h)) && l.push((h << 1) + 1, m);
|
|
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));
|
|
1201
1221
|
}
|
|
1202
1222
|
for (; l.length && l.peek() & 1; )
|
|
1203
|
-
if (l.peekValue() > a || (
|
|
1204
|
-
|
|
1205
|
-
r = l.pop() >> 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;
|
|
1206
1225
|
}
|
|
1207
|
-
return l.clear(),
|
|
1226
|
+
return l.clear(), c;
|
|
1208
1227
|
}
|
|
1209
1228
|
}
|
|
1210
1229
|
function It(t, n, e) {
|
|
1211
1230
|
return t < n ? n - t : t <= e ? 0 : t - e;
|
|
1212
1231
|
}
|
|
1213
|
-
function
|
|
1232
|
+
function Et(t, n) {
|
|
1214
1233
|
let e = 0, s = n.length - 1;
|
|
1215
1234
|
for (; e < s; ) {
|
|
1216
1235
|
const i = e + s >> 1;
|
|
@@ -1219,42 +1238,38 @@ function Ft(t, n) {
|
|
|
1219
1238
|
return n[e];
|
|
1220
1239
|
}
|
|
1221
1240
|
function ot(t, n, e, s, i, o) {
|
|
1222
|
-
if (Math.floor(s / o) >= Math.floor(i / o))
|
|
1223
|
-
return;
|
|
1241
|
+
if (Math.floor(s / o) >= Math.floor(i / o)) return;
|
|
1224
1242
|
const r = t[s + i >> 1];
|
|
1225
|
-
let l = s - 1,
|
|
1243
|
+
let l = s - 1, c = i + 1;
|
|
1226
1244
|
for (; ; ) {
|
|
1227
1245
|
do
|
|
1228
1246
|
l++;
|
|
1229
1247
|
while (t[l] < r);
|
|
1230
1248
|
do
|
|
1231
|
-
|
|
1232
|
-
while (t[
|
|
1233
|
-
if (l >=
|
|
1234
|
-
|
|
1235
|
-
Hn(t, n, e, l, u);
|
|
1249
|
+
c--;
|
|
1250
|
+
while (t[c] > r);
|
|
1251
|
+
if (l >= c) break;
|
|
1252
|
+
Yn(t, n, e, l, c);
|
|
1236
1253
|
}
|
|
1237
|
-
ot(t, n, e, s,
|
|
1254
|
+
ot(t, n, e, s, c, o), ot(t, n, e, c + 1, i, o);
|
|
1238
1255
|
}
|
|
1239
|
-
function
|
|
1256
|
+
function Yn(t, n, e, s, i) {
|
|
1240
1257
|
const o = t[s];
|
|
1241
1258
|
t[s] = t[i], t[i] = o;
|
|
1242
|
-
const r = 4 * s, l = 4 * i,
|
|
1243
|
-
n[r] = n[l], n[r + 1] = n[l + 1], n[r + 2] = n[l + 2], n[r + 3] = n[l + 3], n[l] =
|
|
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;
|
|
1244
1261
|
const h = e[s];
|
|
1245
1262
|
e[s] = e[i], e[i] = h;
|
|
1246
1263
|
}
|
|
1247
1264
|
function Xn(t, n) {
|
|
1248
|
-
let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n), o = t & (n ^ 65535), r = e | s >> 1, l = e >> 1 ^ e,
|
|
1249
|
-
e = r, s = l, i =
|
|
1250
|
-
let f = t ^ n,
|
|
1251
|
-
return f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765,
|
|
1252
|
-
}
|
|
1253
|
-
function
|
|
1254
|
-
if (t.length === 0)
|
|
1255
|
-
|
|
1256
|
-
if (t.length === 1)
|
|
1257
|
-
return [t];
|
|
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;
|
|
1269
|
+
}
|
|
1270
|
+
function Yt(t, n = 1e-7) {
|
|
1271
|
+
if (t.length === 0) return [];
|
|
1272
|
+
if (t.length === 1) return [t];
|
|
1258
1273
|
const e = new at(t.length);
|
|
1259
1274
|
t.forEach((o) => {
|
|
1260
1275
|
const [r, l] = o.firstPoint;
|
|
@@ -1262,31 +1277,30 @@ function Ht(t, n = 1e-7) {
|
|
|
1262
1277
|
}), e.finish();
|
|
1263
1278
|
const s = [], i = /* @__PURE__ */ new Set();
|
|
1264
1279
|
return t.forEach((o, r) => {
|
|
1265
|
-
if (i.has(r))
|
|
1266
|
-
return;
|
|
1280
|
+
if (i.has(r)) return;
|
|
1267
1281
|
const l = [o];
|
|
1268
|
-
let
|
|
1282
|
+
let c = r;
|
|
1269
1283
|
i.add(r);
|
|
1270
1284
|
let a = t.length;
|
|
1271
1285
|
for (; ; ) {
|
|
1272
1286
|
if (a-- < 0)
|
|
1273
1287
|
throw new Error("Infinite loop detected");
|
|
1274
|
-
const f = l[l.length - 1].lastPoint, [
|
|
1275
|
-
|
|
1288
|
+
const f = l[l.length - 1].lastPoint, [u, h] = f, p = e.search(
|
|
1289
|
+
u - n,
|
|
1276
1290
|
h - n,
|
|
1277
|
-
|
|
1291
|
+
u + n,
|
|
1278
1292
|
h + n
|
|
1279
|
-
), d = (x) => Math.abs((
|
|
1293
|
+
), d = (x) => Math.abs((c - x) % t.length), m = p.filter((x) => !i.has(x)).map((x) => [
|
|
1280
1294
|
t[x],
|
|
1281
1295
|
x,
|
|
1282
1296
|
d(x)
|
|
1283
|
-
]).sort(([, , x], [, ,
|
|
1297
|
+
]).sort(([, , x], [, , F]) => d(x) - d(F));
|
|
1284
1298
|
if (m.length === 0) {
|
|
1285
1299
|
s.push(l);
|
|
1286
1300
|
break;
|
|
1287
1301
|
}
|
|
1288
1302
|
const [P, w] = m[0];
|
|
1289
|
-
l.push(P), i.add(w),
|
|
1303
|
+
l.push(P), i.add(w), c = w;
|
|
1290
1304
|
}
|
|
1291
1305
|
}), s;
|
|
1292
1306
|
}
|
|
@@ -1328,12 +1342,11 @@ class v extends lt {
|
|
|
1328
1342
|
}
|
|
1329
1343
|
overlappingStrands(e) {
|
|
1330
1344
|
const s = e instanceof v ? e.allLoops : [e], i = this.allLoops.flatMap((o) => s.flatMap((r) => o.overlappingSegments(r)));
|
|
1331
|
-
return
|
|
1345
|
+
return Yt(i).map((o) => new B(o));
|
|
1332
1346
|
}
|
|
1333
1347
|
}
|
|
1334
1348
|
function Gn(t, n = []) {
|
|
1335
|
-
if (!t)
|
|
1336
|
-
throw new Error("Figure must have a contour");
|
|
1349
|
+
if (!t) throw new Error("Figure must have a contour");
|
|
1337
1350
|
for (const [e, s] of st([t, ...n]))
|
|
1338
1351
|
if (e.intersects(s))
|
|
1339
1352
|
throw new Error("Loops in a figure must not intersect");
|
|
@@ -1369,15 +1382,13 @@ const Qn = (t) => {
|
|
|
1369
1382
|
);
|
|
1370
1383
|
return [e, ...s];
|
|
1371
1384
|
}, ft = (t) => {
|
|
1372
|
-
if (!t.length)
|
|
1373
|
-
return [];
|
|
1385
|
+
if (!t.length) return [];
|
|
1374
1386
|
const n = t.filter(({ isIn: s }) => !s.length), e = t.filter(({ isIn: s }) => s.length > 1);
|
|
1375
1387
|
return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ? Wn(n, t) : Jn(e, t);
|
|
1376
1388
|
};
|
|
1377
1389
|
function X(t) {
|
|
1378
1390
|
return Qn(t).map(Xt).flatMap(ft).map((e) => {
|
|
1379
|
-
if (e.length === 1)
|
|
1380
|
-
return new v(e[0].loop);
|
|
1391
|
+
if (e.length === 1) return new v(e[0].loop);
|
|
1381
1392
|
e.sort((o, r) => o.isIn.length - r.isIn.length);
|
|
1382
1393
|
const [s, ...i] = e.map(({ loop: o }) => o);
|
|
1383
1394
|
return new v(s, i);
|
|
@@ -1390,7 +1401,7 @@ function Kn(t, n) {
|
|
|
1390
1401
|
e.push([s, i]);
|
|
1391
1402
|
return e;
|
|
1392
1403
|
}
|
|
1393
|
-
function*
|
|
1404
|
+
function* Ft(t, n, e) {
|
|
1394
1405
|
const s = (r) => n.some((l) => g(l, r.lastPoint)), i = (r) => e.some((l) => r.isSame(l));
|
|
1395
1406
|
let o = [];
|
|
1396
1407
|
for (const r of t)
|
|
@@ -1405,10 +1416,10 @@ const vt = (t, n) => {
|
|
|
1405
1416
|
const s = (l) => g(l.firstPoint, n.firstPoint) && g(l.lastPoint, n.lastPoint);
|
|
1406
1417
|
let i = t.findIndex(s);
|
|
1407
1418
|
if (i === -1) {
|
|
1408
|
-
const l = t.map((
|
|
1419
|
+
const l = t.map((c) => c.reverse());
|
|
1409
1420
|
if (l.reverse(), i = l.findIndex(s), i === -1)
|
|
1410
1421
|
throw console.error(
|
|
1411
|
-
l.map((
|
|
1422
|
+
l.map((c) => c.repr),
|
|
1412
1423
|
n.repr
|
|
1413
1424
|
), new Error("Failed to rotate to segment start");
|
|
1414
1425
|
e = l;
|
|
@@ -1436,26 +1447,24 @@ function te(t, n, e) {
|
|
|
1436
1447
|
e
|
|
1437
1448
|
);
|
|
1438
1449
|
s.push(...P), o[p].push(...P), r[m].push(...P), i.push(...w);
|
|
1439
|
-
const x = w.flatMap((
|
|
1440
|
-
|
|
1441
|
-
|
|
1450
|
+
const x = w.flatMap((F) => [
|
|
1451
|
+
F.firstPoint,
|
|
1452
|
+
F.lastPoint
|
|
1442
1453
|
]);
|
|
1443
1454
|
s.push(...x), o[p].push(...x), r[m].push(...x);
|
|
1444
1455
|
});
|
|
1445
|
-
}), s = U(s, e), !s.length || s.length === 1)
|
|
1446
|
-
return null;
|
|
1456
|
+
}), s = U(s, e), !s.length || s.length === 1) return null;
|
|
1447
1457
|
const l = ([h, p]) => p.length ? h.splitAt(p) : [h];
|
|
1448
|
-
let
|
|
1458
|
+
let c = N([t.segments, o]).flatMap(l), a = N([n.segments, r]).flatMap(l);
|
|
1449
1459
|
if (s = Zn(
|
|
1450
1460
|
s,
|
|
1451
|
-
|
|
1461
|
+
c,
|
|
1452
1462
|
n
|
|
1453
|
-
), !s.length && !i.length)
|
|
1454
|
-
return null;
|
|
1463
|
+
), !s.length && !i.length) return null;
|
|
1455
1464
|
if (i.length) {
|
|
1456
1465
|
const h = i[0];
|
|
1457
|
-
|
|
1458
|
-
|
|
1466
|
+
c = Bt(
|
|
1467
|
+
c,
|
|
1459
1468
|
h
|
|
1460
1469
|
), a = Bt(
|
|
1461
1470
|
a,
|
|
@@ -1463,25 +1472,25 @@ function te(t, n, e) {
|
|
|
1463
1472
|
);
|
|
1464
1473
|
} else {
|
|
1465
1474
|
const h = s[0];
|
|
1466
|
-
|
|
1475
|
+
c = vt(c, h), a = vt(a, h);
|
|
1467
1476
|
}
|
|
1468
1477
|
let f = Array.from(
|
|
1469
|
-
|
|
1470
|
-
|
|
1478
|
+
Ft(
|
|
1479
|
+
c,
|
|
1471
1480
|
s,
|
|
1472
1481
|
i
|
|
1473
1482
|
)
|
|
1474
|
-
),
|
|
1475
|
-
|
|
1483
|
+
), u = Array.from(
|
|
1484
|
+
Ft(
|
|
1476
1485
|
a,
|
|
1477
1486
|
s,
|
|
1478
1487
|
i
|
|
1479
1488
|
)
|
|
1480
1489
|
);
|
|
1481
1490
|
return (!g(
|
|
1482
|
-
|
|
1491
|
+
u[0].lastPoint,
|
|
1483
1492
|
f[0].lastPoint
|
|
1484
|
-
) || i.length > 0 &&
|
|
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]);
|
|
1485
1494
|
}
|
|
1486
1495
|
function kt(t) {
|
|
1487
1496
|
let n = t[0];
|
|
@@ -1505,8 +1514,7 @@ function ne(t, n) {
|
|
|
1505
1514
|
return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(kt(s)), e;
|
|
1506
1515
|
}
|
|
1507
1516
|
function ee(t) {
|
|
1508
|
-
if (!t.length)
|
|
1509
|
-
return [];
|
|
1517
|
+
if (!t.length) return [];
|
|
1510
1518
|
const n = t.map((i) => i.firstPoint);
|
|
1511
1519
|
let e = t.map((i) => i.lastPoint);
|
|
1512
1520
|
e = e.slice(-1).concat(e.slice(0, -1));
|
|
@@ -1516,12 +1524,11 @@ function ee(t) {
|
|
|
1516
1524
|
try {
|
|
1517
1525
|
return ne(t, s);
|
|
1518
1526
|
} catch {
|
|
1519
|
-
return
|
|
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));
|
|
1520
1528
|
}
|
|
1521
1529
|
}
|
|
1522
1530
|
const _t = (t, n) => {
|
|
1523
|
-
if (t.length === 0)
|
|
1524
|
-
return [n];
|
|
1531
|
+
if (t.length === 0) return [n];
|
|
1525
1532
|
const e = t.at(-1);
|
|
1526
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]);
|
|
1527
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);
|
|
@@ -1531,28 +1538,28 @@ function ht(t, n, {
|
|
|
1531
1538
|
}) {
|
|
1532
1539
|
const i = te(t, n);
|
|
1533
1540
|
if (!i) {
|
|
1534
|
-
const
|
|
1541
|
+
const c = t.segments[0].midPoint, a = n.contains(c), f = n.segments[0].midPoint, u = t.contains(f);
|
|
1535
1542
|
return {
|
|
1536
1543
|
identical: !1,
|
|
1537
1544
|
firstCurveInSecond: a,
|
|
1538
|
-
secondCurveInFirst:
|
|
1545
|
+
secondCurveInFirst: u
|
|
1539
1546
|
};
|
|
1540
1547
|
}
|
|
1541
|
-
if (i.every(([,
|
|
1548
|
+
if (i.every(([, c]) => c === "same"))
|
|
1542
1549
|
return { identical: !0 };
|
|
1543
1550
|
let o = null, r = null;
|
|
1544
|
-
const l = i.flatMap(([
|
|
1545
|
-
let f = [],
|
|
1551
|
+
const l = i.flatMap(([c, a]) => {
|
|
1552
|
+
let f = [], u = 0;
|
|
1546
1553
|
if (a === "same")
|
|
1547
|
-
return r === 1 ? (r = 1,
|
|
1548
|
-
const h =
|
|
1549
|
-
(e === "keep" && p || e === "remove" && !p) && (
|
|
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));
|
|
1550
1557
|
const d = a.segments[0].midPoint, m = t.contains(d);
|
|
1551
1558
|
if (s === "keep" && m || s === "remove" && !m) {
|
|
1552
1559
|
const P = a;
|
|
1553
|
-
|
|
1560
|
+
u += 1, u === 2 && f.length ? (f = _t(f, P), o = null) : f = [P];
|
|
1554
1561
|
}
|
|
1555
|
-
return r === null &&
|
|
1562
|
+
return r === null && u === 1 && o && (f = se(f, o)), u === 1 && (r = u, o = null), f.length ? f : (o = null, []);
|
|
1556
1563
|
});
|
|
1557
1564
|
return ee(l);
|
|
1558
1565
|
}
|
|
@@ -1580,16 +1587,14 @@ function oe(t) {
|
|
|
1580
1587
|
return t.forEach((s, i) => {
|
|
1581
1588
|
let o;
|
|
1582
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) => {
|
|
1583
|
-
const
|
|
1584
|
-
if (o.fusedWith.has(a))
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
if (n.has(a) && (f = n.get(a).current, c = !0), !u.some(
|
|
1590
|
+
const c = o.current, a = i + l + 1;
|
|
1591
|
+
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(
|
|
1588
1594
|
(d) => f.some((m) => d.intersects(m))
|
|
1589
|
-
))
|
|
1590
|
-
return;
|
|
1595
|
+
)) return;
|
|
1591
1596
|
let p;
|
|
1592
|
-
|
|
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);
|
|
1593
1598
|
});
|
|
1594
1599
|
}), e.flatMap(({ current: s }) => s);
|
|
1595
1600
|
}
|
|
@@ -1631,8 +1636,7 @@ function tt(t, n) {
|
|
|
1631
1636
|
}
|
|
1632
1637
|
function re(t, n) {
|
|
1633
1638
|
const e = pt(t.contour, n.contour);
|
|
1634
|
-
if (!e.length)
|
|
1635
|
-
return [];
|
|
1639
|
+
if (!e.length) return [];
|
|
1636
1640
|
let s = X(e);
|
|
1637
1641
|
return s = Q(
|
|
1638
1642
|
s,
|
|
@@ -1643,10 +1647,8 @@ function re(t, n) {
|
|
|
1643
1647
|
);
|
|
1644
1648
|
}
|
|
1645
1649
|
function G(t, n) {
|
|
1646
|
-
if (!t.length)
|
|
1647
|
-
|
|
1648
|
-
if (!n.length)
|
|
1649
|
-
return t;
|
|
1650
|
+
if (!t.length) return n;
|
|
1651
|
+
if (!n.length) return t;
|
|
1650
1652
|
if (t.length === 1 && n.length > 1 || n.length === 1 && t.length > 1)
|
|
1651
1653
|
return oe([...t, ...n]);
|
|
1652
1654
|
if (t.length > 1 && n.length > 1) {
|
|
@@ -1658,10 +1660,8 @@ function G(t, n) {
|
|
|
1658
1660
|
return t.length === 1 && n.length === 1 ? Gt(t[0], n[0]) : [];
|
|
1659
1661
|
}
|
|
1660
1662
|
function Q(t, n) {
|
|
1661
|
-
if (!t.length)
|
|
1662
|
-
|
|
1663
|
-
if (!n.length)
|
|
1664
|
-
return t;
|
|
1663
|
+
if (!t.length) return [];
|
|
1664
|
+
if (!n.length) return t;
|
|
1665
1665
|
if (t.length === 1 && n.length === 1)
|
|
1666
1666
|
return tt(t[0], n[0]);
|
|
1667
1667
|
if (t.length > 1)
|
|
@@ -1685,8 +1685,7 @@ class _ extends lt {
|
|
|
1685
1685
|
return this.figures.length === 0;
|
|
1686
1686
|
}
|
|
1687
1687
|
get boundingBox() {
|
|
1688
|
-
if (this.isEmpty)
|
|
1689
|
-
return new hn();
|
|
1688
|
+
if (this.isEmpty) return new hn();
|
|
1690
1689
|
if (this._boundingBox === null) {
|
|
1691
1690
|
let e = this.figures[0].boundingBox;
|
|
1692
1691
|
for (const s of this.figures.slice(1))
|
|
@@ -1734,17 +1733,17 @@ export {
|
|
|
1734
1733
|
v as F,
|
|
1735
1734
|
O as L,
|
|
1736
1735
|
B as S,
|
|
1737
|
-
|
|
1738
|
-
|
|
1736
|
+
K as a,
|
|
1737
|
+
G as b,
|
|
1739
1738
|
Q as c,
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1739
|
+
qt as d,
|
|
1740
|
+
Yt as e,
|
|
1741
|
+
ae as f,
|
|
1742
|
+
jn as g,
|
|
1743
|
+
Mt as h,
|
|
1745
1744
|
rt as i,
|
|
1746
1745
|
J as l,
|
|
1747
1746
|
pn as p,
|
|
1748
|
-
|
|
1747
|
+
Ft as s
|
|
1749
1748
|
};
|
|
1750
|
-
//# sourceMappingURL=
|
|
1749
|
+
//# sourceMappingURL=models-BjaFYsN2.js.map
|