pantograph2d 0.8.1 → 0.9.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/dist/QuadraticBezier--UZr_xcV.cjs +9 -0
- package/dist/QuadraticBezier--UZr_xcV.cjs.map +1 -0
- package/dist/{QuadraticBezier-BzVqiExF.js → QuadraticBezier-DxieHk9z.js} +1811 -1772
- package/dist/QuadraticBezier-DxieHk9z.js.map +1 -0
- package/dist/draw-SMxwuKNJ.cjs +2 -0
- package/dist/draw-SMxwuKNJ.cjs.map +1 -0
- package/dist/draw-yb7FrCL_.js +418 -0
- package/dist/draw-yb7FrCL_.js.map +1 -0
- package/dist/{models-Dxwusy3i.cjs → models-wvgj1vj2.cjs} +2 -2
- package/dist/{models-Dxwusy3i.cjs.map → models-wvgj1vj2.cjs.map} +1 -1
- package/dist/{models-WQ-B7GSL.js → models-zEMLdtLw.js} +18 -18
- package/dist/{models-WQ-B7GSL.js.map → models-zEMLdtLw.js.map} +1 -1
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.cjs.map +1 -1
- package/dist/pantograph/drawShape.js +1 -1
- 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 +1 -1
- package/dist/pantograph.cjs +2 -2
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.js +693 -455
- package/dist/pantograph.js.map +1 -1
- package/dist/{svg-BylQQgsL.js → svg-BIphc_zE.js} +3 -3
- package/dist/{svg-BylQQgsL.js.map → svg-BIphc_zE.js.map} +1 -1
- package/dist/{svg-D0nYyMk7.cjs → svg-BY5h3CDD.cjs} +3 -3
- package/dist/{svg-D0nYyMk7.cjs.map → svg-BY5h3CDD.cjs.map} +1 -1
- 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/types/src/algorithms/intersections/fullLinesIntersection.d.ts +18 -0
- package/dist/types/src/algorithms/offsets/offsetSegment.d.ts +4 -1
- package/dist/types/src/algorithms/offsets/offsetStroke.d.ts +3 -1
- package/dist/types/src/conversionOperations.d.ts +8 -0
- package/dist/types/src/featureOperations.d.ts +88 -0
- package/dist/types/src/main.d.ts +1 -1
- package/dist/types/src/models/segments/Arc.d.ts +1 -0
- package/dist/types/src/models/segments/CubicBezier.d.ts +7 -0
- package/dist/types/src/models/segments/QuadraticBezier.d.ts +5 -0
- package/dist/types/src/operations.d.ts +1 -0
- package/dist/types/src/vectorOperations.d.ts +1 -1
- package/package.json +2 -2
- package/dist/QuadraticBezier-BAVasVfu.cjs +0 -9
- package/dist/QuadraticBezier-BAVasVfu.cjs.map +0 -1
- package/dist/QuadraticBezier-BzVqiExF.js.map +0 -1
- package/dist/draw-DqsKIWJD.js +0 -337
- package/dist/draw-DqsKIWJD.js.map +0 -1
- package/dist/draw-NcYfDZjT.cjs +0 -2
- package/dist/draw-NcYfDZjT.cjs.map +0 -1
- package/dist/types/src/algorithms/solvers/zeroViaNewton.d.ts +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { o as
|
|
5
|
-
import { d as
|
|
6
|
-
import { F as
|
|
7
|
-
import { h as
|
|
8
|
-
import { r as
|
|
9
|
-
import { s as
|
|
10
|
-
function
|
|
11
|
-
if (
|
|
12
|
-
return [
|
|
13
|
-
if (
|
|
14
|
-
return [new
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
1
|
+
var yt = Object.defineProperty;
|
|
2
|
+
var Ct = (n, t, e) => t in n ? yt(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var P = (n, t, e) => Ct(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { o as xt, D as U, f as lt } from "./draw-yb7FrCL_.js";
|
|
5
|
+
import { d as _n } from "./draw-yb7FrCL_.js";
|
|
6
|
+
import { F as m, L as w, D as h, a as N, s as Ot, b as Dt, c as Bt, i as Rt, S as y, l as zt, p as Tt, d as $t, e as ut, g as Gt } from "./models-zEMLdtLw.js";
|
|
7
|
+
import { h as Kn } from "./models-zEMLdtLw.js";
|
|
8
|
+
import { r as Ut, z as _t, l as Vt, e as b, n as ht, b as F, a as Kt, s as qt, m as Ht, o as gt, L as A, A as E, C as $, p as Y, q as V, d as Nt, T as Jt, g as I, E as pt, Q as dt, t as Qt, c as Xt, D as Yt, B as Zt } from "./QuadraticBezier-DxieHk9z.js";
|
|
9
|
+
import { s as Wt, a as jt, b as tn, c as nn, d as en, w as Z } from "./svg-BIphc_zE.js";
|
|
10
|
+
function L(n) {
|
|
11
|
+
if (n instanceof m)
|
|
12
|
+
return [n];
|
|
13
|
+
if (n instanceof w)
|
|
14
|
+
return [new m(n)];
|
|
15
|
+
if (n instanceof h)
|
|
16
|
+
return n.figures;
|
|
17
17
|
throw new Error("Unknown shape");
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function mt(n, t, e = 1e-9) {
|
|
20
20
|
let s = [];
|
|
21
|
-
const r = [], i = new Array(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const { intersections:
|
|
25
|
-
c,
|
|
21
|
+
const r = [], i = new Array(t.segments.length).fill(0).map(() => []);
|
|
22
|
+
t.segments.forEach((a, f) => {
|
|
23
|
+
n.segments.forEach((c) => {
|
|
24
|
+
const { intersections: l, overlaps: p } = N(
|
|
26
25
|
a,
|
|
27
|
-
|
|
26
|
+
c,
|
|
27
|
+
e
|
|
28
28
|
);
|
|
29
|
-
s.push(...
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
s.push(...l), i[f].push(...l), r.push(...p);
|
|
30
|
+
const g = p.flatMap((d) => [
|
|
31
|
+
d.firstPoint,
|
|
32
|
+
d.lastPoint
|
|
33
33
|
]);
|
|
34
|
-
s.push(...
|
|
34
|
+
s.push(...g), i[f].push(...g);
|
|
35
35
|
});
|
|
36
|
-
}), s =
|
|
37
|
-
const o =
|
|
36
|
+
}), s = Ut(s, e);
|
|
37
|
+
const o = _t([t.segments, i]).flatMap(([a, f]) => f.length ? a.splitAt(f) : [a]);
|
|
38
38
|
return Array.from(
|
|
39
|
-
|
|
39
|
+
Ot(
|
|
40
40
|
o,
|
|
41
41
|
s,
|
|
42
42
|
r
|
|
43
43
|
)
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
return
|
|
46
|
+
function J(n, t, e = !1) {
|
|
47
|
+
return mt(t, n).filter((r) => {
|
|
48
48
|
const i = r.segments[0].midPoint;
|
|
49
|
-
return
|
|
49
|
+
return t.onStroke(i) ? !e : !t.contains(i);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
52
|
+
function Q(n, t, e = !1) {
|
|
53
|
+
return mt(t, n).filter((r) => {
|
|
54
54
|
const i = r.segments[0].midPoint;
|
|
55
|
-
return
|
|
55
|
+
return t.onStroke(i) ? !e : t.contains(i);
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
const s =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
), r =
|
|
64
|
-
(i) =>
|
|
58
|
+
function W(n, t, e = !1) {
|
|
59
|
+
const s = J(
|
|
60
|
+
n,
|
|
61
|
+
t.contour,
|
|
62
|
+
e
|
|
63
|
+
), r = t.holes.flatMap(
|
|
64
|
+
(i) => Q(n, i, e)
|
|
65
65
|
);
|
|
66
66
|
return [...s, ...r];
|
|
67
67
|
}
|
|
68
|
-
function
|
|
69
|
-
let s =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
function j(n, t, e = !1) {
|
|
69
|
+
let s = Q(
|
|
70
|
+
n,
|
|
71
|
+
t.contour,
|
|
72
|
+
e
|
|
73
73
|
);
|
|
74
|
-
return
|
|
74
|
+
return t.holes.forEach((r) => {
|
|
75
75
|
s = s.flatMap(
|
|
76
|
-
(i) =>
|
|
76
|
+
(i) => J(i, r, e)
|
|
77
77
|
);
|
|
78
78
|
}), s;
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
return new
|
|
82
|
-
|
|
80
|
+
function sn(n, t) {
|
|
81
|
+
return new h(
|
|
82
|
+
Dt(L(n), L(t))
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
return
|
|
87
|
-
(
|
|
88
|
-
new
|
|
85
|
+
function z(n) {
|
|
86
|
+
return n.reduce(
|
|
87
|
+
(t, e) => sn(t, e),
|
|
88
|
+
new h()
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return new
|
|
93
|
-
|
|
91
|
+
function Pt(n, t) {
|
|
92
|
+
return new h(
|
|
93
|
+
Bt(L(n), L(t))
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
return new
|
|
98
|
-
|
|
96
|
+
function yn(n, t) {
|
|
97
|
+
return new h(
|
|
98
|
+
Rt(L(n), L(t))
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
104
|
-
if (
|
|
105
|
-
return
|
|
106
|
-
let s = [new
|
|
107
|
-
return
|
|
108
|
-
s = s.flatMap((i) =>
|
|
101
|
+
function Cn(n, t, e = !0) {
|
|
102
|
+
if (t instanceof w)
|
|
103
|
+
return J(n, t, e);
|
|
104
|
+
if (t instanceof m)
|
|
105
|
+
return W(n, t, e);
|
|
106
|
+
let s = [new y([...n.segments])];
|
|
107
|
+
return t.figures.forEach((r) => {
|
|
108
|
+
s = s.flatMap((i) => W(i, r, e));
|
|
109
109
|
}), s;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
if (
|
|
113
|
-
return
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
116
|
-
let s = [new
|
|
117
|
-
return
|
|
118
|
-
s = s.flatMap((i) =>
|
|
111
|
+
function xn(n, t, e = !1) {
|
|
112
|
+
if (t instanceof w)
|
|
113
|
+
return Q(n, t, e);
|
|
114
|
+
if (t instanceof m)
|
|
115
|
+
return j(n, t, e);
|
|
116
|
+
let s = [new y([...n.segments])];
|
|
117
|
+
return t.figures.forEach((r) => {
|
|
118
|
+
s = s.flatMap((i) => j(i, r, e));
|
|
119
119
|
}), s;
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function tt(n) {
|
|
122
|
+
return n < 0 ? "before" : n > 1 ? "after" : "between";
|
|
123
123
|
}
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
return
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
124
|
+
const nt = (n, t, e) => {
|
|
125
|
+
if (e === "before")
|
|
126
|
+
return n.distanceFrom(t.firstPoint);
|
|
127
|
+
if (e === "after")
|
|
128
|
+
return n.distanceFrom(t.lastPoint);
|
|
129
129
|
throw new Error("Invalid position");
|
|
130
130
|
};
|
|
131
|
-
function
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
131
|
+
function rn(n, t) {
|
|
132
|
+
const e = Vt(n, t);
|
|
133
|
+
if (e === "parallel")
|
|
134
134
|
return Math.min(
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
n.distanceFrom(t.firstPoint),
|
|
136
|
+
n.distanceFrom(t.lastPoint)
|
|
137
137
|
);
|
|
138
|
-
const { intersectionParam1: s, intersectionParam2: r } =
|
|
138
|
+
const { intersectionParam1: s, intersectionParam2: r } = e, i = tt(s), o = tt(r);
|
|
139
139
|
if (i === "between" && o === "between")
|
|
140
140
|
return 0;
|
|
141
141
|
if (i === "between" && o !== "between")
|
|
142
|
-
return
|
|
142
|
+
return nt(n, t, o);
|
|
143
143
|
if (o === "between" && i !== "between")
|
|
144
|
-
return
|
|
144
|
+
return nt(t, n, i);
|
|
145
145
|
if (i === "before" && o === "before")
|
|
146
|
-
return
|
|
146
|
+
return b(n.firstPoint, t.firstPoint);
|
|
147
147
|
if (i === "after" && o === "after")
|
|
148
|
-
return
|
|
148
|
+
return b(n.lastPoint, t.lastPoint);
|
|
149
149
|
if (i === "before" && o === "after")
|
|
150
|
-
return
|
|
150
|
+
return b(n.firstPoint, t.lastPoint);
|
|
151
151
|
if (i === "after" && o === "before")
|
|
152
|
-
return
|
|
152
|
+
return b(n.lastPoint, t.firstPoint);
|
|
153
153
|
throw new Error("Invalid position");
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
if (
|
|
155
|
+
function et(n, t) {
|
|
156
|
+
if (zt(n, t).length > 0)
|
|
157
157
|
return 0;
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
const s =
|
|
161
|
-
if (Math.abs(s -
|
|
158
|
+
const e = Tt(n, t.center);
|
|
159
|
+
if (n.isOnSegment(e)) {
|
|
160
|
+
const s = b(e, t.center);
|
|
161
|
+
if (Math.abs(s - t.radius) < n.precision && t.isOnSegment(e))
|
|
162
162
|
return 0;
|
|
163
|
-
if (s -
|
|
164
|
-
const r =
|
|
165
|
-
|
|
166
|
-
), i =
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
if (s - t.radius > n.precision) {
|
|
164
|
+
const r = ht(
|
|
165
|
+
F(e, t.center)
|
|
166
|
+
), i = Kt(
|
|
167
|
+
t.center,
|
|
168
|
+
qt(r, t.radius)
|
|
169
169
|
);
|
|
170
|
-
if (
|
|
171
|
-
return
|
|
170
|
+
if (t.isOnSegment(i))
|
|
171
|
+
return b(i, e);
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
return Math.min(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
t.distanceFrom(n.firstPoint),
|
|
176
|
+
t.distanceFrom(n.lastPoint),
|
|
177
|
+
n.distanceFrom(t.firstPoint),
|
|
178
|
+
n.distanceFrom(t.lastPoint)
|
|
179
179
|
);
|
|
180
180
|
}
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
const s =
|
|
185
|
-
return !!
|
|
181
|
+
const on = (n, t) => {
|
|
182
|
+
const e = n.angleToParam(t.firstAngle);
|
|
183
|
+
if (n.isValidParameter(e)) return !0;
|
|
184
|
+
const s = n.angleToParam(t.lastAngle);
|
|
185
|
+
return !!n.isValidParameter(s);
|
|
186
186
|
};
|
|
187
|
-
function
|
|
188
|
-
if (
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
return Math.abs(
|
|
192
|
-
const s =
|
|
193
|
-
let i =
|
|
194
|
-
r &&
|
|
195
|
-
const o = r ? i : i + Math.PI,
|
|
196
|
-
return
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
187
|
+
function an(n, t) {
|
|
188
|
+
if ($t(n, t, !0).length > 0) return 0;
|
|
189
|
+
const e = b(n.center, t.center);
|
|
190
|
+
if (e < n.precision && on(n, t))
|
|
191
|
+
return Math.abs(n.radius - t.radius);
|
|
192
|
+
const s = ht(F(t.center, n.center)), r = e - Math.abs(n.radius - t.radius) < n.precision;
|
|
193
|
+
let i = Ht(s);
|
|
194
|
+
r && t.radius > n.radius && (i += Math.PI);
|
|
195
|
+
const o = r ? i : i + Math.PI, a = n.angleToParam(i), f = t.angleToParam(o);
|
|
196
|
+
return n.isValidParameter(a) && t.isValidParameter(f) ? b(n.paramPoint(a), t.paramPoint(f)) : Math.min(
|
|
197
|
+
n.distanceFrom(t.firstPoint),
|
|
198
|
+
n.distanceFrom(t.lastPoint),
|
|
199
|
+
t.distanceFrom(n.firstPoint),
|
|
200
|
+
t.distanceFrom(n.lastPoint)
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
|
-
function
|
|
204
|
-
let s = 0, r =
|
|
203
|
+
function cn(n, t, e) {
|
|
204
|
+
let s = 0, r = n.length - 1;
|
|
205
205
|
for (; s <= r; ) {
|
|
206
|
-
const i = Math.floor((s + r) / 2), o = n
|
|
206
|
+
const i = Math.floor((s + r) / 2), o = e(n[i], t);
|
|
207
207
|
if (o < 0)
|
|
208
208
|
s = i + 1;
|
|
209
209
|
else if (o > 0)
|
|
@@ -213,428 +213,666 @@ function _t(t, e, n) {
|
|
|
213
213
|
}
|
|
214
214
|
return -(s + 1);
|
|
215
215
|
}
|
|
216
|
-
function
|
|
217
|
-
const s =
|
|
218
|
-
s < 0 ?
|
|
216
|
+
function fn(n, t, e) {
|
|
217
|
+
const s = cn(n, t, e);
|
|
218
|
+
s < 0 ? n.splice(-(s + 1), 0, t) : n.splice(s, 0, t);
|
|
219
219
|
}
|
|
220
|
-
class
|
|
220
|
+
class ln {
|
|
221
221
|
constructor() {
|
|
222
|
-
|
|
222
|
+
P(this, "buckets");
|
|
223
223
|
this.buckets = [];
|
|
224
224
|
}
|
|
225
|
-
addInterval(
|
|
226
|
-
const
|
|
227
|
-
|
|
225
|
+
addInterval(t) {
|
|
226
|
+
const e = this.buckets[t.rectangle.diagonalBucketIndex];
|
|
227
|
+
e === void 0 ? this.buckets[t.rectangle.diagonalBucketIndex] = [t] : fn(e, t, (s, r) => s.value - r.value);
|
|
228
228
|
}
|
|
229
|
-
removeInterval(
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
229
|
+
removeInterval(t) {
|
|
230
|
+
const e = this.buckets[t.rectangle.diagonalBucketIndex];
|
|
231
|
+
if (e === void 0)
|
|
232
232
|
throw new Error("Interval not found");
|
|
233
|
-
|
|
233
|
+
e.shift();
|
|
234
234
|
}
|
|
235
235
|
getBottomRightHullIntervals() {
|
|
236
|
-
const
|
|
237
|
-
for (let
|
|
238
|
-
const s = this.buckets[
|
|
236
|
+
const t = [];
|
|
237
|
+
for (let e = this.buckets.length - 1; e >= 0; e--) {
|
|
238
|
+
const s = this.buckets[e];
|
|
239
239
|
if (!s === void 0) continue;
|
|
240
240
|
const r = s[0];
|
|
241
241
|
if (r !== void 0) {
|
|
242
|
-
if (!
|
|
243
|
-
|
|
242
|
+
if (!t.length) {
|
|
243
|
+
t.push(r);
|
|
244
244
|
continue;
|
|
245
245
|
}
|
|
246
|
-
for (;
|
|
247
|
-
|
|
248
|
-
for (;
|
|
249
|
-
const i =
|
|
250
|
-
if (o.value + (i.rectangle.diagonal - o.rectangle.diagonal) / 2 *
|
|
251
|
-
|
|
246
|
+
for (; t.length && t[t.length - 1].value >= r.value; )
|
|
247
|
+
t.pop();
|
|
248
|
+
for (; t.length >= 2; ) {
|
|
249
|
+
const i = t[t.length - 1], o = t[t.length - 2], a = (r.value - o.value) / ((r.rectangle.diagonal - o.rectangle.diagonal) * 2);
|
|
250
|
+
if (o.value + (i.rectangle.diagonal - o.rectangle.diagonal) / 2 * a < i.value)
|
|
251
|
+
t.pop();
|
|
252
252
|
else
|
|
253
253
|
break;
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
t.push(r);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
return
|
|
258
|
+
return t;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
-
class
|
|
262
|
-
constructor(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
this.x =
|
|
261
|
+
class un {
|
|
262
|
+
constructor(t, e) {
|
|
263
|
+
P(this, "diagonal");
|
|
264
|
+
P(this, "diagonalBucketIndex");
|
|
265
|
+
P(this, "xLength");
|
|
266
|
+
P(this, "yLength");
|
|
267
|
+
P(this, "index");
|
|
268
|
+
this.x = t, this.y = e, this.xLength = Math.pow(3, -t), this.yLength = Math.pow(3, -e), this.diagonal = Math.sqrt(
|
|
269
269
|
this.xLength * this.xLength + this.yLength * this.yLength
|
|
270
|
-
), this.diagonalBucketIndex =
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
class
|
|
274
|
-
constructor(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
this.fcn =
|
|
281
|
-
const i = [0.5, 0.5], o = this.rect(0, 0),
|
|
282
|
-
this.buckets.addInterval(new
|
|
283
|
-
}
|
|
284
|
-
registerInterval(
|
|
285
|
-
this.buckets.addInterval(
|
|
286
|
-
}
|
|
287
|
-
rect(
|
|
288
|
-
const s = `${
|
|
289
|
-
return this.rectangles.has(s) || this.rectangles.set(s, new
|
|
290
|
-
}
|
|
291
|
-
splitInterval(
|
|
292
|
-
let
|
|
293
|
-
const [i, o] =
|
|
294
|
-
return
|
|
295
|
-
new
|
|
296
|
-
new
|
|
297
|
-
new
|
|
270
|
+
), this.diagonalBucketIndex = t + e, this.index = `${t},${e}`;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
class hn {
|
|
274
|
+
constructor(t, e = 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 = t, this.endTolerance = e, this.maxIterations = s, this.epsilon = r, this.fcn = t, this.epsilon = r, this.endTolerance = e, this.maxIterations = s, this.rectangles = /* @__PURE__ */ new Map(), this.buckets = new ln();
|
|
281
|
+
const i = [0.5, 0.5], o = this.rect(0, 0), a = this.fcn(i);
|
|
282
|
+
this.buckets.addInterval(new D(i, a, o)), this.fMin = a, this.argMin = i, this.tol = o.diagonal;
|
|
283
|
+
}
|
|
284
|
+
registerInterval(t) {
|
|
285
|
+
this.buckets.addInterval(t), t.value <= this.fMin && (this.fMin = t.value, this.argMin = t.center, this.tol = t.rectangle.diagonal);
|
|
286
|
+
}
|
|
287
|
+
rect(t, e) {
|
|
288
|
+
const s = `${t},${e}`;
|
|
289
|
+
return this.rectangles.has(s) || this.rectangles.set(s, new un(t, e)), this.rectangles.get(s);
|
|
290
|
+
}
|
|
291
|
+
splitInterval(t) {
|
|
292
|
+
let e, s, r;
|
|
293
|
+
const [i, o] = t.center;
|
|
294
|
+
return t.rectangle.x <= t.rectangle.y ? (e = this.rect(t.rectangle.x + 1, t.rectangle.y), s = [i - e.xLength, o], r = [i + e.xLength, o]) : (e = this.rect(t.rectangle.x, t.rectangle.y + 1), s = [i, o - e.yLength], r = [i, o + e.yLength]), [
|
|
295
|
+
new D(s, this.fcn(s), e),
|
|
296
|
+
new D(t.center, t.value, e),
|
|
297
|
+
new D(r, this.fcn(r), e)
|
|
298
298
|
];
|
|
299
299
|
}
|
|
300
300
|
single_iteration() {
|
|
301
|
-
const
|
|
302
|
-
for (;
|
|
303
|
-
const
|
|
301
|
+
const t = this.buckets.getBottomRightHullIntervals();
|
|
302
|
+
for (; t.length >= 2; ) {
|
|
303
|
+
const e = t[0], s = t[1], r = (s.value - e.value) / ((s.rectangle.diagonal - e.rectangle.diagonal) / 2), i = e.value - r * s.value / 2;
|
|
304
304
|
if ((this.fMin - i) / Math.abs(this.fMin) < this.epsilon)
|
|
305
|
-
|
|
305
|
+
t.shift();
|
|
306
306
|
else
|
|
307
307
|
break;
|
|
308
308
|
}
|
|
309
|
-
|
|
310
|
-
this.buckets.removeInterval(
|
|
309
|
+
t.forEach((e) => {
|
|
310
|
+
this.buckets.removeInterval(e);
|
|
311
311
|
});
|
|
312
|
-
for (const
|
|
313
|
-
const [s, r, i] = this.splitInterval(
|
|
312
|
+
for (const e of t) {
|
|
313
|
+
const [s, r, i] = this.splitInterval(e);
|
|
314
314
|
this.registerInterval(s), this.registerInterval(r), this.registerInterval(i);
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
run() {
|
|
318
|
-
let
|
|
319
|
-
for (; this.tol > this.endTolerance / 2 && (this.single_iteration(),
|
|
318
|
+
let t = 0;
|
|
319
|
+
for (; this.tol > this.endTolerance / 2 && (this.single_iteration(), t++, !(t > this.maxIterations)); )
|
|
320
320
|
;
|
|
321
321
|
return {
|
|
322
322
|
fMin: this.fMin,
|
|
323
323
|
argMin: this.argMin,
|
|
324
324
|
tol: this.tol,
|
|
325
|
-
iterations:
|
|
325
|
+
iterations: t
|
|
326
326
|
};
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
|
-
class
|
|
330
|
-
constructor(
|
|
331
|
-
this.center =
|
|
329
|
+
class D {
|
|
330
|
+
constructor(t, e, s) {
|
|
331
|
+
this.center = t, this.value = e, this.rectangle = s;
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
function
|
|
335
|
-
return new
|
|
334
|
+
function gn(n, t = 1e-8, e = 1e3, s = 1e-6) {
|
|
335
|
+
return new hn(
|
|
336
|
+
n,
|
|
336
337
|
t,
|
|
337
338
|
e,
|
|
338
|
-
n,
|
|
339
339
|
s
|
|
340
340
|
).run();
|
|
341
341
|
}
|
|
342
|
-
function
|
|
343
|
-
const s =
|
|
344
|
-
const i =
|
|
345
|
-
return
|
|
346
|
-
},
|
|
342
|
+
function pn(n, t, e = 1e-9) {
|
|
343
|
+
const s = gn((r) => {
|
|
344
|
+
const i = n.paramPoint(r[0]), o = t.paramPoint(r[1]);
|
|
345
|
+
return gt(i, o);
|
|
346
|
+
}, e);
|
|
347
347
|
return Math.sqrt(s.fMin);
|
|
348
348
|
}
|
|
349
|
-
function
|
|
350
|
-
return
|
|
349
|
+
function dn(n, t) {
|
|
350
|
+
return n instanceof A && t instanceof A ? rn(n, t) : n instanceof A && t instanceof E ? et(n, t) : n instanceof E && t instanceof A ? et(t, n) : n instanceof E && t instanceof E ? an(n, t) : pn(n, t);
|
|
351
351
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
352
|
+
function wt(n) {
|
|
353
|
+
if (n instanceof $) {
|
|
354
|
+
const r = F(n.lastPoint, n.firstPoint), i = F(n.firstControlPoint, n.firstPoint), o = F(n.lastControlPoint, n.firstPoint), a = V(r, i), f = V(r, o);
|
|
355
|
+
if (a > 0 && f < 0 || a < 0 && f > 0) return !1;
|
|
356
|
+
}
|
|
357
|
+
const t = Y(n.tangentAtFirstPoint), e = Y(n.tangentAtLastPoint);
|
|
358
|
+
let s = Nt(t, e);
|
|
359
|
+
return Math.abs(Math.acos(s)) < Math.PI / 3;
|
|
360
|
+
}
|
|
361
|
+
function K(n) {
|
|
362
|
+
if (wt(n)) return [n];
|
|
363
|
+
const [t, e] = n.splitAtParameters([0.5]);
|
|
364
|
+
return [
|
|
365
|
+
...K(t),
|
|
366
|
+
...K(e)
|
|
367
|
+
];
|
|
368
|
+
}
|
|
369
|
+
function st(n) {
|
|
370
|
+
return wt(n) ? [n] : n.splitAtParameters(n.getParametersOfExtrema()).flatMap(K);
|
|
371
|
+
}
|
|
372
|
+
function mn(n) {
|
|
373
|
+
const t = n.deltaAngle, e = Math.ceil(Math.abs(t) / (Math.PI / 2)), s = t / e, r = 4 * Math.tan(s / 4) / 3, i = n.clockwise ? -1 : 1, o = Array.from(
|
|
374
|
+
{ length: e + 1 },
|
|
375
|
+
(f, c) => n.firstAngle + c * s * i
|
|
376
|
+
);
|
|
377
|
+
return o.slice(0, -1).map((f, c) => [f, o[c + 1]]).map(([f, c]) => {
|
|
378
|
+
const l = Math.cos(f), p = Math.sin(f), g = Math.cos(c), d = Math.sin(c), [u, S] = n.center, M = n.minorRadius, v = n.majorRadius, k = new Jt().rotate(
|
|
379
|
+
n.tiltAngle,
|
|
380
|
+
n.center
|
|
381
|
+
), C = (Ft) => k.transform(Ft), O = C([u + v * l, S + M * p]), G = C([
|
|
382
|
+
u + v * (l - r * p * i),
|
|
383
|
+
S + M * (p + r * l * i)
|
|
384
|
+
]), kt = C([
|
|
385
|
+
u + v * (g + r * d * i),
|
|
386
|
+
S + M * (d - r * g * i)
|
|
387
|
+
]), Et = C([u + v * g, S + M * d]);
|
|
388
|
+
return new $(O, Et, G, kt);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const X = 1e-8, Mt = (n) => n.flatMap((t) => t instanceof A ? [t] : t instanceof E ? [t] : t instanceof pt ? mn(t).flatMap(
|
|
392
|
+
(e) => st(e)
|
|
393
|
+
) : t instanceof dt || t instanceof $ ? st(t) : [new A(t.firstPoint, t.lastPoint)]);
|
|
394
|
+
function q(n, t, e = !0) {
|
|
395
|
+
const s = n.map((c) => ({
|
|
396
|
+
offset: xt(c, t),
|
|
397
|
+
original: c
|
|
357
398
|
})), r = [];
|
|
358
|
-
let i =
|
|
399
|
+
let i = e ? null : s.at(-1), o = e ? s.at(-1) : null;
|
|
359
400
|
if (r.length === 1) return r;
|
|
360
|
-
const
|
|
361
|
-
i ?
|
|
362
|
-
new
|
|
363
|
-
) : r.push(
|
|
401
|
+
const a = (c) => {
|
|
402
|
+
i ? c.offset instanceof U ? I(c.offset.firstPoint, c.offset.lastPoint) || r.push(
|
|
403
|
+
new A(c.offset.firstPoint, c.offset.lastPoint)
|
|
404
|
+
) : r.push(c.offset) : i = c;
|
|
364
405
|
}, f = function* () {
|
|
365
|
-
for (const
|
|
366
|
-
yield
|
|
406
|
+
for (const c of s.slice(0, -1))
|
|
407
|
+
yield c;
|
|
367
408
|
if (!i) throw new Error("Bug in the offset algorithm");
|
|
368
409
|
yield i;
|
|
369
410
|
};
|
|
370
|
-
for (const
|
|
411
|
+
for (const c of f()) {
|
|
371
412
|
if (!o) {
|
|
372
|
-
o =
|
|
413
|
+
o = c;
|
|
373
414
|
continue;
|
|
374
415
|
}
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
377
|
-
|
|
416
|
+
const l = o.offset.lastPoint, p = c.offset.firstPoint;
|
|
417
|
+
if (I(l, p)) {
|
|
418
|
+
a(o), o = c;
|
|
378
419
|
continue;
|
|
379
420
|
}
|
|
380
|
-
let
|
|
381
|
-
if (!(o.offset instanceof
|
|
382
|
-
const { intersections:
|
|
421
|
+
let g = [];
|
|
422
|
+
if (!(o.offset instanceof U) && !(c.offset instanceof U)) {
|
|
423
|
+
const { intersections: M, overlaps: v } = N(
|
|
383
424
|
o.offset,
|
|
384
|
-
|
|
385
|
-
|
|
425
|
+
c.offset,
|
|
426
|
+
X / 100
|
|
386
427
|
);
|
|
387
|
-
|
|
388
|
-
...
|
|
389
|
-
...
|
|
428
|
+
g = [
|
|
429
|
+
...M,
|
|
430
|
+
...v.flatMap((k) => [k.firstPoint, k.lastPoint])
|
|
390
431
|
];
|
|
391
432
|
}
|
|
392
|
-
if (
|
|
393
|
-
let
|
|
394
|
-
if (
|
|
395
|
-
const
|
|
396
|
-
(
|
|
433
|
+
if (g.length > 0) {
|
|
434
|
+
let M = g[0];
|
|
435
|
+
if (g.length > 1) {
|
|
436
|
+
const C = o == null ? void 0 : o.original.lastPoint, O = g.map(
|
|
437
|
+
(G) => gt(G, C)
|
|
397
438
|
);
|
|
398
|
-
|
|
439
|
+
M = g[O.indexOf(Math.min(...O))];
|
|
399
440
|
}
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
])[0],
|
|
403
|
-
if (!
|
|
404
|
-
|
|
405
|
-
offset:
|
|
441
|
+
const v = o.offset.splitAt([
|
|
442
|
+
M
|
|
443
|
+
])[0], k = c.offset.splitAt([M]).at(-1);
|
|
444
|
+
if (!k) throw new Error("Bug in the splitting algo in offset");
|
|
445
|
+
a({
|
|
446
|
+
offset: v,
|
|
406
447
|
original: o.original
|
|
407
|
-
}), o = { offset:
|
|
448
|
+
}), o = { offset: k, original: c.original };
|
|
408
449
|
continue;
|
|
409
450
|
}
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
) > 0,
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
return o &&
|
|
417
|
-
}
|
|
418
|
-
function
|
|
419
|
-
const
|
|
420
|
-
const i =
|
|
421
|
-
|
|
451
|
+
const d = o.original.lastPoint, u = Xt(
|
|
452
|
+
F(p, d),
|
|
453
|
+
F(l, d)
|
|
454
|
+
) > 0, S = new E(l, p, d, u);
|
|
455
|
+
a(o), r.push(S), o = c;
|
|
456
|
+
}
|
|
457
|
+
return o && a(o), r;
|
|
458
|
+
}
|
|
459
|
+
function It(n) {
|
|
460
|
+
const t = /* @__PURE__ */ new Map(), e = (s, r) => {
|
|
461
|
+
const i = t.get(s) || [];
|
|
462
|
+
t.set(s, [...i, ...r]);
|
|
422
463
|
};
|
|
423
|
-
return
|
|
424
|
-
|
|
425
|
-
const { intersections:
|
|
426
|
-
...
|
|
427
|
-
...f.flatMap((
|
|
428
|
-
].filter((
|
|
429
|
-
const
|
|
430
|
-
return !(
|
|
464
|
+
return n.forEach((s, r) => {
|
|
465
|
+
n.slice(r + 1).forEach((i, o) => {
|
|
466
|
+
const { intersections: a, overlaps: f } = N(s, i, X), c = [
|
|
467
|
+
...a,
|
|
468
|
+
...f.flatMap((l) => [l.firstPoint, l.lastPoint])
|
|
469
|
+
].filter((l) => {
|
|
470
|
+
const p = I(l, s.firstPoint) || I(l, s.lastPoint), g = I(l, i.firstPoint) || I(l, i.lastPoint);
|
|
471
|
+
return !(p && g);
|
|
431
472
|
});
|
|
432
|
-
|
|
473
|
+
c.length && (e(r, c), e(o + r + 1, c));
|
|
433
474
|
});
|
|
434
|
-
}),
|
|
475
|
+
}), t;
|
|
435
476
|
}
|
|
436
|
-
function
|
|
437
|
-
return
|
|
438
|
-
if (!
|
|
439
|
-
const r =
|
|
440
|
-
return r ?
|
|
477
|
+
function St(n, t) {
|
|
478
|
+
return t.flatMap((e, s) => {
|
|
479
|
+
if (!n.has(s)) return e;
|
|
480
|
+
const r = n.get(s);
|
|
481
|
+
return r ? e.splitAt(r) : e;
|
|
441
482
|
});
|
|
442
483
|
}
|
|
443
|
-
function
|
|
444
|
-
return
|
|
484
|
+
function bt(n, t, e) {
|
|
485
|
+
return n.filter((s) => !t.segments.some((i) => dn(i, s) < Math.abs(e) - X));
|
|
445
486
|
}
|
|
446
|
-
function
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
449
|
-
const
|
|
450
|
-
if (!
|
|
451
|
-
const
|
|
452
|
-
return new
|
|
487
|
+
function T(n, t) {
|
|
488
|
+
const e = n.clockwise ? t : -t, s = Mt(n.segments), r = q(s, e);
|
|
489
|
+
if (r.length < 2) return new h();
|
|
490
|
+
const i = It(r);
|
|
491
|
+
if (!i.size) {
|
|
492
|
+
const l = new w(r);
|
|
493
|
+
return new h([new m(l)]);
|
|
453
494
|
}
|
|
454
|
-
const
|
|
495
|
+
const o = St(
|
|
496
|
+
i,
|
|
497
|
+
r
|
|
498
|
+
), a = bt(o, n, t);
|
|
499
|
+
if (!a.length) return new h();
|
|
500
|
+
const c = ut(a).filter((l) => l.length > 1).filter((l) => I(l[0].firstPoint, l.at(-1).lastPoint)).map((l) => new w(l));
|
|
501
|
+
return c.length ? new h(c.map((l) => new m(l))) : new h();
|
|
502
|
+
}
|
|
503
|
+
function Pn(n, t, e = "round") {
|
|
504
|
+
const s = t / 2, r = Mt(n.segments), i = q(r, s, !1), o = q(
|
|
455
505
|
r,
|
|
456
|
-
s
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
);
|
|
466
|
-
i.reverse();
|
|
467
|
-
const o = (l, k) => n === "round" ? Et(
|
|
468
|
-
l.lastPoint,
|
|
469
|
-
k.firstPoint,
|
|
470
|
-
l.tangentAtLastPoint
|
|
471
|
-
) : new S(l.lastPoint, k.firstPoint), c = [
|
|
472
|
-
...r,
|
|
473
|
-
o(
|
|
474
|
-
r[r.length - 1],
|
|
475
|
-
i[0]
|
|
476
|
-
),
|
|
506
|
+
-s,
|
|
507
|
+
!1
|
|
508
|
+
).map((u) => u.reverse());
|
|
509
|
+
o.reverse();
|
|
510
|
+
const a = (u, S) => e === "round" ? Qt(
|
|
511
|
+
u.lastPoint,
|
|
512
|
+
S.firstPoint,
|
|
513
|
+
u.tangentAtLastPoint
|
|
514
|
+
) : new A(u.lastPoint, S.firstPoint), f = [
|
|
477
515
|
...i,
|
|
478
|
-
|
|
516
|
+
a(
|
|
479
517
|
i[i.length - 1],
|
|
480
|
-
|
|
518
|
+
o[0]
|
|
519
|
+
),
|
|
520
|
+
...o,
|
|
521
|
+
a(
|
|
522
|
+
o[o.length - 1],
|
|
523
|
+
i[0]
|
|
481
524
|
)
|
|
482
|
-
],
|
|
483
|
-
if (!
|
|
484
|
-
const
|
|
485
|
-
return new
|
|
486
|
-
}
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
),
|
|
491
|
-
if (!
|
|
492
|
-
const
|
|
493
|
-
return
|
|
494
|
-
}
|
|
495
|
-
function
|
|
496
|
-
const
|
|
497
|
-
const r =
|
|
498
|
-
s.holes.map((i) =>
|
|
525
|
+
], c = It(f);
|
|
526
|
+
if (!c.size) {
|
|
527
|
+
const u = new w(f);
|
|
528
|
+
return new h([new m(u)]);
|
|
529
|
+
}
|
|
530
|
+
const l = St(
|
|
531
|
+
c,
|
|
532
|
+
f
|
|
533
|
+
), p = bt(l, n, s);
|
|
534
|
+
if (!p.length) return new h();
|
|
535
|
+
const d = ut(p).filter((u) => u.length > 1).filter((u) => I(u[0].firstPoint, u.at(-1).lastPoint)).map((u) => new w(u));
|
|
536
|
+
return d.length ? new h(d.map((u) => new m(u))) : new h();
|
|
537
|
+
}
|
|
538
|
+
function wn(n, t) {
|
|
539
|
+
const e = n.map((s) => {
|
|
540
|
+
const r = z(
|
|
541
|
+
s.holes.map((i) => T(i, t))
|
|
499
542
|
);
|
|
500
|
-
return
|
|
543
|
+
return Pt(T(s.contour, t), r);
|
|
501
544
|
});
|
|
502
|
-
return
|
|
545
|
+
return z(e);
|
|
503
546
|
}
|
|
504
|
-
function
|
|
505
|
-
const
|
|
506
|
-
(r) =>
|
|
507
|
-
r.allLoops.map((i) =>
|
|
547
|
+
function Mn(n, t) {
|
|
548
|
+
const e = Math.abs(t / 2), s = n.map(
|
|
549
|
+
(r) => z(
|
|
550
|
+
r.allLoops.map((i) => Pt(T(i, e), T(i, -e)))
|
|
508
551
|
)
|
|
509
552
|
);
|
|
510
|
-
return
|
|
511
|
-
}
|
|
512
|
-
function
|
|
513
|
-
return
|
|
514
|
-
}
|
|
515
|
-
function
|
|
516
|
-
return
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
553
|
+
return z(s);
|
|
554
|
+
}
|
|
555
|
+
function On(n, t) {
|
|
556
|
+
return wn(L(n), t);
|
|
557
|
+
}
|
|
558
|
+
function Dn(n, t, { endCap: e = "round" } = {}) {
|
|
559
|
+
return n instanceof y ? Pn(n, t, e) : Mn(L(n), t);
|
|
560
|
+
}
|
|
561
|
+
class In {
|
|
562
|
+
constructor() {
|
|
563
|
+
P(this, "filters");
|
|
564
|
+
this.filters = [];
|
|
565
|
+
}
|
|
566
|
+
delete() {
|
|
567
|
+
this.filters = [];
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Combine logically a set of filter with an AND operation.
|
|
571
|
+
*
|
|
572
|
+
*/
|
|
573
|
+
and(t) {
|
|
574
|
+
return t.forEach((e) => e(this)), this;
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Invert the result of a particular filter
|
|
578
|
+
*
|
|
579
|
+
*/
|
|
580
|
+
not(t) {
|
|
581
|
+
const e = new this.constructor();
|
|
582
|
+
t(e);
|
|
583
|
+
const s = ({ element: r }) => !e.shouldKeep(r);
|
|
584
|
+
return this.filters.push(s), this;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Combine logically a set of filter with an OR operation.
|
|
588
|
+
*
|
|
589
|
+
*/
|
|
590
|
+
either(t) {
|
|
591
|
+
const e = t.map((r) => {
|
|
592
|
+
const i = new this.constructor();
|
|
593
|
+
return r(i), i;
|
|
594
|
+
}), s = ({ element: r }) => e.some((i) => i.shouldKeep(r));
|
|
595
|
+
return this.filters.push(s), this;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const _ = 2 * Math.PI, rt = (n) => {
|
|
599
|
+
const t = n % _, e = t < 0 ? t + _ : t;
|
|
600
|
+
return e < Math.PI ? e : e === Math.PI ? 0 : Math.abs(e - _);
|
|
601
|
+
};
|
|
602
|
+
class x extends In {
|
|
603
|
+
clone() {
|
|
604
|
+
const t = new x();
|
|
605
|
+
return t.filters = [...this.filters], t;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Filter to find corner that have their point are in the list.
|
|
609
|
+
*
|
|
610
|
+
*/
|
|
611
|
+
inList(t) {
|
|
612
|
+
const e = ({ element: s }) => !!t.find((r) => I(r, s.point));
|
|
613
|
+
return this.filters.push(e), this;
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Filter to find elements that are at a specified distance from a point.
|
|
617
|
+
*
|
|
618
|
+
*/
|
|
619
|
+
atDistance(t, e = [0, 0]) {
|
|
620
|
+
function s({ element: r }) {
|
|
621
|
+
return Math.abs(b(e, r.point) - t) < 1e-9;
|
|
622
|
+
}
|
|
623
|
+
return this.filters.push(s), this;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Filter to find elements that contain a certain point
|
|
627
|
+
*
|
|
628
|
+
* @category Filter
|
|
629
|
+
*/
|
|
630
|
+
atPoint(t) {
|
|
631
|
+
function e({ element: s }) {
|
|
632
|
+
return I(t, s.point);
|
|
633
|
+
}
|
|
634
|
+
return this.filters.push(e), this;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Filter to find elements that are within a box
|
|
638
|
+
*
|
|
639
|
+
* @category Filter
|
|
640
|
+
*/
|
|
641
|
+
inBox(t, e) {
|
|
642
|
+
const [s, r] = t, [i, o] = e, a = Math.min(s, i), f = Math.max(s, i), c = Math.min(r, o), l = Math.max(r, o);
|
|
643
|
+
function p({ element: g }) {
|
|
644
|
+
const [d, u] = g.point;
|
|
645
|
+
return d >= a && d <= f && u >= c && u <= l;
|
|
646
|
+
}
|
|
647
|
+
return this.filters.push(p), this;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Filter to find corner that a certain angle between them - only between
|
|
651
|
+
* 0 and 180.
|
|
652
|
+
*
|
|
653
|
+
*/
|
|
654
|
+
ofAngle(t) {
|
|
655
|
+
function e({ element: s }) {
|
|
656
|
+
const r = s.firstCurve.tangentAtLastPoint, i = s.secondCurve.tangentAtFirstPoint;
|
|
657
|
+
return Math.abs(
|
|
658
|
+
rt(V(r, i)) - rt(Yt * t)
|
|
659
|
+
) < 1e-9;
|
|
660
|
+
}
|
|
661
|
+
return this.filters.push(e), this;
|
|
662
|
+
}
|
|
663
|
+
above(t = 0) {
|
|
664
|
+
function e({ element: s }) {
|
|
665
|
+
return s.point[1] > t;
|
|
666
|
+
}
|
|
667
|
+
return this.filters.push(e), this;
|
|
668
|
+
}
|
|
669
|
+
below(t = 0) {
|
|
670
|
+
function e({ element: s }) {
|
|
671
|
+
return s.point[1] < t;
|
|
672
|
+
}
|
|
673
|
+
return this.filters.push(e), this;
|
|
674
|
+
}
|
|
675
|
+
leftOf(t = 0) {
|
|
676
|
+
function e({ element: s }) {
|
|
677
|
+
return s.point[0] < t;
|
|
678
|
+
}
|
|
679
|
+
return this.filters.push(e), this;
|
|
680
|
+
}
|
|
681
|
+
rightOf(t = 0) {
|
|
682
|
+
function e({ element: s }) {
|
|
683
|
+
return s.point[0] > t;
|
|
684
|
+
}
|
|
685
|
+
return this.filters.push(e), this;
|
|
686
|
+
}
|
|
687
|
+
shouldKeep(t) {
|
|
688
|
+
return this.filters.every((s) => s({ element: t }));
|
|
689
|
+
}
|
|
690
|
+
asFilterFun() {
|
|
691
|
+
return this.shouldKeep.bind(this);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
function At(n, t, e, s = () => !0) {
|
|
695
|
+
const r = [t.segments[0]], i = (a, f) => {
|
|
696
|
+
s({ firstCurve: a, secondCurve: f, point: a.lastPoint }) ? r.push(...n(a, f, e)) : r.push(a, f);
|
|
697
|
+
};
|
|
698
|
+
if (t.segments.slice(1).forEach((a) => {
|
|
699
|
+
const f = r.pop();
|
|
700
|
+
if (!f) throw new Error("Bug in the stroke filletting algo");
|
|
701
|
+
i(f, a);
|
|
702
|
+
}), !r.at(-1)) throw new Error("Bug in the stroke corner algo");
|
|
703
|
+
if (t instanceof w) {
|
|
704
|
+
const a = r.pop(), f = r.shift();
|
|
705
|
+
if (!a || !f)
|
|
706
|
+
throw new Error("Bug in the filletting algo");
|
|
707
|
+
return i(a, f), new w(r, { ignoreChecks: !0 });
|
|
708
|
+
} else
|
|
709
|
+
return new y(r, { ignoreChecks: !0 });
|
|
710
|
+
}
|
|
711
|
+
function B(n, t, e) {
|
|
712
|
+
const s = typeof e == "function" ? e(new x()) : e, r = s && s.asFilterFun();
|
|
713
|
+
if (n instanceof w || n instanceof y)
|
|
714
|
+
return At(lt, n, t, r);
|
|
715
|
+
if (n instanceof m) {
|
|
716
|
+
const i = B(n.contour, t, s), o = n.holes.map((a) => B(a, t, s));
|
|
717
|
+
return new m(i, o, { ignoreChecks: !0 });
|
|
718
|
+
}
|
|
719
|
+
if (n instanceof h) {
|
|
720
|
+
const i = n.figures.map((o) => B(o, t, s));
|
|
721
|
+
return new h(i, { ignoreChecks: !0 });
|
|
722
|
+
}
|
|
723
|
+
throw new Error("invalid shape to fillet");
|
|
724
|
+
}
|
|
725
|
+
function R(n, t, e) {
|
|
726
|
+
const s = typeof e == "function" ? e(new x()) : e, r = s && s.asFilterFun();
|
|
727
|
+
if (n instanceof w || n instanceof y)
|
|
728
|
+
return At(lt, n, t, r);
|
|
729
|
+
if (n instanceof m) {
|
|
730
|
+
const i = R(n.contour, t, s), o = n.holes.map((a) => R(a, t, s));
|
|
731
|
+
return new m(i, o, { ignoreChecks: !0 });
|
|
732
|
+
}
|
|
733
|
+
if (n instanceof h) {
|
|
734
|
+
const i = n.figures.map((o) => R(o, t, s));
|
|
735
|
+
return new h(i, { ignoreChecks: !0 });
|
|
736
|
+
}
|
|
737
|
+
throw new Error("invalid shape to chamfer");
|
|
738
|
+
}
|
|
739
|
+
class Sn extends x {
|
|
740
|
+
constructor(t) {
|
|
741
|
+
super(), this.shape = t;
|
|
742
|
+
}
|
|
743
|
+
fillet(t) {
|
|
744
|
+
return B(this.shape, t, this.clone());
|
|
745
|
+
}
|
|
746
|
+
chamfer(t) {
|
|
747
|
+
return R(this.shape, t, this.clone());
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function Bn(n) {
|
|
751
|
+
return new Sn(n);
|
|
752
|
+
}
|
|
753
|
+
function it(n) {
|
|
754
|
+
if (n instanceof h)
|
|
755
|
+
return Wt(n);
|
|
756
|
+
if (n instanceof m)
|
|
757
|
+
return jt(n);
|
|
758
|
+
if (n instanceof w)
|
|
759
|
+
return `<path d="${tn(n)}" />`;
|
|
760
|
+
if (n instanceof y)
|
|
761
|
+
return `<path d="${nn(n)}" />`;
|
|
762
|
+
if (Gt(n))
|
|
763
|
+
return `<path d="${`M ${n.firstPoint.join(" ")}`} ${en(
|
|
764
|
+
n
|
|
530
765
|
)}" />`;
|
|
531
766
|
throw new Error("Unknown shape type");
|
|
532
767
|
}
|
|
533
|
-
const
|
|
534
|
-
if (!("shape" in
|
|
535
|
-
const { color:
|
|
536
|
-
return
|
|
537
|
-
},
|
|
538
|
-
function
|
|
539
|
-
margin:
|
|
540
|
-
unit:
|
|
768
|
+
const ot = (n) => "shape" in n ? n.shape : n, at = (n, t) => {
|
|
769
|
+
if (!("shape" in n)) return t;
|
|
770
|
+
const { color: e } = n;
|
|
771
|
+
return e ? `<g stroke="${e}">${t}</g>` : t;
|
|
772
|
+
}, ct = (n) => new Zt(n.xMin, -n.yMax, n.xMax, -n.yMin);
|
|
773
|
+
function Rn(n, {
|
|
774
|
+
margin: t = 1,
|
|
775
|
+
unit: e = null,
|
|
541
776
|
viewBox: s
|
|
542
777
|
} = {}) {
|
|
543
|
-
if (Array.isArray(
|
|
544
|
-
const i =
|
|
545
|
-
`),
|
|
546
|
-
return
|
|
547
|
-
}
|
|
548
|
-
const r =
|
|
549
|
-
return
|
|
550
|
-
|
|
551
|
-
s ?
|
|
552
|
-
|
|
553
|
-
|
|
778
|
+
if (Array.isArray(n)) {
|
|
779
|
+
const i = n.map((f) => ot(f).mirror()), o = i.map((f, c) => at(n[c], it(f))).join(`
|
|
780
|
+
`), a = i.slice(1).reduce((f, c) => f.merge(c.boundingBox), i[0].boundingBox);
|
|
781
|
+
return Z(o, s ? ct(s) : a, t, e);
|
|
782
|
+
}
|
|
783
|
+
const r = ot(n).mirror();
|
|
784
|
+
return Z(
|
|
785
|
+
at(n, it(r)),
|
|
786
|
+
s ? ct(s) : r.boundingBox,
|
|
787
|
+
t,
|
|
788
|
+
e
|
|
554
789
|
);
|
|
555
790
|
}
|
|
556
|
-
const
|
|
557
|
-
if (
|
|
558
|
-
return new
|
|
559
|
-
if (
|
|
560
|
-
return new
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
791
|
+
const vt = (n) => {
|
|
792
|
+
if (n.type === "LINE")
|
|
793
|
+
return new A(n.firstPoint, n.lastPoint);
|
|
794
|
+
if (n.type === "ARC")
|
|
795
|
+
return new E(
|
|
796
|
+
n.firstPoint,
|
|
797
|
+
n.lastPoint,
|
|
798
|
+
n.center,
|
|
799
|
+
n.clockwise
|
|
565
800
|
);
|
|
566
|
-
if (
|
|
567
|
-
return new
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
801
|
+
if (n.type === "ELLIPSE_ARC")
|
|
802
|
+
return new pt(
|
|
803
|
+
n.firstPoint,
|
|
804
|
+
n.lastPoint,
|
|
805
|
+
n.center,
|
|
806
|
+
n.majorRadius,
|
|
807
|
+
n.minorRadius,
|
|
808
|
+
n.tiltAngle,
|
|
809
|
+
n.clockwise,
|
|
575
810
|
{ angleUnits: "rad" }
|
|
576
811
|
);
|
|
577
|
-
if (
|
|
578
|
-
return new
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
812
|
+
if (n.type === "QUADRATIC_BEZIER")
|
|
813
|
+
return new dt(
|
|
814
|
+
n.firstPoint,
|
|
815
|
+
n.lastPoint,
|
|
816
|
+
n.controlPoint
|
|
582
817
|
);
|
|
583
|
-
if (
|
|
584
|
-
return new
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
818
|
+
if (n.type === "CUBIC_BEZIER")
|
|
819
|
+
return new $(
|
|
820
|
+
n.firstPoint,
|
|
821
|
+
n.lastPoint,
|
|
822
|
+
n.firstControlPoint,
|
|
823
|
+
n.lastControlPoint
|
|
589
824
|
);
|
|
590
825
|
throw new Error("Unknown segment type");
|
|
591
|
-
},
|
|
592
|
-
const
|
|
593
|
-
return new
|
|
594
|
-
},
|
|
595
|
-
const
|
|
596
|
-
return new
|
|
597
|
-
},
|
|
598
|
-
const
|
|
599
|
-
return new
|
|
826
|
+
}, H = (n) => {
|
|
827
|
+
const t = n.segments.map(vt);
|
|
828
|
+
return new w(t);
|
|
829
|
+
}, Lt = (n) => {
|
|
830
|
+
const t = H(n.contour), e = n.holes.map(H);
|
|
831
|
+
return new m(t, e);
|
|
832
|
+
}, bn = (n) => {
|
|
833
|
+
const t = n.figures.map(Lt);
|
|
834
|
+
return new h(t);
|
|
600
835
|
};
|
|
601
|
-
function
|
|
602
|
-
if (
|
|
603
|
-
return
|
|
604
|
-
if (
|
|
605
|
-
return
|
|
606
|
-
if (
|
|
607
|
-
return
|
|
608
|
-
if (
|
|
609
|
-
return
|
|
836
|
+
function zn(n) {
|
|
837
|
+
if (n.type === "DIAGRAM")
|
|
838
|
+
return bn(n);
|
|
839
|
+
if (n.type === "FIGURE")
|
|
840
|
+
return Lt(n);
|
|
841
|
+
if (n.type === "LOOP")
|
|
842
|
+
return H(n);
|
|
843
|
+
if (n.type === "LINE" || n.type === "ARC" || n.type === "ELLIPSE_ARC" || n.type === "CUBIC_BEZIER")
|
|
844
|
+
return vt(n);
|
|
610
845
|
throw new Error("Unknown shape type");
|
|
611
846
|
}
|
|
612
|
-
const
|
|
613
|
-
function
|
|
614
|
-
const
|
|
615
|
-
return [
|
|
847
|
+
const ft = Math.PI / 180, An = 180 / Math.PI;
|
|
848
|
+
function Tn(n, t) {
|
|
849
|
+
const e = Math.cos(t * ft) * n, s = Math.sin(t * ft) * n;
|
|
850
|
+
return [e, s];
|
|
616
851
|
}
|
|
617
|
-
function
|
|
618
|
-
const
|
|
619
|
-
return [
|
|
852
|
+
function $n([n, t]) {
|
|
853
|
+
const e = Math.sqrt(n * n + t * t), s = Math.atan2(t, n) * An;
|
|
854
|
+
return [e, s];
|
|
620
855
|
}
|
|
621
856
|
export {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
857
|
+
ft as DEG2RAD,
|
|
858
|
+
An as RAD2DEG,
|
|
859
|
+
$n as cartesianToPolar,
|
|
860
|
+
R as chamfer,
|
|
861
|
+
xn as confineStrand,
|
|
862
|
+
Pt as cut,
|
|
863
|
+
_n as draw,
|
|
864
|
+
Cn as eraseStrand,
|
|
865
|
+
Kn as exportJSON,
|
|
866
|
+
Rn as exportSVG,
|
|
867
|
+
B as fillet,
|
|
868
|
+
sn as fuse,
|
|
869
|
+
z as fuseAll,
|
|
870
|
+
zn as importJSON,
|
|
871
|
+
yn as intersect,
|
|
872
|
+
On as offset,
|
|
873
|
+
Dn as outlineStroke,
|
|
874
|
+
Tn as polarToCartesian,
|
|
875
|
+
Bn as selectCorners,
|
|
876
|
+
it as svgBody
|
|
639
877
|
};
|
|
640
878
|
//# sourceMappingURL=pantograph.js.map
|