pantograph2d 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -658
- package/dist/QuadraticBezier-BAVasVfu.cjs +9 -0
- package/dist/QuadraticBezier-BAVasVfu.cjs.map +1 -0
- package/dist/QuadraticBezier-BzVqiExF.js +4736 -0
- package/dist/QuadraticBezier-BzVqiExF.js.map +1 -0
- package/dist/draw-DqsKIWJD.js +337 -0
- package/dist/draw-DqsKIWJD.js.map +1 -0
- package/dist/draw-NcYfDZjT.cjs +2 -0
- package/dist/draw-NcYfDZjT.cjs.map +1 -0
- package/dist/models-Dxwusy3i.cjs +4 -0
- package/dist/models-Dxwusy3i.cjs.map +1 -0
- package/dist/models-WQ-B7GSL.js +1749 -0
- package/dist/models-WQ-B7GSL.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 -13
- package/dist/pantograph/drawShape.js.map +1 -1
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +15 -12
- package/dist/pantograph/models.js.map +1 -1
- package/dist/pantograph/svg.cjs +2 -0
- package/dist/pantograph/svg.cjs.map +1 -0
- package/dist/pantograph/svg.js +10 -0
- package/dist/pantograph/svg.js.map +1 -0
- package/dist/pantograph.cjs +2 -8
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +406 -452
- package/dist/pantograph.js.map +1 -1
- package/dist/svg-BylQQgsL.js +62 -0
- package/dist/svg-BylQQgsL.js.map +1 -0
- package/dist/svg-D0nYyMk7.cjs +8 -0
- package/dist/svg-D0nYyMk7.cjs.map +1 -0
- package/dist/types/examples/importSVG.d.ts +4 -0
- package/dist/types/{algorithms → src/algorithms}/boolean/figureBooleans.d.ts +1 -1
- package/dist/types/{algorithms → src/algorithms}/boolean/loopBooleans.d.ts +1 -1
- package/dist/types/{algorithms → src/algorithms}/boolean/strandBoolean.d.ts +4 -4
- package/dist/types/{algorithms → src/algorithms}/boolean/strandsBetweenIntersections.d.ts +3 -3
- package/dist/types/{algorithms → src/algorithms}/distances/arcArcDistance.d.ts +1 -1
- package/dist/types/{algorithms → src/algorithms}/distances/genericDistance.d.ts +1 -1
- package/dist/types/{algorithms → src/algorithms}/distances/index.d.ts +1 -1
- package/dist/types/src/algorithms/distances/lineArcDistance.d.ts +3 -0
- package/dist/types/{algorithms → src/algorithms}/distances/lineLineDistance.d.ts +1 -1
- package/dist/types/{algorithms → src/algorithms}/filletSegments.d.ts +1 -1
- package/dist/types/{algorithms → 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/types/{algorithms → src/algorithms}/intersections/bezierClip.d.ts +3 -3
- package/dist/types/{algorithms → src/algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +2 -2
- package/dist/types/{algorithms → src/algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/ellipseEllipseIntersection.d.ts +4 -0
- package/dist/types/{algorithms → 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/types/{algorithms → src/algorithms}/intersections/lineLineIntersection.d.ts +4 -4
- package/dist/types/{algorithms → src/algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +2 -2
- package/dist/types/src/algorithms/intersections/rayIntersections.d.ts +3 -0
- package/dist/types/{algorithms → src/algorithms}/offsets/offsetFigure.d.ts +2 -2
- package/dist/types/{algorithms → src/algorithms}/offsets/offsetSegment.d.ts +4 -4
- package/dist/types/{algorithms → src/algorithms}/offsets/offsetStroke.d.ts +5 -5
- package/dist/types/{algorithms → 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/types/src/algorithms/solvers/zeroViaNewton.d.ts +1 -0
- package/dist/types/{algorithms → 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/types/{booleanOperations.d.ts → src/booleanOperations.d.ts} +5 -5
- package/dist/types/{draw.d.ts → src/draw.d.ts} +4 -4
- package/dist/types/{drawShape → src/drawShape}/drawCircle.d.ts +1 -1
- package/dist/types/src/drawShape/drawEllipse.d.ts +2 -0
- package/dist/types/{drawShape → 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/types/{export → src/export}/json/exportJSON.d.ts +94 -94
- package/dist/types/{export → src/export}/json/jsonDiagram.d.ts +31 -31
- package/dist/types/{export → src/export}/json/jsonFigure.d.ts +31 -31
- package/dist/types/{export → src/export}/json/jsonLoop.d.ts +16 -16
- package/dist/types/{export → src/export}/json/jsonSegment.d.ts +16 -16
- package/dist/types/src/export/svg/api.d.ts +6 -0
- package/dist/types/{export → src/export}/svg/exportSVG.d.ts +6 -6
- package/dist/types/{export → src/export}/svg/svgDiagram.d.ts +1 -1
- package/dist/types/{export → src/export}/svg/svgFigure.d.ts +1 -1
- package/dist/types/{export → src/export}/svg/svgLoop.d.ts +1 -1
- package/dist/types/{export → src/export}/svg/svgSegment.d.ts +1 -1
- package/dist/types/{export → src/export}/svg/svgStrand.d.ts +1 -1
- package/dist/types/{export → src/export}/svg/wrapSVG.d.ts +2 -2
- package/dist/types/src/import/json/importJSON.d.ts +9 -0
- package/dist/types/{main.d.ts → src/main.d.ts} +7 -7
- package/dist/types/{models → src/models}/BoundingBox.d.ts +1 -1
- package/dist/types/{models → src/models}/Diagram.d.ts +7 -7
- package/dist/types/{models → src/models}/Figure.d.ts +7 -7
- package/dist/types/{models → src/models}/Loop.d.ts +4 -4
- package/dist/types/{models → src/models}/Strand.d.ts +2 -2
- package/dist/types/{models → src/models}/Stroke.d.ts +5 -5
- package/dist/types/{models → 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/types/{models → src/models}/segments/Arc.d.ts +4 -4
- package/dist/types/{models → src/models}/segments/CubicBezier.d.ts +4 -4
- package/dist/types/{models → src/models}/segments/EllipseArc.d.ts +5 -5
- package/dist/types/{models → src/models}/segments/Line.d.ts +4 -4
- package/dist/types/{models → src/models}/segments/QuadraticBezier.d.ts +4 -4
- package/dist/types/{models → src/models}/segments/Segment.d.ts +4 -4
- package/dist/types/{models → src/models}/segments/utils/deCasteljau.d.ts +1 -1
- package/dist/types/src/models/segments/utils/isSegment.d.ts +8 -0
- package/dist/types/{models → src/models}/utils/Transformable.d.ts +2 -2
- package/dist/types/{offsetOperations.d.ts → 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/types/{utils → src/utils}/removeDuplicatePoints.d.ts +1 -1
- package/dist/types/{vectorOperations.d.ts → src/vectorOperations.d.ts} +1 -1
- package/package.json +33 -25
- package/dist/Diagram-8c3c5e1b.js +0 -5301
- package/dist/Diagram-8c3c5e1b.js.map +0 -1
- package/dist/Diagram-d8288579.cjs +0 -11
- package/dist/Diagram-d8288579.cjs.map +0 -1
- package/dist/draw-3ee546c3.cjs +0 -2
- package/dist/draw-3ee546c3.cjs.map +0 -1
- package/dist/draw-825692f1.js +0 -336
- package/dist/draw-825692f1.js.map +0 -1
- package/dist/types/algorithms/distances/lineArcDistance.d.ts +0 -3
- package/dist/types/algorithms/intersections/arcEllipseArcIntersection.d.ts +0 -3
- package/dist/types/algorithms/intersections/arcsCubicBezierIntersection.d.ts +0 -5
- package/dist/types/algorithms/intersections/arcsQuadraticBezierIntersection.d.ts +0 -5
- package/dist/types/algorithms/intersections/ellipseEllipseIntersection.d.ts +0 -4
- package/dist/types/algorithms/intersections/lineArcIntersection.d.ts +0 -4
- package/dist/types/algorithms/intersections/lineBezierIntersection.d.ts +0 -5
- package/dist/types/algorithms/intersections/lineEllipseArcIntersection.d.ts +0 -4
- package/dist/types/algorithms/intersections/rayIntersections.d.ts +0 -3
- package/dist/types/algorithms/simplify.d.ts +0 -3
- package/dist/types/api/drawShape.d.ts +0 -2
- package/dist/types/api/models.d.ts +0 -1
- package/dist/types/import/json/importJSON.d.ts +0 -9
- package/dist/types/models/exports.d.ts +0 -13
- package/dist/types/models/segments/utils/isSegment.d.ts +0 -8
- package/dist/types/operations.d.ts +0 -2
- package/dist/types/utils/listOfFigures.d.ts +0 -4
- package/dist/types/utils/projectPointOnLine.d.ts +0 -3
- /package/dist/types/{algorithms → src/algorithms}/optimisation/Brent.d.ts +0 -0
- /package/dist/types/{algorithms → src/algorithms}/optimisation/DiRect.d.ts +0 -0
- /package/dist/types/{algorithms → src/algorithms}/solvers/solvePolynomials.d.ts +0 -0
- /package/dist/types/{definitions.d.ts → src/definitions.d.ts} +0 -0
- /package/dist/types/{utils → src/utils}/allCombinations.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/allPairs.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/angularDistance.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/range.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/removeDuplicateValues.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/unitAngle.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/zip.d.ts +0 -0
package/dist/pantograph.js
CHANGED
|
@@ -1,616 +1,570 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var lt = Object.defineProperty;
|
|
2
|
+
var ut = (t, e, n) => e in t ? lt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var p = (t, e, n) => ut(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { o as gt, D } from "./draw-DqsKIWJD.js";
|
|
5
|
+
import { d as Pe } from "./draw-DqsKIWJD.js";
|
|
6
|
+
import { F as d, L as P, D as g, a as B, s as ht, b as pt, c as dt, i as mt, S as C, l as Pt, p as wt, d as Mt, e as X, g as It } from "./models-WQ-B7GSL.js";
|
|
7
|
+
import { h as Me } from "./models-WQ-B7GSL.js";
|
|
8
|
+
import { r as St, z as bt, l as Lt, f as w, n as Y, i as E, a as vt, s as kt, k as At, m as j, L as S, A as b, d as M, t as Et, c as yt, B as Ft, E as Ct, Q as xt, C as Dt } from "./QuadraticBezier-BzVqiExF.js";
|
|
9
|
+
import { s as Rt, a as Ot, b as Bt, c as $t, d as Gt, w as z } from "./svg-BylQQgsL.js";
|
|
10
|
+
function I(t) {
|
|
11
|
+
if (t instanceof d)
|
|
7
12
|
return [t];
|
|
8
13
|
if (t instanceof P)
|
|
9
|
-
return [new
|
|
10
|
-
if (t instanceof
|
|
14
|
+
return [new d(t)];
|
|
15
|
+
if (t instanceof g)
|
|
11
16
|
return t.figures;
|
|
12
17
|
throw new Error("Unknown shape");
|
|
13
18
|
}
|
|
14
|
-
function
|
|
15
|
-
let
|
|
16
|
-
const r = [],
|
|
17
|
-
|
|
19
|
+
function tt(t, e, n = 1e-9) {
|
|
20
|
+
let s = [];
|
|
21
|
+
const r = [], i = new Array(e.segments.length).fill(0).map(() => []);
|
|
22
|
+
e.segments.forEach((c, f) => {
|
|
18
23
|
t.segments.forEach((a) => {
|
|
19
|
-
const { intersections: u, overlaps:
|
|
24
|
+
const { intersections: u, overlaps: m } = B(
|
|
20
25
|
c,
|
|
21
26
|
a,
|
|
22
|
-
|
|
27
|
+
n
|
|
23
28
|
);
|
|
24
|
-
|
|
25
|
-
const
|
|
29
|
+
s.push(...u), i[f].push(...u), r.push(...m);
|
|
30
|
+
const h = m.flatMap((l) => [
|
|
26
31
|
l.firstPoint,
|
|
27
32
|
l.lastPoint
|
|
28
33
|
]);
|
|
29
|
-
|
|
34
|
+
s.push(...h), i[f].push(...h);
|
|
30
35
|
});
|
|
31
|
-
}),
|
|
32
|
-
const o =
|
|
36
|
+
}), s = St(s, n);
|
|
37
|
+
const o = bt([e.segments, i]).flatMap(([c, f]) => f.length ? c.splitAt(f) : [c]);
|
|
33
38
|
return Array.from(
|
|
34
|
-
|
|
39
|
+
ht(
|
|
35
40
|
o,
|
|
36
|
-
|
|
41
|
+
s,
|
|
37
42
|
r
|
|
38
43
|
)
|
|
39
44
|
);
|
|
40
45
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
43
|
-
const
|
|
44
|
-
return
|
|
46
|
+
function $(t, e, n = !1) {
|
|
47
|
+
return tt(e, t).filter((r) => {
|
|
48
|
+
const i = r.segments[0].midPoint;
|
|
49
|
+
return e.onStroke(i) ? !n : !e.contains(i);
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
|
-
function G(t,
|
|
48
|
-
return
|
|
49
|
-
const
|
|
50
|
-
return
|
|
52
|
+
function G(t, e, n = !1) {
|
|
53
|
+
return tt(e, t).filter((r) => {
|
|
54
|
+
const i = r.segments[0].midPoint;
|
|
55
|
+
return e.onStroke(i) ? !n : e.contains(i);
|
|
51
56
|
});
|
|
52
57
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
58
|
+
function V(t, e, n = !1) {
|
|
59
|
+
const s = $(
|
|
55
60
|
t,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
), r =
|
|
59
|
-
(
|
|
61
|
+
e.contour,
|
|
62
|
+
n
|
|
63
|
+
), r = e.holes.flatMap(
|
|
64
|
+
(i) => G(t, i, n)
|
|
60
65
|
);
|
|
61
|
-
return [...
|
|
66
|
+
return [...s, ...r];
|
|
62
67
|
}
|
|
63
|
-
function _(t,
|
|
64
|
-
let
|
|
68
|
+
function _(t, e, n = !1) {
|
|
69
|
+
let s = G(
|
|
65
70
|
t,
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
e.contour,
|
|
72
|
+
n
|
|
68
73
|
);
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
(
|
|
74
|
+
return e.holes.forEach((r) => {
|
|
75
|
+
s = s.flatMap(
|
|
76
|
+
(i) => $(i, r, n)
|
|
72
77
|
);
|
|
73
|
-
}),
|
|
78
|
+
}), s;
|
|
74
79
|
}
|
|
75
|
-
function
|
|
76
|
-
return new
|
|
77
|
-
|
|
80
|
+
function Tt(t, e) {
|
|
81
|
+
return new g(
|
|
82
|
+
pt(I(t), I(e))
|
|
78
83
|
);
|
|
79
84
|
}
|
|
80
|
-
function
|
|
85
|
+
function y(t) {
|
|
81
86
|
return t.reduce(
|
|
82
|
-
(
|
|
83
|
-
new
|
|
87
|
+
(e, n) => Tt(e, n),
|
|
88
|
+
new g()
|
|
84
89
|
);
|
|
85
90
|
}
|
|
86
|
-
function
|
|
87
|
-
return new
|
|
88
|
-
|
|
91
|
+
function et(t, e) {
|
|
92
|
+
return new g(
|
|
93
|
+
dt(I(t), I(e))
|
|
89
94
|
);
|
|
90
95
|
}
|
|
91
|
-
function
|
|
92
|
-
return new
|
|
93
|
-
|
|
96
|
+
function oe(t, e) {
|
|
97
|
+
return new g(
|
|
98
|
+
mt(I(t), I(e))
|
|
94
99
|
);
|
|
95
100
|
}
|
|
96
|
-
function
|
|
97
|
-
if (
|
|
98
|
-
return
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
101
|
-
let
|
|
102
|
-
return
|
|
103
|
-
|
|
104
|
-
}),
|
|
105
|
-
}
|
|
106
|
-
function
|
|
107
|
-
if (
|
|
108
|
-
return G(t,
|
|
109
|
-
if (
|
|
110
|
-
return _(t,
|
|
111
|
-
let
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
}),
|
|
115
|
-
}
|
|
116
|
-
function
|
|
101
|
+
function ae(t, e, n = !0) {
|
|
102
|
+
if (e instanceof P)
|
|
103
|
+
return $(t, e, n);
|
|
104
|
+
if (e instanceof d)
|
|
105
|
+
return V(t, e, n);
|
|
106
|
+
let s = [new C([...t.segments])];
|
|
107
|
+
return e.figures.forEach((r) => {
|
|
108
|
+
s = s.flatMap((i) => V(i, r, n));
|
|
109
|
+
}), s;
|
|
110
|
+
}
|
|
111
|
+
function ce(t, e, n = !1) {
|
|
112
|
+
if (e instanceof P)
|
|
113
|
+
return G(t, e, n);
|
|
114
|
+
if (e instanceof d)
|
|
115
|
+
return _(t, e, n);
|
|
116
|
+
let s = [new C([...t.segments])];
|
|
117
|
+
return e.figures.forEach((r) => {
|
|
118
|
+
s = s.flatMap((i) => _(i, r, n));
|
|
119
|
+
}), s;
|
|
120
|
+
}
|
|
121
|
+
function N(t) {
|
|
117
122
|
return t < 0 ? "before" : t > 1 ? "after" : "between";
|
|
118
123
|
}
|
|
119
|
-
const
|
|
120
|
-
if (
|
|
121
|
-
return t.distanceFrom(
|
|
122
|
-
if (
|
|
123
|
-
return t.distanceFrom(
|
|
124
|
+
const q = (t, e, n) => {
|
|
125
|
+
if (n === "before")
|
|
126
|
+
return t.distanceFrom(e.firstPoint);
|
|
127
|
+
if (n === "after")
|
|
128
|
+
return t.distanceFrom(e.lastPoint);
|
|
124
129
|
throw new Error("Invalid position");
|
|
125
130
|
};
|
|
126
|
-
function
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
131
|
+
function Ut(t, e) {
|
|
132
|
+
const n = Lt(t, e);
|
|
133
|
+
if (n === "parallel")
|
|
129
134
|
return Math.min(
|
|
130
|
-
t.distanceFrom(
|
|
131
|
-
t.distanceFrom(
|
|
135
|
+
t.distanceFrom(e.firstPoint),
|
|
136
|
+
t.distanceFrom(e.lastPoint)
|
|
132
137
|
);
|
|
133
|
-
const { intersectionParam1:
|
|
134
|
-
if (
|
|
138
|
+
const { intersectionParam1: s, intersectionParam2: r } = n, i = N(s), o = N(r);
|
|
139
|
+
if (i === "between" && o === "between")
|
|
135
140
|
return 0;
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
if (o === "between" &&
|
|
139
|
-
return
|
|
140
|
-
if (
|
|
141
|
-
return
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
144
|
-
if (
|
|
145
|
-
return
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
141
|
+
if (i === "between" && o !== "between")
|
|
142
|
+
return q(t, e, o);
|
|
143
|
+
if (o === "between" && i !== "between")
|
|
144
|
+
return q(e, t, i);
|
|
145
|
+
if (i === "before" && o === "before")
|
|
146
|
+
return w(t.firstPoint, e.firstPoint);
|
|
147
|
+
if (i === "after" && o === "after")
|
|
148
|
+
return w(t.lastPoint, e.lastPoint);
|
|
149
|
+
if (i === "before" && o === "after")
|
|
150
|
+
return w(t.firstPoint, e.lastPoint);
|
|
151
|
+
if (i === "after" && o === "before")
|
|
152
|
+
return w(t.lastPoint, e.firstPoint);
|
|
148
153
|
throw new Error("Invalid position");
|
|
149
154
|
}
|
|
150
|
-
function
|
|
151
|
-
if (
|
|
155
|
+
function J(t, e) {
|
|
156
|
+
if (Pt(t, e).length > 0)
|
|
152
157
|
return 0;
|
|
153
|
-
const
|
|
154
|
-
if (t.isOnSegment(
|
|
155
|
-
const
|
|
156
|
-
if (Math.abs(
|
|
158
|
+
const n = wt(t, e.center);
|
|
159
|
+
if (t.isOnSegment(n)) {
|
|
160
|
+
const s = w(n, e.center);
|
|
161
|
+
if (Math.abs(s - e.radius) < t.precision && e.isOnSegment(n))
|
|
157
162
|
return 0;
|
|
158
|
-
if (
|
|
159
|
-
const r =
|
|
160
|
-
E(
|
|
161
|
-
),
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
if (s - e.radius > t.precision) {
|
|
164
|
+
const r = Y(
|
|
165
|
+
E(n, e.center)
|
|
166
|
+
), i = vt(
|
|
167
|
+
e.center,
|
|
168
|
+
kt(r, e.radius)
|
|
164
169
|
);
|
|
165
|
-
if (
|
|
166
|
-
return
|
|
170
|
+
if (e.isOnSegment(i))
|
|
171
|
+
return w(i, n);
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
return Math.min(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
t.distanceFrom(
|
|
173
|
-
t.distanceFrom(
|
|
175
|
+
e.distanceFrom(t.firstPoint),
|
|
176
|
+
e.distanceFrom(t.lastPoint),
|
|
177
|
+
t.distanceFrom(e.firstPoint),
|
|
178
|
+
t.distanceFrom(e.lastPoint)
|
|
174
179
|
);
|
|
175
180
|
}
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
if (t.isValidParameter(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return !!t.isValidParameter(i);
|
|
181
|
+
const zt = (t, e) => {
|
|
182
|
+
const n = t.angleToParam(e.firstAngle);
|
|
183
|
+
if (t.isValidParameter(n)) return !0;
|
|
184
|
+
const s = t.angleToParam(e.lastAngle);
|
|
185
|
+
return !!t.isValidParameter(s);
|
|
182
186
|
};
|
|
183
|
-
function
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
r
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
t.distanceFrom(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
n.distanceFrom(t.lastPoint)
|
|
187
|
+
function Vt(t, e) {
|
|
188
|
+
if (Mt(t, e, !0).length > 0) return 0;
|
|
189
|
+
const n = w(t.center, e.center);
|
|
190
|
+
if (n < t.precision && zt(t, e))
|
|
191
|
+
return Math.abs(t.radius - e.radius);
|
|
192
|
+
const s = Y(E(e.center, t.center)), r = n - Math.abs(t.radius - e.radius) < t.precision;
|
|
193
|
+
let i = At(s);
|
|
194
|
+
r && e.radius > t.radius && (i += Math.PI);
|
|
195
|
+
const o = r ? i : i + Math.PI, c = t.angleToParam(i), f = e.angleToParam(o);
|
|
196
|
+
return t.isValidParameter(c) && e.isValidParameter(f) ? w(t.paramPoint(c), e.paramPoint(f)) : Math.min(
|
|
197
|
+
t.distanceFrom(e.firstPoint),
|
|
198
|
+
t.distanceFrom(e.lastPoint),
|
|
199
|
+
e.distanceFrom(t.firstPoint),
|
|
200
|
+
e.distanceFrom(t.lastPoint)
|
|
198
201
|
);
|
|
199
202
|
}
|
|
200
|
-
function
|
|
201
|
-
let
|
|
202
|
-
for (;
|
|
203
|
-
const
|
|
203
|
+
function _t(t, e, n) {
|
|
204
|
+
let s = 0, r = t.length - 1;
|
|
205
|
+
for (; s <= r; ) {
|
|
206
|
+
const i = Math.floor((s + r) / 2), o = n(t[i], e);
|
|
204
207
|
if (o < 0)
|
|
205
|
-
|
|
208
|
+
s = i + 1;
|
|
206
209
|
else if (o > 0)
|
|
207
|
-
r =
|
|
210
|
+
r = i - 1;
|
|
208
211
|
else
|
|
209
|
-
return
|
|
212
|
+
return i;
|
|
210
213
|
}
|
|
211
|
-
return -(
|
|
214
|
+
return -(s + 1);
|
|
212
215
|
}
|
|
213
|
-
function
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
+
function Nt(t, e, n) {
|
|
217
|
+
const s = _t(t, e, n);
|
|
218
|
+
s < 0 ? t.splice(-(s + 1), 0, e) : t.splice(s, 0, e);
|
|
216
219
|
}
|
|
217
|
-
class
|
|
220
|
+
class qt {
|
|
218
221
|
constructor() {
|
|
222
|
+
p(this, "buckets");
|
|
219
223
|
this.buckets = [];
|
|
220
224
|
}
|
|
221
|
-
addInterval(
|
|
222
|
-
const
|
|
223
|
-
|
|
225
|
+
addInterval(e) {
|
|
226
|
+
const n = this.buckets[e.rectangle.diagonalBucketIndex];
|
|
227
|
+
n === void 0 ? this.buckets[e.rectangle.diagonalBucketIndex] = [e] : Nt(n, e, (s, r) => s.value - r.value);
|
|
224
228
|
}
|
|
225
|
-
removeInterval(
|
|
226
|
-
const
|
|
227
|
-
if (
|
|
229
|
+
removeInterval(e) {
|
|
230
|
+
const n = this.buckets[e.rectangle.diagonalBucketIndex];
|
|
231
|
+
if (n === void 0)
|
|
228
232
|
throw new Error("Interval not found");
|
|
229
|
-
|
|
233
|
+
n.shift();
|
|
230
234
|
}
|
|
231
235
|
getBottomRightHullIntervals() {
|
|
232
|
-
const
|
|
233
|
-
for (let
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
236
|
-
|
|
237
|
-
const r = i[0];
|
|
236
|
+
const e = [];
|
|
237
|
+
for (let n = this.buckets.length - 1; n >= 0; n--) {
|
|
238
|
+
const s = this.buckets[n];
|
|
239
|
+
if (!s === void 0) continue;
|
|
240
|
+
const r = s[0];
|
|
238
241
|
if (r !== void 0) {
|
|
239
|
-
if (!
|
|
240
|
-
|
|
242
|
+
if (!e.length) {
|
|
243
|
+
e.push(r);
|
|
241
244
|
continue;
|
|
242
245
|
}
|
|
243
|
-
for (;
|
|
244
|
-
|
|
245
|
-
for (;
|
|
246
|
-
const
|
|
247
|
-
if (o.value + (
|
|
248
|
-
|
|
246
|
+
for (; e.length && e[e.length - 1].value >= r.value; )
|
|
247
|
+
e.pop();
|
|
248
|
+
for (; e.length >= 2; ) {
|
|
249
|
+
const i = e[e.length - 1], o = e[e.length - 2], c = (r.value - o.value) / ((r.rectangle.diagonal - o.rectangle.diagonal) * 2);
|
|
250
|
+
if (o.value + (i.rectangle.diagonal - o.rectangle.diagonal) / 2 * c < i.value)
|
|
251
|
+
e.pop();
|
|
249
252
|
else
|
|
250
253
|
break;
|
|
251
254
|
}
|
|
252
|
-
|
|
255
|
+
e.push(r);
|
|
253
256
|
}
|
|
254
257
|
}
|
|
255
|
-
return
|
|
258
|
+
return e;
|
|
256
259
|
}
|
|
257
260
|
}
|
|
258
|
-
class
|
|
259
|
-
constructor(
|
|
260
|
-
|
|
261
|
+
class Jt {
|
|
262
|
+
constructor(e, n) {
|
|
263
|
+
p(this, "diagonal");
|
|
264
|
+
p(this, "diagonalBucketIndex");
|
|
265
|
+
p(this, "xLength");
|
|
266
|
+
p(this, "yLength");
|
|
267
|
+
p(this, "index");
|
|
268
|
+
this.x = e, this.y = n, this.xLength = Math.pow(3, -e), this.yLength = Math.pow(3, -n), this.diagonal = Math.sqrt(
|
|
261
269
|
this.xLength * this.xLength + this.yLength * this.yLength
|
|
262
|
-
), this.diagonalBucketIndex =
|
|
270
|
+
), this.diagonalBucketIndex = e + n, this.index = `${e},${n}`;
|
|
263
271
|
}
|
|
264
272
|
}
|
|
265
|
-
class
|
|
266
|
-
constructor(
|
|
267
|
-
this
|
|
268
|
-
|
|
269
|
-
this
|
|
273
|
+
class Qt {
|
|
274
|
+
constructor(e, n = 1e-8, s = 1e3, r = 1e-6) {
|
|
275
|
+
p(this, "rectangles");
|
|
276
|
+
p(this, "buckets");
|
|
277
|
+
p(this, "fMin");
|
|
278
|
+
p(this, "argMin");
|
|
279
|
+
p(this, "tol");
|
|
280
|
+
this.fcn = e, this.endTolerance = n, this.maxIterations = s, this.epsilon = r, this.fcn = e, this.epsilon = r, this.endTolerance = n, this.maxIterations = s, this.rectangles = /* @__PURE__ */ new Map(), this.buckets = new qt();
|
|
281
|
+
const i = [0.5, 0.5], o = this.rect(0, 0), c = this.fcn(i);
|
|
282
|
+
this.buckets.addInterval(new A(i, c, o)), this.fMin = c, this.argMin = i, this.tol = o.diagonal;
|
|
270
283
|
}
|
|
271
|
-
registerInterval(
|
|
272
|
-
this.buckets.addInterval(
|
|
284
|
+
registerInterval(e) {
|
|
285
|
+
this.buckets.addInterval(e), e.value <= this.fMin && (this.fMin = e.value, this.argMin = e.center, this.tol = e.rectangle.diagonal);
|
|
273
286
|
}
|
|
274
|
-
rect(
|
|
275
|
-
const
|
|
276
|
-
return this.rectangles.has(
|
|
287
|
+
rect(e, n) {
|
|
288
|
+
const s = `${e},${n}`;
|
|
289
|
+
return this.rectangles.has(s) || this.rectangles.set(s, new Jt(e, n)), this.rectangles.get(s);
|
|
277
290
|
}
|
|
278
|
-
splitInterval(
|
|
279
|
-
let
|
|
280
|
-
const [
|
|
281
|
-
return
|
|
282
|
-
new
|
|
283
|
-
new
|
|
284
|
-
new
|
|
291
|
+
splitInterval(e) {
|
|
292
|
+
let n, s, r;
|
|
293
|
+
const [i, o] = e.center;
|
|
294
|
+
return e.rectangle.x <= e.rectangle.y ? (n = this.rect(e.rectangle.x + 1, e.rectangle.y), s = [i - n.xLength, o], r = [i + n.xLength, o]) : (n = this.rect(e.rectangle.x, e.rectangle.y + 1), s = [i, o - n.yLength], r = [i, o + n.yLength]), [
|
|
295
|
+
new A(s, this.fcn(s), n),
|
|
296
|
+
new A(e.center, e.value, n),
|
|
297
|
+
new A(r, this.fcn(r), n)
|
|
285
298
|
];
|
|
286
299
|
}
|
|
287
300
|
single_iteration() {
|
|
288
|
-
const
|
|
289
|
-
for (;
|
|
290
|
-
const
|
|
291
|
-
if ((this.fMin -
|
|
292
|
-
|
|
301
|
+
const e = this.buckets.getBottomRightHullIntervals();
|
|
302
|
+
for (; e.length >= 2; ) {
|
|
303
|
+
const n = e[0], s = e[1], r = (s.value - n.value) / ((s.rectangle.diagonal - n.rectangle.diagonal) / 2), i = n.value - r * s.value / 2;
|
|
304
|
+
if ((this.fMin - i) / Math.abs(this.fMin) < this.epsilon)
|
|
305
|
+
e.shift();
|
|
293
306
|
else
|
|
294
307
|
break;
|
|
295
308
|
}
|
|
296
|
-
|
|
297
|
-
this.buckets.removeInterval(
|
|
309
|
+
e.forEach((n) => {
|
|
310
|
+
this.buckets.removeInterval(n);
|
|
298
311
|
});
|
|
299
|
-
for (const
|
|
300
|
-
const [
|
|
301
|
-
this.registerInterval(
|
|
312
|
+
for (const n of e) {
|
|
313
|
+
const [s, r, i] = this.splitInterval(n);
|
|
314
|
+
this.registerInterval(s), this.registerInterval(r), this.registerInterval(i);
|
|
302
315
|
}
|
|
303
316
|
}
|
|
304
317
|
run() {
|
|
305
|
-
let
|
|
306
|
-
for (; this.tol > this.endTolerance / 2 && (this.single_iteration(),
|
|
318
|
+
let e = 0;
|
|
319
|
+
for (; this.tol > this.endTolerance / 2 && (this.single_iteration(), e++, !(e > this.maxIterations)); )
|
|
307
320
|
;
|
|
308
321
|
return {
|
|
309
322
|
fMin: this.fMin,
|
|
310
323
|
argMin: this.argMin,
|
|
311
324
|
tol: this.tol,
|
|
312
|
-
iterations:
|
|
325
|
+
iterations: e
|
|
313
326
|
};
|
|
314
327
|
}
|
|
315
328
|
}
|
|
316
|
-
class
|
|
317
|
-
constructor(
|
|
318
|
-
this.center =
|
|
329
|
+
class A {
|
|
330
|
+
constructor(e, n, s) {
|
|
331
|
+
this.center = e, this.value = n, this.rectangle = s;
|
|
319
332
|
}
|
|
320
333
|
}
|
|
321
|
-
function
|
|
322
|
-
return new
|
|
334
|
+
function Zt(t, e = 1e-8, n = 1e3, s = 1e-6) {
|
|
335
|
+
return new Qt(
|
|
323
336
|
t,
|
|
324
|
-
n,
|
|
325
337
|
e,
|
|
326
|
-
|
|
338
|
+
n,
|
|
339
|
+
s
|
|
327
340
|
).run();
|
|
328
341
|
}
|
|
329
|
-
function
|
|
330
|
-
const
|
|
331
|
-
const
|
|
332
|
-
return j(
|
|
333
|
-
},
|
|
334
|
-
return Math.sqrt(
|
|
342
|
+
function Ht(t, e, n = 1e-9) {
|
|
343
|
+
const s = Zt((r) => {
|
|
344
|
+
const i = t.paramPoint(r[0]), o = e.paramPoint(r[1]);
|
|
345
|
+
return j(i, o);
|
|
346
|
+
}, n);
|
|
347
|
+
return Math.sqrt(s.fMin);
|
|
335
348
|
}
|
|
336
|
-
function
|
|
337
|
-
return t instanceof
|
|
349
|
+
function Wt(t, e) {
|
|
350
|
+
return t instanceof S && e instanceof S ? Ut(t, e) : t instanceof S && e instanceof b ? J(t, e) : t instanceof b && e instanceof S ? J(e, t) : t instanceof b && e instanceof b ? Vt(t, e) : Ht(t, e);
|
|
338
351
|
}
|
|
339
352
|
const T = 1e-8;
|
|
340
|
-
function
|
|
341
|
-
const
|
|
342
|
-
offset:
|
|
353
|
+
function R(t, e, n = !0) {
|
|
354
|
+
const s = t.map((a) => ({
|
|
355
|
+
offset: gt(a, e),
|
|
343
356
|
original: a
|
|
344
357
|
})), r = [];
|
|
345
|
-
let
|
|
346
|
-
if (r.length === 1)
|
|
347
|
-
return r;
|
|
358
|
+
let i = n ? null : s.at(-1), o = n ? s.at(-1) : null;
|
|
359
|
+
if (r.length === 1) return r;
|
|
348
360
|
const c = (a) => {
|
|
349
|
-
|
|
350
|
-
new
|
|
351
|
-
) : r.push(a.offset) :
|
|
361
|
+
i ? a.offset instanceof D ? M(a.offset.firstPoint, a.offset.lastPoint) || r.push(
|
|
362
|
+
new S(a.offset.firstPoint, a.offset.lastPoint)
|
|
363
|
+
) : r.push(a.offset) : i = a;
|
|
352
364
|
}, f = function* () {
|
|
353
|
-
for (const a of
|
|
365
|
+
for (const a of s.slice(0, -1))
|
|
354
366
|
yield a;
|
|
355
|
-
if (!
|
|
356
|
-
|
|
357
|
-
yield s;
|
|
367
|
+
if (!i) throw new Error("Bug in the offset algorithm");
|
|
368
|
+
yield i;
|
|
358
369
|
};
|
|
359
370
|
for (const a of f()) {
|
|
360
371
|
if (!o) {
|
|
361
372
|
o = a;
|
|
362
373
|
continue;
|
|
363
374
|
}
|
|
364
|
-
const u = o.offset.lastPoint,
|
|
365
|
-
if (
|
|
375
|
+
const u = o.offset.lastPoint, m = a.offset.firstPoint;
|
|
376
|
+
if (M(u, m)) {
|
|
366
377
|
c(o), o = a;
|
|
367
378
|
continue;
|
|
368
379
|
}
|
|
369
|
-
let
|
|
380
|
+
let h = [];
|
|
370
381
|
if (!(o.offset instanceof D) && !(a.offset instanceof D)) {
|
|
371
|
-
const { intersections:
|
|
382
|
+
const { intersections: L, overlaps: x } = B(
|
|
372
383
|
o.offset,
|
|
373
384
|
a.offset,
|
|
374
385
|
T / 100
|
|
375
386
|
);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
...
|
|
387
|
+
h = [
|
|
388
|
+
...L,
|
|
389
|
+
...x.flatMap((v) => [v.firstPoint, v.lastPoint])
|
|
379
390
|
];
|
|
380
391
|
}
|
|
381
|
-
if (
|
|
382
|
-
let
|
|
383
|
-
if (
|
|
384
|
-
const
|
|
385
|
-
(
|
|
392
|
+
if (h.length > 0) {
|
|
393
|
+
let L = h[0];
|
|
394
|
+
if (h.length > 1) {
|
|
395
|
+
const ct = o == null ? void 0 : o.original.lastPoint, U = h.map(
|
|
396
|
+
(ft) => j(ft, ct)
|
|
386
397
|
);
|
|
387
|
-
|
|
398
|
+
L = h[U.indexOf(Math.min(...U))];
|
|
388
399
|
}
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
])[0],
|
|
392
|
-
if (!
|
|
393
|
-
throw new Error("Bug in the splitting algo in offset");
|
|
400
|
+
const x = o.offset.splitAt([
|
|
401
|
+
L
|
|
402
|
+
])[0], v = a.offset.splitAt([L]).at(-1);
|
|
403
|
+
if (!v) throw new Error("Bug in the splitting algo in offset");
|
|
394
404
|
c({
|
|
395
|
-
offset:
|
|
405
|
+
offset: x,
|
|
396
406
|
original: o.original
|
|
397
|
-
}), o = { offset:
|
|
407
|
+
}), o = { offset: v, original: a.original };
|
|
398
408
|
continue;
|
|
399
409
|
}
|
|
400
|
-
const l = o.original.lastPoint,
|
|
401
|
-
E(
|
|
410
|
+
const l = o.original.lastPoint, k = yt(
|
|
411
|
+
E(m, l),
|
|
402
412
|
E(u, l)
|
|
403
|
-
) > 0,
|
|
404
|
-
c(o), r.push(
|
|
413
|
+
) > 0, at = new b(u, m, l, k);
|
|
414
|
+
c(o), r.push(at), o = a;
|
|
405
415
|
}
|
|
406
416
|
return o && c(o), r;
|
|
407
417
|
}
|
|
408
|
-
function
|
|
409
|
-
const
|
|
410
|
-
const
|
|
411
|
-
|
|
418
|
+
function nt(t) {
|
|
419
|
+
const e = /* @__PURE__ */ new Map(), n = (s, r) => {
|
|
420
|
+
const i = e.get(s) || [];
|
|
421
|
+
e.set(s, [...i, ...r]);
|
|
412
422
|
};
|
|
413
|
-
return t.forEach((
|
|
414
|
-
t.slice(r + 1).forEach((
|
|
415
|
-
const { intersections: c, overlaps: f } =
|
|
423
|
+
return t.forEach((s, r) => {
|
|
424
|
+
t.slice(r + 1).forEach((i, o) => {
|
|
425
|
+
const { intersections: c, overlaps: f } = B(s, i, T), a = [
|
|
416
426
|
...c,
|
|
417
427
|
...f.flatMap((u) => [u.firstPoint, u.lastPoint])
|
|
418
428
|
].filter((u) => {
|
|
419
|
-
const
|
|
420
|
-
return !(
|
|
429
|
+
const m = M(u, s.firstPoint) || M(u, s.lastPoint), h = M(u, i.firstPoint) || M(u, i.lastPoint);
|
|
430
|
+
return !(m && h);
|
|
421
431
|
});
|
|
422
|
-
a.length && (
|
|
432
|
+
a.length && (n(r, a), n(o + r + 1, a));
|
|
423
433
|
});
|
|
424
|
-
}),
|
|
425
|
-
}
|
|
426
|
-
function
|
|
427
|
-
return
|
|
428
|
-
if (!t.has(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return r ? e.splitAt(r) : e;
|
|
434
|
+
}), e;
|
|
435
|
+
}
|
|
436
|
+
function st(t, e) {
|
|
437
|
+
return e.flatMap((n, s) => {
|
|
438
|
+
if (!t.has(s)) return n;
|
|
439
|
+
const r = t.get(s);
|
|
440
|
+
return r ? n.splitAt(r) : n;
|
|
432
441
|
});
|
|
433
442
|
}
|
|
434
|
-
function
|
|
435
|
-
return t.filter((
|
|
443
|
+
function it(t, e, n) {
|
|
444
|
+
return t.filter((s) => !e.segments.some((i) => Wt(i, s) < Math.abs(n) - T));
|
|
436
445
|
}
|
|
437
|
-
function
|
|
438
|
-
const
|
|
439
|
-
if (
|
|
440
|
-
|
|
441
|
-
const r = ot(i);
|
|
446
|
+
function F(t, e) {
|
|
447
|
+
const n = t.clockwise ? e : -e, s = R(t.segments, n);
|
|
448
|
+
if (s.length < 2) return new g();
|
|
449
|
+
const r = nt(s);
|
|
442
450
|
if (!r.size) {
|
|
443
|
-
const a = new P(
|
|
444
|
-
return new
|
|
451
|
+
const a = new P(s);
|
|
452
|
+
return new g([new d(a)]);
|
|
445
453
|
}
|
|
446
|
-
const
|
|
454
|
+
const i = st(
|
|
447
455
|
r,
|
|
448
|
-
|
|
449
|
-
), o =
|
|
450
|
-
if (!o.length)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const i = n / 2, r = x(t.segments, i, !1), s = x(t.segments, -i, !1).map(
|
|
456
|
+
s
|
|
457
|
+
), o = it(i, t, e);
|
|
458
|
+
if (!o.length) return new g();
|
|
459
|
+
const f = X(o).filter((a) => a.length > 1).filter((a) => M(a[0].firstPoint, a.at(-1).lastPoint)).map((a) => new P(a));
|
|
460
|
+
return f.length ? new g(f.map((a) => new d(a))) : new g();
|
|
461
|
+
}
|
|
462
|
+
function Kt(t, e, n = "round") {
|
|
463
|
+
const s = e / 2, r = R(t.segments, s, !1), i = R(t.segments, -s, !1).map(
|
|
457
464
|
(l) => l.reverse()
|
|
458
465
|
);
|
|
459
|
-
|
|
460
|
-
const o = (l,
|
|
466
|
+
i.reverse();
|
|
467
|
+
const o = (l, k) => n === "round" ? Et(
|
|
461
468
|
l.lastPoint,
|
|
462
|
-
|
|
469
|
+
k.firstPoint,
|
|
463
470
|
l.tangentAtLastPoint
|
|
464
|
-
) : new
|
|
471
|
+
) : new S(l.lastPoint, k.firstPoint), c = [
|
|
465
472
|
...r,
|
|
466
473
|
o(
|
|
467
474
|
r[r.length - 1],
|
|
468
|
-
|
|
475
|
+
i[0]
|
|
469
476
|
),
|
|
470
|
-
...
|
|
477
|
+
...i,
|
|
471
478
|
o(
|
|
472
|
-
|
|
479
|
+
i[i.length - 1],
|
|
473
480
|
r[0]
|
|
474
481
|
)
|
|
475
|
-
], f =
|
|
482
|
+
], f = nt(c);
|
|
476
483
|
if (!f.size) {
|
|
477
484
|
const l = new P(c);
|
|
478
|
-
return new
|
|
485
|
+
return new g([new d(l)]);
|
|
479
486
|
}
|
|
480
|
-
const a =
|
|
487
|
+
const a = st(
|
|
481
488
|
f,
|
|
482
489
|
c
|
|
483
|
-
), u =
|
|
484
|
-
if (!u.length)
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
i.holes.map((s) => y(s, n))
|
|
490
|
+
), u = it(a, t, s);
|
|
491
|
+
if (!u.length) return new g();
|
|
492
|
+
const h = X(u).filter((l) => l.length > 1).filter((l) => M(l[0].firstPoint, l.at(-1).lastPoint)).map((l) => new P(l));
|
|
493
|
+
return h.length ? new g(h.map((l) => new d(l))) : new g();
|
|
494
|
+
}
|
|
495
|
+
function Xt(t, e) {
|
|
496
|
+
const n = t.map((s) => {
|
|
497
|
+
const r = y(
|
|
498
|
+
s.holes.map((i) => F(i, e))
|
|
493
499
|
);
|
|
494
|
-
return
|
|
500
|
+
return et(F(s.contour, e), r);
|
|
495
501
|
});
|
|
496
|
-
return
|
|
502
|
+
return y(n);
|
|
497
503
|
}
|
|
498
|
-
function
|
|
499
|
-
const
|
|
500
|
-
(r) =>
|
|
501
|
-
r.allLoops.map((
|
|
504
|
+
function Yt(t, e) {
|
|
505
|
+
const n = Math.abs(e / 2), s = t.map(
|
|
506
|
+
(r) => y(
|
|
507
|
+
r.allLoops.map((i) => et(F(i, n), F(i, -n)))
|
|
502
508
|
)
|
|
503
509
|
);
|
|
504
|
-
return
|
|
505
|
-
}
|
|
506
|
-
function
|
|
507
|
-
return
|
|
508
|
-
}
|
|
509
|
-
function
|
|
510
|
-
return t instanceof C ?
|
|
511
|
-
}
|
|
512
|
-
function w([t, n]) {
|
|
513
|
-
return `${t} ${n}`;
|
|
514
|
-
}
|
|
515
|
-
function U(t) {
|
|
516
|
-
if (t instanceof M)
|
|
517
|
-
return `L ${w(t.lastPoint)}`;
|
|
518
|
-
if (t instanceof v)
|
|
519
|
-
return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${w(t.lastPoint)}`;
|
|
520
|
-
if (t instanceof nt)
|
|
521
|
-
return `A ${t.majorRadius} ${t.minorRadius} ${t.tiltAngle * Dt} ${t.deltaAngle > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${w(t.lastPoint)}`;
|
|
522
|
-
if (t instanceof et)
|
|
523
|
-
return `Q ${[
|
|
524
|
-
w(t.controlPoint),
|
|
525
|
-
w(t.lastPoint)
|
|
526
|
-
].join(" ")}`;
|
|
527
|
-
if (t instanceof it)
|
|
528
|
-
return `C ${[
|
|
529
|
-
w(t.firstControlPoint),
|
|
530
|
-
w(t.lastControlPoint),
|
|
531
|
-
w(t.lastPoint)
|
|
532
|
-
].join(" ")}`;
|
|
533
|
-
throw new Error("Unknown segment type");
|
|
510
|
+
return y(s);
|
|
511
|
+
}
|
|
512
|
+
function fe(t, e) {
|
|
513
|
+
return Xt(I(t), e);
|
|
514
|
+
}
|
|
515
|
+
function le(t, e, { endCap: n = "round" } = {}) {
|
|
516
|
+
return t instanceof C ? Kt(t, e, n) : Yt(I(t), e);
|
|
534
517
|
}
|
|
535
|
-
function
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
return `<path d="${t.allLoops.map(ft).join(" ")}" />`;
|
|
541
|
-
}
|
|
542
|
-
function Xt(t) {
|
|
543
|
-
return `<g>
|
|
544
|
-
${t.figures.map(lt).join(`
|
|
545
|
-
`)}
|
|
546
|
-
</g>`;
|
|
547
|
-
}
|
|
548
|
-
function Yt(t) {
|
|
549
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(U).join(" ");
|
|
550
|
-
return `${n} ${e}`;
|
|
551
|
-
}
|
|
552
|
-
function Kt(t, n = 1) {
|
|
553
|
-
const e = t.xMin - n, i = t.yMin - n;
|
|
554
|
-
return `${e} ${i} ${t.width + 2 * n} ${t.height + 2 * n}`;
|
|
555
|
-
}
|
|
556
|
-
function Z(t, n, e = 1, i) {
|
|
557
|
-
const r = Kt(n, e), s = i ? `width="${n.width + 2 * e}${i}" height="${n.height + 2 * e}${i}"` : "";
|
|
558
|
-
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
559
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${r}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${s}>
|
|
560
|
-
${t}
|
|
561
|
-
</svg>`;
|
|
562
|
-
}
|
|
563
|
-
function J(t) {
|
|
564
|
-
if (t instanceof h)
|
|
565
|
-
return Xt(t);
|
|
566
|
-
if (t instanceof p)
|
|
567
|
-
return lt(t);
|
|
518
|
+
function Q(t) {
|
|
519
|
+
if (t instanceof g)
|
|
520
|
+
return Rt(t);
|
|
521
|
+
if (t instanceof d)
|
|
522
|
+
return Ot(t);
|
|
568
523
|
if (t instanceof P)
|
|
569
|
-
return `<path d="${
|
|
524
|
+
return `<path d="${Bt(t)}" />`;
|
|
570
525
|
if (t instanceof C)
|
|
571
|
-
return `<path d="${
|
|
572
|
-
if (
|
|
573
|
-
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${
|
|
526
|
+
return `<path d="${$t(t)}" />`;
|
|
527
|
+
if (It(t))
|
|
528
|
+
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${Gt(
|
|
574
529
|
t
|
|
575
530
|
)}" />`;
|
|
576
531
|
throw new Error("Unknown shape type");
|
|
577
532
|
}
|
|
578
|
-
const
|
|
579
|
-
if (!("shape" in t))
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
viewBox: i
|
|
533
|
+
const Z = (t) => "shape" in t ? t.shape : t, H = (t, e) => {
|
|
534
|
+
if (!("shape" in t)) return e;
|
|
535
|
+
const { color: n } = t;
|
|
536
|
+
return n ? `<g stroke="${n}">${e}</g>` : e;
|
|
537
|
+
}, W = (t) => new Ft(t.xMin, -t.yMax, t.xMax, -t.yMin);
|
|
538
|
+
function ue(t, {
|
|
539
|
+
margin: e = 1,
|
|
540
|
+
unit: n = null,
|
|
541
|
+
viewBox: s
|
|
588
542
|
} = {}) {
|
|
589
543
|
if (Array.isArray(t)) {
|
|
590
|
-
const
|
|
591
|
-
`), c =
|
|
592
|
-
return
|
|
544
|
+
const i = t.map((f) => Z(f).mirror()), o = i.map((f, a) => H(t[a], Q(f))).join(`
|
|
545
|
+
`), c = i.slice(1).reduce((f, a) => f.merge(a.boundingBox), i[0].boundingBox);
|
|
546
|
+
return z(o, s ? W(s) : c, e, n);
|
|
593
547
|
}
|
|
594
|
-
const r =
|
|
595
|
-
return
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
548
|
+
const r = Z(t).mirror();
|
|
549
|
+
return z(
|
|
550
|
+
H(t, Q(r)),
|
|
551
|
+
s ? W(s) : r.boundingBox,
|
|
552
|
+
e,
|
|
553
|
+
n
|
|
600
554
|
);
|
|
601
555
|
}
|
|
602
|
-
const
|
|
556
|
+
const rt = (t) => {
|
|
603
557
|
if (t.type === "LINE")
|
|
604
|
-
return new
|
|
558
|
+
return new S(t.firstPoint, t.lastPoint);
|
|
605
559
|
if (t.type === "ARC")
|
|
606
|
-
return new
|
|
560
|
+
return new b(
|
|
607
561
|
t.firstPoint,
|
|
608
562
|
t.lastPoint,
|
|
609
563
|
t.center,
|
|
610
564
|
t.clockwise
|
|
611
565
|
);
|
|
612
566
|
if (t.type === "ELLIPSE_ARC")
|
|
613
|
-
return new
|
|
567
|
+
return new Ct(
|
|
614
568
|
t.firstPoint,
|
|
615
569
|
t.lastPoint,
|
|
616
570
|
t.center,
|
|
@@ -621,66 +575,66 @@ const ut = (t) => {
|
|
|
621
575
|
{ angleUnits: "rad" }
|
|
622
576
|
);
|
|
623
577
|
if (t.type === "QUADRATIC_BEZIER")
|
|
624
|
-
return new
|
|
578
|
+
return new xt(
|
|
625
579
|
t.firstPoint,
|
|
626
580
|
t.lastPoint,
|
|
627
581
|
t.controlPoint
|
|
628
582
|
);
|
|
629
583
|
if (t.type === "CUBIC_BEZIER")
|
|
630
|
-
return new
|
|
584
|
+
return new Dt(
|
|
631
585
|
t.firstPoint,
|
|
632
586
|
t.lastPoint,
|
|
633
587
|
t.firstControlPoint,
|
|
634
588
|
t.lastControlPoint
|
|
635
589
|
);
|
|
636
590
|
throw new Error("Unknown segment type");
|
|
637
|
-
},
|
|
638
|
-
const
|
|
639
|
-
return new P(
|
|
640
|
-
},
|
|
641
|
-
const
|
|
642
|
-
return new
|
|
591
|
+
}, O = (t) => {
|
|
592
|
+
const e = t.segments.map(rt);
|
|
593
|
+
return new P(e);
|
|
594
|
+
}, ot = (t) => {
|
|
595
|
+
const e = O(t.contour), n = t.holes.map(O);
|
|
596
|
+
return new d(e, n);
|
|
643
597
|
}, jt = (t) => {
|
|
644
|
-
const
|
|
645
|
-
return new
|
|
598
|
+
const e = t.figures.map(ot);
|
|
599
|
+
return new g(e);
|
|
646
600
|
};
|
|
647
|
-
function
|
|
601
|
+
function ge(t) {
|
|
648
602
|
if (t.type === "DIAGRAM")
|
|
649
603
|
return jt(t);
|
|
650
604
|
if (t.type === "FIGURE")
|
|
651
|
-
return
|
|
605
|
+
return ot(t);
|
|
652
606
|
if (t.type === "LOOP")
|
|
653
|
-
return
|
|
607
|
+
return O(t);
|
|
654
608
|
if (t.type === "LINE" || t.type === "ARC" || t.type === "ELLIPSE_ARC" || t.type === "CUBIC_BEZIER")
|
|
655
|
-
return
|
|
609
|
+
return rt(t);
|
|
656
610
|
throw new Error("Unknown shape type");
|
|
657
611
|
}
|
|
658
|
-
const
|
|
659
|
-
function
|
|
660
|
-
const
|
|
661
|
-
return [
|
|
612
|
+
const K = Math.PI / 180, te = 180 / Math.PI;
|
|
613
|
+
function he(t, e) {
|
|
614
|
+
const n = Math.cos(e * K) * t, s = Math.sin(e * K) * t;
|
|
615
|
+
return [n, s];
|
|
662
616
|
}
|
|
663
|
-
function
|
|
664
|
-
const
|
|
665
|
-
return [
|
|
617
|
+
function pe([t, e]) {
|
|
618
|
+
const n = Math.sqrt(t * t + e * e), s = Math.atan2(e, t) * te;
|
|
619
|
+
return [n, s];
|
|
666
620
|
}
|
|
667
621
|
export {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
622
|
+
K as DEG2RAD,
|
|
623
|
+
te as RAD2DEG,
|
|
624
|
+
pe as cartesianToPolar,
|
|
625
|
+
ce as confineStrand,
|
|
626
|
+
et as cut,
|
|
627
|
+
Pe as draw,
|
|
628
|
+
ae as eraseStrand,
|
|
629
|
+
Me as exportJSON,
|
|
630
|
+
ue as exportSVG,
|
|
631
|
+
Tt as fuse,
|
|
632
|
+
y as fuseAll,
|
|
633
|
+
ge as importJSON,
|
|
634
|
+
oe as intersect,
|
|
635
|
+
fe as offset,
|
|
636
|
+
le as outlineStroke,
|
|
637
|
+
he as polarToCartesian,
|
|
638
|
+
Q as svgBody
|
|
685
639
|
};
|
|
686
640
|
//# sourceMappingURL=pantograph.js.map
|