dielines 0.6.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/README.md +7 -0
- package/dist/dielines.js +4814 -0
- package/dist/dielines.js.map +1 -0
- package/dist/dielines.umd.cjs +18 -0
- package/dist/dielines.umd.cjs.map +1 -0
- package/dist/types/Dieline.d.ts +23 -0
- package/dist/types/FoldLockBump.d.ts +16 -0
- package/dist/types/drawFlaps.d.ts +26 -0
- package/dist/types/linearDistribution.d.ts +18 -0
- package/dist/types/main.d.ts +4 -0
- package/package.json +48 -0
package/dist/dielines.js
ADDED
|
@@ -0,0 +1,4814 @@
|
|
|
1
|
+
function kt(r, t, e, s) {
|
|
2
|
+
return r <= s && t >= e;
|
|
3
|
+
}
|
|
4
|
+
class ht {
|
|
5
|
+
constructor(t = 1 / 0, e = 1 / 0, s = -1 / 0, n = -1 / 0) {
|
|
6
|
+
this.xMin = t, this.yMin = e, this.xMax = s, this.yMax = n;
|
|
7
|
+
}
|
|
8
|
+
get width() {
|
|
9
|
+
return this.xMax - this.xMin;
|
|
10
|
+
}
|
|
11
|
+
get height() {
|
|
12
|
+
return this.yMax - this.yMin;
|
|
13
|
+
}
|
|
14
|
+
contains(t) {
|
|
15
|
+
const [e, s] = t;
|
|
16
|
+
return kt(this.xMin, this.xMax, e, e) && kt(this.yMin, this.yMax, s, s);
|
|
17
|
+
}
|
|
18
|
+
overlaps(t) {
|
|
19
|
+
return kt(this.xMin, this.xMax, t.xMin, t.xMax) && kt(this.yMin, this.yMax, t.yMin, t.yMax);
|
|
20
|
+
}
|
|
21
|
+
addPoint(t) {
|
|
22
|
+
const [e, s] = t;
|
|
23
|
+
return new ht(
|
|
24
|
+
Math.min(this.xMin, e),
|
|
25
|
+
Math.min(this.yMin, s),
|
|
26
|
+
Math.max(this.xMax, e),
|
|
27
|
+
Math.max(this.yMax, s)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
merge(t) {
|
|
31
|
+
return new ht(
|
|
32
|
+
Math.min(this.xMin, t.xMin),
|
|
33
|
+
Math.min(this.yMin, t.yMin),
|
|
34
|
+
Math.max(this.xMax, t.xMax),
|
|
35
|
+
Math.max(this.yMax, t.yMax)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function Es(r) {
|
|
40
|
+
return r.reduce((t, e) => t.addPoint(e), new ht());
|
|
41
|
+
}
|
|
42
|
+
const le = (r, t = 1e-9) => {
|
|
43
|
+
let e = r;
|
|
44
|
+
return Math.abs(r) < t && (e = 0), e.toFixed(-Math.log10(t));
|
|
45
|
+
};
|
|
46
|
+
function at(r, t = 1e-9) {
|
|
47
|
+
return Array.from(
|
|
48
|
+
new Map(
|
|
49
|
+
r.map(([e, s]) => [
|
|
50
|
+
`[${le(e, t)},${le(s, t)}]`,
|
|
51
|
+
[e, s]
|
|
52
|
+
])
|
|
53
|
+
).values()
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const Pt = Math.PI / 180, Qt = 180 / Math.PI, I = (r) => `[${r[0]}, ${r[1]}]`, b = ([r, t], [e, s], n = 1e-9) => Math.abs(r - e) <= n && Math.abs(t - s) <= n, _ = ([r, t], [e, s]) => [r + e, t + s], V = ([r, t], [e, s]) => [r - e, t - s], Ft = ([r, t]) => r * r + t * t, L = ([r, t], e) => [r * e, t * e], xt = ([r, t], [e, s] = [0, 0]) => (r - e) ** 2 + (t - s) ** 2, B = (r, t = [0, 0]) => Math.sqrt(xt(r, t));
|
|
57
|
+
function it([r, t], [e, s]) {
|
|
58
|
+
return r * s - t * e;
|
|
59
|
+
}
|
|
60
|
+
function Ut([r, t], [e, s]) {
|
|
61
|
+
return r * e + t * s;
|
|
62
|
+
}
|
|
63
|
+
function J([r, t]) {
|
|
64
|
+
const e = B([r, t]);
|
|
65
|
+
return [r / e, t / e];
|
|
66
|
+
}
|
|
67
|
+
function rt(r, t) {
|
|
68
|
+
const e = Math.cos(t) * r, s = Math.sin(t) * r;
|
|
69
|
+
return [e, s];
|
|
70
|
+
}
|
|
71
|
+
function vs([r, t]) {
|
|
72
|
+
return Math.atan2(t, r);
|
|
73
|
+
}
|
|
74
|
+
function je(r) {
|
|
75
|
+
const t = B(r), e = vs(r);
|
|
76
|
+
return [t, e];
|
|
77
|
+
}
|
|
78
|
+
function Zt(r, t, e = 1e-9) {
|
|
79
|
+
const s = it(r, t), n = Ft(r), o = Ft(t);
|
|
80
|
+
return s * s < n * o * e * e;
|
|
81
|
+
}
|
|
82
|
+
function z(r) {
|
|
83
|
+
return [-r[1], r[0]];
|
|
84
|
+
}
|
|
85
|
+
function Mt(r) {
|
|
86
|
+
return [r[1], -r[0]];
|
|
87
|
+
}
|
|
88
|
+
function As(r, t, e) {
|
|
89
|
+
return b(e, r) || Zt(V(e, r), t);
|
|
90
|
+
}
|
|
91
|
+
const ct = (r, t) => {
|
|
92
|
+
const [e, s, n, o, i, h, l, a, c] = r, [u, m, p, g, d, M, f, w, y] = t;
|
|
93
|
+
return [
|
|
94
|
+
e * u + s * g + n * f,
|
|
95
|
+
e * m + s * d + n * w,
|
|
96
|
+
e * p + s * M + n * y,
|
|
97
|
+
o * u + i * g + h * f,
|
|
98
|
+
o * m + i * d + h * w,
|
|
99
|
+
o * p + i * M + h * y,
|
|
100
|
+
l * u + a * g + c * f,
|
|
101
|
+
l * m + a * d + c * w,
|
|
102
|
+
l * p + a * M + c * y
|
|
103
|
+
];
|
|
104
|
+
}, Ss = (r) => {
|
|
105
|
+
const [t, e, s, n, o, i, h, l, a] = r, c = t * (o * a - i * l) - e * (n * a - i * h) + s * (n * l - o * h);
|
|
106
|
+
return [
|
|
107
|
+
(o * a - i * l) / c,
|
|
108
|
+
(s * l - e * a) / c,
|
|
109
|
+
(e * i - s * o) / c,
|
|
110
|
+
(i * h - n * a) / c,
|
|
111
|
+
(t * a - s * h) / c,
|
|
112
|
+
(s * n - t * i) / c,
|
|
113
|
+
(n * l - o * h) / c,
|
|
114
|
+
(e * h - t * l) / c,
|
|
115
|
+
(t * o - e * n) / c
|
|
116
|
+
];
|
|
117
|
+
}, ks = (r) => {
|
|
118
|
+
const [t, e, s, n, o, i, h, l, a] = r;
|
|
119
|
+
return [t, n, h, e, o, l, s, i, a];
|
|
120
|
+
};
|
|
121
|
+
class q {
|
|
122
|
+
constructor(t) {
|
|
123
|
+
this._matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1], t && (this._matrix = [...t]);
|
|
124
|
+
}
|
|
125
|
+
clone() {
|
|
126
|
+
return new q(this._matrix);
|
|
127
|
+
}
|
|
128
|
+
transpose() {
|
|
129
|
+
return this._matrix = ks(this._matrix), this;
|
|
130
|
+
}
|
|
131
|
+
inverse() {
|
|
132
|
+
return this._matrix = Ss(this._matrix), this;
|
|
133
|
+
}
|
|
134
|
+
translate(t, e) {
|
|
135
|
+
return this._matrix = ct(this._matrix, [1, 0, t, 0, 1, e, 0, 0, 1]), this;
|
|
136
|
+
}
|
|
137
|
+
rotate(t, e) {
|
|
138
|
+
const s = Math.cos(t), n = Math.sin(t), o = [s, -n, 0, n, s, 0, 0, 0, 1];
|
|
139
|
+
return e && this.translate(e[0], e[1]), this._matrix = ct(this._matrix, o), e && this.translate(-e[0], -e[1]), this;
|
|
140
|
+
}
|
|
141
|
+
mirrorX() {
|
|
142
|
+
return this._matrix = ct(this._matrix, [1, 0, 0, 0, -1, 0, 0, 0, 1]), this;
|
|
143
|
+
}
|
|
144
|
+
mirrorY() {
|
|
145
|
+
return this._matrix = ct(this._matrix, [-1, 0, 0, 0, 1, 0, 0, 0, 1]), this;
|
|
146
|
+
}
|
|
147
|
+
mirrorLine(t, e) {
|
|
148
|
+
const [s, n] = t, o = Math.atan2(n, s);
|
|
149
|
+
return e && this.translate(e[0], e[1]), this.rotate(o), this.mirrorX(), this.rotate(-o), e && this.translate(-e[0], -e[1]), this;
|
|
150
|
+
}
|
|
151
|
+
mirrorCenter(t) {
|
|
152
|
+
return t && this.translate(t[0], t[1]), this._matrix = ct(this._matrix, [-1, 0, 0, 0, -1, 0, 0, 0, 1]), t && this.translate(-t[0], -t[1]), this;
|
|
153
|
+
}
|
|
154
|
+
scale(t, e) {
|
|
155
|
+
return e && this.translate(e[0], e[1]), this._matrix = ct(this._matrix, [t, 0, 0, 0, t, 0, 0, 0, 1]), e && this.translate(-e[0], -e[1]), this;
|
|
156
|
+
}
|
|
157
|
+
transform(t) {
|
|
158
|
+
const [e, s] = t, [n, o, i, h, l, a] = this._matrix;
|
|
159
|
+
return [n * e + o * s + i, h * e + l * s + a];
|
|
160
|
+
}
|
|
161
|
+
transformAngle(t) {
|
|
162
|
+
const [e, s] = this.transform([Math.cos(t), Math.sin(t)]), [n, o] = this.transform([0, 0]);
|
|
163
|
+
return Math.atan2(s - o, e - n);
|
|
164
|
+
}
|
|
165
|
+
keepsOrientation() {
|
|
166
|
+
const [t, , , , e] = this._matrix;
|
|
167
|
+
return t * e > 0;
|
|
168
|
+
}
|
|
169
|
+
scaleFactor() {
|
|
170
|
+
const [t, , , e] = this._matrix;
|
|
171
|
+
return Math.sqrt(t * t + e * e);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
let lt = class {
|
|
175
|
+
translateX(t) {
|
|
176
|
+
const e = new q().translate(t, 0);
|
|
177
|
+
return this.transform(e);
|
|
178
|
+
}
|
|
179
|
+
translateY(t) {
|
|
180
|
+
const e = new q().translate(0, t);
|
|
181
|
+
return this.transform(e);
|
|
182
|
+
}
|
|
183
|
+
translate(t, e) {
|
|
184
|
+
const s = new q().translate(t, e);
|
|
185
|
+
return this.transform(s);
|
|
186
|
+
}
|
|
187
|
+
translateTo([t, e]) {
|
|
188
|
+
const s = new q().translate(t, e);
|
|
189
|
+
return this.transform(s);
|
|
190
|
+
}
|
|
191
|
+
rotate(t, e) {
|
|
192
|
+
const s = new q().rotate(
|
|
193
|
+
t * Pt,
|
|
194
|
+
e
|
|
195
|
+
);
|
|
196
|
+
return this.transform(s);
|
|
197
|
+
}
|
|
198
|
+
scale(t, e) {
|
|
199
|
+
const s = new q().scale(t, e);
|
|
200
|
+
return this.transform(s);
|
|
201
|
+
}
|
|
202
|
+
mirrorCenter(t) {
|
|
203
|
+
const e = new q().mirrorCenter(t);
|
|
204
|
+
return this.transform(e);
|
|
205
|
+
}
|
|
206
|
+
mirror(t = "x", e) {
|
|
207
|
+
const s = new q();
|
|
208
|
+
return t === "x" ? s.mirrorX() : t === "y" ? s.mirrorY() : s.mirrorLine(t, e), this.transform(s);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
class te extends lt {
|
|
212
|
+
constructor(t, e) {
|
|
213
|
+
super(), this.firstPoint = t, this.lastPoint = e, this.precision = 1e-9, this.firstPoint = t, this.lastPoint = e;
|
|
214
|
+
}
|
|
215
|
+
get repr() {
|
|
216
|
+
return `${this.segmentType} ${I(this.firstPoint)} - ${I(
|
|
217
|
+
this.lastPoint
|
|
218
|
+
)}`;
|
|
219
|
+
}
|
|
220
|
+
get info() {
|
|
221
|
+
return this.repr;
|
|
222
|
+
}
|
|
223
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
224
|
+
return this.repr;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
class A extends te {
|
|
228
|
+
constructor() {
|
|
229
|
+
super(...arguments), this.segmentType = "LINE", this._V = null, this._slope = null, this._yIntercept = null, this._boundingBox = null;
|
|
230
|
+
}
|
|
231
|
+
isValidParameter(t) {
|
|
232
|
+
const e = this.length * this.precision;
|
|
233
|
+
return t >= -e && 1 - t >= -e;
|
|
234
|
+
}
|
|
235
|
+
paramPoint(t) {
|
|
236
|
+
return _(this.firstPoint, L(this.V, t));
|
|
237
|
+
}
|
|
238
|
+
get length() {
|
|
239
|
+
return B(this.firstPoint, this.lastPoint);
|
|
240
|
+
}
|
|
241
|
+
get squareLength() {
|
|
242
|
+
return xt(this.firstPoint, this.lastPoint);
|
|
243
|
+
}
|
|
244
|
+
get V() {
|
|
245
|
+
return this._V === null && (this._V = V(this.lastPoint, this.firstPoint)), this._V;
|
|
246
|
+
}
|
|
247
|
+
get slope() {
|
|
248
|
+
if (this._slope === null) {
|
|
249
|
+
const [t, e] = this.V;
|
|
250
|
+
this._slope = e / t;
|
|
251
|
+
}
|
|
252
|
+
return this._slope;
|
|
253
|
+
}
|
|
254
|
+
get yIntercept() {
|
|
255
|
+
return this._yIntercept === null && (this._yIntercept = this.firstPoint[1] - this.slope * this.firstPoint[0]), this._yIntercept;
|
|
256
|
+
}
|
|
257
|
+
get midPoint() {
|
|
258
|
+
return _(this.firstPoint, L(this.V, 0.5));
|
|
259
|
+
}
|
|
260
|
+
isSame(t) {
|
|
261
|
+
return t instanceof A ? b(this.firstPoint, t.firstPoint) && b(this.lastPoint, t.lastPoint) || b(this.lastPoint, t.firstPoint) && b(this.firstPoint, t.lastPoint) : !1;
|
|
262
|
+
}
|
|
263
|
+
clone() {
|
|
264
|
+
return new A(this.firstPoint, this.lastPoint);
|
|
265
|
+
}
|
|
266
|
+
reverse() {
|
|
267
|
+
return new A(this.lastPoint, this.firstPoint);
|
|
268
|
+
}
|
|
269
|
+
get boundingBox() {
|
|
270
|
+
return this._boundingBox === null && (this._boundingBox = new ht(
|
|
271
|
+
Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
|
|
272
|
+
Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
|
|
273
|
+
Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
|
|
274
|
+
Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
|
|
275
|
+
)), this._boundingBox;
|
|
276
|
+
}
|
|
277
|
+
distanceFrom(t) {
|
|
278
|
+
const e = V(t, this.firstPoint), s = Ut(e, this.V) / this.squareLength;
|
|
279
|
+
if (s < 0)
|
|
280
|
+
return B(t, this.firstPoint);
|
|
281
|
+
if (s > 1)
|
|
282
|
+
return B(t, this.lastPoint);
|
|
283
|
+
const n = this.paramPoint(s);
|
|
284
|
+
return B(t, n);
|
|
285
|
+
}
|
|
286
|
+
isOnSegment(t) {
|
|
287
|
+
if (b(t, this.firstPoint, this.precision))
|
|
288
|
+
return !0;
|
|
289
|
+
const e = V(t, this.firstPoint);
|
|
290
|
+
if (!Zt(this.V, e))
|
|
291
|
+
return !1;
|
|
292
|
+
const s = Ut(e, this.V) / this.squareLength;
|
|
293
|
+
return this.isValidParameter(s);
|
|
294
|
+
}
|
|
295
|
+
gradientAt(t) {
|
|
296
|
+
return this.V;
|
|
297
|
+
}
|
|
298
|
+
tangentAt(t) {
|
|
299
|
+
if (!this.isOnSegment(t))
|
|
300
|
+
throw new Error("Point is not on segment");
|
|
301
|
+
return J(this.V);
|
|
302
|
+
}
|
|
303
|
+
get normalVector() {
|
|
304
|
+
return z(J(this.V));
|
|
305
|
+
}
|
|
306
|
+
get tangentAtFirstPoint() {
|
|
307
|
+
return J(this.V);
|
|
308
|
+
}
|
|
309
|
+
get tangentAtLastPoint() {
|
|
310
|
+
return J(this.V);
|
|
311
|
+
}
|
|
312
|
+
splitAt(t) {
|
|
313
|
+
let e;
|
|
314
|
+
if (Array.isArray(t) && t.length === 0)
|
|
315
|
+
return [this];
|
|
316
|
+
Array.isArray(t[0]) ? e = t : e = [t], e.forEach((l) => {
|
|
317
|
+
if (!this.isOnSegment(l))
|
|
318
|
+
throw new Error(
|
|
319
|
+
`Point ${I(l)} is not on segment ${this.repr}`
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
const s = [this.firstPoint, ...e, this.lastPoint], n = at(s), o = this.lastPoint[0] - this.firstPoint[0];
|
|
323
|
+
let i = Math.sign(o), h = 0;
|
|
324
|
+
return Math.abs(o) < this.precision && (i = Math.sign(this.lastPoint[1] - this.firstPoint[1]), h = 1), n.sort(
|
|
325
|
+
(l, a) => i * (l[h] - a[h])
|
|
326
|
+
), n.flatMap((l, a) => a === n.length - 1 ? [] : new A(l, n[a + 1]));
|
|
327
|
+
}
|
|
328
|
+
transform(t) {
|
|
329
|
+
return new A(
|
|
330
|
+
t.transform(this.firstPoint),
|
|
331
|
+
t.transform(this.lastPoint)
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function Rs(r) {
|
|
336
|
+
return Array.from(Array(r).keys());
|
|
337
|
+
}
|
|
338
|
+
function et(r) {
|
|
339
|
+
const t = Math.min(...r.map((e) => e.length));
|
|
340
|
+
return Rs(t).map((e) => r.map((s) => s[e]));
|
|
341
|
+
}
|
|
342
|
+
function ot(r, t = 1e-9) {
|
|
343
|
+
return r < 0 ? r + 2 * Math.PI : r >= 2 * Math.PI ? r % (2 * Math.PI) : r > 2 * Math.PI - t ? 0 : r;
|
|
344
|
+
}
|
|
345
|
+
function Lt(r, t, e, s = 1e-9) {
|
|
346
|
+
let n = t - r;
|
|
347
|
+
return e && (n = -n), n < 0 && (n += 2 * Math.PI), n > 2 * Math.PI - s ? 0 : n;
|
|
348
|
+
}
|
|
349
|
+
const Vt = (r, t, e) => {
|
|
350
|
+
const s = it(r.V, t.V), n = Ft(r.V), o = Ft(t.V), i = e ? e * e : r.precision * t.precision;
|
|
351
|
+
if (s * s < n * o * i)
|
|
352
|
+
return "parallel";
|
|
353
|
+
const h = V(t.firstPoint, r.firstPoint), l = it(h, t.V) / s, a = it(h, r.V) / s;
|
|
354
|
+
return {
|
|
355
|
+
intersectionParam1: l,
|
|
356
|
+
intersectionParam2: a
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
function Ve(r, t, e = !1, s) {
|
|
360
|
+
const n = Vt(r, t, s);
|
|
361
|
+
if (n === "parallel") {
|
|
362
|
+
if (!e)
|
|
363
|
+
return null;
|
|
364
|
+
if (r.isSame(t))
|
|
365
|
+
return r;
|
|
366
|
+
const h = at(
|
|
367
|
+
[
|
|
368
|
+
t.isOnSegment(r.firstPoint) ? r.firstPoint : null,
|
|
369
|
+
t.isOnSegment(r.lastPoint) ? r.lastPoint : null,
|
|
370
|
+
r.isOnSegment(t.firstPoint) ? t.firstPoint : null,
|
|
371
|
+
r.isOnSegment(t.lastPoint) ? t.lastPoint : null
|
|
372
|
+
].filter((l) => l !== null)
|
|
373
|
+
).sort((l, a) => l[0] - a[0]);
|
|
374
|
+
if (h.length === 0 || h.length === 1)
|
|
375
|
+
return null;
|
|
376
|
+
if (h.length === 2)
|
|
377
|
+
return new A(h[0], h[1]);
|
|
378
|
+
throw console.error(h), new Error(
|
|
379
|
+
"Unexpected number of points while intersecting parallel lines"
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
const { intersectionParam1: o, intersectionParam2: i } = n;
|
|
383
|
+
return !r.isValidParameter(o) || !t.isValidParameter(i) ? null : r.paramPoint(o);
|
|
384
|
+
}
|
|
385
|
+
const Rt = (r, t) => {
|
|
386
|
+
const e = V(r, t);
|
|
387
|
+
return je(e);
|
|
388
|
+
};
|
|
389
|
+
class S extends te {
|
|
390
|
+
constructor(t, e, s, n = !1, { ignoreChecks: o = !1 } = {}) {
|
|
391
|
+
if (super(t, e), this.segmentType = "ARC", this._coefficients = null, this._angularLength = null, this._radius = null, this._firstAngle = null, this._lastAngle = null, this._boundingBox = null, this.center = s, this.clockwise = n, !o) {
|
|
392
|
+
if (b(t, e))
|
|
393
|
+
throw new Error("Invalid arc, cannot be a full circle");
|
|
394
|
+
if (Math.abs(this.radius - B(this.lastPoint, this.center)) > this.precision)
|
|
395
|
+
throw new Error(
|
|
396
|
+
`Invalid arc, radius does not match between ${I(
|
|
397
|
+
t
|
|
398
|
+
)} and ${I(e)}} (center ${I(s)})`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
get info() {
|
|
403
|
+
return `ARC(${I(this.firstPoint)}, ${I(
|
|
404
|
+
this.lastPoint
|
|
405
|
+
)}, ${I(this.center)}, ${this.clockwise ? "CW" : "CCW"})`;
|
|
406
|
+
}
|
|
407
|
+
get coefficients() {
|
|
408
|
+
if (this._coefficients === null) {
|
|
409
|
+
const [t, e] = this.center, s = this.radius * this.radius;
|
|
410
|
+
this._coefficients = {
|
|
411
|
+
x2: 1 / s,
|
|
412
|
+
xy: 0,
|
|
413
|
+
y2: 1 / s,
|
|
414
|
+
x: -(2 * t) / s,
|
|
415
|
+
y: -(2 * e) / s,
|
|
416
|
+
c: (t * t + e * e - s) / s
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return this._coefficients;
|
|
420
|
+
}
|
|
421
|
+
isValidParameter(t) {
|
|
422
|
+
return 1 - t >= -this.precision && t >= -this.precision;
|
|
423
|
+
}
|
|
424
|
+
angleToParam(t) {
|
|
425
|
+
return Lt(this.firstAngle, ot(t), this.clockwise) / this.angularLength;
|
|
426
|
+
}
|
|
427
|
+
get angularLength() {
|
|
428
|
+
return this._angularLength || (this._angularLength = Lt(
|
|
429
|
+
this.firstAngle,
|
|
430
|
+
this.lastAngle,
|
|
431
|
+
this.clockwise
|
|
432
|
+
)), this._angularLength;
|
|
433
|
+
}
|
|
434
|
+
paramPoint(t) {
|
|
435
|
+
return _(
|
|
436
|
+
this.center,
|
|
437
|
+
rt(
|
|
438
|
+
this.radius,
|
|
439
|
+
this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1)
|
|
440
|
+
)
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
pointToParam(t) {
|
|
444
|
+
const [e, s] = Rt(t, this.center);
|
|
445
|
+
if (Math.abs(e - this.radius) > this.precision)
|
|
446
|
+
throw new Error(
|
|
447
|
+
`Point ${I(t)} is not on segment ${this.repr}`
|
|
448
|
+
);
|
|
449
|
+
const n = this.angleToParam(s);
|
|
450
|
+
if (!this.isValidParameter(n))
|
|
451
|
+
throw new Error(
|
|
452
|
+
`Point ${I(t)} is not on segment ${this.repr}`
|
|
453
|
+
);
|
|
454
|
+
return n;
|
|
455
|
+
}
|
|
456
|
+
get radius() {
|
|
457
|
+
return this._radius === null && (this._radius = B(this.firstPoint, this.center)), this._radius;
|
|
458
|
+
}
|
|
459
|
+
get firstAngle() {
|
|
460
|
+
if (this._firstAngle === null) {
|
|
461
|
+
const [t, e] = V(this.firstPoint, this.center);
|
|
462
|
+
this._firstAngle = ot(Math.atan2(e, t));
|
|
463
|
+
}
|
|
464
|
+
return this._firstAngle;
|
|
465
|
+
}
|
|
466
|
+
get lastAngle() {
|
|
467
|
+
if (this._lastAngle === null) {
|
|
468
|
+
const [t, e] = V(this.lastPoint, this.center);
|
|
469
|
+
this._lastAngle = ot(Math.atan2(e, t));
|
|
470
|
+
}
|
|
471
|
+
return this._lastAngle;
|
|
472
|
+
}
|
|
473
|
+
get length() {
|
|
474
|
+
return this.radius * this.angularLength;
|
|
475
|
+
}
|
|
476
|
+
get squareLength() {
|
|
477
|
+
return this.length * this.length;
|
|
478
|
+
}
|
|
479
|
+
get midPoint() {
|
|
480
|
+
return this.paramPoint(0.5);
|
|
481
|
+
}
|
|
482
|
+
isSame(t) {
|
|
483
|
+
return !(t instanceof S) || !b(this.center, t.center) ? !1 : b(this.firstPoint, t.firstPoint) && b(this.lastPoint, t.lastPoint) && this.clockwise === t.clockwise || b(this.lastPoint, t.firstPoint) && b(this.firstPoint, t.lastPoint) && this.clockwise === !t.clockwise;
|
|
484
|
+
}
|
|
485
|
+
clone() {
|
|
486
|
+
return new S(
|
|
487
|
+
this.firstPoint,
|
|
488
|
+
this.lastPoint,
|
|
489
|
+
this.center,
|
|
490
|
+
this.clockwise
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
reverse() {
|
|
494
|
+
return new S(
|
|
495
|
+
this.lastPoint,
|
|
496
|
+
this.firstPoint,
|
|
497
|
+
this.center,
|
|
498
|
+
!this.clockwise
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
get boundingBox() {
|
|
502
|
+
if (this._boundingBox === null) {
|
|
503
|
+
const t = this.radius + this.precision, e = (s) => this.isValidParameter(this.angleToParam(s));
|
|
504
|
+
this._boundingBox = new ht(
|
|
505
|
+
e(Math.PI) ? this.center[0] - t : Math.min(this.firstPoint[0], this.lastPoint[0]) - this.precision,
|
|
506
|
+
e(Math.PI * 1.5) ? this.center[1] - t : Math.min(this.firstPoint[1], this.lastPoint[1]) - this.precision,
|
|
507
|
+
e(0) ? this.center[0] + t : Math.max(this.firstPoint[0], this.lastPoint[0]) + this.precision,
|
|
508
|
+
e(Math.PI / 2) ? this.center[1] + t : Math.max(this.firstPoint[1], this.lastPoint[1]) + this.precision
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
return this._boundingBox;
|
|
512
|
+
}
|
|
513
|
+
distanceFrom(t) {
|
|
514
|
+
const [e, s] = Rt(t, this.center);
|
|
515
|
+
return this.isValidParameter(this.angleToParam(s)) ? Math.abs(e - this.radius) : Math.sqrt(
|
|
516
|
+
Math.min(
|
|
517
|
+
xt(t, this.firstPoint),
|
|
518
|
+
xt(t, this.lastPoint)
|
|
519
|
+
)
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
isOnSegment(t) {
|
|
523
|
+
if (b(t, this.firstPoint) || b(t, this.lastPoint))
|
|
524
|
+
return !0;
|
|
525
|
+
const [e, s] = Rt(t, this.center);
|
|
526
|
+
if (Math.abs(e - this.radius) > this.precision)
|
|
527
|
+
return !1;
|
|
528
|
+
const n = this.angleToParam(s);
|
|
529
|
+
return this.isValidParameter(n);
|
|
530
|
+
}
|
|
531
|
+
gradientAt(t) {
|
|
532
|
+
const e = this.firstAngle + t * this.angularLength * (this.clockwise ? -1 : 1), s = this.radius * this.angularLength, n = -s * Math.sin(e), o = s * Math.cos(e);
|
|
533
|
+
return this.clockwise ? [-n, -o] : [n, o];
|
|
534
|
+
}
|
|
535
|
+
tangentAt(t) {
|
|
536
|
+
const [e, s] = Rt(t, this.center);
|
|
537
|
+
if (Math.abs(e - this.radius) > this.precision)
|
|
538
|
+
throw new Error("Point is not on the arc");
|
|
539
|
+
const n = this.angleToParam(s);
|
|
540
|
+
if (!this.isValidParameter(n))
|
|
541
|
+
throw new Error("Point is not on the arc");
|
|
542
|
+
const o = rt(1, s);
|
|
543
|
+
return (this.clockwise ? Mt : z)(J(o));
|
|
544
|
+
}
|
|
545
|
+
get tangentAtFirstPoint() {
|
|
546
|
+
const t = rt(1, this.firstAngle);
|
|
547
|
+
return (this.clockwise ? Mt : z)(J(t));
|
|
548
|
+
}
|
|
549
|
+
get tangentAtLastPoint() {
|
|
550
|
+
const t = rt(1, this.lastAngle);
|
|
551
|
+
return (this.clockwise ? Mt : z)(J(t));
|
|
552
|
+
}
|
|
553
|
+
splitAt(t) {
|
|
554
|
+
let e;
|
|
555
|
+
if (Array.isArray(t) && t.length === 0)
|
|
556
|
+
return [this];
|
|
557
|
+
Array.isArray(t[0]) ? e = t : e = [t];
|
|
558
|
+
const s = [0, 1, ...e.map((i) => this.pointToParam(i))], n = new Map(
|
|
559
|
+
et([s, [this.firstPoint, this.lastPoint, ...e]])
|
|
560
|
+
);
|
|
561
|
+
s.sort((i, h) => i - h);
|
|
562
|
+
let o = null;
|
|
563
|
+
return s.flatMap((i, h) => {
|
|
564
|
+
if (h === s.length - 1)
|
|
565
|
+
return [];
|
|
566
|
+
const l = s[h + 1];
|
|
567
|
+
if (l - i < this.precision)
|
|
568
|
+
return o === null && (o = i), [];
|
|
569
|
+
const a = o === null ? i : o, c = new S(
|
|
570
|
+
n.get(a) || this.paramPoint(a),
|
|
571
|
+
n.get(l) || this.paramPoint(l),
|
|
572
|
+
this.center,
|
|
573
|
+
this.clockwise
|
|
574
|
+
);
|
|
575
|
+
return o = null, c;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
transform(t) {
|
|
579
|
+
return new S(
|
|
580
|
+
t.transform(this.firstPoint),
|
|
581
|
+
t.transform(this.lastPoint),
|
|
582
|
+
t.transform(this.center),
|
|
583
|
+
t.keepsOrientation() ? this.clockwise : !this.clockwise
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function Ts(r, t, e) {
|
|
588
|
+
const s = new A(t, r), n = new A(t, e), o = z(s.tangentAtFirstPoint), i = z(n.tangentAtLastPoint), h = Vt(
|
|
589
|
+
{ firstPoint: s.midPoint, V: o, precision: 1e-9 },
|
|
590
|
+
{ firstPoint: n.midPoint, V: i, precision: 1e-9 }
|
|
591
|
+
);
|
|
592
|
+
if (h === "parallel")
|
|
593
|
+
throw new Error("Cannot create an arc from three colinear points");
|
|
594
|
+
const l = it(
|
|
595
|
+
V(r, t),
|
|
596
|
+
V(e, t)
|
|
597
|
+
) > 0;
|
|
598
|
+
return new S(
|
|
599
|
+
r,
|
|
600
|
+
e,
|
|
601
|
+
_(s.midPoint, L(o, h.intersectionParam1)),
|
|
602
|
+
l,
|
|
603
|
+
{ ignoreChecks: !0 }
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
function Ne(r, t, e) {
|
|
607
|
+
const s = new A(t, r), n = z(s.tangentAtFirstPoint), o = Vt(
|
|
608
|
+
{ firstPoint: s.midPoint, V: n, precision: 1e-9 },
|
|
609
|
+
{
|
|
610
|
+
firstPoint: r,
|
|
611
|
+
V: z(e),
|
|
612
|
+
precision: 1e-9
|
|
613
|
+
}
|
|
614
|
+
);
|
|
615
|
+
if (o === "parallel")
|
|
616
|
+
throw new Error("Cannot create an arc from three colinear points");
|
|
617
|
+
const i = _(
|
|
618
|
+
s.midPoint,
|
|
619
|
+
L(n, o.intersectionParam1)
|
|
620
|
+
), h = it(
|
|
621
|
+
V(i, r),
|
|
622
|
+
V(i, _(r, e))
|
|
623
|
+
) < 0;
|
|
624
|
+
return new S(r, t, i, h, {
|
|
625
|
+
ignoreChecks: !0
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
function $s(r, t) {
|
|
629
|
+
const e = V(t, r.firstPoint), s = Ut(e, r.V) / r.squareLength;
|
|
630
|
+
return r.paramPoint(s);
|
|
631
|
+
}
|
|
632
|
+
function Ct(r, t, e) {
|
|
633
|
+
const s = e || r.precision, n = $s(r, t.center), o = B(n, t.center);
|
|
634
|
+
if (o > t.radius + s)
|
|
635
|
+
return [];
|
|
636
|
+
if (Math.abs(o - t.radius) < s) {
|
|
637
|
+
const u = n;
|
|
638
|
+
return r.isOnSegment(u) && t.isOnSegment(u) ? [u] : [];
|
|
639
|
+
}
|
|
640
|
+
const i = [], h = Math.sqrt(
|
|
641
|
+
t.radius * t.radius - o * o
|
|
642
|
+
), l = r.tangentAtFirstPoint, a = _(n, L(l, h));
|
|
643
|
+
r.isOnSegment(a) && t.isOnSegment(a) && i.push(a);
|
|
644
|
+
const c = _(n, L(l, -h));
|
|
645
|
+
return r.isOnSegment(c) && t.isOnSegment(c) && i.push(c), i;
|
|
646
|
+
}
|
|
647
|
+
const _s = (r) => {
|
|
648
|
+
const { firstPoint: t, lastPoint: e, center: s, clockwise: n } = r;
|
|
649
|
+
return new S(e, t, s, n, {
|
|
650
|
+
ignoreChecks: !0
|
|
651
|
+
});
|
|
652
|
+
}, Is = (r, t) => {
|
|
653
|
+
if (r.isSame(t))
|
|
654
|
+
return [r];
|
|
655
|
+
const e = at(
|
|
656
|
+
[
|
|
657
|
+
t.isOnSegment(r.firstPoint) ? r.firstPoint : null,
|
|
658
|
+
t.isOnSegment(r.lastPoint) ? r.lastPoint : null,
|
|
659
|
+
r.isOnSegment(t.firstPoint) ? t.firstPoint : null,
|
|
660
|
+
r.isOnSegment(t.lastPoint) ? t.lastPoint : null
|
|
661
|
+
].filter((s) => s !== null)
|
|
662
|
+
// We sort by the param value of the first arc. This means that the points
|
|
663
|
+
// will be sorted with the same orientation than arc1
|
|
664
|
+
).sort((s, n) => r.pointToParam(s) - r.pointToParam(n));
|
|
665
|
+
if (e.length === 0)
|
|
666
|
+
return [];
|
|
667
|
+
if (e.length === 1)
|
|
668
|
+
return [];
|
|
669
|
+
if (e.length === 2)
|
|
670
|
+
return r.isSame(_s(t)) ? [] : [new S(e[0], e[1], r.center, r.clockwise)];
|
|
671
|
+
if (e.length === 3) {
|
|
672
|
+
const s = b(e[0], t.lastPoint) || b(e[0], t.firstPoint) ? 1 : 0;
|
|
673
|
+
return [
|
|
674
|
+
new S(
|
|
675
|
+
e[0 + s],
|
|
676
|
+
e[1 + s],
|
|
677
|
+
r.center,
|
|
678
|
+
r.clockwise
|
|
679
|
+
)
|
|
680
|
+
];
|
|
681
|
+
} else if (e.length === 4)
|
|
682
|
+
return [
|
|
683
|
+
new S(e[0], e[1], r.center, r.clockwise),
|
|
684
|
+
new S(e[2], e[3], r.center, r.clockwise)
|
|
685
|
+
];
|
|
686
|
+
throw new Error("Bug in the arc arc overlap algorithm");
|
|
687
|
+
};
|
|
688
|
+
function qe(r, t, e = !1, s) {
|
|
689
|
+
const n = s || r.precision, o = B(r.center, t.center), i = r.radius + t.radius;
|
|
690
|
+
if (o > i + n)
|
|
691
|
+
return [];
|
|
692
|
+
const h = Math.abs(r.radius - t.radius);
|
|
693
|
+
if (o < h - n)
|
|
694
|
+
return [];
|
|
695
|
+
if (o < n)
|
|
696
|
+
return h > n ? [] : e ? Is(r, t) : [];
|
|
697
|
+
const l = J(V(t.center, r.center)), a = o > i - n;
|
|
698
|
+
if (
|
|
699
|
+
// circles are outside each other
|
|
700
|
+
a || // circles are inside each other
|
|
701
|
+
Math.abs(o - h) < n
|
|
702
|
+
) {
|
|
703
|
+
const f = a || r.radius > t.radius ? 1 : -1, w = _(
|
|
704
|
+
r.center,
|
|
705
|
+
L(l, f * r.radius)
|
|
706
|
+
);
|
|
707
|
+
return r.isOnSegment(w) && t.isOnSegment(w) ? [w] : [];
|
|
708
|
+
}
|
|
709
|
+
const c = r.radius * r.radius / (2 * o) - t.radius * t.radius / (2 * o) + o / 2, u = _(
|
|
710
|
+
r.center,
|
|
711
|
+
L(l, c)
|
|
712
|
+
), m = Math.sqrt(
|
|
713
|
+
r.radius * r.radius - c * c
|
|
714
|
+
), p = z(l), g = _(u, L(p, m)), d = _(u, L(p, -m)), M = [];
|
|
715
|
+
return r.isOnSegment(g) && t.isOnSegment(g) && M.push(g), r.isOnSegment(d) && t.isOnSegment(d) && M.push(d), M;
|
|
716
|
+
}
|
|
717
|
+
let O = class dt extends te {
|
|
718
|
+
constructor(t, e, s, n, o, i, h = !1, {
|
|
719
|
+
ignoreChecks: l = !1,
|
|
720
|
+
angleUnits: a = "deg"
|
|
721
|
+
} = {}) {
|
|
722
|
+
super(t, e), this.segmentType = "ELLIPSE_ARC", this.precision = 1e-6, this._coefficients = null, this.center = s;
|
|
723
|
+
const c = n >= o;
|
|
724
|
+
this.majorRadius = c ? n : o, this.minorRadius = c ? o : n;
|
|
725
|
+
const u = a === "deg" ? i * Pt : i;
|
|
726
|
+
if (this.tiltAngle = ot(
|
|
727
|
+
c ? u : u + Math.PI / 2
|
|
728
|
+
), this.clockwise = h, !l) {
|
|
729
|
+
if (b(t, e))
|
|
730
|
+
throw new Error("Invalid arc, cannot be a full circle");
|
|
731
|
+
if (!this.isPointOnEllipse(t))
|
|
732
|
+
throw new Error(
|
|
733
|
+
`First point ${I(
|
|
734
|
+
t
|
|
735
|
+
)} not on the ellipse defined by ${this.info}`
|
|
736
|
+
);
|
|
737
|
+
if (!this.isPointOnEllipse(e))
|
|
738
|
+
throw new Error(
|
|
739
|
+
`Last point ${I(e)} not on the ellipse defined by ${this.info}`
|
|
740
|
+
);
|
|
741
|
+
if (Math.abs(this.majorRadius - this.minorRadius) < this.precision)
|
|
742
|
+
throw new Error(
|
|
743
|
+
"Both radii should be different, create an arc instead"
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
get coefficients() {
|
|
748
|
+
if (this._coefficients === null) {
|
|
749
|
+
const [t, e] = this.center, s = this.majorRadius * this.majorRadius, n = this.minorRadius * this.minorRadius, o = Math.cos(this.tiltAngle), i = Math.sin(this.tiltAngle), h = s * i * i + n * o * o, l = 2 * (n - s) * i * o, a = s * o * o + n * i * i;
|
|
750
|
+
this._coefficients = {
|
|
751
|
+
x2: h,
|
|
752
|
+
xy: l,
|
|
753
|
+
y2: a,
|
|
754
|
+
x: -2 * h * t - l * e,
|
|
755
|
+
y: -2 * a * e - l * t,
|
|
756
|
+
c: h * t * t + l * t * e + a * e * e - s * n
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
return this._coefficients;
|
|
760
|
+
}
|
|
761
|
+
get info() {
|
|
762
|
+
return `ELLIPSE_ARC(${I(this.firstPoint)}, ${I(
|
|
763
|
+
this.lastPoint
|
|
764
|
+
)}, ${I(this.center)}, ${this.majorRadius}, ${this.minorRadius}, ${this.tiltAngle * Qt}, ${this.clockwise ? "CW" : "CCW"})`;
|
|
765
|
+
}
|
|
766
|
+
reverse() {
|
|
767
|
+
return new dt(
|
|
768
|
+
this.lastPoint,
|
|
769
|
+
this.firstPoint,
|
|
770
|
+
this.center,
|
|
771
|
+
this.majorRadius,
|
|
772
|
+
this.minorRadius,
|
|
773
|
+
this.tiltAngle,
|
|
774
|
+
!this.clockwise,
|
|
775
|
+
{ ignoreChecks: !0, angleUnits: "rad" }
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
clone() {
|
|
779
|
+
return new dt(
|
|
780
|
+
this.firstPoint,
|
|
781
|
+
this.lastPoint,
|
|
782
|
+
this.center,
|
|
783
|
+
this.majorRadius,
|
|
784
|
+
this.minorRadius,
|
|
785
|
+
this.tiltAngle,
|
|
786
|
+
this.clockwise,
|
|
787
|
+
{ ignoreChecks: !0, angleUnits: "rad" }
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
computeEllipseExtrema() {
|
|
791
|
+
const t = Math.tan(this.tiltAngle), e = this.minorRadius / this.majorRadius, s = -Math.atan(e * t), n = Math.atan(e / t);
|
|
792
|
+
return [s, Math.PI + s, n, Math.PI + n].map((o) => this.thetaToParam(o)).filter((o) => this.isValidParameter(o)).map((o) => this.paramPoint(o));
|
|
793
|
+
}
|
|
794
|
+
get boundingBox() {
|
|
795
|
+
if (this._boundingBox === void 0) {
|
|
796
|
+
const t = this.computeEllipseExtrema(), e = [
|
|
797
|
+
this.firstPoint,
|
|
798
|
+
this.lastPoint,
|
|
799
|
+
...t
|
|
800
|
+
];
|
|
801
|
+
this._boundingBox = Es(e);
|
|
802
|
+
}
|
|
803
|
+
return this._boundingBox;
|
|
804
|
+
}
|
|
805
|
+
get linearExentricity() {
|
|
806
|
+
return this._linearExentricity === void 0 && (this._linearExentricity = Math.sqrt(
|
|
807
|
+
this.majorRadius * this.majorRadius - this.minorRadius * this.minorRadius
|
|
808
|
+
)), this._linearExentricity;
|
|
809
|
+
}
|
|
810
|
+
get exentricity() {
|
|
811
|
+
return this._exentricity === void 0 && (this._exentricity = this.linearExentricity / this.majorRadius), this._exentricity;
|
|
812
|
+
}
|
|
813
|
+
get focals() {
|
|
814
|
+
if (this._focals === void 0) {
|
|
815
|
+
const t = this.majorAxis;
|
|
816
|
+
this._focals = [
|
|
817
|
+
_(this.center, L(t, this.linearExentricity)),
|
|
818
|
+
_(this.center, L(t, -this.linearExentricity))
|
|
819
|
+
];
|
|
820
|
+
}
|
|
821
|
+
return this._focals;
|
|
822
|
+
}
|
|
823
|
+
get majorAxis() {
|
|
824
|
+
return rt(1, this.tiltAngle);
|
|
825
|
+
}
|
|
826
|
+
paramPoint(t) {
|
|
827
|
+
const e = this.firstAngle + t * this.deltaAngle * (this.clockwise ? -1 : 1);
|
|
828
|
+
return this.reverseEllipseReferenceFrameTransform.transform([
|
|
829
|
+
this.majorRadius * Math.cos(e),
|
|
830
|
+
this.minorRadius * Math.sin(e)
|
|
831
|
+
]);
|
|
832
|
+
}
|
|
833
|
+
pointToParam(t) {
|
|
834
|
+
if (!this.isPointOnEllipse(t))
|
|
835
|
+
throw new Error(
|
|
836
|
+
`Point ${I(t)} not on the ellipse defined by ${this.repr}`
|
|
837
|
+
);
|
|
838
|
+
const e = this.thetaToParam(this.pointTheta(t));
|
|
839
|
+
if (!this.isValidParameter(e))
|
|
840
|
+
throw new Error(
|
|
841
|
+
`Point ${I(t)} is not on segment ${this.repr}`
|
|
842
|
+
);
|
|
843
|
+
return e;
|
|
844
|
+
}
|
|
845
|
+
get midPoint() {
|
|
846
|
+
return this.paramPoint(0.5);
|
|
847
|
+
}
|
|
848
|
+
isValidParameter(t) {
|
|
849
|
+
return 1 - t >= -this.precision && t >= -this.precision;
|
|
850
|
+
}
|
|
851
|
+
isSame(t) {
|
|
852
|
+
return b(this.center, t.center) && Math.abs(this.majorRadius - t.majorRadius) < this.precision && Math.abs(this.minorRadius - t.minorRadius) < this.precision && (Math.abs(this.tiltAngle - t.tiltAngle) < this.precision || Math.abs(Math.abs(this.tiltAngle - t.tiltAngle) - Math.PI) < this.precision) && (b(this.firstPoint, t.firstPoint) && this.clockwise === t.clockwise || b(this.firstPoint, t.lastPoint) && this.clockwise !== t.clockwise);
|
|
853
|
+
}
|
|
854
|
+
pointTheta(t) {
|
|
855
|
+
const e = this.ellipseReferenceFrameTransform.transform(t), s = Math.atan2(
|
|
856
|
+
e[1] / this.minorRadius,
|
|
857
|
+
e[0] / this.majorRadius
|
|
858
|
+
);
|
|
859
|
+
return ot(s);
|
|
860
|
+
}
|
|
861
|
+
thetaToParam(t) {
|
|
862
|
+
return Lt(this.firstAngle, ot(t), this.clockwise) / this.deltaAngle;
|
|
863
|
+
}
|
|
864
|
+
isPointOnEllipse(t) {
|
|
865
|
+
const [e, s] = this.focals, n = B(t, e), o = B(t, s);
|
|
866
|
+
return Math.abs(2 * this.majorRadius - n - o) < this.precision;
|
|
867
|
+
}
|
|
868
|
+
isOnSegment(t) {
|
|
869
|
+
return this.isPointOnEllipse(t) ? this.isValidParameter(this.thetaToParam(this.pointTheta(t))) : !1;
|
|
870
|
+
}
|
|
871
|
+
distanceFrom(t) {
|
|
872
|
+
let e;
|
|
873
|
+
if (b(t, this.center) ? e = _(
|
|
874
|
+
this.center,
|
|
875
|
+
L(z(this.majorAxis), this.minorRadius)
|
|
876
|
+
) : e = this.reverseEllipseReferenceFrameTransform.transform(
|
|
877
|
+
Cs(
|
|
878
|
+
this.majorRadius,
|
|
879
|
+
this.minorRadius,
|
|
880
|
+
this.ellipseReferenceFrameTransform.transform(t)
|
|
881
|
+
)
|
|
882
|
+
), this.isValidParameter(this.thetaToParam(this.pointTheta(t))))
|
|
883
|
+
return B(t, e);
|
|
884
|
+
if (As(t, this.majorAxis, this.center)) {
|
|
885
|
+
const s = ot(
|
|
886
|
+
2 * Math.PI - this.pointTheta(t)
|
|
887
|
+
), n = this.thetaToParam(s);
|
|
888
|
+
if (this.isValidParameter(n))
|
|
889
|
+
return B(t, this.paramPoint(n));
|
|
890
|
+
}
|
|
891
|
+
return Math.min(
|
|
892
|
+
B(t, this.firstPoint),
|
|
893
|
+
B(t, this.lastPoint)
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
get ellipseReferenceFrameTransform() {
|
|
897
|
+
return this._ellipseReferenceFrameTransform === void 0 && (this._ellipseReferenceFrameTransform = new q().rotate(-this.tiltAngle).translate(-this.center[0], -this.center[1])), this._ellipseReferenceFrameTransform;
|
|
898
|
+
}
|
|
899
|
+
get reverseEllipseReferenceFrameTransform() {
|
|
900
|
+
return this._reverseEllipseReferenceFrameTransform === void 0 && (this._reverseEllipseReferenceFrameTransform = new q().translate(this.center[0], this.center[1]).rotate(this.tiltAngle)), this._reverseEllipseReferenceFrameTransform;
|
|
901
|
+
}
|
|
902
|
+
get rotateFromEllipseReferenceFrame() {
|
|
903
|
+
return this._rotateFromEllipseReferenceFrame === void 0 && (this._rotateFromEllipseReferenceFrame = new q().rotate(
|
|
904
|
+
this.tiltAngle
|
|
905
|
+
)), this._rotateFromEllipseReferenceFrame;
|
|
906
|
+
}
|
|
907
|
+
get firstAngle() {
|
|
908
|
+
return this._firstAngle === void 0 && (this._firstAngle = this.pointTheta(this.firstPoint)), this._firstAngle;
|
|
909
|
+
}
|
|
910
|
+
get lastAngle() {
|
|
911
|
+
return this._lastAngle === void 0 && (this._lastAngle = this.pointTheta(this.lastPoint)), this._lastAngle;
|
|
912
|
+
}
|
|
913
|
+
get deltaAngle() {
|
|
914
|
+
return this._deltaAngle === void 0 && (this._deltaAngle = Lt(
|
|
915
|
+
this.firstAngle,
|
|
916
|
+
this.lastAngle,
|
|
917
|
+
this.clockwise
|
|
918
|
+
)), this._deltaAngle;
|
|
919
|
+
}
|
|
920
|
+
normalAt(t) {
|
|
921
|
+
const e = this.tangentAt(t);
|
|
922
|
+
return this.clockwise ? z(e) : Mt(e);
|
|
923
|
+
}
|
|
924
|
+
gradientAt(t) {
|
|
925
|
+
const e = this.firstAngle + t * this.deltaAngle * (this.clockwise ? -1 : 1), s = -this.majorRadius * this.deltaAngle * Math.sin(e), n = this.minorRadius * this.deltaAngle * Math.cos(e), o = this.clockwise ? [-s, -n] : [s, n];
|
|
926
|
+
return this.rotateFromEllipseReferenceFrame.transform(o);
|
|
927
|
+
}
|
|
928
|
+
tangentAt(t) {
|
|
929
|
+
const e = this.pointTheta(t), s = -this.majorRadius * Math.sin(e), n = this.minorRadius * Math.cos(e), o = this.clockwise ? [-s, -n] : [s, n];
|
|
930
|
+
return J(this.rotateFromEllipseReferenceFrame.transform(o));
|
|
931
|
+
}
|
|
932
|
+
get tangentAtFirstPoint() {
|
|
933
|
+
const t = -this.majorRadius * Math.sin(this.firstAngle), e = this.minorRadius * Math.cos(this.firstAngle), s = this.clockwise ? [-t, -e] : [t, e];
|
|
934
|
+
return J(this.rotateFromEllipseReferenceFrame.transform(s));
|
|
935
|
+
}
|
|
936
|
+
get tangentAtLastPoint() {
|
|
937
|
+
const t = -this.majorRadius * Math.sin(this.lastAngle), e = this.minorRadius * Math.cos(this.lastAngle), s = this.clockwise ? [-t, -e] : [t, e];
|
|
938
|
+
return J(this.rotateFromEllipseReferenceFrame.transform(s));
|
|
939
|
+
}
|
|
940
|
+
transform(t) {
|
|
941
|
+
const e = t.transformAngle(this.tiltAngle), s = t.scaleFactor();
|
|
942
|
+
return new dt(
|
|
943
|
+
t.transform(this.firstPoint),
|
|
944
|
+
t.transform(this.lastPoint),
|
|
945
|
+
t.transform(this.center),
|
|
946
|
+
this.majorRadius * s,
|
|
947
|
+
this.minorRadius * s,
|
|
948
|
+
e,
|
|
949
|
+
t.keepsOrientation() ? this.clockwise : !this.clockwise,
|
|
950
|
+
{ angleUnits: "rad" }
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
splitAt(t) {
|
|
954
|
+
let e;
|
|
955
|
+
if (Array.isArray(t) && t.length === 0)
|
|
956
|
+
return [this];
|
|
957
|
+
Array.isArray(t[0]) ? e = t : e = [t];
|
|
958
|
+
const s = [0, 1, ...e.map((i) => this.pointToParam(i))], n = new Map(
|
|
959
|
+
et([s, [this.firstPoint, this.lastPoint, ...e]])
|
|
960
|
+
);
|
|
961
|
+
s.sort((i, h) => i - h);
|
|
962
|
+
let o = null;
|
|
963
|
+
return s.flatMap((i, h) => {
|
|
964
|
+
if (h === s.length - 1)
|
|
965
|
+
return [];
|
|
966
|
+
const l = s[h + 1];
|
|
967
|
+
if (l - i < this.precision)
|
|
968
|
+
return o === null && (o = i), [];
|
|
969
|
+
const a = o === null ? i : o, c = new dt(
|
|
970
|
+
n.get(a) || this.paramPoint(a),
|
|
971
|
+
n.get(l) || this.paramPoint(l),
|
|
972
|
+
this.center,
|
|
973
|
+
this.majorRadius,
|
|
974
|
+
this.minorRadius,
|
|
975
|
+
this.tiltAngle,
|
|
976
|
+
this.clockwise,
|
|
977
|
+
{ angleUnits: "rad" }
|
|
978
|
+
);
|
|
979
|
+
return o = null, c;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
function Fs(r, t, e, s, n, o, i) {
|
|
984
|
+
const { center: h, rx: l, ry: a } = Ls(
|
|
985
|
+
r,
|
|
986
|
+
t,
|
|
987
|
+
e,
|
|
988
|
+
s,
|
|
989
|
+
n * Pt,
|
|
990
|
+
!o,
|
|
991
|
+
i
|
|
992
|
+
);
|
|
993
|
+
return Math.abs(l - a) < 1e-9 ? new S(r, t, h, i) : new O(r, t, h, l, a, n, i);
|
|
994
|
+
}
|
|
995
|
+
function Ls([r, t], [e, s], n, o, i, h, l) {
|
|
996
|
+
if (n < 0 && (n = -n), o < 0 && (o = -o), n == 0 || o == 0)
|
|
997
|
+
throw Error("rx and ry can not be 0");
|
|
998
|
+
const a = Math.sin(i), c = Math.cos(i), u = (r - e) / 2, m = (t - s) / 2, p = (r + e) / 2, g = (t + s) / 2, d = c * u + a * m, M = c * m - a * u, f = d * d / (n * n) + M * M / (o * o);
|
|
999
|
+
f > 1 && (n = n * Math.sqrt(f), o = o * Math.sqrt(f));
|
|
1000
|
+
const w = n * o, y = n * M, x = o * d, E = y * y + x * x;
|
|
1001
|
+
if (!E)
|
|
1002
|
+
throw Error("start point can not be same as end point");
|
|
1003
|
+
let R = Math.sqrt(Math.abs((w * w - E) / E));
|
|
1004
|
+
h == l && (R = -R);
|
|
1005
|
+
const k = R * y / o, P = -R * x / n, T = c * k - a * P + p, $ = a * k + c * P + g;
|
|
1006
|
+
return {
|
|
1007
|
+
center: [T, $],
|
|
1008
|
+
rx: n,
|
|
1009
|
+
ry: o
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
function Cs(r, t, e) {
|
|
1013
|
+
const s = Math.abs(e[0]), n = Math.abs(e[1]);
|
|
1014
|
+
let o = 0.707, i = 0.707;
|
|
1015
|
+
const h = r, l = t;
|
|
1016
|
+
for (let a = 0; a < 3; a++) {
|
|
1017
|
+
const c = h * o, u = l * i, m = (h * h - l * l) * o ** 3 / h, p = (l * l - h * h) * i ** 3 / l, g = c - m, d = u - p, M = s - m, f = n - p, w = Math.hypot(g, d), y = Math.hypot(M, f);
|
|
1018
|
+
o = Math.min(1, Math.max(0, (M * w / y + m) / h)), i = Math.min(1, Math.max(0, (f * w / y + p) / l));
|
|
1019
|
+
const x = Math.hypot(o, i);
|
|
1020
|
+
o /= x, i /= x;
|
|
1021
|
+
}
|
|
1022
|
+
return [h * o * Math.sign(e[0]), l * i * Math.sign(e[1])];
|
|
1023
|
+
}
|
|
1024
|
+
function Yt(r, t, e = 1e-9) {
|
|
1025
|
+
const s = r.transform(t.ellipseReferenceFrameTransform), n = s.slope, o = s.yIntercept, i = t.majorRadius * t.majorRadius, h = t.minorRadius * t.minorRadius, l = t.majorRadius * t.minorRadius, a = s.slope * s.slope, c = s.yIntercept * s.yIntercept, u = (f) => f.map(
|
|
1026
|
+
(w) => t.reverseEllipseReferenceFrameTransform.transform(w)
|
|
1027
|
+
).filter((w) => r.isOnSegment(w) && t.isOnSegment(w));
|
|
1028
|
+
if (!Number.isFinite(n)) {
|
|
1029
|
+
const f = s.firstPoint[0];
|
|
1030
|
+
if (Math.abs(f) - t.majorRadius > e)
|
|
1031
|
+
return [];
|
|
1032
|
+
if (Math.abs(Math.abs(f) - t.majorRadius) < e)
|
|
1033
|
+
return u([[f, 0]]);
|
|
1034
|
+
const w = t.minorRadius * Math.sqrt(1 - f * f / i), y = [f, w], x = [f, -w];
|
|
1035
|
+
return u([y, x]);
|
|
1036
|
+
}
|
|
1037
|
+
const m = i * a + h - c;
|
|
1038
|
+
if (m < -e)
|
|
1039
|
+
return [];
|
|
1040
|
+
const p = i * a + h;
|
|
1041
|
+
if (Math.abs(m) < e) {
|
|
1042
|
+
const f = -(i * n * o) / p, w = h * o / p;
|
|
1043
|
+
return u([[f, w]]);
|
|
1044
|
+
}
|
|
1045
|
+
const g = Math.sqrt(m), d = [
|
|
1046
|
+
-(i * n * o + l * g) / p,
|
|
1047
|
+
(h * o - l * n * g) / p
|
|
1048
|
+
], M = [
|
|
1049
|
+
-(i * n * o - l * g) / p,
|
|
1050
|
+
(h * o + l * n * g) / p
|
|
1051
|
+
];
|
|
1052
|
+
return u([d, M]);
|
|
1053
|
+
}
|
|
1054
|
+
const Bs = Object.prototype.toString;
|
|
1055
|
+
function D(r) {
|
|
1056
|
+
const t = Bs.call(r);
|
|
1057
|
+
return t.endsWith("Array]") && !t.includes("Big");
|
|
1058
|
+
}
|
|
1059
|
+
function js(r) {
|
|
1060
|
+
var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1061
|
+
if (!D(r))
|
|
1062
|
+
throw new TypeError("input must be an array");
|
|
1063
|
+
if (r.length === 0)
|
|
1064
|
+
throw new TypeError("input must not be empty");
|
|
1065
|
+
var e = t.fromIndex, s = e === void 0 ? 0 : e, n = t.toIndex, o = n === void 0 ? r.length : n;
|
|
1066
|
+
if (s < 0 || s >= r.length || !Number.isInteger(s))
|
|
1067
|
+
throw new Error("fromIndex must be a positive integer smaller than length");
|
|
1068
|
+
if (o <= s || o > r.length || !Number.isInteger(o))
|
|
1069
|
+
throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");
|
|
1070
|
+
for (var i = r[s], h = s + 1; h < o; h++)
|
|
1071
|
+
r[h] > i && (i = r[h]);
|
|
1072
|
+
return i;
|
|
1073
|
+
}
|
|
1074
|
+
function Vs(r) {
|
|
1075
|
+
var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1076
|
+
if (!D(r))
|
|
1077
|
+
throw new TypeError("input must be an array");
|
|
1078
|
+
if (r.length === 0)
|
|
1079
|
+
throw new TypeError("input must not be empty");
|
|
1080
|
+
var e = t.fromIndex, s = e === void 0 ? 0 : e, n = t.toIndex, o = n === void 0 ? r.length : n;
|
|
1081
|
+
if (s < 0 || s >= r.length || !Number.isInteger(s))
|
|
1082
|
+
throw new Error("fromIndex must be a positive integer smaller than length");
|
|
1083
|
+
if (o <= s || o > r.length || !Number.isInteger(o))
|
|
1084
|
+
throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");
|
|
1085
|
+
for (var i = r[s], h = s + 1; h < o; h++)
|
|
1086
|
+
r[h] < i && (i = r[h]);
|
|
1087
|
+
return i;
|
|
1088
|
+
}
|
|
1089
|
+
function ue(r) {
|
|
1090
|
+
var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1091
|
+
if (D(r)) {
|
|
1092
|
+
if (r.length === 0)
|
|
1093
|
+
throw new TypeError("input must not be empty");
|
|
1094
|
+
} else
|
|
1095
|
+
throw new TypeError("input must be an array");
|
|
1096
|
+
var e;
|
|
1097
|
+
if (t.output !== void 0) {
|
|
1098
|
+
if (!D(t.output))
|
|
1099
|
+
throw new TypeError("output option must be an array if specified");
|
|
1100
|
+
e = t.output;
|
|
1101
|
+
} else
|
|
1102
|
+
e = new Array(r.length);
|
|
1103
|
+
var s = Vs(r), n = js(r);
|
|
1104
|
+
if (s === n)
|
|
1105
|
+
throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");
|
|
1106
|
+
var o = t.min, i = o === void 0 ? t.autoMinMax ? s : 0 : o, h = t.max, l = h === void 0 ? t.autoMinMax ? n : 1 : h;
|
|
1107
|
+
if (i >= l)
|
|
1108
|
+
throw new RangeError("min option must be smaller than max option");
|
|
1109
|
+
for (var a = (l - i) / (n - s), c = 0; c < r.length; c++)
|
|
1110
|
+
e[c] = (r[c] - s) * a + i;
|
|
1111
|
+
return e;
|
|
1112
|
+
}
|
|
1113
|
+
const Tt = " ".repeat(2), Oe = " ".repeat(4);
|
|
1114
|
+
function Ns() {
|
|
1115
|
+
return ze(this);
|
|
1116
|
+
}
|
|
1117
|
+
function ze(r, t = {}) {
|
|
1118
|
+
const {
|
|
1119
|
+
maxRows: e = 15,
|
|
1120
|
+
maxColumns: s = 10,
|
|
1121
|
+
maxNumSize: n = 8,
|
|
1122
|
+
padMinus: o = "auto"
|
|
1123
|
+
} = t;
|
|
1124
|
+
return `${r.constructor.name} {
|
|
1125
|
+
${Tt}[
|
|
1126
|
+
${Oe}${qs(r, e, s, n, o)}
|
|
1127
|
+
${Tt}]
|
|
1128
|
+
${Tt}rows: ${r.rows}
|
|
1129
|
+
${Tt}columns: ${r.columns}
|
|
1130
|
+
}`;
|
|
1131
|
+
}
|
|
1132
|
+
function qs(r, t, e, s, n) {
|
|
1133
|
+
const { rows: o, columns: i } = r, h = Math.min(o, t), l = Math.min(i, e), a = [];
|
|
1134
|
+
if (n === "auto") {
|
|
1135
|
+
n = !1;
|
|
1136
|
+
t:
|
|
1137
|
+
for (let c = 0; c < h; c++)
|
|
1138
|
+
for (let u = 0; u < l; u++)
|
|
1139
|
+
if (r.get(c, u) < 0) {
|
|
1140
|
+
n = !0;
|
|
1141
|
+
break t;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
for (let c = 0; c < h; c++) {
|
|
1145
|
+
let u = [];
|
|
1146
|
+
for (let m = 0; m < l; m++)
|
|
1147
|
+
u.push(Os(r.get(c, m), s, n));
|
|
1148
|
+
a.push(`${u.join(" ")}`);
|
|
1149
|
+
}
|
|
1150
|
+
return l !== i && (a[a.length - 1] += ` ... ${i - e} more columns`), h !== o && a.push(`... ${o - t} more rows`), a.join(`
|
|
1151
|
+
${Oe}`);
|
|
1152
|
+
}
|
|
1153
|
+
function Os(r, t, e) {
|
|
1154
|
+
return (r >= 0 && e ? ` ${ce(r, t - 1)}` : ce(r, t)).padEnd(t);
|
|
1155
|
+
}
|
|
1156
|
+
function ce(r, t) {
|
|
1157
|
+
let e = r.toString();
|
|
1158
|
+
if (e.length <= t)
|
|
1159
|
+
return e;
|
|
1160
|
+
let s = r.toFixed(t);
|
|
1161
|
+
if (s.length > t && (s = r.toFixed(Math.max(0, t - (s.length - t)))), s.length <= t && !s.startsWith("0.000") && !s.startsWith("-0.000"))
|
|
1162
|
+
return s;
|
|
1163
|
+
let n = r.toExponential(t);
|
|
1164
|
+
return n.length > t && (n = r.toExponential(Math.max(0, t - (n.length - t)))), n.slice(0);
|
|
1165
|
+
}
|
|
1166
|
+
function zs(r, t) {
|
|
1167
|
+
r.prototype.add = function(e) {
|
|
1168
|
+
return typeof e == "number" ? this.addS(e) : this.addM(e);
|
|
1169
|
+
}, r.prototype.addS = function(e) {
|
|
1170
|
+
for (let s = 0; s < this.rows; s++)
|
|
1171
|
+
for (let n = 0; n < this.columns; n++)
|
|
1172
|
+
this.set(s, n, this.get(s, n) + e);
|
|
1173
|
+
return this;
|
|
1174
|
+
}, r.prototype.addM = function(e) {
|
|
1175
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1176
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1177
|
+
for (let s = 0; s < this.rows; s++)
|
|
1178
|
+
for (let n = 0; n < this.columns; n++)
|
|
1179
|
+
this.set(s, n, this.get(s, n) + e.get(s, n));
|
|
1180
|
+
return this;
|
|
1181
|
+
}, r.add = function(e, s) {
|
|
1182
|
+
return new t(e).add(s);
|
|
1183
|
+
}, r.prototype.sub = function(e) {
|
|
1184
|
+
return typeof e == "number" ? this.subS(e) : this.subM(e);
|
|
1185
|
+
}, r.prototype.subS = function(e) {
|
|
1186
|
+
for (let s = 0; s < this.rows; s++)
|
|
1187
|
+
for (let n = 0; n < this.columns; n++)
|
|
1188
|
+
this.set(s, n, this.get(s, n) - e);
|
|
1189
|
+
return this;
|
|
1190
|
+
}, r.prototype.subM = function(e) {
|
|
1191
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1192
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1193
|
+
for (let s = 0; s < this.rows; s++)
|
|
1194
|
+
for (let n = 0; n < this.columns; n++)
|
|
1195
|
+
this.set(s, n, this.get(s, n) - e.get(s, n));
|
|
1196
|
+
return this;
|
|
1197
|
+
}, r.sub = function(e, s) {
|
|
1198
|
+
return new t(e).sub(s);
|
|
1199
|
+
}, r.prototype.subtract = r.prototype.sub, r.prototype.subtractS = r.prototype.subS, r.prototype.subtractM = r.prototype.subM, r.subtract = r.sub, r.prototype.mul = function(e) {
|
|
1200
|
+
return typeof e == "number" ? this.mulS(e) : this.mulM(e);
|
|
1201
|
+
}, r.prototype.mulS = function(e) {
|
|
1202
|
+
for (let s = 0; s < this.rows; s++)
|
|
1203
|
+
for (let n = 0; n < this.columns; n++)
|
|
1204
|
+
this.set(s, n, this.get(s, n) * e);
|
|
1205
|
+
return this;
|
|
1206
|
+
}, r.prototype.mulM = function(e) {
|
|
1207
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1208
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1209
|
+
for (let s = 0; s < this.rows; s++)
|
|
1210
|
+
for (let n = 0; n < this.columns; n++)
|
|
1211
|
+
this.set(s, n, this.get(s, n) * e.get(s, n));
|
|
1212
|
+
return this;
|
|
1213
|
+
}, r.mul = function(e, s) {
|
|
1214
|
+
return new t(e).mul(s);
|
|
1215
|
+
}, r.prototype.multiply = r.prototype.mul, r.prototype.multiplyS = r.prototype.mulS, r.prototype.multiplyM = r.prototype.mulM, r.multiply = r.mul, r.prototype.div = function(e) {
|
|
1216
|
+
return typeof e == "number" ? this.divS(e) : this.divM(e);
|
|
1217
|
+
}, r.prototype.divS = function(e) {
|
|
1218
|
+
for (let s = 0; s < this.rows; s++)
|
|
1219
|
+
for (let n = 0; n < this.columns; n++)
|
|
1220
|
+
this.set(s, n, this.get(s, n) / e);
|
|
1221
|
+
return this;
|
|
1222
|
+
}, r.prototype.divM = function(e) {
|
|
1223
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1224
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1225
|
+
for (let s = 0; s < this.rows; s++)
|
|
1226
|
+
for (let n = 0; n < this.columns; n++)
|
|
1227
|
+
this.set(s, n, this.get(s, n) / e.get(s, n));
|
|
1228
|
+
return this;
|
|
1229
|
+
}, r.div = function(e, s) {
|
|
1230
|
+
return new t(e).div(s);
|
|
1231
|
+
}, r.prototype.divide = r.prototype.div, r.prototype.divideS = r.prototype.divS, r.prototype.divideM = r.prototype.divM, r.divide = r.div, r.prototype.mod = function(e) {
|
|
1232
|
+
return typeof e == "number" ? this.modS(e) : this.modM(e);
|
|
1233
|
+
}, r.prototype.modS = function(e) {
|
|
1234
|
+
for (let s = 0; s < this.rows; s++)
|
|
1235
|
+
for (let n = 0; n < this.columns; n++)
|
|
1236
|
+
this.set(s, n, this.get(s, n) % e);
|
|
1237
|
+
return this;
|
|
1238
|
+
}, r.prototype.modM = function(e) {
|
|
1239
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1240
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1241
|
+
for (let s = 0; s < this.rows; s++)
|
|
1242
|
+
for (let n = 0; n < this.columns; n++)
|
|
1243
|
+
this.set(s, n, this.get(s, n) % e.get(s, n));
|
|
1244
|
+
return this;
|
|
1245
|
+
}, r.mod = function(e, s) {
|
|
1246
|
+
return new t(e).mod(s);
|
|
1247
|
+
}, r.prototype.modulus = r.prototype.mod, r.prototype.modulusS = r.prototype.modS, r.prototype.modulusM = r.prototype.modM, r.modulus = r.mod, r.prototype.and = function(e) {
|
|
1248
|
+
return typeof e == "number" ? this.andS(e) : this.andM(e);
|
|
1249
|
+
}, r.prototype.andS = function(e) {
|
|
1250
|
+
for (let s = 0; s < this.rows; s++)
|
|
1251
|
+
for (let n = 0; n < this.columns; n++)
|
|
1252
|
+
this.set(s, n, this.get(s, n) & e);
|
|
1253
|
+
return this;
|
|
1254
|
+
}, r.prototype.andM = function(e) {
|
|
1255
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1256
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1257
|
+
for (let s = 0; s < this.rows; s++)
|
|
1258
|
+
for (let n = 0; n < this.columns; n++)
|
|
1259
|
+
this.set(s, n, this.get(s, n) & e.get(s, n));
|
|
1260
|
+
return this;
|
|
1261
|
+
}, r.and = function(e, s) {
|
|
1262
|
+
return new t(e).and(s);
|
|
1263
|
+
}, r.prototype.or = function(e) {
|
|
1264
|
+
return typeof e == "number" ? this.orS(e) : this.orM(e);
|
|
1265
|
+
}, r.prototype.orS = function(e) {
|
|
1266
|
+
for (let s = 0; s < this.rows; s++)
|
|
1267
|
+
for (let n = 0; n < this.columns; n++)
|
|
1268
|
+
this.set(s, n, this.get(s, n) | e);
|
|
1269
|
+
return this;
|
|
1270
|
+
}, r.prototype.orM = function(e) {
|
|
1271
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1272
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1273
|
+
for (let s = 0; s < this.rows; s++)
|
|
1274
|
+
for (let n = 0; n < this.columns; n++)
|
|
1275
|
+
this.set(s, n, this.get(s, n) | e.get(s, n));
|
|
1276
|
+
return this;
|
|
1277
|
+
}, r.or = function(e, s) {
|
|
1278
|
+
return new t(e).or(s);
|
|
1279
|
+
}, r.prototype.xor = function(e) {
|
|
1280
|
+
return typeof e == "number" ? this.xorS(e) : this.xorM(e);
|
|
1281
|
+
}, r.prototype.xorS = function(e) {
|
|
1282
|
+
for (let s = 0; s < this.rows; s++)
|
|
1283
|
+
for (let n = 0; n < this.columns; n++)
|
|
1284
|
+
this.set(s, n, this.get(s, n) ^ e);
|
|
1285
|
+
return this;
|
|
1286
|
+
}, r.prototype.xorM = function(e) {
|
|
1287
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1288
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1289
|
+
for (let s = 0; s < this.rows; s++)
|
|
1290
|
+
for (let n = 0; n < this.columns; n++)
|
|
1291
|
+
this.set(s, n, this.get(s, n) ^ e.get(s, n));
|
|
1292
|
+
return this;
|
|
1293
|
+
}, r.xor = function(e, s) {
|
|
1294
|
+
return new t(e).xor(s);
|
|
1295
|
+
}, r.prototype.leftShift = function(e) {
|
|
1296
|
+
return typeof e == "number" ? this.leftShiftS(e) : this.leftShiftM(e);
|
|
1297
|
+
}, r.prototype.leftShiftS = function(e) {
|
|
1298
|
+
for (let s = 0; s < this.rows; s++)
|
|
1299
|
+
for (let n = 0; n < this.columns; n++)
|
|
1300
|
+
this.set(s, n, this.get(s, n) << e);
|
|
1301
|
+
return this;
|
|
1302
|
+
}, r.prototype.leftShiftM = function(e) {
|
|
1303
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1304
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1305
|
+
for (let s = 0; s < this.rows; s++)
|
|
1306
|
+
for (let n = 0; n < this.columns; n++)
|
|
1307
|
+
this.set(s, n, this.get(s, n) << e.get(s, n));
|
|
1308
|
+
return this;
|
|
1309
|
+
}, r.leftShift = function(e, s) {
|
|
1310
|
+
return new t(e).leftShift(s);
|
|
1311
|
+
}, r.prototype.signPropagatingRightShift = function(e) {
|
|
1312
|
+
return typeof e == "number" ? this.signPropagatingRightShiftS(e) : this.signPropagatingRightShiftM(e);
|
|
1313
|
+
}, r.prototype.signPropagatingRightShiftS = function(e) {
|
|
1314
|
+
for (let s = 0; s < this.rows; s++)
|
|
1315
|
+
for (let n = 0; n < this.columns; n++)
|
|
1316
|
+
this.set(s, n, this.get(s, n) >> e);
|
|
1317
|
+
return this;
|
|
1318
|
+
}, r.prototype.signPropagatingRightShiftM = function(e) {
|
|
1319
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1320
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1321
|
+
for (let s = 0; s < this.rows; s++)
|
|
1322
|
+
for (let n = 0; n < this.columns; n++)
|
|
1323
|
+
this.set(s, n, this.get(s, n) >> e.get(s, n));
|
|
1324
|
+
return this;
|
|
1325
|
+
}, r.signPropagatingRightShift = function(e, s) {
|
|
1326
|
+
return new t(e).signPropagatingRightShift(s);
|
|
1327
|
+
}, r.prototype.rightShift = function(e) {
|
|
1328
|
+
return typeof e == "number" ? this.rightShiftS(e) : this.rightShiftM(e);
|
|
1329
|
+
}, r.prototype.rightShiftS = function(e) {
|
|
1330
|
+
for (let s = 0; s < this.rows; s++)
|
|
1331
|
+
for (let n = 0; n < this.columns; n++)
|
|
1332
|
+
this.set(s, n, this.get(s, n) >>> e);
|
|
1333
|
+
return this;
|
|
1334
|
+
}, r.prototype.rightShiftM = function(e) {
|
|
1335
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1336
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1337
|
+
for (let s = 0; s < this.rows; s++)
|
|
1338
|
+
for (let n = 0; n < this.columns; n++)
|
|
1339
|
+
this.set(s, n, this.get(s, n) >>> e.get(s, n));
|
|
1340
|
+
return this;
|
|
1341
|
+
}, r.rightShift = function(e, s) {
|
|
1342
|
+
return new t(e).rightShift(s);
|
|
1343
|
+
}, r.prototype.zeroFillRightShift = r.prototype.rightShift, r.prototype.zeroFillRightShiftS = r.prototype.rightShiftS, r.prototype.zeroFillRightShiftM = r.prototype.rightShiftM, r.zeroFillRightShift = r.rightShift, r.prototype.not = function() {
|
|
1344
|
+
for (let e = 0; e < this.rows; e++)
|
|
1345
|
+
for (let s = 0; s < this.columns; s++)
|
|
1346
|
+
this.set(e, s, ~this.get(e, s));
|
|
1347
|
+
return this;
|
|
1348
|
+
}, r.not = function(e) {
|
|
1349
|
+
return new t(e).not();
|
|
1350
|
+
}, r.prototype.abs = function() {
|
|
1351
|
+
for (let e = 0; e < this.rows; e++)
|
|
1352
|
+
for (let s = 0; s < this.columns; s++)
|
|
1353
|
+
this.set(e, s, Math.abs(this.get(e, s)));
|
|
1354
|
+
return this;
|
|
1355
|
+
}, r.abs = function(e) {
|
|
1356
|
+
return new t(e).abs();
|
|
1357
|
+
}, r.prototype.acos = function() {
|
|
1358
|
+
for (let e = 0; e < this.rows; e++)
|
|
1359
|
+
for (let s = 0; s < this.columns; s++)
|
|
1360
|
+
this.set(e, s, Math.acos(this.get(e, s)));
|
|
1361
|
+
return this;
|
|
1362
|
+
}, r.acos = function(e) {
|
|
1363
|
+
return new t(e).acos();
|
|
1364
|
+
}, r.prototype.acosh = function() {
|
|
1365
|
+
for (let e = 0; e < this.rows; e++)
|
|
1366
|
+
for (let s = 0; s < this.columns; s++)
|
|
1367
|
+
this.set(e, s, Math.acosh(this.get(e, s)));
|
|
1368
|
+
return this;
|
|
1369
|
+
}, r.acosh = function(e) {
|
|
1370
|
+
return new t(e).acosh();
|
|
1371
|
+
}, r.prototype.asin = function() {
|
|
1372
|
+
for (let e = 0; e < this.rows; e++)
|
|
1373
|
+
for (let s = 0; s < this.columns; s++)
|
|
1374
|
+
this.set(e, s, Math.asin(this.get(e, s)));
|
|
1375
|
+
return this;
|
|
1376
|
+
}, r.asin = function(e) {
|
|
1377
|
+
return new t(e).asin();
|
|
1378
|
+
}, r.prototype.asinh = function() {
|
|
1379
|
+
for (let e = 0; e < this.rows; e++)
|
|
1380
|
+
for (let s = 0; s < this.columns; s++)
|
|
1381
|
+
this.set(e, s, Math.asinh(this.get(e, s)));
|
|
1382
|
+
return this;
|
|
1383
|
+
}, r.asinh = function(e) {
|
|
1384
|
+
return new t(e).asinh();
|
|
1385
|
+
}, r.prototype.atan = function() {
|
|
1386
|
+
for (let e = 0; e < this.rows; e++)
|
|
1387
|
+
for (let s = 0; s < this.columns; s++)
|
|
1388
|
+
this.set(e, s, Math.atan(this.get(e, s)));
|
|
1389
|
+
return this;
|
|
1390
|
+
}, r.atan = function(e) {
|
|
1391
|
+
return new t(e).atan();
|
|
1392
|
+
}, r.prototype.atanh = function() {
|
|
1393
|
+
for (let e = 0; e < this.rows; e++)
|
|
1394
|
+
for (let s = 0; s < this.columns; s++)
|
|
1395
|
+
this.set(e, s, Math.atanh(this.get(e, s)));
|
|
1396
|
+
return this;
|
|
1397
|
+
}, r.atanh = function(e) {
|
|
1398
|
+
return new t(e).atanh();
|
|
1399
|
+
}, r.prototype.cbrt = function() {
|
|
1400
|
+
for (let e = 0; e < this.rows; e++)
|
|
1401
|
+
for (let s = 0; s < this.columns; s++)
|
|
1402
|
+
this.set(e, s, Math.cbrt(this.get(e, s)));
|
|
1403
|
+
return this;
|
|
1404
|
+
}, r.cbrt = function(e) {
|
|
1405
|
+
return new t(e).cbrt();
|
|
1406
|
+
}, r.prototype.ceil = function() {
|
|
1407
|
+
for (let e = 0; e < this.rows; e++)
|
|
1408
|
+
for (let s = 0; s < this.columns; s++)
|
|
1409
|
+
this.set(e, s, Math.ceil(this.get(e, s)));
|
|
1410
|
+
return this;
|
|
1411
|
+
}, r.ceil = function(e) {
|
|
1412
|
+
return new t(e).ceil();
|
|
1413
|
+
}, r.prototype.clz32 = function() {
|
|
1414
|
+
for (let e = 0; e < this.rows; e++)
|
|
1415
|
+
for (let s = 0; s < this.columns; s++)
|
|
1416
|
+
this.set(e, s, Math.clz32(this.get(e, s)));
|
|
1417
|
+
return this;
|
|
1418
|
+
}, r.clz32 = function(e) {
|
|
1419
|
+
return new t(e).clz32();
|
|
1420
|
+
}, r.prototype.cos = function() {
|
|
1421
|
+
for (let e = 0; e < this.rows; e++)
|
|
1422
|
+
for (let s = 0; s < this.columns; s++)
|
|
1423
|
+
this.set(e, s, Math.cos(this.get(e, s)));
|
|
1424
|
+
return this;
|
|
1425
|
+
}, r.cos = function(e) {
|
|
1426
|
+
return new t(e).cos();
|
|
1427
|
+
}, r.prototype.cosh = function() {
|
|
1428
|
+
for (let e = 0; e < this.rows; e++)
|
|
1429
|
+
for (let s = 0; s < this.columns; s++)
|
|
1430
|
+
this.set(e, s, Math.cosh(this.get(e, s)));
|
|
1431
|
+
return this;
|
|
1432
|
+
}, r.cosh = function(e) {
|
|
1433
|
+
return new t(e).cosh();
|
|
1434
|
+
}, r.prototype.exp = function() {
|
|
1435
|
+
for (let e = 0; e < this.rows; e++)
|
|
1436
|
+
for (let s = 0; s < this.columns; s++)
|
|
1437
|
+
this.set(e, s, Math.exp(this.get(e, s)));
|
|
1438
|
+
return this;
|
|
1439
|
+
}, r.exp = function(e) {
|
|
1440
|
+
return new t(e).exp();
|
|
1441
|
+
}, r.prototype.expm1 = function() {
|
|
1442
|
+
for (let e = 0; e < this.rows; e++)
|
|
1443
|
+
for (let s = 0; s < this.columns; s++)
|
|
1444
|
+
this.set(e, s, Math.expm1(this.get(e, s)));
|
|
1445
|
+
return this;
|
|
1446
|
+
}, r.expm1 = function(e) {
|
|
1447
|
+
return new t(e).expm1();
|
|
1448
|
+
}, r.prototype.floor = function() {
|
|
1449
|
+
for (let e = 0; e < this.rows; e++)
|
|
1450
|
+
for (let s = 0; s < this.columns; s++)
|
|
1451
|
+
this.set(e, s, Math.floor(this.get(e, s)));
|
|
1452
|
+
return this;
|
|
1453
|
+
}, r.floor = function(e) {
|
|
1454
|
+
return new t(e).floor();
|
|
1455
|
+
}, r.prototype.fround = function() {
|
|
1456
|
+
for (let e = 0; e < this.rows; e++)
|
|
1457
|
+
for (let s = 0; s < this.columns; s++)
|
|
1458
|
+
this.set(e, s, Math.fround(this.get(e, s)));
|
|
1459
|
+
return this;
|
|
1460
|
+
}, r.fround = function(e) {
|
|
1461
|
+
return new t(e).fround();
|
|
1462
|
+
}, r.prototype.log = function() {
|
|
1463
|
+
for (let e = 0; e < this.rows; e++)
|
|
1464
|
+
for (let s = 0; s < this.columns; s++)
|
|
1465
|
+
this.set(e, s, Math.log(this.get(e, s)));
|
|
1466
|
+
return this;
|
|
1467
|
+
}, r.log = function(e) {
|
|
1468
|
+
return new t(e).log();
|
|
1469
|
+
}, r.prototype.log1p = function() {
|
|
1470
|
+
for (let e = 0; e < this.rows; e++)
|
|
1471
|
+
for (let s = 0; s < this.columns; s++)
|
|
1472
|
+
this.set(e, s, Math.log1p(this.get(e, s)));
|
|
1473
|
+
return this;
|
|
1474
|
+
}, r.log1p = function(e) {
|
|
1475
|
+
return new t(e).log1p();
|
|
1476
|
+
}, r.prototype.log10 = function() {
|
|
1477
|
+
for (let e = 0; e < this.rows; e++)
|
|
1478
|
+
for (let s = 0; s < this.columns; s++)
|
|
1479
|
+
this.set(e, s, Math.log10(this.get(e, s)));
|
|
1480
|
+
return this;
|
|
1481
|
+
}, r.log10 = function(e) {
|
|
1482
|
+
return new t(e).log10();
|
|
1483
|
+
}, r.prototype.log2 = function() {
|
|
1484
|
+
for (let e = 0; e < this.rows; e++)
|
|
1485
|
+
for (let s = 0; s < this.columns; s++)
|
|
1486
|
+
this.set(e, s, Math.log2(this.get(e, s)));
|
|
1487
|
+
return this;
|
|
1488
|
+
}, r.log2 = function(e) {
|
|
1489
|
+
return new t(e).log2();
|
|
1490
|
+
}, r.prototype.round = function() {
|
|
1491
|
+
for (let e = 0; e < this.rows; e++)
|
|
1492
|
+
for (let s = 0; s < this.columns; s++)
|
|
1493
|
+
this.set(e, s, Math.round(this.get(e, s)));
|
|
1494
|
+
return this;
|
|
1495
|
+
}, r.round = function(e) {
|
|
1496
|
+
return new t(e).round();
|
|
1497
|
+
}, r.prototype.sign = function() {
|
|
1498
|
+
for (let e = 0; e < this.rows; e++)
|
|
1499
|
+
for (let s = 0; s < this.columns; s++)
|
|
1500
|
+
this.set(e, s, Math.sign(this.get(e, s)));
|
|
1501
|
+
return this;
|
|
1502
|
+
}, r.sign = function(e) {
|
|
1503
|
+
return new t(e).sign();
|
|
1504
|
+
}, r.prototype.sin = function() {
|
|
1505
|
+
for (let e = 0; e < this.rows; e++)
|
|
1506
|
+
for (let s = 0; s < this.columns; s++)
|
|
1507
|
+
this.set(e, s, Math.sin(this.get(e, s)));
|
|
1508
|
+
return this;
|
|
1509
|
+
}, r.sin = function(e) {
|
|
1510
|
+
return new t(e).sin();
|
|
1511
|
+
}, r.prototype.sinh = function() {
|
|
1512
|
+
for (let e = 0; e < this.rows; e++)
|
|
1513
|
+
for (let s = 0; s < this.columns; s++)
|
|
1514
|
+
this.set(e, s, Math.sinh(this.get(e, s)));
|
|
1515
|
+
return this;
|
|
1516
|
+
}, r.sinh = function(e) {
|
|
1517
|
+
return new t(e).sinh();
|
|
1518
|
+
}, r.prototype.sqrt = function() {
|
|
1519
|
+
for (let e = 0; e < this.rows; e++)
|
|
1520
|
+
for (let s = 0; s < this.columns; s++)
|
|
1521
|
+
this.set(e, s, Math.sqrt(this.get(e, s)));
|
|
1522
|
+
return this;
|
|
1523
|
+
}, r.sqrt = function(e) {
|
|
1524
|
+
return new t(e).sqrt();
|
|
1525
|
+
}, r.prototype.tan = function() {
|
|
1526
|
+
for (let e = 0; e < this.rows; e++)
|
|
1527
|
+
for (let s = 0; s < this.columns; s++)
|
|
1528
|
+
this.set(e, s, Math.tan(this.get(e, s)));
|
|
1529
|
+
return this;
|
|
1530
|
+
}, r.tan = function(e) {
|
|
1531
|
+
return new t(e).tan();
|
|
1532
|
+
}, r.prototype.tanh = function() {
|
|
1533
|
+
for (let e = 0; e < this.rows; e++)
|
|
1534
|
+
for (let s = 0; s < this.columns; s++)
|
|
1535
|
+
this.set(e, s, Math.tanh(this.get(e, s)));
|
|
1536
|
+
return this;
|
|
1537
|
+
}, r.tanh = function(e) {
|
|
1538
|
+
return new t(e).tanh();
|
|
1539
|
+
}, r.prototype.trunc = function() {
|
|
1540
|
+
for (let e = 0; e < this.rows; e++)
|
|
1541
|
+
for (let s = 0; s < this.columns; s++)
|
|
1542
|
+
this.set(e, s, Math.trunc(this.get(e, s)));
|
|
1543
|
+
return this;
|
|
1544
|
+
}, r.trunc = function(e) {
|
|
1545
|
+
return new t(e).trunc();
|
|
1546
|
+
}, r.pow = function(e, s) {
|
|
1547
|
+
return new t(e).pow(s);
|
|
1548
|
+
}, r.prototype.pow = function(e) {
|
|
1549
|
+
return typeof e == "number" ? this.powS(e) : this.powM(e);
|
|
1550
|
+
}, r.prototype.powS = function(e) {
|
|
1551
|
+
for (let s = 0; s < this.rows; s++)
|
|
1552
|
+
for (let n = 0; n < this.columns; n++)
|
|
1553
|
+
this.set(s, n, Math.pow(this.get(s, n), e));
|
|
1554
|
+
return this;
|
|
1555
|
+
}, r.prototype.powM = function(e) {
|
|
1556
|
+
if (e = t.checkMatrix(e), this.rows !== e.rows || this.columns !== e.columns)
|
|
1557
|
+
throw new RangeError("Matrices dimensions must be equal");
|
|
1558
|
+
for (let s = 0; s < this.rows; s++)
|
|
1559
|
+
for (let n = 0; n < this.columns; n++)
|
|
1560
|
+
this.set(s, n, Math.pow(this.get(s, n), e.get(s, n)));
|
|
1561
|
+
return this;
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
function G(r, t, e) {
|
|
1565
|
+
let s = e ? r.rows : r.rows - 1;
|
|
1566
|
+
if (t < 0 || t > s)
|
|
1567
|
+
throw new RangeError("Row index out of range");
|
|
1568
|
+
}
|
|
1569
|
+
function H(r, t, e) {
|
|
1570
|
+
let s = e ? r.columns : r.columns - 1;
|
|
1571
|
+
if (t < 0 || t > s)
|
|
1572
|
+
throw new RangeError("Column index out of range");
|
|
1573
|
+
}
|
|
1574
|
+
function mt(r, t) {
|
|
1575
|
+
if (t.to1DArray && (t = t.to1DArray()), t.length !== r.columns)
|
|
1576
|
+
throw new RangeError(
|
|
1577
|
+
"vector size must be the same as the number of columns"
|
|
1578
|
+
);
|
|
1579
|
+
return t;
|
|
1580
|
+
}
|
|
1581
|
+
function gt(r, t) {
|
|
1582
|
+
if (t.to1DArray && (t = t.to1DArray()), t.length !== r.rows)
|
|
1583
|
+
throw new RangeError("vector size must be the same as the number of rows");
|
|
1584
|
+
return t;
|
|
1585
|
+
}
|
|
1586
|
+
function Us(r, t) {
|
|
1587
|
+
if (!D(t))
|
|
1588
|
+
throw new TypeError("row indices must be an array");
|
|
1589
|
+
for (let e = 0; e < t.length; e++)
|
|
1590
|
+
if (t[e] < 0 || t[e] >= r.rows)
|
|
1591
|
+
throw new RangeError("row indices are out of range");
|
|
1592
|
+
}
|
|
1593
|
+
function Ys(r, t) {
|
|
1594
|
+
if (!D(t))
|
|
1595
|
+
throw new TypeError("column indices must be an array");
|
|
1596
|
+
for (let e = 0; e < t.length; e++)
|
|
1597
|
+
if (t[e] < 0 || t[e] >= r.columns)
|
|
1598
|
+
throw new RangeError("column indices are out of range");
|
|
1599
|
+
}
|
|
1600
|
+
function fe(r, t, e, s, n) {
|
|
1601
|
+
if (arguments.length !== 5)
|
|
1602
|
+
throw new RangeError("expected 4 arguments");
|
|
1603
|
+
if ($t("startRow", t), $t("endRow", e), $t("startColumn", s), $t("endColumn", n), t > e || s > n || t < 0 || t >= r.rows || e < 0 || e >= r.rows || s < 0 || s >= r.columns || n < 0 || n >= r.columns)
|
|
1604
|
+
throw new RangeError("Submatrix indices are out of range");
|
|
1605
|
+
}
|
|
1606
|
+
function Nt(r, t = 0) {
|
|
1607
|
+
let e = [];
|
|
1608
|
+
for (let s = 0; s < r; s++)
|
|
1609
|
+
e.push(t);
|
|
1610
|
+
return e;
|
|
1611
|
+
}
|
|
1612
|
+
function $t(r, t) {
|
|
1613
|
+
if (typeof t != "number")
|
|
1614
|
+
throw new TypeError(`${r} must be a number`);
|
|
1615
|
+
}
|
|
1616
|
+
function ft(r) {
|
|
1617
|
+
if (r.isEmpty())
|
|
1618
|
+
throw new Error("Empty matrix has no elements to index");
|
|
1619
|
+
}
|
|
1620
|
+
function Ds(r) {
|
|
1621
|
+
let t = Nt(r.rows);
|
|
1622
|
+
for (let e = 0; e < r.rows; ++e)
|
|
1623
|
+
for (let s = 0; s < r.columns; ++s)
|
|
1624
|
+
t[e] += r.get(e, s);
|
|
1625
|
+
return t;
|
|
1626
|
+
}
|
|
1627
|
+
function Xs(r) {
|
|
1628
|
+
let t = Nt(r.columns);
|
|
1629
|
+
for (let e = 0; e < r.rows; ++e)
|
|
1630
|
+
for (let s = 0; s < r.columns; ++s)
|
|
1631
|
+
t[s] += r.get(e, s);
|
|
1632
|
+
return t;
|
|
1633
|
+
}
|
|
1634
|
+
function Ws(r) {
|
|
1635
|
+
let t = 0;
|
|
1636
|
+
for (let e = 0; e < r.rows; e++)
|
|
1637
|
+
for (let s = 0; s < r.columns; s++)
|
|
1638
|
+
t += r.get(e, s);
|
|
1639
|
+
return t;
|
|
1640
|
+
}
|
|
1641
|
+
function Gs(r) {
|
|
1642
|
+
let t = Nt(r.rows, 1);
|
|
1643
|
+
for (let e = 0; e < r.rows; ++e)
|
|
1644
|
+
for (let s = 0; s < r.columns; ++s)
|
|
1645
|
+
t[e] *= r.get(e, s);
|
|
1646
|
+
return t;
|
|
1647
|
+
}
|
|
1648
|
+
function Hs(r) {
|
|
1649
|
+
let t = Nt(r.columns, 1);
|
|
1650
|
+
for (let e = 0; e < r.rows; ++e)
|
|
1651
|
+
for (let s = 0; s < r.columns; ++s)
|
|
1652
|
+
t[s] *= r.get(e, s);
|
|
1653
|
+
return t;
|
|
1654
|
+
}
|
|
1655
|
+
function Js(r) {
|
|
1656
|
+
let t = 1;
|
|
1657
|
+
for (let e = 0; e < r.rows; e++)
|
|
1658
|
+
for (let s = 0; s < r.columns; s++)
|
|
1659
|
+
t *= r.get(e, s);
|
|
1660
|
+
return t;
|
|
1661
|
+
}
|
|
1662
|
+
function Ks(r, t, e) {
|
|
1663
|
+
const s = r.rows, n = r.columns, o = [];
|
|
1664
|
+
for (let i = 0; i < s; i++) {
|
|
1665
|
+
let h = 0, l = 0, a = 0;
|
|
1666
|
+
for (let c = 0; c < n; c++)
|
|
1667
|
+
a = r.get(i, c) - e[i], h += a, l += a * a;
|
|
1668
|
+
t ? o.push((l - h * h / n) / (n - 1)) : o.push((l - h * h / n) / n);
|
|
1669
|
+
}
|
|
1670
|
+
return o;
|
|
1671
|
+
}
|
|
1672
|
+
function Qs(r, t, e) {
|
|
1673
|
+
const s = r.rows, n = r.columns, o = [];
|
|
1674
|
+
for (let i = 0; i < n; i++) {
|
|
1675
|
+
let h = 0, l = 0, a = 0;
|
|
1676
|
+
for (let c = 0; c < s; c++)
|
|
1677
|
+
a = r.get(c, i) - e[i], h += a, l += a * a;
|
|
1678
|
+
t ? o.push((l - h * h / s) / (s - 1)) : o.push((l - h * h / s) / s);
|
|
1679
|
+
}
|
|
1680
|
+
return o;
|
|
1681
|
+
}
|
|
1682
|
+
function Zs(r, t, e) {
|
|
1683
|
+
const s = r.rows, n = r.columns, o = s * n;
|
|
1684
|
+
let i = 0, h = 0, l = 0;
|
|
1685
|
+
for (let a = 0; a < s; a++)
|
|
1686
|
+
for (let c = 0; c < n; c++)
|
|
1687
|
+
l = r.get(a, c) - e, i += l, h += l * l;
|
|
1688
|
+
return t ? (h - i * i / o) / (o - 1) : (h - i * i / o) / o;
|
|
1689
|
+
}
|
|
1690
|
+
function tn(r, t) {
|
|
1691
|
+
for (let e = 0; e < r.rows; e++)
|
|
1692
|
+
for (let s = 0; s < r.columns; s++)
|
|
1693
|
+
r.set(e, s, r.get(e, s) - t[e]);
|
|
1694
|
+
}
|
|
1695
|
+
function en(r, t) {
|
|
1696
|
+
for (let e = 0; e < r.rows; e++)
|
|
1697
|
+
for (let s = 0; s < r.columns; s++)
|
|
1698
|
+
r.set(e, s, r.get(e, s) - t[s]);
|
|
1699
|
+
}
|
|
1700
|
+
function sn(r, t) {
|
|
1701
|
+
for (let e = 0; e < r.rows; e++)
|
|
1702
|
+
for (let s = 0; s < r.columns; s++)
|
|
1703
|
+
r.set(e, s, r.get(e, s) - t);
|
|
1704
|
+
}
|
|
1705
|
+
function nn(r) {
|
|
1706
|
+
const t = [];
|
|
1707
|
+
for (let e = 0; e < r.rows; e++) {
|
|
1708
|
+
let s = 0;
|
|
1709
|
+
for (let n = 0; n < r.columns; n++)
|
|
1710
|
+
s += Math.pow(r.get(e, n), 2) / (r.columns - 1);
|
|
1711
|
+
t.push(Math.sqrt(s));
|
|
1712
|
+
}
|
|
1713
|
+
return t;
|
|
1714
|
+
}
|
|
1715
|
+
function rn(r, t) {
|
|
1716
|
+
for (let e = 0; e < r.rows; e++)
|
|
1717
|
+
for (let s = 0; s < r.columns; s++)
|
|
1718
|
+
r.set(e, s, r.get(e, s) / t[e]);
|
|
1719
|
+
}
|
|
1720
|
+
function on(r) {
|
|
1721
|
+
const t = [];
|
|
1722
|
+
for (let e = 0; e < r.columns; e++) {
|
|
1723
|
+
let s = 0;
|
|
1724
|
+
for (let n = 0; n < r.rows; n++)
|
|
1725
|
+
s += Math.pow(r.get(n, e), 2) / (r.rows - 1);
|
|
1726
|
+
t.push(Math.sqrt(s));
|
|
1727
|
+
}
|
|
1728
|
+
return t;
|
|
1729
|
+
}
|
|
1730
|
+
function hn(r, t) {
|
|
1731
|
+
for (let e = 0; e < r.rows; e++)
|
|
1732
|
+
for (let s = 0; s < r.columns; s++)
|
|
1733
|
+
r.set(e, s, r.get(e, s) / t[s]);
|
|
1734
|
+
}
|
|
1735
|
+
function an(r) {
|
|
1736
|
+
const t = r.size - 1;
|
|
1737
|
+
let e = 0;
|
|
1738
|
+
for (let s = 0; s < r.columns; s++)
|
|
1739
|
+
for (let n = 0; n < r.rows; n++)
|
|
1740
|
+
e += Math.pow(r.get(n, s), 2) / t;
|
|
1741
|
+
return Math.sqrt(e);
|
|
1742
|
+
}
|
|
1743
|
+
function ln(r, t) {
|
|
1744
|
+
for (let e = 0; e < r.rows; e++)
|
|
1745
|
+
for (let s = 0; s < r.columns; s++)
|
|
1746
|
+
r.set(e, s, r.get(e, s) / t);
|
|
1747
|
+
}
|
|
1748
|
+
let C = class F {
|
|
1749
|
+
static from1DArray(t, e, s) {
|
|
1750
|
+
if (t * e !== s.length)
|
|
1751
|
+
throw new RangeError("data length does not match given dimensions");
|
|
1752
|
+
let n = new v(t, e);
|
|
1753
|
+
for (let o = 0; o < t; o++)
|
|
1754
|
+
for (let i = 0; i < e; i++)
|
|
1755
|
+
n.set(o, i, s[o * e + i]);
|
|
1756
|
+
return n;
|
|
1757
|
+
}
|
|
1758
|
+
static rowVector(t) {
|
|
1759
|
+
let e = new v(1, t.length);
|
|
1760
|
+
for (let s = 0; s < t.length; s++)
|
|
1761
|
+
e.set(0, s, t[s]);
|
|
1762
|
+
return e;
|
|
1763
|
+
}
|
|
1764
|
+
static columnVector(t) {
|
|
1765
|
+
let e = new v(t.length, 1);
|
|
1766
|
+
for (let s = 0; s < t.length; s++)
|
|
1767
|
+
e.set(s, 0, t[s]);
|
|
1768
|
+
return e;
|
|
1769
|
+
}
|
|
1770
|
+
static zeros(t, e) {
|
|
1771
|
+
return new v(t, e);
|
|
1772
|
+
}
|
|
1773
|
+
static ones(t, e) {
|
|
1774
|
+
return new v(t, e).fill(1);
|
|
1775
|
+
}
|
|
1776
|
+
static rand(t, e, s = {}) {
|
|
1777
|
+
if (typeof s != "object")
|
|
1778
|
+
throw new TypeError("options must be an object");
|
|
1779
|
+
const { random: n = Math.random } = s;
|
|
1780
|
+
let o = new v(t, e);
|
|
1781
|
+
for (let i = 0; i < t; i++)
|
|
1782
|
+
for (let h = 0; h < e; h++)
|
|
1783
|
+
o.set(i, h, n());
|
|
1784
|
+
return o;
|
|
1785
|
+
}
|
|
1786
|
+
static randInt(t, e, s = {}) {
|
|
1787
|
+
if (typeof s != "object")
|
|
1788
|
+
throw new TypeError("options must be an object");
|
|
1789
|
+
const { min: n = 0, max: o = 1e3, random: i = Math.random } = s;
|
|
1790
|
+
if (!Number.isInteger(n))
|
|
1791
|
+
throw new TypeError("min must be an integer");
|
|
1792
|
+
if (!Number.isInteger(o))
|
|
1793
|
+
throw new TypeError("max must be an integer");
|
|
1794
|
+
if (n >= o)
|
|
1795
|
+
throw new RangeError("min must be smaller than max");
|
|
1796
|
+
let h = o - n, l = new v(t, e);
|
|
1797
|
+
for (let a = 0; a < t; a++)
|
|
1798
|
+
for (let c = 0; c < e; c++) {
|
|
1799
|
+
let u = n + Math.round(i() * h);
|
|
1800
|
+
l.set(a, c, u);
|
|
1801
|
+
}
|
|
1802
|
+
return l;
|
|
1803
|
+
}
|
|
1804
|
+
static eye(t, e, s) {
|
|
1805
|
+
e === void 0 && (e = t), s === void 0 && (s = 1);
|
|
1806
|
+
let n = Math.min(t, e), o = this.zeros(t, e);
|
|
1807
|
+
for (let i = 0; i < n; i++)
|
|
1808
|
+
o.set(i, i, s);
|
|
1809
|
+
return o;
|
|
1810
|
+
}
|
|
1811
|
+
static diag(t, e, s) {
|
|
1812
|
+
let n = t.length;
|
|
1813
|
+
e === void 0 && (e = n), s === void 0 && (s = e);
|
|
1814
|
+
let o = Math.min(n, e, s), i = this.zeros(e, s);
|
|
1815
|
+
for (let h = 0; h < o; h++)
|
|
1816
|
+
i.set(h, h, t[h]);
|
|
1817
|
+
return i;
|
|
1818
|
+
}
|
|
1819
|
+
static min(t, e) {
|
|
1820
|
+
t = this.checkMatrix(t), e = this.checkMatrix(e);
|
|
1821
|
+
let s = t.rows, n = t.columns, o = new v(s, n);
|
|
1822
|
+
for (let i = 0; i < s; i++)
|
|
1823
|
+
for (let h = 0; h < n; h++)
|
|
1824
|
+
o.set(i, h, Math.min(t.get(i, h), e.get(i, h)));
|
|
1825
|
+
return o;
|
|
1826
|
+
}
|
|
1827
|
+
static max(t, e) {
|
|
1828
|
+
t = this.checkMatrix(t), e = this.checkMatrix(e);
|
|
1829
|
+
let s = t.rows, n = t.columns, o = new this(s, n);
|
|
1830
|
+
for (let i = 0; i < s; i++)
|
|
1831
|
+
for (let h = 0; h < n; h++)
|
|
1832
|
+
o.set(i, h, Math.max(t.get(i, h), e.get(i, h)));
|
|
1833
|
+
return o;
|
|
1834
|
+
}
|
|
1835
|
+
static checkMatrix(t) {
|
|
1836
|
+
return F.isMatrix(t) ? t : new v(t);
|
|
1837
|
+
}
|
|
1838
|
+
static isMatrix(t) {
|
|
1839
|
+
return t != null && t.klass === "Matrix";
|
|
1840
|
+
}
|
|
1841
|
+
get size() {
|
|
1842
|
+
return this.rows * this.columns;
|
|
1843
|
+
}
|
|
1844
|
+
apply(t) {
|
|
1845
|
+
if (typeof t != "function")
|
|
1846
|
+
throw new TypeError("callback must be a function");
|
|
1847
|
+
for (let e = 0; e < this.rows; e++)
|
|
1848
|
+
for (let s = 0; s < this.columns; s++)
|
|
1849
|
+
t.call(this, e, s);
|
|
1850
|
+
return this;
|
|
1851
|
+
}
|
|
1852
|
+
to1DArray() {
|
|
1853
|
+
let t = [];
|
|
1854
|
+
for (let e = 0; e < this.rows; e++)
|
|
1855
|
+
for (let s = 0; s < this.columns; s++)
|
|
1856
|
+
t.push(this.get(e, s));
|
|
1857
|
+
return t;
|
|
1858
|
+
}
|
|
1859
|
+
to2DArray() {
|
|
1860
|
+
let t = [];
|
|
1861
|
+
for (let e = 0; e < this.rows; e++) {
|
|
1862
|
+
t.push([]);
|
|
1863
|
+
for (let s = 0; s < this.columns; s++)
|
|
1864
|
+
t[e].push(this.get(e, s));
|
|
1865
|
+
}
|
|
1866
|
+
return t;
|
|
1867
|
+
}
|
|
1868
|
+
toJSON() {
|
|
1869
|
+
return this.to2DArray();
|
|
1870
|
+
}
|
|
1871
|
+
isRowVector() {
|
|
1872
|
+
return this.rows === 1;
|
|
1873
|
+
}
|
|
1874
|
+
isColumnVector() {
|
|
1875
|
+
return this.columns === 1;
|
|
1876
|
+
}
|
|
1877
|
+
isVector() {
|
|
1878
|
+
return this.rows === 1 || this.columns === 1;
|
|
1879
|
+
}
|
|
1880
|
+
isSquare() {
|
|
1881
|
+
return this.rows === this.columns;
|
|
1882
|
+
}
|
|
1883
|
+
isEmpty() {
|
|
1884
|
+
return this.rows === 0 || this.columns === 0;
|
|
1885
|
+
}
|
|
1886
|
+
isSymmetric() {
|
|
1887
|
+
if (this.isSquare()) {
|
|
1888
|
+
for (let t = 0; t < this.rows; t++)
|
|
1889
|
+
for (let e = 0; e <= t; e++)
|
|
1890
|
+
if (this.get(t, e) !== this.get(e, t))
|
|
1891
|
+
return !1;
|
|
1892
|
+
return !0;
|
|
1893
|
+
}
|
|
1894
|
+
return !1;
|
|
1895
|
+
}
|
|
1896
|
+
isEchelonForm() {
|
|
1897
|
+
let t = 0, e = 0, s = -1, n = !0, o = !1;
|
|
1898
|
+
for (; t < this.rows && n; ) {
|
|
1899
|
+
for (e = 0, o = !1; e < this.columns && o === !1; )
|
|
1900
|
+
this.get(t, e) === 0 ? e++ : this.get(t, e) === 1 && e > s ? (o = !0, s = e) : (n = !1, o = !0);
|
|
1901
|
+
t++;
|
|
1902
|
+
}
|
|
1903
|
+
return n;
|
|
1904
|
+
}
|
|
1905
|
+
isReducedEchelonForm() {
|
|
1906
|
+
let t = 0, e = 0, s = -1, n = !0, o = !1;
|
|
1907
|
+
for (; t < this.rows && n; ) {
|
|
1908
|
+
for (e = 0, o = !1; e < this.columns && o === !1; )
|
|
1909
|
+
this.get(t, e) === 0 ? e++ : this.get(t, e) === 1 && e > s ? (o = !0, s = e) : (n = !1, o = !0);
|
|
1910
|
+
for (let i = e + 1; i < this.rows; i++)
|
|
1911
|
+
this.get(t, i) !== 0 && (n = !1);
|
|
1912
|
+
t++;
|
|
1913
|
+
}
|
|
1914
|
+
return n;
|
|
1915
|
+
}
|
|
1916
|
+
echelonForm() {
|
|
1917
|
+
let t = this.clone(), e = 0, s = 0;
|
|
1918
|
+
for (; e < t.rows && s < t.columns; ) {
|
|
1919
|
+
let n = e;
|
|
1920
|
+
for (let o = e; o < t.rows; o++)
|
|
1921
|
+
t.get(o, s) > t.get(n, s) && (n = o);
|
|
1922
|
+
if (t.get(n, s) === 0)
|
|
1923
|
+
s++;
|
|
1924
|
+
else {
|
|
1925
|
+
t.swapRows(e, n);
|
|
1926
|
+
let o = t.get(e, s);
|
|
1927
|
+
for (let i = s; i < t.columns; i++)
|
|
1928
|
+
t.set(e, i, t.get(e, i) / o);
|
|
1929
|
+
for (let i = e + 1; i < t.rows; i++) {
|
|
1930
|
+
let h = t.get(i, s) / t.get(e, s);
|
|
1931
|
+
t.set(i, s, 0);
|
|
1932
|
+
for (let l = s + 1; l < t.columns; l++)
|
|
1933
|
+
t.set(i, l, t.get(i, l) - t.get(e, l) * h);
|
|
1934
|
+
}
|
|
1935
|
+
e++, s++;
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
return t;
|
|
1939
|
+
}
|
|
1940
|
+
reducedEchelonForm() {
|
|
1941
|
+
let t = this.echelonForm(), e = t.columns, s = t.rows, n = s - 1;
|
|
1942
|
+
for (; n >= 0; )
|
|
1943
|
+
if (t.maxRow(n) === 0)
|
|
1944
|
+
n--;
|
|
1945
|
+
else {
|
|
1946
|
+
let o = 0, i = !1;
|
|
1947
|
+
for (; o < s && i === !1; )
|
|
1948
|
+
t.get(n, o) === 1 ? i = !0 : o++;
|
|
1949
|
+
for (let h = 0; h < n; h++) {
|
|
1950
|
+
let l = t.get(h, o);
|
|
1951
|
+
for (let a = o; a < e; a++) {
|
|
1952
|
+
let c = t.get(h, a) - l * t.get(n, a);
|
|
1953
|
+
t.set(h, a, c);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
n--;
|
|
1957
|
+
}
|
|
1958
|
+
return t;
|
|
1959
|
+
}
|
|
1960
|
+
set() {
|
|
1961
|
+
throw new Error("set method is unimplemented");
|
|
1962
|
+
}
|
|
1963
|
+
get() {
|
|
1964
|
+
throw new Error("get method is unimplemented");
|
|
1965
|
+
}
|
|
1966
|
+
repeat(t = {}) {
|
|
1967
|
+
if (typeof t != "object")
|
|
1968
|
+
throw new TypeError("options must be an object");
|
|
1969
|
+
const { rows: e = 1, columns: s = 1 } = t;
|
|
1970
|
+
if (!Number.isInteger(e) || e <= 0)
|
|
1971
|
+
throw new TypeError("rows must be a positive integer");
|
|
1972
|
+
if (!Number.isInteger(s) || s <= 0)
|
|
1973
|
+
throw new TypeError("columns must be a positive integer");
|
|
1974
|
+
let n = new v(this.rows * e, this.columns * s);
|
|
1975
|
+
for (let o = 0; o < e; o++)
|
|
1976
|
+
for (let i = 0; i < s; i++)
|
|
1977
|
+
n.setSubMatrix(this, this.rows * o, this.columns * i);
|
|
1978
|
+
return n;
|
|
1979
|
+
}
|
|
1980
|
+
fill(t) {
|
|
1981
|
+
for (let e = 0; e < this.rows; e++)
|
|
1982
|
+
for (let s = 0; s < this.columns; s++)
|
|
1983
|
+
this.set(e, s, t);
|
|
1984
|
+
return this;
|
|
1985
|
+
}
|
|
1986
|
+
neg() {
|
|
1987
|
+
return this.mulS(-1);
|
|
1988
|
+
}
|
|
1989
|
+
getRow(t) {
|
|
1990
|
+
G(this, t);
|
|
1991
|
+
let e = [];
|
|
1992
|
+
for (let s = 0; s < this.columns; s++)
|
|
1993
|
+
e.push(this.get(t, s));
|
|
1994
|
+
return e;
|
|
1995
|
+
}
|
|
1996
|
+
getRowVector(t) {
|
|
1997
|
+
return v.rowVector(this.getRow(t));
|
|
1998
|
+
}
|
|
1999
|
+
setRow(t, e) {
|
|
2000
|
+
G(this, t), e = mt(this, e);
|
|
2001
|
+
for (let s = 0; s < this.columns; s++)
|
|
2002
|
+
this.set(t, s, e[s]);
|
|
2003
|
+
return this;
|
|
2004
|
+
}
|
|
2005
|
+
swapRows(t, e) {
|
|
2006
|
+
G(this, t), G(this, e);
|
|
2007
|
+
for (let s = 0; s < this.columns; s++) {
|
|
2008
|
+
let n = this.get(t, s);
|
|
2009
|
+
this.set(t, s, this.get(e, s)), this.set(e, s, n);
|
|
2010
|
+
}
|
|
2011
|
+
return this;
|
|
2012
|
+
}
|
|
2013
|
+
getColumn(t) {
|
|
2014
|
+
H(this, t);
|
|
2015
|
+
let e = [];
|
|
2016
|
+
for (let s = 0; s < this.rows; s++)
|
|
2017
|
+
e.push(this.get(s, t));
|
|
2018
|
+
return e;
|
|
2019
|
+
}
|
|
2020
|
+
getColumnVector(t) {
|
|
2021
|
+
return v.columnVector(this.getColumn(t));
|
|
2022
|
+
}
|
|
2023
|
+
setColumn(t, e) {
|
|
2024
|
+
H(this, t), e = gt(this, e);
|
|
2025
|
+
for (let s = 0; s < this.rows; s++)
|
|
2026
|
+
this.set(s, t, e[s]);
|
|
2027
|
+
return this;
|
|
2028
|
+
}
|
|
2029
|
+
swapColumns(t, e) {
|
|
2030
|
+
H(this, t), H(this, e);
|
|
2031
|
+
for (let s = 0; s < this.rows; s++) {
|
|
2032
|
+
let n = this.get(s, t);
|
|
2033
|
+
this.set(s, t, this.get(s, e)), this.set(s, e, n);
|
|
2034
|
+
}
|
|
2035
|
+
return this;
|
|
2036
|
+
}
|
|
2037
|
+
addRowVector(t) {
|
|
2038
|
+
t = mt(this, t);
|
|
2039
|
+
for (let e = 0; e < this.rows; e++)
|
|
2040
|
+
for (let s = 0; s < this.columns; s++)
|
|
2041
|
+
this.set(e, s, this.get(e, s) + t[s]);
|
|
2042
|
+
return this;
|
|
2043
|
+
}
|
|
2044
|
+
subRowVector(t) {
|
|
2045
|
+
t = mt(this, t);
|
|
2046
|
+
for (let e = 0; e < this.rows; e++)
|
|
2047
|
+
for (let s = 0; s < this.columns; s++)
|
|
2048
|
+
this.set(e, s, this.get(e, s) - t[s]);
|
|
2049
|
+
return this;
|
|
2050
|
+
}
|
|
2051
|
+
mulRowVector(t) {
|
|
2052
|
+
t = mt(this, t);
|
|
2053
|
+
for (let e = 0; e < this.rows; e++)
|
|
2054
|
+
for (let s = 0; s < this.columns; s++)
|
|
2055
|
+
this.set(e, s, this.get(e, s) * t[s]);
|
|
2056
|
+
return this;
|
|
2057
|
+
}
|
|
2058
|
+
divRowVector(t) {
|
|
2059
|
+
t = mt(this, t);
|
|
2060
|
+
for (let e = 0; e < this.rows; e++)
|
|
2061
|
+
for (let s = 0; s < this.columns; s++)
|
|
2062
|
+
this.set(e, s, this.get(e, s) / t[s]);
|
|
2063
|
+
return this;
|
|
2064
|
+
}
|
|
2065
|
+
addColumnVector(t) {
|
|
2066
|
+
t = gt(this, t);
|
|
2067
|
+
for (let e = 0; e < this.rows; e++)
|
|
2068
|
+
for (let s = 0; s < this.columns; s++)
|
|
2069
|
+
this.set(e, s, this.get(e, s) + t[e]);
|
|
2070
|
+
return this;
|
|
2071
|
+
}
|
|
2072
|
+
subColumnVector(t) {
|
|
2073
|
+
t = gt(this, t);
|
|
2074
|
+
for (let e = 0; e < this.rows; e++)
|
|
2075
|
+
for (let s = 0; s < this.columns; s++)
|
|
2076
|
+
this.set(e, s, this.get(e, s) - t[e]);
|
|
2077
|
+
return this;
|
|
2078
|
+
}
|
|
2079
|
+
mulColumnVector(t) {
|
|
2080
|
+
t = gt(this, t);
|
|
2081
|
+
for (let e = 0; e < this.rows; e++)
|
|
2082
|
+
for (let s = 0; s < this.columns; s++)
|
|
2083
|
+
this.set(e, s, this.get(e, s) * t[e]);
|
|
2084
|
+
return this;
|
|
2085
|
+
}
|
|
2086
|
+
divColumnVector(t) {
|
|
2087
|
+
t = gt(this, t);
|
|
2088
|
+
for (let e = 0; e < this.rows; e++)
|
|
2089
|
+
for (let s = 0; s < this.columns; s++)
|
|
2090
|
+
this.set(e, s, this.get(e, s) / t[e]);
|
|
2091
|
+
return this;
|
|
2092
|
+
}
|
|
2093
|
+
mulRow(t, e) {
|
|
2094
|
+
G(this, t);
|
|
2095
|
+
for (let s = 0; s < this.columns; s++)
|
|
2096
|
+
this.set(t, s, this.get(t, s) * e);
|
|
2097
|
+
return this;
|
|
2098
|
+
}
|
|
2099
|
+
mulColumn(t, e) {
|
|
2100
|
+
H(this, t);
|
|
2101
|
+
for (let s = 0; s < this.rows; s++)
|
|
2102
|
+
this.set(s, t, this.get(s, t) * e);
|
|
2103
|
+
return this;
|
|
2104
|
+
}
|
|
2105
|
+
max(t) {
|
|
2106
|
+
if (this.isEmpty())
|
|
2107
|
+
return NaN;
|
|
2108
|
+
switch (t) {
|
|
2109
|
+
case "row": {
|
|
2110
|
+
const e = new Array(this.rows).fill(Number.NEGATIVE_INFINITY);
|
|
2111
|
+
for (let s = 0; s < this.rows; s++)
|
|
2112
|
+
for (let n = 0; n < this.columns; n++)
|
|
2113
|
+
this.get(s, n) > e[s] && (e[s] = this.get(s, n));
|
|
2114
|
+
return e;
|
|
2115
|
+
}
|
|
2116
|
+
case "column": {
|
|
2117
|
+
const e = new Array(this.columns).fill(Number.NEGATIVE_INFINITY);
|
|
2118
|
+
for (let s = 0; s < this.rows; s++)
|
|
2119
|
+
for (let n = 0; n < this.columns; n++)
|
|
2120
|
+
this.get(s, n) > e[n] && (e[n] = this.get(s, n));
|
|
2121
|
+
return e;
|
|
2122
|
+
}
|
|
2123
|
+
case void 0: {
|
|
2124
|
+
let e = this.get(0, 0);
|
|
2125
|
+
for (let s = 0; s < this.rows; s++)
|
|
2126
|
+
for (let n = 0; n < this.columns; n++)
|
|
2127
|
+
this.get(s, n) > e && (e = this.get(s, n));
|
|
2128
|
+
return e;
|
|
2129
|
+
}
|
|
2130
|
+
default:
|
|
2131
|
+
throw new Error(`invalid option: ${t}`);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
maxIndex() {
|
|
2135
|
+
ft(this);
|
|
2136
|
+
let t = this.get(0, 0), e = [0, 0];
|
|
2137
|
+
for (let s = 0; s < this.rows; s++)
|
|
2138
|
+
for (let n = 0; n < this.columns; n++)
|
|
2139
|
+
this.get(s, n) > t && (t = this.get(s, n), e[0] = s, e[1] = n);
|
|
2140
|
+
return e;
|
|
2141
|
+
}
|
|
2142
|
+
min(t) {
|
|
2143
|
+
if (this.isEmpty())
|
|
2144
|
+
return NaN;
|
|
2145
|
+
switch (t) {
|
|
2146
|
+
case "row": {
|
|
2147
|
+
const e = new Array(this.rows).fill(Number.POSITIVE_INFINITY);
|
|
2148
|
+
for (let s = 0; s < this.rows; s++)
|
|
2149
|
+
for (let n = 0; n < this.columns; n++)
|
|
2150
|
+
this.get(s, n) < e[s] && (e[s] = this.get(s, n));
|
|
2151
|
+
return e;
|
|
2152
|
+
}
|
|
2153
|
+
case "column": {
|
|
2154
|
+
const e = new Array(this.columns).fill(Number.POSITIVE_INFINITY);
|
|
2155
|
+
for (let s = 0; s < this.rows; s++)
|
|
2156
|
+
for (let n = 0; n < this.columns; n++)
|
|
2157
|
+
this.get(s, n) < e[n] && (e[n] = this.get(s, n));
|
|
2158
|
+
return e;
|
|
2159
|
+
}
|
|
2160
|
+
case void 0: {
|
|
2161
|
+
let e = this.get(0, 0);
|
|
2162
|
+
for (let s = 0; s < this.rows; s++)
|
|
2163
|
+
for (let n = 0; n < this.columns; n++)
|
|
2164
|
+
this.get(s, n) < e && (e = this.get(s, n));
|
|
2165
|
+
return e;
|
|
2166
|
+
}
|
|
2167
|
+
default:
|
|
2168
|
+
throw new Error(`invalid option: ${t}`);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
minIndex() {
|
|
2172
|
+
ft(this);
|
|
2173
|
+
let t = this.get(0, 0), e = [0, 0];
|
|
2174
|
+
for (let s = 0; s < this.rows; s++)
|
|
2175
|
+
for (let n = 0; n < this.columns; n++)
|
|
2176
|
+
this.get(s, n) < t && (t = this.get(s, n), e[0] = s, e[1] = n);
|
|
2177
|
+
return e;
|
|
2178
|
+
}
|
|
2179
|
+
maxRow(t) {
|
|
2180
|
+
if (G(this, t), this.isEmpty())
|
|
2181
|
+
return NaN;
|
|
2182
|
+
let e = this.get(t, 0);
|
|
2183
|
+
for (let s = 1; s < this.columns; s++)
|
|
2184
|
+
this.get(t, s) > e && (e = this.get(t, s));
|
|
2185
|
+
return e;
|
|
2186
|
+
}
|
|
2187
|
+
maxRowIndex(t) {
|
|
2188
|
+
G(this, t), ft(this);
|
|
2189
|
+
let e = this.get(t, 0), s = [t, 0];
|
|
2190
|
+
for (let n = 1; n < this.columns; n++)
|
|
2191
|
+
this.get(t, n) > e && (e = this.get(t, n), s[1] = n);
|
|
2192
|
+
return s;
|
|
2193
|
+
}
|
|
2194
|
+
minRow(t) {
|
|
2195
|
+
if (G(this, t), this.isEmpty())
|
|
2196
|
+
return NaN;
|
|
2197
|
+
let e = this.get(t, 0);
|
|
2198
|
+
for (let s = 1; s < this.columns; s++)
|
|
2199
|
+
this.get(t, s) < e && (e = this.get(t, s));
|
|
2200
|
+
return e;
|
|
2201
|
+
}
|
|
2202
|
+
minRowIndex(t) {
|
|
2203
|
+
G(this, t), ft(this);
|
|
2204
|
+
let e = this.get(t, 0), s = [t, 0];
|
|
2205
|
+
for (let n = 1; n < this.columns; n++)
|
|
2206
|
+
this.get(t, n) < e && (e = this.get(t, n), s[1] = n);
|
|
2207
|
+
return s;
|
|
2208
|
+
}
|
|
2209
|
+
maxColumn(t) {
|
|
2210
|
+
if (H(this, t), this.isEmpty())
|
|
2211
|
+
return NaN;
|
|
2212
|
+
let e = this.get(0, t);
|
|
2213
|
+
for (let s = 1; s < this.rows; s++)
|
|
2214
|
+
this.get(s, t) > e && (e = this.get(s, t));
|
|
2215
|
+
return e;
|
|
2216
|
+
}
|
|
2217
|
+
maxColumnIndex(t) {
|
|
2218
|
+
H(this, t), ft(this);
|
|
2219
|
+
let e = this.get(0, t), s = [0, t];
|
|
2220
|
+
for (let n = 1; n < this.rows; n++)
|
|
2221
|
+
this.get(n, t) > e && (e = this.get(n, t), s[0] = n);
|
|
2222
|
+
return s;
|
|
2223
|
+
}
|
|
2224
|
+
minColumn(t) {
|
|
2225
|
+
if (H(this, t), this.isEmpty())
|
|
2226
|
+
return NaN;
|
|
2227
|
+
let e = this.get(0, t);
|
|
2228
|
+
for (let s = 1; s < this.rows; s++)
|
|
2229
|
+
this.get(s, t) < e && (e = this.get(s, t));
|
|
2230
|
+
return e;
|
|
2231
|
+
}
|
|
2232
|
+
minColumnIndex(t) {
|
|
2233
|
+
H(this, t), ft(this);
|
|
2234
|
+
let e = this.get(0, t), s = [0, t];
|
|
2235
|
+
for (let n = 1; n < this.rows; n++)
|
|
2236
|
+
this.get(n, t) < e && (e = this.get(n, t), s[0] = n);
|
|
2237
|
+
return s;
|
|
2238
|
+
}
|
|
2239
|
+
diag() {
|
|
2240
|
+
let t = Math.min(this.rows, this.columns), e = [];
|
|
2241
|
+
for (let s = 0; s < t; s++)
|
|
2242
|
+
e.push(this.get(s, s));
|
|
2243
|
+
return e;
|
|
2244
|
+
}
|
|
2245
|
+
norm(t = "frobenius") {
|
|
2246
|
+
let e = 0;
|
|
2247
|
+
if (t === "max")
|
|
2248
|
+
return this.max();
|
|
2249
|
+
if (t === "frobenius") {
|
|
2250
|
+
for (let s = 0; s < this.rows; s++)
|
|
2251
|
+
for (let n = 0; n < this.columns; n++)
|
|
2252
|
+
e = e + this.get(s, n) * this.get(s, n);
|
|
2253
|
+
return Math.sqrt(e);
|
|
2254
|
+
} else
|
|
2255
|
+
throw new RangeError(`unknown norm type: ${t}`);
|
|
2256
|
+
}
|
|
2257
|
+
cumulativeSum() {
|
|
2258
|
+
let t = 0;
|
|
2259
|
+
for (let e = 0; e < this.rows; e++)
|
|
2260
|
+
for (let s = 0; s < this.columns; s++)
|
|
2261
|
+
t += this.get(e, s), this.set(e, s, t);
|
|
2262
|
+
return this;
|
|
2263
|
+
}
|
|
2264
|
+
dot(t) {
|
|
2265
|
+
F.isMatrix(t) && (t = t.to1DArray());
|
|
2266
|
+
let e = this.to1DArray();
|
|
2267
|
+
if (e.length !== t.length)
|
|
2268
|
+
throw new RangeError("vectors do not have the same size");
|
|
2269
|
+
let s = 0;
|
|
2270
|
+
for (let n = 0; n < e.length; n++)
|
|
2271
|
+
s += e[n] * t[n];
|
|
2272
|
+
return s;
|
|
2273
|
+
}
|
|
2274
|
+
mmul(t) {
|
|
2275
|
+
t = v.checkMatrix(t);
|
|
2276
|
+
let e = this.rows, s = this.columns, n = t.columns, o = new v(e, n), i = new Float64Array(s);
|
|
2277
|
+
for (let h = 0; h < n; h++) {
|
|
2278
|
+
for (let l = 0; l < s; l++)
|
|
2279
|
+
i[l] = t.get(l, h);
|
|
2280
|
+
for (let l = 0; l < e; l++) {
|
|
2281
|
+
let a = 0;
|
|
2282
|
+
for (let c = 0; c < s; c++)
|
|
2283
|
+
a += this.get(l, c) * i[c];
|
|
2284
|
+
o.set(l, h, a);
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
return o;
|
|
2288
|
+
}
|
|
2289
|
+
strassen2x2(t) {
|
|
2290
|
+
t = v.checkMatrix(t);
|
|
2291
|
+
let e = new v(2, 2);
|
|
2292
|
+
const s = this.get(0, 0), n = t.get(0, 0), o = this.get(0, 1), i = t.get(0, 1), h = this.get(1, 0), l = t.get(1, 0), a = this.get(1, 1), c = t.get(1, 1), u = (s + a) * (n + c), m = (h + a) * n, p = s * (i - c), g = a * (l - n), d = (s + o) * c, M = (h - s) * (n + i), f = (o - a) * (l + c), w = u + g - d + f, y = p + d, x = m + g, E = u - m + p + M;
|
|
2293
|
+
return e.set(0, 0, w), e.set(0, 1, y), e.set(1, 0, x), e.set(1, 1, E), e;
|
|
2294
|
+
}
|
|
2295
|
+
strassen3x3(t) {
|
|
2296
|
+
t = v.checkMatrix(t);
|
|
2297
|
+
let e = new v(3, 3);
|
|
2298
|
+
const s = this.get(0, 0), n = this.get(0, 1), o = this.get(0, 2), i = this.get(1, 0), h = this.get(1, 1), l = this.get(1, 2), a = this.get(2, 0), c = this.get(2, 1), u = this.get(2, 2), m = t.get(0, 0), p = t.get(0, 1), g = t.get(0, 2), d = t.get(1, 0), M = t.get(1, 1), f = t.get(1, 2), w = t.get(2, 0), y = t.get(2, 1), x = t.get(2, 2), E = (s + n + o - i - h - c - u) * M, R = (s - i) * (-p + M), k = h * (-m + p + d - M - f - w + x), P = (-s + i + h) * (m - p + M), T = (i + h) * (-m + p), $ = s * m, N = (-s + a + c) * (m - g + f), K = (-s + a) * (g - f), Q = (a + c) * (-m + g), Z = (s + n + o - h - l - a - c) * f, j = c * (-m + g + d - M - f - w + y), U = (-o + c + u) * (M + w - y), St = (o - u) * (M - y), tt = o * w, ut = (c + u) * (-w + y), Y = (-o + h + l) * (f + w - x), he = (o - l) * (f - x), ae = (h + l) * (-w + x), ls = n * d, us = l * y, cs = i * g, fs = a * p, ms = u * x, gs = $ + tt + ls, ps = E + P + T + $ + U + tt + ut, ws = $ + N + Q + Z + tt + Y + ae, ds = R + k + P + $ + tt + Y + he, ys = R + P + T + $ + us, Ms = tt + Y + he + ae + cs, bs = $ + N + K + j + U + St + tt, Ps = U + St + tt + ut + fs, xs = $ + N + K + Q + ms;
|
|
2299
|
+
return e.set(0, 0, gs), e.set(0, 1, ps), e.set(0, 2, ws), e.set(1, 0, ds), e.set(1, 1, ys), e.set(1, 2, Ms), e.set(2, 0, bs), e.set(2, 1, Ps), e.set(2, 2, xs), e;
|
|
2300
|
+
}
|
|
2301
|
+
mmulStrassen(t) {
|
|
2302
|
+
t = v.checkMatrix(t);
|
|
2303
|
+
let e = this.clone(), s = e.rows, n = e.columns, o = t.rows, i = t.columns;
|
|
2304
|
+
n !== o && console.warn(
|
|
2305
|
+
`Multiplying ${s} x ${n} and ${o} x ${i} matrix: dimensions do not match.`
|
|
2306
|
+
);
|
|
2307
|
+
function h(u, m, p) {
|
|
2308
|
+
let g = u.rows, d = u.columns;
|
|
2309
|
+
if (g === m && d === p)
|
|
2310
|
+
return u;
|
|
2311
|
+
{
|
|
2312
|
+
let M = F.zeros(m, p);
|
|
2313
|
+
return M = M.setSubMatrix(u, 0, 0), M;
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
let l = Math.max(s, o), a = Math.max(n, i);
|
|
2317
|
+
e = h(e, l, a), t = h(t, l, a);
|
|
2318
|
+
function c(u, m, p, g) {
|
|
2319
|
+
if (p <= 512 || g <= 512)
|
|
2320
|
+
return u.mmul(m);
|
|
2321
|
+
p % 2 === 1 && g % 2 === 1 ? (u = h(u, p + 1, g + 1), m = h(m, p + 1, g + 1)) : p % 2 === 1 ? (u = h(u, p + 1, g), m = h(m, p + 1, g)) : g % 2 === 1 && (u = h(u, p, g + 1), m = h(m, p, g + 1));
|
|
2322
|
+
let d = parseInt(u.rows / 2, 10), M = parseInt(u.columns / 2, 10), f = u.subMatrix(0, d - 1, 0, M - 1), w = m.subMatrix(0, d - 1, 0, M - 1), y = u.subMatrix(0, d - 1, M, u.columns - 1), x = m.subMatrix(0, d - 1, M, m.columns - 1), E = u.subMatrix(d, u.rows - 1, 0, M - 1), R = m.subMatrix(d, m.rows - 1, 0, M - 1), k = u.subMatrix(d, u.rows - 1, M, u.columns - 1), P = m.subMatrix(d, m.rows - 1, M, m.columns - 1), T = c(
|
|
2323
|
+
F.add(f, k),
|
|
2324
|
+
F.add(w, P),
|
|
2325
|
+
d,
|
|
2326
|
+
M
|
|
2327
|
+
), $ = c(F.add(E, k), w, d, M), N = c(f, F.sub(x, P), d, M), K = c(k, F.sub(R, w), d, M), Q = c(F.add(f, y), P, d, M), Z = c(
|
|
2328
|
+
F.sub(E, f),
|
|
2329
|
+
F.add(w, x),
|
|
2330
|
+
d,
|
|
2331
|
+
M
|
|
2332
|
+
), j = c(
|
|
2333
|
+
F.sub(y, k),
|
|
2334
|
+
F.add(R, P),
|
|
2335
|
+
d,
|
|
2336
|
+
M
|
|
2337
|
+
), U = F.add(T, K);
|
|
2338
|
+
U.sub(Q), U.add(j);
|
|
2339
|
+
let St = F.add(N, Q), tt = F.add($, K), ut = F.sub(T, $);
|
|
2340
|
+
ut.add(N), ut.add(Z);
|
|
2341
|
+
let Y = F.zeros(2 * U.rows, 2 * U.columns);
|
|
2342
|
+
return Y = Y.setSubMatrix(U, 0, 0), Y = Y.setSubMatrix(St, U.rows, 0), Y = Y.setSubMatrix(tt, 0, U.columns), Y = Y.setSubMatrix(ut, U.rows, U.columns), Y.subMatrix(0, p - 1, 0, g - 1);
|
|
2343
|
+
}
|
|
2344
|
+
return c(e, t, l, a);
|
|
2345
|
+
}
|
|
2346
|
+
scaleRows(t = {}) {
|
|
2347
|
+
if (typeof t != "object")
|
|
2348
|
+
throw new TypeError("options must be an object");
|
|
2349
|
+
const { min: e = 0, max: s = 1 } = t;
|
|
2350
|
+
if (!Number.isFinite(e))
|
|
2351
|
+
throw new TypeError("min must be a number");
|
|
2352
|
+
if (!Number.isFinite(s))
|
|
2353
|
+
throw new TypeError("max must be a number");
|
|
2354
|
+
if (e >= s)
|
|
2355
|
+
throw new RangeError("min must be smaller than max");
|
|
2356
|
+
let n = new v(this.rows, this.columns);
|
|
2357
|
+
for (let o = 0; o < this.rows; o++) {
|
|
2358
|
+
const i = this.getRow(o);
|
|
2359
|
+
i.length > 0 && ue(i, { min: e, max: s, output: i }), n.setRow(o, i);
|
|
2360
|
+
}
|
|
2361
|
+
return n;
|
|
2362
|
+
}
|
|
2363
|
+
scaleColumns(t = {}) {
|
|
2364
|
+
if (typeof t != "object")
|
|
2365
|
+
throw new TypeError("options must be an object");
|
|
2366
|
+
const { min: e = 0, max: s = 1 } = t;
|
|
2367
|
+
if (!Number.isFinite(e))
|
|
2368
|
+
throw new TypeError("min must be a number");
|
|
2369
|
+
if (!Number.isFinite(s))
|
|
2370
|
+
throw new TypeError("max must be a number");
|
|
2371
|
+
if (e >= s)
|
|
2372
|
+
throw new RangeError("min must be smaller than max");
|
|
2373
|
+
let n = new v(this.rows, this.columns);
|
|
2374
|
+
for (let o = 0; o < this.columns; o++) {
|
|
2375
|
+
const i = this.getColumn(o);
|
|
2376
|
+
i.length && ue(i, {
|
|
2377
|
+
min: e,
|
|
2378
|
+
max: s,
|
|
2379
|
+
output: i
|
|
2380
|
+
}), n.setColumn(o, i);
|
|
2381
|
+
}
|
|
2382
|
+
return n;
|
|
2383
|
+
}
|
|
2384
|
+
flipRows() {
|
|
2385
|
+
const t = Math.ceil(this.columns / 2);
|
|
2386
|
+
for (let e = 0; e < this.rows; e++)
|
|
2387
|
+
for (let s = 0; s < t; s++) {
|
|
2388
|
+
let n = this.get(e, s), o = this.get(e, this.columns - 1 - s);
|
|
2389
|
+
this.set(e, s, o), this.set(e, this.columns - 1 - s, n);
|
|
2390
|
+
}
|
|
2391
|
+
return this;
|
|
2392
|
+
}
|
|
2393
|
+
flipColumns() {
|
|
2394
|
+
const t = Math.ceil(this.rows / 2);
|
|
2395
|
+
for (let e = 0; e < this.columns; e++)
|
|
2396
|
+
for (let s = 0; s < t; s++) {
|
|
2397
|
+
let n = this.get(s, e), o = this.get(this.rows - 1 - s, e);
|
|
2398
|
+
this.set(s, e, o), this.set(this.rows - 1 - s, e, n);
|
|
2399
|
+
}
|
|
2400
|
+
return this;
|
|
2401
|
+
}
|
|
2402
|
+
kroneckerProduct(t) {
|
|
2403
|
+
t = v.checkMatrix(t);
|
|
2404
|
+
let e = this.rows, s = this.columns, n = t.rows, o = t.columns, i = new v(e * n, s * o);
|
|
2405
|
+
for (let h = 0; h < e; h++)
|
|
2406
|
+
for (let l = 0; l < s; l++)
|
|
2407
|
+
for (let a = 0; a < n; a++)
|
|
2408
|
+
for (let c = 0; c < o; c++)
|
|
2409
|
+
i.set(n * h + a, o * l + c, this.get(h, l) * t.get(a, c));
|
|
2410
|
+
return i;
|
|
2411
|
+
}
|
|
2412
|
+
kroneckerSum(t) {
|
|
2413
|
+
if (t = v.checkMatrix(t), !this.isSquare() || !t.isSquare())
|
|
2414
|
+
throw new Error("Kronecker Sum needs two Square Matrices");
|
|
2415
|
+
let e = this.rows, s = t.rows, n = this.kroneckerProduct(v.eye(s, s)), o = v.eye(e, e).kroneckerProduct(t);
|
|
2416
|
+
return n.add(o);
|
|
2417
|
+
}
|
|
2418
|
+
transpose() {
|
|
2419
|
+
let t = new v(this.columns, this.rows);
|
|
2420
|
+
for (let e = 0; e < this.rows; e++)
|
|
2421
|
+
for (let s = 0; s < this.columns; s++)
|
|
2422
|
+
t.set(s, e, this.get(e, s));
|
|
2423
|
+
return t;
|
|
2424
|
+
}
|
|
2425
|
+
sortRows(t = me) {
|
|
2426
|
+
for (let e = 0; e < this.rows; e++)
|
|
2427
|
+
this.setRow(e, this.getRow(e).sort(t));
|
|
2428
|
+
return this;
|
|
2429
|
+
}
|
|
2430
|
+
sortColumns(t = me) {
|
|
2431
|
+
for (let e = 0; e < this.columns; e++)
|
|
2432
|
+
this.setColumn(e, this.getColumn(e).sort(t));
|
|
2433
|
+
return this;
|
|
2434
|
+
}
|
|
2435
|
+
subMatrix(t, e, s, n) {
|
|
2436
|
+
fe(this, t, e, s, n);
|
|
2437
|
+
let o = new v(
|
|
2438
|
+
e - t + 1,
|
|
2439
|
+
n - s + 1
|
|
2440
|
+
);
|
|
2441
|
+
for (let i = t; i <= e; i++)
|
|
2442
|
+
for (let h = s; h <= n; h++)
|
|
2443
|
+
o.set(i - t, h - s, this.get(i, h));
|
|
2444
|
+
return o;
|
|
2445
|
+
}
|
|
2446
|
+
subMatrixRow(t, e, s) {
|
|
2447
|
+
if (e === void 0 && (e = 0), s === void 0 && (s = this.columns - 1), e > s || e < 0 || e >= this.columns || s < 0 || s >= this.columns)
|
|
2448
|
+
throw new RangeError("Argument out of range");
|
|
2449
|
+
let n = new v(t.length, s - e + 1);
|
|
2450
|
+
for (let o = 0; o < t.length; o++)
|
|
2451
|
+
for (let i = e; i <= s; i++) {
|
|
2452
|
+
if (t[o] < 0 || t[o] >= this.rows)
|
|
2453
|
+
throw new RangeError(`Row index out of range: ${t[o]}`);
|
|
2454
|
+
n.set(o, i - e, this.get(t[o], i));
|
|
2455
|
+
}
|
|
2456
|
+
return n;
|
|
2457
|
+
}
|
|
2458
|
+
subMatrixColumn(t, e, s) {
|
|
2459
|
+
if (e === void 0 && (e = 0), s === void 0 && (s = this.rows - 1), e > s || e < 0 || e >= this.rows || s < 0 || s >= this.rows)
|
|
2460
|
+
throw new RangeError("Argument out of range");
|
|
2461
|
+
let n = new v(s - e + 1, t.length);
|
|
2462
|
+
for (let o = 0; o < t.length; o++)
|
|
2463
|
+
for (let i = e; i <= s; i++) {
|
|
2464
|
+
if (t[o] < 0 || t[o] >= this.columns)
|
|
2465
|
+
throw new RangeError(`Column index out of range: ${t[o]}`);
|
|
2466
|
+
n.set(i - e, o, this.get(i, t[o]));
|
|
2467
|
+
}
|
|
2468
|
+
return n;
|
|
2469
|
+
}
|
|
2470
|
+
setSubMatrix(t, e, s) {
|
|
2471
|
+
if (t = v.checkMatrix(t), t.isEmpty())
|
|
2472
|
+
return this;
|
|
2473
|
+
let n = e + t.rows - 1, o = s + t.columns - 1;
|
|
2474
|
+
fe(this, e, n, s, o);
|
|
2475
|
+
for (let i = 0; i < t.rows; i++)
|
|
2476
|
+
for (let h = 0; h < t.columns; h++)
|
|
2477
|
+
this.set(e + i, s + h, t.get(i, h));
|
|
2478
|
+
return this;
|
|
2479
|
+
}
|
|
2480
|
+
selection(t, e) {
|
|
2481
|
+
Us(this, t), Ys(this, e);
|
|
2482
|
+
let s = new v(t.length, e.length);
|
|
2483
|
+
for (let n = 0; n < t.length; n++) {
|
|
2484
|
+
let o = t[n];
|
|
2485
|
+
for (let i = 0; i < e.length; i++) {
|
|
2486
|
+
let h = e[i];
|
|
2487
|
+
s.set(n, i, this.get(o, h));
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
return s;
|
|
2491
|
+
}
|
|
2492
|
+
trace() {
|
|
2493
|
+
let t = Math.min(this.rows, this.columns), e = 0;
|
|
2494
|
+
for (let s = 0; s < t; s++)
|
|
2495
|
+
e += this.get(s, s);
|
|
2496
|
+
return e;
|
|
2497
|
+
}
|
|
2498
|
+
clone() {
|
|
2499
|
+
let t = new v(this.rows, this.columns);
|
|
2500
|
+
for (let e = 0; e < this.rows; e++)
|
|
2501
|
+
for (let s = 0; s < this.columns; s++)
|
|
2502
|
+
t.set(e, s, this.get(e, s));
|
|
2503
|
+
return t;
|
|
2504
|
+
}
|
|
2505
|
+
sum(t) {
|
|
2506
|
+
switch (t) {
|
|
2507
|
+
case "row":
|
|
2508
|
+
return Ds(this);
|
|
2509
|
+
case "column":
|
|
2510
|
+
return Xs(this);
|
|
2511
|
+
case void 0:
|
|
2512
|
+
return Ws(this);
|
|
2513
|
+
default:
|
|
2514
|
+
throw new Error(`invalid option: ${t}`);
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
product(t) {
|
|
2518
|
+
switch (t) {
|
|
2519
|
+
case "row":
|
|
2520
|
+
return Gs(this);
|
|
2521
|
+
case "column":
|
|
2522
|
+
return Hs(this);
|
|
2523
|
+
case void 0:
|
|
2524
|
+
return Js(this);
|
|
2525
|
+
default:
|
|
2526
|
+
throw new Error(`invalid option: ${t}`);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
mean(t) {
|
|
2530
|
+
const e = this.sum(t);
|
|
2531
|
+
switch (t) {
|
|
2532
|
+
case "row": {
|
|
2533
|
+
for (let s = 0; s < this.rows; s++)
|
|
2534
|
+
e[s] /= this.columns;
|
|
2535
|
+
return e;
|
|
2536
|
+
}
|
|
2537
|
+
case "column": {
|
|
2538
|
+
for (let s = 0; s < this.columns; s++)
|
|
2539
|
+
e[s] /= this.rows;
|
|
2540
|
+
return e;
|
|
2541
|
+
}
|
|
2542
|
+
case void 0:
|
|
2543
|
+
return e / this.size;
|
|
2544
|
+
default:
|
|
2545
|
+
throw new Error(`invalid option: ${t}`);
|
|
2546
|
+
}
|
|
2547
|
+
}
|
|
2548
|
+
variance(t, e = {}) {
|
|
2549
|
+
if (typeof t == "object" && (e = t, t = void 0), typeof e != "object")
|
|
2550
|
+
throw new TypeError("options must be an object");
|
|
2551
|
+
const { unbiased: s = !0, mean: n = this.mean(t) } = e;
|
|
2552
|
+
if (typeof s != "boolean")
|
|
2553
|
+
throw new TypeError("unbiased must be a boolean");
|
|
2554
|
+
switch (t) {
|
|
2555
|
+
case "row": {
|
|
2556
|
+
if (!D(n))
|
|
2557
|
+
throw new TypeError("mean must be an array");
|
|
2558
|
+
return Ks(this, s, n);
|
|
2559
|
+
}
|
|
2560
|
+
case "column": {
|
|
2561
|
+
if (!D(n))
|
|
2562
|
+
throw new TypeError("mean must be an array");
|
|
2563
|
+
return Qs(this, s, n);
|
|
2564
|
+
}
|
|
2565
|
+
case void 0: {
|
|
2566
|
+
if (typeof n != "number")
|
|
2567
|
+
throw new TypeError("mean must be a number");
|
|
2568
|
+
return Zs(this, s, n);
|
|
2569
|
+
}
|
|
2570
|
+
default:
|
|
2571
|
+
throw new Error(`invalid option: ${t}`);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
standardDeviation(t, e) {
|
|
2575
|
+
typeof t == "object" && (e = t, t = void 0);
|
|
2576
|
+
const s = this.variance(t, e);
|
|
2577
|
+
if (t === void 0)
|
|
2578
|
+
return Math.sqrt(s);
|
|
2579
|
+
for (let n = 0; n < s.length; n++)
|
|
2580
|
+
s[n] = Math.sqrt(s[n]);
|
|
2581
|
+
return s;
|
|
2582
|
+
}
|
|
2583
|
+
center(t, e = {}) {
|
|
2584
|
+
if (typeof t == "object" && (e = t, t = void 0), typeof e != "object")
|
|
2585
|
+
throw new TypeError("options must be an object");
|
|
2586
|
+
const { center: s = this.mean(t) } = e;
|
|
2587
|
+
switch (t) {
|
|
2588
|
+
case "row": {
|
|
2589
|
+
if (!D(s))
|
|
2590
|
+
throw new TypeError("center must be an array");
|
|
2591
|
+
return tn(this, s), this;
|
|
2592
|
+
}
|
|
2593
|
+
case "column": {
|
|
2594
|
+
if (!D(s))
|
|
2595
|
+
throw new TypeError("center must be an array");
|
|
2596
|
+
return en(this, s), this;
|
|
2597
|
+
}
|
|
2598
|
+
case void 0: {
|
|
2599
|
+
if (typeof s != "number")
|
|
2600
|
+
throw new TypeError("center must be a number");
|
|
2601
|
+
return sn(this, s), this;
|
|
2602
|
+
}
|
|
2603
|
+
default:
|
|
2604
|
+
throw new Error(`invalid option: ${t}`);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
scale(t, e = {}) {
|
|
2608
|
+
if (typeof t == "object" && (e = t, t = void 0), typeof e != "object")
|
|
2609
|
+
throw new TypeError("options must be an object");
|
|
2610
|
+
let s = e.scale;
|
|
2611
|
+
switch (t) {
|
|
2612
|
+
case "row": {
|
|
2613
|
+
if (s === void 0)
|
|
2614
|
+
s = nn(this);
|
|
2615
|
+
else if (!D(s))
|
|
2616
|
+
throw new TypeError("scale must be an array");
|
|
2617
|
+
return rn(this, s), this;
|
|
2618
|
+
}
|
|
2619
|
+
case "column": {
|
|
2620
|
+
if (s === void 0)
|
|
2621
|
+
s = on(this);
|
|
2622
|
+
else if (!D(s))
|
|
2623
|
+
throw new TypeError("scale must be an array");
|
|
2624
|
+
return hn(this, s), this;
|
|
2625
|
+
}
|
|
2626
|
+
case void 0: {
|
|
2627
|
+
if (s === void 0)
|
|
2628
|
+
s = an(this);
|
|
2629
|
+
else if (typeof s != "number")
|
|
2630
|
+
throw new TypeError("scale must be a number");
|
|
2631
|
+
return ln(this, s), this;
|
|
2632
|
+
}
|
|
2633
|
+
default:
|
|
2634
|
+
throw new Error(`invalid option: ${t}`);
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
toString(t) {
|
|
2638
|
+
return ze(this, t);
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
C.prototype.klass = "Matrix";
|
|
2642
|
+
typeof Symbol < "u" && (C.prototype[Symbol.for("nodejs.util.inspect.custom")] = Ns);
|
|
2643
|
+
function me(r, t) {
|
|
2644
|
+
return r - t;
|
|
2645
|
+
}
|
|
2646
|
+
function un(r) {
|
|
2647
|
+
return r.every((t) => typeof t == "number");
|
|
2648
|
+
}
|
|
2649
|
+
C.random = C.rand;
|
|
2650
|
+
C.randomInt = C.randInt;
|
|
2651
|
+
C.diagonal = C.diag;
|
|
2652
|
+
C.prototype.diagonal = C.prototype.diag;
|
|
2653
|
+
C.identity = C.eye;
|
|
2654
|
+
C.prototype.negate = C.prototype.neg;
|
|
2655
|
+
C.prototype.tensorProduct = C.prototype.kroneckerProduct;
|
|
2656
|
+
let v = class Ue extends C {
|
|
2657
|
+
constructor(t, e) {
|
|
2658
|
+
if (super(), Ue.isMatrix(t))
|
|
2659
|
+
return t.clone();
|
|
2660
|
+
if (Number.isInteger(t) && t >= 0)
|
|
2661
|
+
if (this.data = [], Number.isInteger(e) && e >= 0)
|
|
2662
|
+
for (let s = 0; s < t; s++)
|
|
2663
|
+
this.data.push(new Float64Array(e));
|
|
2664
|
+
else
|
|
2665
|
+
throw new TypeError("nColumns must be a positive integer");
|
|
2666
|
+
else if (D(t)) {
|
|
2667
|
+
const s = t;
|
|
2668
|
+
if (t = s.length, e = t ? s[0].length : 0, typeof e != "number")
|
|
2669
|
+
throw new TypeError(
|
|
2670
|
+
"Data must be a 2D array with at least one element"
|
|
2671
|
+
);
|
|
2672
|
+
this.data = [];
|
|
2673
|
+
for (let n = 0; n < t; n++) {
|
|
2674
|
+
if (s[n].length !== e)
|
|
2675
|
+
throw new RangeError("Inconsistent array dimensions");
|
|
2676
|
+
if (!un(s[n]))
|
|
2677
|
+
throw new TypeError("Input data contains non-numeric values");
|
|
2678
|
+
this.data.push(Float64Array.from(s[n]));
|
|
2679
|
+
}
|
|
2680
|
+
} else
|
|
2681
|
+
throw new TypeError(
|
|
2682
|
+
"First argument must be a positive number or an array"
|
|
2683
|
+
);
|
|
2684
|
+
this.rows = t, this.columns = e;
|
|
2685
|
+
}
|
|
2686
|
+
set(t, e, s) {
|
|
2687
|
+
return this.data[t][e] = s, this;
|
|
2688
|
+
}
|
|
2689
|
+
get(t, e) {
|
|
2690
|
+
return this.data[t][e];
|
|
2691
|
+
}
|
|
2692
|
+
removeRow(t) {
|
|
2693
|
+
return G(this, t), this.data.splice(t, 1), this.rows -= 1, this;
|
|
2694
|
+
}
|
|
2695
|
+
addRow(t, e) {
|
|
2696
|
+
return e === void 0 && (e = t, t = this.rows), G(this, t, !0), e = Float64Array.from(mt(this, e)), this.data.splice(t, 0, e), this.rows += 1, this;
|
|
2697
|
+
}
|
|
2698
|
+
removeColumn(t) {
|
|
2699
|
+
H(this, t);
|
|
2700
|
+
for (let e = 0; e < this.rows; e++) {
|
|
2701
|
+
const s = new Float64Array(this.columns - 1);
|
|
2702
|
+
for (let n = 0; n < t; n++)
|
|
2703
|
+
s[n] = this.data[e][n];
|
|
2704
|
+
for (let n = t + 1; n < this.columns; n++)
|
|
2705
|
+
s[n - 1] = this.data[e][n];
|
|
2706
|
+
this.data[e] = s;
|
|
2707
|
+
}
|
|
2708
|
+
return this.columns -= 1, this;
|
|
2709
|
+
}
|
|
2710
|
+
addColumn(t, e) {
|
|
2711
|
+
typeof e > "u" && (e = t, t = this.columns), H(this, t, !0), e = gt(this, e);
|
|
2712
|
+
for (let s = 0; s < this.rows; s++) {
|
|
2713
|
+
const n = new Float64Array(this.columns + 1);
|
|
2714
|
+
let o = 0;
|
|
2715
|
+
for (; o < t; o++)
|
|
2716
|
+
n[o] = this.data[s][o];
|
|
2717
|
+
for (n[o++] = e[s]; o < this.columns + 1; o++)
|
|
2718
|
+
n[o] = this.data[s][o - 1];
|
|
2719
|
+
this.data[s] = n;
|
|
2720
|
+
}
|
|
2721
|
+
return this.columns += 1, this;
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
zs(C, v);
|
|
2725
|
+
class cn extends C {
|
|
2726
|
+
constructor(t) {
|
|
2727
|
+
super(), this.data = t, this.rows = t.length, this.columns = t[0].length;
|
|
2728
|
+
}
|
|
2729
|
+
set(t, e, s) {
|
|
2730
|
+
return this.data[t][e] = s, this;
|
|
2731
|
+
}
|
|
2732
|
+
get(t, e) {
|
|
2733
|
+
return this.data[t][e];
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
function ge(r, t) {
|
|
2737
|
+
let e = 0;
|
|
2738
|
+
return Math.abs(r) > Math.abs(t) ? (e = t / r, Math.abs(r) * Math.sqrt(1 + e * e)) : t !== 0 ? (e = r / t, Math.abs(t) * Math.sqrt(1 + e * e)) : 0;
|
|
2739
|
+
}
|
|
2740
|
+
class fn {
|
|
2741
|
+
constructor(t, e = {}) {
|
|
2742
|
+
const { assumeSymmetric: s = !1 } = e;
|
|
2743
|
+
if (t = cn.checkMatrix(t), !t.isSquare())
|
|
2744
|
+
throw new Error("Matrix is not a square matrix");
|
|
2745
|
+
if (t.isEmpty())
|
|
2746
|
+
throw new Error("Matrix must be non-empty");
|
|
2747
|
+
let n = t.columns, o = new v(n, n), i = new Float64Array(n), h = new Float64Array(n), l = t, a, c, u = !1;
|
|
2748
|
+
if (s ? u = !0 : u = t.isSymmetric(), u) {
|
|
2749
|
+
for (a = 0; a < n; a++)
|
|
2750
|
+
for (c = 0; c < n; c++)
|
|
2751
|
+
o.set(a, c, l.get(a, c));
|
|
2752
|
+
mn(n, h, i, o), gn(n, h, i, o);
|
|
2753
|
+
} else {
|
|
2754
|
+
let m = new v(n, n), p = new Float64Array(n);
|
|
2755
|
+
for (c = 0; c < n; c++)
|
|
2756
|
+
for (a = 0; a < n; a++)
|
|
2757
|
+
m.set(a, c, l.get(a, c));
|
|
2758
|
+
pn(n, m, p, o), wn(n, h, i, o, m);
|
|
2759
|
+
}
|
|
2760
|
+
this.n = n, this.e = h, this.d = i, this.V = o;
|
|
2761
|
+
}
|
|
2762
|
+
get realEigenvalues() {
|
|
2763
|
+
return Array.from(this.d);
|
|
2764
|
+
}
|
|
2765
|
+
get imaginaryEigenvalues() {
|
|
2766
|
+
return Array.from(this.e);
|
|
2767
|
+
}
|
|
2768
|
+
get eigenvectorMatrix() {
|
|
2769
|
+
return this.V;
|
|
2770
|
+
}
|
|
2771
|
+
get diagonalMatrix() {
|
|
2772
|
+
let t = this.n, e = this.e, s = this.d, n = new v(t, t), o, i;
|
|
2773
|
+
for (o = 0; o < t; o++) {
|
|
2774
|
+
for (i = 0; i < t; i++)
|
|
2775
|
+
n.set(o, i, 0);
|
|
2776
|
+
n.set(o, o, s[o]), e[o] > 0 ? n.set(o, o + 1, e[o]) : e[o] < 0 && n.set(o, o - 1, e[o]);
|
|
2777
|
+
}
|
|
2778
|
+
return n;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
function mn(r, t, e, s) {
|
|
2782
|
+
let n, o, i, h, l, a, c, u;
|
|
2783
|
+
for (l = 0; l < r; l++)
|
|
2784
|
+
e[l] = s.get(r - 1, l);
|
|
2785
|
+
for (h = r - 1; h > 0; h--) {
|
|
2786
|
+
for (u = 0, i = 0, a = 0; a < h; a++)
|
|
2787
|
+
u = u + Math.abs(e[a]);
|
|
2788
|
+
if (u === 0)
|
|
2789
|
+
for (t[h] = e[h - 1], l = 0; l < h; l++)
|
|
2790
|
+
e[l] = s.get(h - 1, l), s.set(h, l, 0), s.set(l, h, 0);
|
|
2791
|
+
else {
|
|
2792
|
+
for (a = 0; a < h; a++)
|
|
2793
|
+
e[a] /= u, i += e[a] * e[a];
|
|
2794
|
+
for (n = e[h - 1], o = Math.sqrt(i), n > 0 && (o = -o), t[h] = u * o, i = i - n * o, e[h - 1] = n - o, l = 0; l < h; l++)
|
|
2795
|
+
t[l] = 0;
|
|
2796
|
+
for (l = 0; l < h; l++) {
|
|
2797
|
+
for (n = e[l], s.set(l, h, n), o = t[l] + s.get(l, l) * n, a = l + 1; a <= h - 1; a++)
|
|
2798
|
+
o += s.get(a, l) * e[a], t[a] += s.get(a, l) * n;
|
|
2799
|
+
t[l] = o;
|
|
2800
|
+
}
|
|
2801
|
+
for (n = 0, l = 0; l < h; l++)
|
|
2802
|
+
t[l] /= i, n += t[l] * e[l];
|
|
2803
|
+
for (c = n / (i + i), l = 0; l < h; l++)
|
|
2804
|
+
t[l] -= c * e[l];
|
|
2805
|
+
for (l = 0; l < h; l++) {
|
|
2806
|
+
for (n = e[l], o = t[l], a = l; a <= h - 1; a++)
|
|
2807
|
+
s.set(a, l, s.get(a, l) - (n * t[a] + o * e[a]));
|
|
2808
|
+
e[l] = s.get(h - 1, l), s.set(h, l, 0);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
e[h] = i;
|
|
2812
|
+
}
|
|
2813
|
+
for (h = 0; h < r - 1; h++) {
|
|
2814
|
+
if (s.set(r - 1, h, s.get(h, h)), s.set(h, h, 1), i = e[h + 1], i !== 0) {
|
|
2815
|
+
for (a = 0; a <= h; a++)
|
|
2816
|
+
e[a] = s.get(a, h + 1) / i;
|
|
2817
|
+
for (l = 0; l <= h; l++) {
|
|
2818
|
+
for (o = 0, a = 0; a <= h; a++)
|
|
2819
|
+
o += s.get(a, h + 1) * s.get(a, l);
|
|
2820
|
+
for (a = 0; a <= h; a++)
|
|
2821
|
+
s.set(a, l, s.get(a, l) - o * e[a]);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
for (a = 0; a <= h; a++)
|
|
2825
|
+
s.set(a, h + 1, 0);
|
|
2826
|
+
}
|
|
2827
|
+
for (l = 0; l < r; l++)
|
|
2828
|
+
e[l] = s.get(r - 1, l), s.set(r - 1, l, 0);
|
|
2829
|
+
s.set(r - 1, r - 1, 1), t[0] = 0;
|
|
2830
|
+
}
|
|
2831
|
+
function gn(r, t, e, s) {
|
|
2832
|
+
let n, o, i, h, l, a, c, u, m, p, g, d, M, f, w, y;
|
|
2833
|
+
for (i = 1; i < r; i++)
|
|
2834
|
+
t[i - 1] = t[i];
|
|
2835
|
+
t[r - 1] = 0;
|
|
2836
|
+
let x = 0, E = 0, R = Number.EPSILON;
|
|
2837
|
+
for (a = 0; a < r; a++) {
|
|
2838
|
+
for (E = Math.max(E, Math.abs(e[a]) + Math.abs(t[a])), c = a; c < r && !(Math.abs(t[c]) <= R * E); )
|
|
2839
|
+
c++;
|
|
2840
|
+
if (c > a)
|
|
2841
|
+
do {
|
|
2842
|
+
for (n = e[a], u = (e[a + 1] - n) / (2 * t[a]), m = ge(u, 1), u < 0 && (m = -m), e[a] = t[a] / (u + m), e[a + 1] = t[a] * (u + m), p = e[a + 1], o = n - e[a], i = a + 2; i < r; i++)
|
|
2843
|
+
e[i] -= o;
|
|
2844
|
+
for (x = x + o, u = e[c], g = 1, d = g, M = g, f = t[a + 1], w = 0, y = 0, i = c - 1; i >= a; i--)
|
|
2845
|
+
for (M = d, d = g, y = w, n = g * t[i], o = g * u, m = ge(u, t[i]), t[i + 1] = w * m, w = t[i] / m, g = u / m, u = g * e[i] - w * n, e[i + 1] = o + w * (g * n + w * e[i]), l = 0; l < r; l++)
|
|
2846
|
+
o = s.get(l, i + 1), s.set(l, i + 1, w * s.get(l, i) + g * o), s.set(l, i, g * s.get(l, i) - w * o);
|
|
2847
|
+
u = -w * y * M * f * t[a] / p, t[a] = w * u, e[a] = g * u;
|
|
2848
|
+
} while (Math.abs(t[a]) > R * E);
|
|
2849
|
+
e[a] = e[a] + x, t[a] = 0;
|
|
2850
|
+
}
|
|
2851
|
+
for (i = 0; i < r - 1; i++) {
|
|
2852
|
+
for (l = i, u = e[i], h = i + 1; h < r; h++)
|
|
2853
|
+
e[h] < u && (l = h, u = e[h]);
|
|
2854
|
+
if (l !== i)
|
|
2855
|
+
for (e[l] = e[i], e[i] = u, h = 0; h < r; h++)
|
|
2856
|
+
u = s.get(h, i), s.set(h, i, s.get(h, l)), s.set(h, l, u);
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
function pn(r, t, e, s) {
|
|
2860
|
+
let n = 0, o = r - 1, i, h, l, a, c, u, m;
|
|
2861
|
+
for (u = n + 1; u <= o - 1; u++) {
|
|
2862
|
+
for (m = 0, a = u; a <= o; a++)
|
|
2863
|
+
m = m + Math.abs(t.get(a, u - 1));
|
|
2864
|
+
if (m !== 0) {
|
|
2865
|
+
for (l = 0, a = o; a >= u; a--)
|
|
2866
|
+
e[a] = t.get(a, u - 1) / m, l += e[a] * e[a];
|
|
2867
|
+
for (h = Math.sqrt(l), e[u] > 0 && (h = -h), l = l - e[u] * h, e[u] = e[u] - h, c = u; c < r; c++) {
|
|
2868
|
+
for (i = 0, a = o; a >= u; a--)
|
|
2869
|
+
i += e[a] * t.get(a, c);
|
|
2870
|
+
for (i = i / l, a = u; a <= o; a++)
|
|
2871
|
+
t.set(a, c, t.get(a, c) - i * e[a]);
|
|
2872
|
+
}
|
|
2873
|
+
for (a = 0; a <= o; a++) {
|
|
2874
|
+
for (i = 0, c = o; c >= u; c--)
|
|
2875
|
+
i += e[c] * t.get(a, c);
|
|
2876
|
+
for (i = i / l, c = u; c <= o; c++)
|
|
2877
|
+
t.set(a, c, t.get(a, c) - i * e[c]);
|
|
2878
|
+
}
|
|
2879
|
+
e[u] = m * e[u], t.set(u, u - 1, m * h);
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
for (a = 0; a < r; a++)
|
|
2883
|
+
for (c = 0; c < r; c++)
|
|
2884
|
+
s.set(a, c, a === c ? 1 : 0);
|
|
2885
|
+
for (u = o - 1; u >= n + 1; u--)
|
|
2886
|
+
if (t.get(u, u - 1) !== 0) {
|
|
2887
|
+
for (a = u + 1; a <= o; a++)
|
|
2888
|
+
e[a] = t.get(a, u - 1);
|
|
2889
|
+
for (c = u; c <= o; c++) {
|
|
2890
|
+
for (h = 0, a = u; a <= o; a++)
|
|
2891
|
+
h += e[a] * s.get(a, c);
|
|
2892
|
+
for (h = h / e[u] / t.get(u, u - 1), a = u; a <= o; a++)
|
|
2893
|
+
s.set(a, c, s.get(a, c) + h * e[a]);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
function wn(r, t, e, s, n) {
|
|
2898
|
+
let o = r - 1, i = 0, h = r - 1, l = Number.EPSILON, a = 0, c = 0, u = 0, m = 0, p = 0, g = 0, d = 0, M = 0, f, w, y, x, E, R, k, P, T, $, N, K, Q, Z, j;
|
|
2899
|
+
for (f = 0; f < r; f++)
|
|
2900
|
+
for ((f < i || f > h) && (e[f] = n.get(f, f), t[f] = 0), w = Math.max(f - 1, 0); w < r; w++)
|
|
2901
|
+
c = c + Math.abs(n.get(f, w));
|
|
2902
|
+
for (; o >= i; ) {
|
|
2903
|
+
for (x = o; x > i && (g = Math.abs(n.get(x - 1, x - 1)) + Math.abs(n.get(x, x)), g === 0 && (g = c), !(Math.abs(n.get(x, x - 1)) < l * g)); )
|
|
2904
|
+
x--;
|
|
2905
|
+
if (x === o)
|
|
2906
|
+
n.set(o, o, n.get(o, o) + a), e[o] = n.get(o, o), t[o] = 0, o--, M = 0;
|
|
2907
|
+
else if (x === o - 1) {
|
|
2908
|
+
if (k = n.get(o, o - 1) * n.get(o - 1, o), u = (n.get(o - 1, o - 1) - n.get(o, o)) / 2, m = u * u + k, d = Math.sqrt(Math.abs(m)), n.set(o, o, n.get(o, o) + a), n.set(o - 1, o - 1, n.get(o - 1, o - 1) + a), P = n.get(o, o), m >= 0) {
|
|
2909
|
+
for (d = u >= 0 ? u + d : u - d, e[o - 1] = P + d, e[o] = e[o - 1], d !== 0 && (e[o] = P - k / d), t[o - 1] = 0, t[o] = 0, P = n.get(o, o - 1), g = Math.abs(P) + Math.abs(d), u = P / g, m = d / g, p = Math.sqrt(u * u + m * m), u = u / p, m = m / p, w = o - 1; w < r; w++)
|
|
2910
|
+
d = n.get(o - 1, w), n.set(o - 1, w, m * d + u * n.get(o, w)), n.set(o, w, m * n.get(o, w) - u * d);
|
|
2911
|
+
for (f = 0; f <= o; f++)
|
|
2912
|
+
d = n.get(f, o - 1), n.set(f, o - 1, m * d + u * n.get(f, o)), n.set(f, o, m * n.get(f, o) - u * d);
|
|
2913
|
+
for (f = i; f <= h; f++)
|
|
2914
|
+
d = s.get(f, o - 1), s.set(f, o - 1, m * d + u * s.get(f, o)), s.set(f, o, m * s.get(f, o) - u * d);
|
|
2915
|
+
} else
|
|
2916
|
+
e[o - 1] = P + u, e[o] = P + u, t[o - 1] = d, t[o] = -d;
|
|
2917
|
+
o = o - 2, M = 0;
|
|
2918
|
+
} else {
|
|
2919
|
+
if (P = n.get(o, o), T = 0, k = 0, x < o && (T = n.get(o - 1, o - 1), k = n.get(o, o - 1) * n.get(o - 1, o)), M === 10) {
|
|
2920
|
+
for (a += P, f = i; f <= o; f++)
|
|
2921
|
+
n.set(f, f, n.get(f, f) - P);
|
|
2922
|
+
g = Math.abs(n.get(o, o - 1)) + Math.abs(n.get(o - 1, o - 2)), P = T = 0.75 * g, k = -0.4375 * g * g;
|
|
2923
|
+
}
|
|
2924
|
+
if (M === 30 && (g = (T - P) / 2, g = g * g + k, g > 0)) {
|
|
2925
|
+
for (g = Math.sqrt(g), T < P && (g = -g), g = P - k / ((T - P) / 2 + g), f = i; f <= o; f++)
|
|
2926
|
+
n.set(f, f, n.get(f, f) - g);
|
|
2927
|
+
a += g, P = T = k = 0.964;
|
|
2928
|
+
}
|
|
2929
|
+
for (M = M + 1, E = o - 2; E >= x && (d = n.get(E, E), p = P - d, g = T - d, u = (p * g - k) / n.get(E + 1, E) + n.get(E, E + 1), m = n.get(E + 1, E + 1) - d - p - g, p = n.get(E + 2, E + 1), g = Math.abs(u) + Math.abs(m) + Math.abs(p), u = u / g, m = m / g, p = p / g, !(E === x || Math.abs(n.get(E, E - 1)) * (Math.abs(m) + Math.abs(p)) < l * (Math.abs(u) * (Math.abs(n.get(E - 1, E - 1)) + Math.abs(d) + Math.abs(n.get(E + 1, E + 1)))))); )
|
|
2930
|
+
E--;
|
|
2931
|
+
for (f = E + 2; f <= o; f++)
|
|
2932
|
+
n.set(f, f - 2, 0), f > E + 2 && n.set(f, f - 3, 0);
|
|
2933
|
+
for (y = E; y <= o - 1 && (Z = y !== o - 1, y !== E && (u = n.get(y, y - 1), m = n.get(y + 1, y - 1), p = Z ? n.get(y + 2, y - 1) : 0, P = Math.abs(u) + Math.abs(m) + Math.abs(p), P !== 0 && (u = u / P, m = m / P, p = p / P)), P !== 0); y++)
|
|
2934
|
+
if (g = Math.sqrt(u * u + m * m + p * p), u < 0 && (g = -g), g !== 0) {
|
|
2935
|
+
for (y !== E ? n.set(y, y - 1, -g * P) : x !== E && n.set(y, y - 1, -n.get(y, y - 1)), u = u + g, P = u / g, T = m / g, d = p / g, m = m / u, p = p / u, w = y; w < r; w++)
|
|
2936
|
+
u = n.get(y, w) + m * n.get(y + 1, w), Z && (u = u + p * n.get(y + 2, w), n.set(y + 2, w, n.get(y + 2, w) - u * d)), n.set(y, w, n.get(y, w) - u * P), n.set(y + 1, w, n.get(y + 1, w) - u * T);
|
|
2937
|
+
for (f = 0; f <= Math.min(o, y + 3); f++)
|
|
2938
|
+
u = P * n.get(f, y) + T * n.get(f, y + 1), Z && (u = u + d * n.get(f, y + 2), n.set(f, y + 2, n.get(f, y + 2) - u * p)), n.set(f, y, n.get(f, y) - u), n.set(f, y + 1, n.get(f, y + 1) - u * m);
|
|
2939
|
+
for (f = i; f <= h; f++)
|
|
2940
|
+
u = P * s.get(f, y) + T * s.get(f, y + 1), Z && (u = u + d * s.get(f, y + 2), s.set(f, y + 2, s.get(f, y + 2) - u * p)), s.set(f, y, s.get(f, y) - u), s.set(f, y + 1, s.get(f, y + 1) - u * m);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
if (c !== 0) {
|
|
2945
|
+
for (o = r - 1; o >= 0; o--)
|
|
2946
|
+
if (u = e[o], m = t[o], m === 0)
|
|
2947
|
+
for (x = o, n.set(o, o, 1), f = o - 1; f >= 0; f--) {
|
|
2948
|
+
for (k = n.get(f, f) - u, p = 0, w = x; w <= o; w++)
|
|
2949
|
+
p = p + n.get(f, w) * n.get(w, o);
|
|
2950
|
+
if (t[f] < 0)
|
|
2951
|
+
d = k, g = p;
|
|
2952
|
+
else if (x = f, t[f] === 0 ? n.set(f, o, k !== 0 ? -p / k : -p / (l * c)) : (P = n.get(f, f + 1), T = n.get(f + 1, f), m = (e[f] - u) * (e[f] - u) + t[f] * t[f], R = (P * g - d * p) / m, n.set(f, o, R), n.set(
|
|
2953
|
+
f + 1,
|
|
2954
|
+
o,
|
|
2955
|
+
Math.abs(P) > Math.abs(d) ? (-p - k * R) / P : (-g - T * R) / d
|
|
2956
|
+
)), R = Math.abs(n.get(f, o)), l * R * R > 1)
|
|
2957
|
+
for (w = f; w <= o; w++)
|
|
2958
|
+
n.set(w, o, n.get(w, o) / R);
|
|
2959
|
+
}
|
|
2960
|
+
else if (m < 0)
|
|
2961
|
+
for (x = o - 1, Math.abs(n.get(o, o - 1)) > Math.abs(n.get(o - 1, o)) ? (n.set(o - 1, o - 1, m / n.get(o, o - 1)), n.set(o - 1, o, -(n.get(o, o) - u) / n.get(o, o - 1))) : (j = _t(0, -n.get(o - 1, o), n.get(o - 1, o - 1) - u, m), n.set(o - 1, o - 1, j[0]), n.set(o - 1, o, j[1])), n.set(o, o - 1, 0), n.set(o, o, 1), f = o - 2; f >= 0; f--) {
|
|
2962
|
+
for ($ = 0, N = 0, w = x; w <= o; w++)
|
|
2963
|
+
$ = $ + n.get(f, w) * n.get(w, o - 1), N = N + n.get(f, w) * n.get(w, o);
|
|
2964
|
+
if (k = n.get(f, f) - u, t[f] < 0)
|
|
2965
|
+
d = k, p = $, g = N;
|
|
2966
|
+
else if (x = f, t[f] === 0 ? (j = _t(-$, -N, k, m), n.set(f, o - 1, j[0]), n.set(f, o, j[1])) : (P = n.get(f, f + 1), T = n.get(f + 1, f), K = (e[f] - u) * (e[f] - u) + t[f] * t[f] - m * m, Q = (e[f] - u) * 2 * m, K === 0 && Q === 0 && (K = l * c * (Math.abs(k) + Math.abs(m) + Math.abs(P) + Math.abs(T) + Math.abs(d))), j = _t(
|
|
2967
|
+
P * p - d * $ + m * N,
|
|
2968
|
+
P * g - d * N - m * $,
|
|
2969
|
+
K,
|
|
2970
|
+
Q
|
|
2971
|
+
), n.set(f, o - 1, j[0]), n.set(f, o, j[1]), Math.abs(P) > Math.abs(d) + Math.abs(m) ? (n.set(
|
|
2972
|
+
f + 1,
|
|
2973
|
+
o - 1,
|
|
2974
|
+
(-$ - k * n.get(f, o - 1) + m * n.get(f, o)) / P
|
|
2975
|
+
), n.set(
|
|
2976
|
+
f + 1,
|
|
2977
|
+
o,
|
|
2978
|
+
(-N - k * n.get(f, o) - m * n.get(f, o - 1)) / P
|
|
2979
|
+
)) : (j = _t(
|
|
2980
|
+
-p - T * n.get(f, o - 1),
|
|
2981
|
+
-g - T * n.get(f, o),
|
|
2982
|
+
d,
|
|
2983
|
+
m
|
|
2984
|
+
), n.set(f + 1, o - 1, j[0]), n.set(f + 1, o, j[1]))), R = Math.max(Math.abs(n.get(f, o - 1)), Math.abs(n.get(f, o))), l * R * R > 1)
|
|
2985
|
+
for (w = f; w <= o; w++)
|
|
2986
|
+
n.set(w, o - 1, n.get(w, o - 1) / R), n.set(w, o, n.get(w, o) / R);
|
|
2987
|
+
}
|
|
2988
|
+
for (f = 0; f < r; f++)
|
|
2989
|
+
if (f < i || f > h)
|
|
2990
|
+
for (w = f; w < r; w++)
|
|
2991
|
+
s.set(f, w, n.get(f, w));
|
|
2992
|
+
for (w = r - 1; w >= i; w--)
|
|
2993
|
+
for (f = i; f <= h; f++) {
|
|
2994
|
+
for (d = 0, y = i; y <= Math.min(w, h); y++)
|
|
2995
|
+
d = d + s.get(f, y) * n.get(y, w);
|
|
2996
|
+
s.set(f, w, d);
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
function _t(r, t, e, s) {
|
|
3001
|
+
let n, o;
|
|
3002
|
+
return Math.abs(e) > Math.abs(s) ? (n = s / e, o = e + n * s, [(r + n * t) / o, (t - n * r) / o]) : (n = e / s, o = s + n * e, [(n * r + t) / o, (n * t - r) / o]);
|
|
3003
|
+
}
|
|
3004
|
+
function Ye(r, t = 1e-9) {
|
|
3005
|
+
if (r[r.length - 1] == 0)
|
|
3006
|
+
return Ye(r.slice(0, -1), t);
|
|
3007
|
+
const e = new v([
|
|
3008
|
+
r.slice(0, -1).reverse().map((n) => -n / r[r.length - 1]),
|
|
3009
|
+
...Array.from({ length: r.length - 2 }, (n, o) => {
|
|
3010
|
+
const i = new Array(r.length - 1).fill(0);
|
|
3011
|
+
return i[o] = 1, i;
|
|
3012
|
+
})
|
|
3013
|
+
]), s = new fn(e);
|
|
3014
|
+
return s.realEigenvalues.filter(
|
|
3015
|
+
(n, o) => Math.abs(s.imaginaryEigenvalues[o]) < t
|
|
3016
|
+
);
|
|
3017
|
+
}
|
|
3018
|
+
function De(r, t) {
|
|
3019
|
+
const e = Math.max(r.precision, t.precision), s = r.coefficients, n = s.x2, o = s.xy, i = s.y2, h = s.x, l = s.y, a = s.c, c = t.coefficients, u = c.x2, m = c.xy, p = c.y2, g = c.x, d = c.y, M = c.c, f = {
|
|
3020
|
+
z0: a * n * g * g + n * n * M * M - h * n * g * M + u * u * a * a - 2 * n * M * u * a - h * g * u * a + u * h * h * M,
|
|
3021
|
+
z1: d * h * h * u - M * g * n * o - 2 * n * M * u * l - a * u * m * h + 2 * g * m * n * a + 2 * d * M * n * n + g * g * n * l - d * g * n * h - 2 * n * d * u * a - a * u * g * o + 2 * a * l * u * u - M * m * n * h - l * u * g * h + 2 * M * o * u * h,
|
|
3022
|
+
z2: d * d * n * n + 2 * p * M * n * n - l * u * g * o + M * u * o * o - l * u * m * h - M * m * n * o - 2 * n * d * u * l + 2 * g * m * n * l - p * g * n * h - 2 * n * p * u * a + m * m * n * a + 2 * d * o * u * h + l * l * u * u - i * u * g * h - d * m * n * h + 2 * a * i * u * u - a * u * m * o + p * h * h * u + g * g * n * i - d * g * n * o - 2 * n * M * u * i,
|
|
3023
|
+
z3: -2 * n * u * i * d + d * u * o * o + 2 * p * o * u * h - i * u * m * h + m * m * n * l - d * m * n * o - 2 * n * p * u * l - l * u * m * o - p * m * n * h + 2 * d * p * n * n + 2 * l * i * u * u - i * u * g * o + 2 * g * m * n * i - p * g * n * o,
|
|
3024
|
+
z4: n * n * p * p - 2 * n * p * u * i + u * u * i * i - o * n * m * p - o * m * u * i + o * o * u * p + i * n * m * m
|
|
3025
|
+
}, w = Ye(
|
|
3026
|
+
[f.z0, f.z1, f.z2, f.z3, f.z4],
|
|
3027
|
+
e
|
|
3028
|
+
).flatMap((y) => {
|
|
3029
|
+
const x = n * m * y + n * g - u * o * y - u * h;
|
|
3030
|
+
if (x)
|
|
3031
|
+
return [[-(n * M + n * p * y * y - u * i * y * y + n * d * y - u * l * y - u * a) / x, y]];
|
|
3032
|
+
const E = o * y + h, R = -E / (2 * n), k = i * y * y + l * y + a, P = E * E / (4 * n * n) - k / n;
|
|
3033
|
+
if (Math.abs(P) < e)
|
|
3034
|
+
return [[R, y]];
|
|
3035
|
+
if (P > 0) {
|
|
3036
|
+
const T = Math.sqrt(P);
|
|
3037
|
+
return [[R + T, y], [R - T, y]];
|
|
3038
|
+
}
|
|
3039
|
+
return [];
|
|
3040
|
+
});
|
|
3041
|
+
return at(w, e);
|
|
3042
|
+
}
|
|
3043
|
+
function pe(r, t) {
|
|
3044
|
+
return De(r, t).filter((e) => r.isOnSegment(e) && t.isOnSegment(e));
|
|
3045
|
+
}
|
|
3046
|
+
const dn = (r) => {
|
|
3047
|
+
const {
|
|
3048
|
+
firstPoint: t,
|
|
3049
|
+
lastPoint: e,
|
|
3050
|
+
center: s,
|
|
3051
|
+
majorRadius: n,
|
|
3052
|
+
minorRadius: o,
|
|
3053
|
+
tiltAngle: i,
|
|
3054
|
+
clockwise: h
|
|
3055
|
+
} = r;
|
|
3056
|
+
return new O(
|
|
3057
|
+
e,
|
|
3058
|
+
t,
|
|
3059
|
+
s,
|
|
3060
|
+
n,
|
|
3061
|
+
o,
|
|
3062
|
+
i,
|
|
3063
|
+
h,
|
|
3064
|
+
{
|
|
3065
|
+
ignoreChecks: !0,
|
|
3066
|
+
angleUnits: "rad"
|
|
3067
|
+
}
|
|
3068
|
+
);
|
|
3069
|
+
}, yn = (r, t) => {
|
|
3070
|
+
if (r.isSame(t))
|
|
3071
|
+
return [r];
|
|
3072
|
+
const e = (n, o) => new O(
|
|
3073
|
+
n,
|
|
3074
|
+
o,
|
|
3075
|
+
r.center,
|
|
3076
|
+
r.majorRadius,
|
|
3077
|
+
r.minorRadius,
|
|
3078
|
+
r.tiltAngle,
|
|
3079
|
+
r.clockwise,
|
|
3080
|
+
{ ignoreChecks: !0, angleUnits: "rad" }
|
|
3081
|
+
), s = at(
|
|
3082
|
+
[
|
|
3083
|
+
t.isOnSegment(r.firstPoint) ? r.firstPoint : null,
|
|
3084
|
+
t.isOnSegment(r.lastPoint) ? r.lastPoint : null,
|
|
3085
|
+
r.isOnSegment(t.firstPoint) ? t.firstPoint : null,
|
|
3086
|
+
r.isOnSegment(t.lastPoint) ? t.lastPoint : null
|
|
3087
|
+
].filter((n) => n !== null)
|
|
3088
|
+
// We sort by the param value of the first arc. This means that the points
|
|
3089
|
+
// will be sorted with the same orientation than arc1
|
|
3090
|
+
).sort((n, o) => r.pointToParam(n) - r.pointToParam(o));
|
|
3091
|
+
if (s.length === 0)
|
|
3092
|
+
return [];
|
|
3093
|
+
if (s.length === 1)
|
|
3094
|
+
return [];
|
|
3095
|
+
if (s.length === 2)
|
|
3096
|
+
return r.isSame(dn(t)) ? [] : [e(s[0], s[1])];
|
|
3097
|
+
if (s.length === 3) {
|
|
3098
|
+
const n = b(s[0], t.lastPoint) || b(s[0], t.firstPoint) ? 1 : 0;
|
|
3099
|
+
return [e(s[0 + n], s[1 + n])];
|
|
3100
|
+
} else if (s.length === 4)
|
|
3101
|
+
return [e(s[0], s[1]), e(s[2], s[3])];
|
|
3102
|
+
throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm");
|
|
3103
|
+
};
|
|
3104
|
+
function Mn(r, t, e = !1) {
|
|
3105
|
+
const s = Math.max(r.precision, t.precision);
|
|
3106
|
+
return b(r.center, t.center) && Math.abs(r.majorRadius - t.majorRadius) < s && Math.abs(r.minorRadius - t.minorRadius) < s && (Math.abs(r.tiltAngle - t.tiltAngle) < s || Math.abs(Math.abs(r.tiltAngle - t.tiltAngle) - Math.PI) < s) ? e ? yn(r, t) : [] : De(r, t).filter((n) => r.isOnSegment(n) && t.isOnSegment(n));
|
|
3107
|
+
}
|
|
3108
|
+
function bn(r, t, e) {
|
|
3109
|
+
if (r instanceof A && t instanceof A) {
|
|
3110
|
+
const s = Ve(
|
|
3111
|
+
r,
|
|
3112
|
+
t,
|
|
3113
|
+
!1,
|
|
3114
|
+
e
|
|
3115
|
+
);
|
|
3116
|
+
return s === null ? [] : [s];
|
|
3117
|
+
}
|
|
3118
|
+
if (r instanceof A && t instanceof S)
|
|
3119
|
+
return Ct(r, t, e);
|
|
3120
|
+
if (r instanceof S && t instanceof A)
|
|
3121
|
+
return Ct(t, r, e);
|
|
3122
|
+
if (r instanceof S && t instanceof S)
|
|
3123
|
+
return qe(r, t, !1, e);
|
|
3124
|
+
throw new Error("Not implemented");
|
|
3125
|
+
}
|
|
3126
|
+
function Et(r, t, e) {
|
|
3127
|
+
if (r instanceof A && t instanceof A) {
|
|
3128
|
+
const s = Ve(
|
|
3129
|
+
r,
|
|
3130
|
+
t,
|
|
3131
|
+
!0,
|
|
3132
|
+
e
|
|
3133
|
+
);
|
|
3134
|
+
return s === null ? { intersections: [], overlaps: [], count: 0 } : s instanceof A ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
|
|
3135
|
+
}
|
|
3136
|
+
if (!r.boundingBox.overlaps(t.boundingBox))
|
|
3137
|
+
return { intersections: [], overlaps: [], count: 0 };
|
|
3138
|
+
if (r instanceof A && t instanceof S) {
|
|
3139
|
+
const s = Ct(r, t, e);
|
|
3140
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3141
|
+
}
|
|
3142
|
+
if (r instanceof S && t instanceof A) {
|
|
3143
|
+
const s = Ct(t, r, e);
|
|
3144
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3145
|
+
}
|
|
3146
|
+
if (r instanceof S && t instanceof S) {
|
|
3147
|
+
const s = qe(
|
|
3148
|
+
r,
|
|
3149
|
+
t,
|
|
3150
|
+
!0,
|
|
3151
|
+
e
|
|
3152
|
+
);
|
|
3153
|
+
return s.length ? s[0] instanceof S ? {
|
|
3154
|
+
intersections: [],
|
|
3155
|
+
overlaps: s,
|
|
3156
|
+
count: s.length
|
|
3157
|
+
} : {
|
|
3158
|
+
intersections: s,
|
|
3159
|
+
overlaps: [],
|
|
3160
|
+
count: s.length
|
|
3161
|
+
} : { intersections: [], overlaps: [], count: 0 };
|
|
3162
|
+
}
|
|
3163
|
+
if (r instanceof A && t instanceof O) {
|
|
3164
|
+
const s = Yt(
|
|
3165
|
+
r,
|
|
3166
|
+
t,
|
|
3167
|
+
e
|
|
3168
|
+
);
|
|
3169
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3170
|
+
}
|
|
3171
|
+
if (t instanceof A && r instanceof O) {
|
|
3172
|
+
const s = Yt(
|
|
3173
|
+
t,
|
|
3174
|
+
r,
|
|
3175
|
+
e
|
|
3176
|
+
);
|
|
3177
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3178
|
+
}
|
|
3179
|
+
if (r instanceof S && t instanceof O) {
|
|
3180
|
+
const s = pe(r, t);
|
|
3181
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3182
|
+
}
|
|
3183
|
+
if (t instanceof S && r instanceof O) {
|
|
3184
|
+
const s = pe(t, r);
|
|
3185
|
+
return { intersections: s, overlaps: [], count: s.length };
|
|
3186
|
+
}
|
|
3187
|
+
if (r instanceof O && t instanceof O) {
|
|
3188
|
+
const s = Mn(
|
|
3189
|
+
r,
|
|
3190
|
+
t,
|
|
3191
|
+
!0
|
|
3192
|
+
);
|
|
3193
|
+
return s.length ? s[0] instanceof O ? {
|
|
3194
|
+
intersections: [],
|
|
3195
|
+
overlaps: s,
|
|
3196
|
+
count: s.length
|
|
3197
|
+
} : {
|
|
3198
|
+
intersections: s,
|
|
3199
|
+
overlaps: [],
|
|
3200
|
+
count: s.length
|
|
3201
|
+
} : { intersections: [], overlaps: [], count: 0 };
|
|
3202
|
+
}
|
|
3203
|
+
throw new Error("Not implemented");
|
|
3204
|
+
}
|
|
3205
|
+
function Xe(r) {
|
|
3206
|
+
const t = [];
|
|
3207
|
+
for (let e = 0; e < r; e++)
|
|
3208
|
+
for (let s = 0; s <= e; s++)
|
|
3209
|
+
t.push([e, s]);
|
|
3210
|
+
return t;
|
|
3211
|
+
}
|
|
3212
|
+
function* Dt(r) {
|
|
3213
|
+
for (const [t, e] of Xe(r.length))
|
|
3214
|
+
t !== e && (yield [r[t], r[e]]);
|
|
3215
|
+
}
|
|
3216
|
+
class We extends lt {
|
|
3217
|
+
constructor(t, { ignoreChecks: e = !1 } = {}) {
|
|
3218
|
+
super(), this._boundingBox = null, e || Ge(t), this.segments = t;
|
|
3219
|
+
}
|
|
3220
|
+
get repr() {
|
|
3221
|
+
return this.segments.map((t) => t.repr).join(`
|
|
3222
|
+
`) + `
|
|
3223
|
+
`;
|
|
3224
|
+
}
|
|
3225
|
+
get info() {
|
|
3226
|
+
return this.repr;
|
|
3227
|
+
}
|
|
3228
|
+
get firstPoint() {
|
|
3229
|
+
return this.segments[0].firstPoint;
|
|
3230
|
+
}
|
|
3231
|
+
get lastPoint() {
|
|
3232
|
+
return this.segments[this.segments.length - 1].lastPoint;
|
|
3233
|
+
}
|
|
3234
|
+
get segmentsCount() {
|
|
3235
|
+
return this.segments.length;
|
|
3236
|
+
}
|
|
3237
|
+
onStroke(t) {
|
|
3238
|
+
return this.segments.some((e) => e.isOnSegment(t));
|
|
3239
|
+
}
|
|
3240
|
+
intersects(t) {
|
|
3241
|
+
return this.boundingBox.overlaps(t.boundingBox) ? this.segments.some(
|
|
3242
|
+
(e) => t.segments.some(
|
|
3243
|
+
(s) => Et(e, s).count > 0
|
|
3244
|
+
)
|
|
3245
|
+
) : !1;
|
|
3246
|
+
}
|
|
3247
|
+
overlappingSegments(t) {
|
|
3248
|
+
return this.segments.flatMap((e) => t.segments.flatMap((s) => e.boundingBox.overlaps(s.boundingBox) ? Et(e, s).overlaps : []));
|
|
3249
|
+
}
|
|
3250
|
+
get boundingBox() {
|
|
3251
|
+
if (this._boundingBox === null) {
|
|
3252
|
+
let t = this.segments[0].boundingBox;
|
|
3253
|
+
this.segments.slice(1).forEach((e) => {
|
|
3254
|
+
t = t.merge(e.boundingBox);
|
|
3255
|
+
}), this._boundingBox = t;
|
|
3256
|
+
}
|
|
3257
|
+
return this._boundingBox;
|
|
3258
|
+
}
|
|
3259
|
+
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
3260
|
+
return this.repr;
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
function Pn(r, t = "Stroke") {
|
|
3264
|
+
Xe(r.length).forEach(
|
|
3265
|
+
([e, s]) => {
|
|
3266
|
+
if (e === s)
|
|
3267
|
+
return;
|
|
3268
|
+
const n = r[e], o = r[s], i = Et(n, o), h = Math.max(n.precision, o.precision);
|
|
3269
|
+
if (i.count !== 0) {
|
|
3270
|
+
if (i.count === 1 && !i.overlaps.length) {
|
|
3271
|
+
const l = e - s, a = i.intersections[0];
|
|
3272
|
+
if (l === 1 && b(n.firstPoint, a, h) || l === -1 && b(n.lastPoint, a, h) || l === r.length - 1 && b(n.lastPoint, a, h) && b(o.firstPoint, a, h) || -l === r.length - 1 && b(n.firstPoint, a, h) && b(o.lastPoint, a, h))
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3275
|
+
if (!(i.count === 2 && r.length === 2 && (b(
|
|
3276
|
+
n.firstPoint,
|
|
3277
|
+
i.intersections[0],
|
|
3278
|
+
h
|
|
3279
|
+
) && b(
|
|
3280
|
+
n.lastPoint,
|
|
3281
|
+
i.intersections[1],
|
|
3282
|
+
h
|
|
3283
|
+
) || b(
|
|
3284
|
+
n.firstPoint,
|
|
3285
|
+
i.intersections[1],
|
|
3286
|
+
h
|
|
3287
|
+
) && b(
|
|
3288
|
+
n.lastPoint,
|
|
3289
|
+
i.intersections[0],
|
|
3290
|
+
h
|
|
3291
|
+
))))
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
`${t} segments must not intersect, but segments ${n.info} and ${o.info} do at ${JSON.stringify(
|
|
3294
|
+
i.intersections
|
|
3295
|
+
)}`
|
|
3296
|
+
);
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
);
|
|
3300
|
+
}
|
|
3301
|
+
function Ge(r, t = "Stroke") {
|
|
3302
|
+
if (r.length === 0)
|
|
3303
|
+
throw new Error(`${t} must have at least one segment`);
|
|
3304
|
+
et([r.slice(0, -1), r.slice(1)]).forEach(
|
|
3305
|
+
([e, s]) => {
|
|
3306
|
+
if (!b(e.lastPoint, s.firstPoint))
|
|
3307
|
+
throw new Error(
|
|
3308
|
+
`${t} segments must be connected, but ${e.info} and ${s.info} are not`
|
|
3309
|
+
);
|
|
3310
|
+
}
|
|
3311
|
+
), Pn(r, t);
|
|
3312
|
+
}
|
|
3313
|
+
function we(r, t) {
|
|
3314
|
+
return !!(r instanceof A && t instanceof A && Zt(r.V, t.V) || r instanceof S && t instanceof S && b(r.center, t.center) && r.radius - t.radius < r.precision);
|
|
3315
|
+
}
|
|
3316
|
+
function de(r, t) {
|
|
3317
|
+
if (r instanceof A && t instanceof A)
|
|
3318
|
+
return new A(r.firstPoint, t.lastPoint);
|
|
3319
|
+
if (r instanceof S && t instanceof S)
|
|
3320
|
+
return new S(
|
|
3321
|
+
r.firstPoint,
|
|
3322
|
+
t.lastPoint,
|
|
3323
|
+
r.center,
|
|
3324
|
+
r.clockwise
|
|
3325
|
+
);
|
|
3326
|
+
throw new Error("Not implemented");
|
|
3327
|
+
}
|
|
3328
|
+
function He(r) {
|
|
3329
|
+
let t = !1;
|
|
3330
|
+
const e = [];
|
|
3331
|
+
for (const s of r.segments) {
|
|
3332
|
+
if (e.length === 0) {
|
|
3333
|
+
e.push(s);
|
|
3334
|
+
continue;
|
|
3335
|
+
}
|
|
3336
|
+
const n = e[e.length - 1];
|
|
3337
|
+
we(n, s) ? (t = !0, e.pop(), e.push(de(n, s))) : e.push(s);
|
|
3338
|
+
}
|
|
3339
|
+
if (b(r.firstPoint, r.lastPoint) && we(
|
|
3340
|
+
e[0],
|
|
3341
|
+
e[e.length - 1]
|
|
3342
|
+
)) {
|
|
3343
|
+
t = !0;
|
|
3344
|
+
const s = e.pop();
|
|
3345
|
+
e[0] = de(s, e[0]);
|
|
3346
|
+
}
|
|
3347
|
+
return t ? e : null;
|
|
3348
|
+
}
|
|
3349
|
+
let st = class pt extends We {
|
|
3350
|
+
constructor() {
|
|
3351
|
+
super(...arguments), this.strokeType = "STRAND";
|
|
3352
|
+
}
|
|
3353
|
+
reverse() {
|
|
3354
|
+
const t = this.segments.map((e) => e.reverse());
|
|
3355
|
+
return t.reverse(), new pt(t, { ignoreChecks: !0 });
|
|
3356
|
+
}
|
|
3357
|
+
clone() {
|
|
3358
|
+
return new pt(
|
|
3359
|
+
this.segments.map((t) => t.clone()),
|
|
3360
|
+
{ ignoreChecks: !0 }
|
|
3361
|
+
);
|
|
3362
|
+
}
|
|
3363
|
+
extend(t) {
|
|
3364
|
+
if (!b(this.lastPoint, t.firstPoint))
|
|
3365
|
+
throw console.error(this.repr, t.repr), new Error("Cannot extend strand: connection point is not the same");
|
|
3366
|
+
return new pt([...this.segments, ...t.segments]);
|
|
3367
|
+
}
|
|
3368
|
+
simplify() {
|
|
3369
|
+
const t = He(this);
|
|
3370
|
+
return t ? new pt(t, { ignoreChecks: !0 }) : this;
|
|
3371
|
+
}
|
|
3372
|
+
transform(t) {
|
|
3373
|
+
return new pt(
|
|
3374
|
+
this.segments.map((e) => e.transform(t)),
|
|
3375
|
+
{ ignoreChecks: !0 }
|
|
3376
|
+
);
|
|
3377
|
+
}
|
|
3378
|
+
};
|
|
3379
|
+
const xn = (r, t) => {
|
|
3380
|
+
const e = Vt(t, {
|
|
3381
|
+
V: [1, 0],
|
|
3382
|
+
firstPoint: r,
|
|
3383
|
+
precision: t.precision
|
|
3384
|
+
});
|
|
3385
|
+
if (e === "parallel")
|
|
3386
|
+
return 0;
|
|
3387
|
+
const { intersectionParam1: s, intersectionParam2: n } = e;
|
|
3388
|
+
if (!t.isValidParameter(s) || n <= -t.precision)
|
|
3389
|
+
return 0;
|
|
3390
|
+
if (Math.abs(s) < t.precision || Math.abs(s - 1) < t.precision) {
|
|
3391
|
+
const [, o] = t.midPoint;
|
|
3392
|
+
return r[1] - o < 0 ? 1 : 0;
|
|
3393
|
+
}
|
|
3394
|
+
return 1;
|
|
3395
|
+
};
|
|
3396
|
+
class Je {
|
|
3397
|
+
constructor(t) {
|
|
3398
|
+
this._count = 0, this.segment = t;
|
|
3399
|
+
}
|
|
3400
|
+
update(t, e = !1) {
|
|
3401
|
+
!e && !this.segment.isOnSegment(t) || (b(t, this.segment.firstPoint) ? this._count += this.segment.tangentAtFirstPoint[1] > 0 ? 1 : 0 : b(t, this.segment.lastPoint) ? this._count += this.segment.tangentAtLastPoint[1] > 0 ? 0 : 1 : this._count += 1);
|
|
3402
|
+
}
|
|
3403
|
+
get count() {
|
|
3404
|
+
return this._count;
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
const En = (r, t) => {
|
|
3408
|
+
const e = t.precision, s = Math.abs(r[1] - t.center[1]);
|
|
3409
|
+
if (s > t.radius + e)
|
|
3410
|
+
return 0;
|
|
3411
|
+
const n = xt(r, t.center), o = t.radius * t.radius, i = e * e;
|
|
3412
|
+
if (Math.abs(n - o) < i && t.isOnSegment(r))
|
|
3413
|
+
return 0;
|
|
3414
|
+
const h = n - o > i;
|
|
3415
|
+
if (h && t.center[0] < r[0])
|
|
3416
|
+
return 0;
|
|
3417
|
+
const l = Math.sqrt(
|
|
3418
|
+
t.radius * t.radius - s * s
|
|
3419
|
+
), a = new Je(t);
|
|
3420
|
+
return a.update([t.center[0] + l, r[1]]), h && a.update([t.center[0] - l, r[1]]), a.count;
|
|
3421
|
+
}, vn = (r, t) => {
|
|
3422
|
+
const e = t.boundingBox.xMax + t.boundingBox.width / 2, s = new A(r, [e, r[1]]), n = new Je(t);
|
|
3423
|
+
return Yt(s, t).forEach((o) => {
|
|
3424
|
+
n.update(o, !0);
|
|
3425
|
+
}), n.count;
|
|
3426
|
+
};
|
|
3427
|
+
function An(r, t) {
|
|
3428
|
+
if (t instanceof A)
|
|
3429
|
+
return xn(r, t);
|
|
3430
|
+
if (t instanceof S)
|
|
3431
|
+
return En(r, t);
|
|
3432
|
+
if (t instanceof O)
|
|
3433
|
+
return vn(r, t);
|
|
3434
|
+
throw new Error("Not implemented");
|
|
3435
|
+
}
|
|
3436
|
+
class W extends We {
|
|
3437
|
+
constructor(t, { ignoreChecks: e = !1 } = {}) {
|
|
3438
|
+
super(t, { ignoreChecks: !0 }), this.strokeType = "LOOP", this._clockwise = null, e || Sn(t);
|
|
3439
|
+
}
|
|
3440
|
+
get clockwise() {
|
|
3441
|
+
if (this._clockwise === null) {
|
|
3442
|
+
const t = this.segments.flatMap((s) => s instanceof A ? [s.firstPoint] : [s.firstPoint, s.paramPoint(0.5)]), e = t.map((s, n) => {
|
|
3443
|
+
const o = t[(n + 1) % t.length];
|
|
3444
|
+
return (o[0] - s[0]) * (o[1] + s[1]);
|
|
3445
|
+
}).reduce((s, n) => s + n, 0);
|
|
3446
|
+
this._clockwise = e > 0;
|
|
3447
|
+
}
|
|
3448
|
+
return this._clockwise;
|
|
3449
|
+
}
|
|
3450
|
+
clone() {
|
|
3451
|
+
return new W(
|
|
3452
|
+
this.segments.map((t) => t.clone()),
|
|
3453
|
+
{ ignoreChecks: !0 }
|
|
3454
|
+
);
|
|
3455
|
+
}
|
|
3456
|
+
reverse() {
|
|
3457
|
+
const t = this.segments.map((e) => e.reverse());
|
|
3458
|
+
return t.reverse(), new W(t, { ignoreChecks: !0 });
|
|
3459
|
+
}
|
|
3460
|
+
transform(t) {
|
|
3461
|
+
return new W(
|
|
3462
|
+
this.segments.map((e) => e.transform(t)),
|
|
3463
|
+
{ ignoreChecks: !0 }
|
|
3464
|
+
);
|
|
3465
|
+
}
|
|
3466
|
+
contains(t) {
|
|
3467
|
+
return this.onStroke(t) || !this.boundingBox.contains(t) ? !1 : this.segments.reduce((e, s) => e + An(t, s), 0) % 2 === 1;
|
|
3468
|
+
}
|
|
3469
|
+
simplify() {
|
|
3470
|
+
const t = He(this);
|
|
3471
|
+
return t ? new W(t, { ignoreChecks: !0 }) : this;
|
|
3472
|
+
}
|
|
3473
|
+
}
|
|
3474
|
+
function Sn(r) {
|
|
3475
|
+
if (Ge(r, "Loop"), !b(r[0].firstPoint, r[r.length - 1].lastPoint))
|
|
3476
|
+
throw new Error("Loop segment must be closed");
|
|
3477
|
+
}
|
|
3478
|
+
function Ke(r) {
|
|
3479
|
+
if (r instanceof A)
|
|
3480
|
+
return {
|
|
3481
|
+
type: r.segmentType,
|
|
3482
|
+
firstPoint: r.firstPoint,
|
|
3483
|
+
lastPoint: r.lastPoint
|
|
3484
|
+
};
|
|
3485
|
+
if (r instanceof S)
|
|
3486
|
+
return {
|
|
3487
|
+
type: r.segmentType,
|
|
3488
|
+
firstPoint: r.firstPoint,
|
|
3489
|
+
lastPoint: r.lastPoint,
|
|
3490
|
+
center: r.center,
|
|
3491
|
+
clockwise: r.clockwise
|
|
3492
|
+
};
|
|
3493
|
+
if (r instanceof O)
|
|
3494
|
+
return {
|
|
3495
|
+
type: r.segmentType,
|
|
3496
|
+
firstPoint: r.firstPoint,
|
|
3497
|
+
lastPoint: r.lastPoint,
|
|
3498
|
+
center: r.center,
|
|
3499
|
+
clockwise: r.clockwise,
|
|
3500
|
+
majorRadius: r.majorRadius,
|
|
3501
|
+
minorRadius: r.minorRadius,
|
|
3502
|
+
tiltAngle: r.tiltAngle
|
|
3503
|
+
};
|
|
3504
|
+
throw new Error("Unknown segment type");
|
|
3505
|
+
}
|
|
3506
|
+
function Xt(r) {
|
|
3507
|
+
return {
|
|
3508
|
+
type: "LOOP",
|
|
3509
|
+
segments: r.segments.map(Ke)
|
|
3510
|
+
};
|
|
3511
|
+
}
|
|
3512
|
+
function Qe(r) {
|
|
3513
|
+
return {
|
|
3514
|
+
type: "FIGURE",
|
|
3515
|
+
contour: Xt(r.contour),
|
|
3516
|
+
holes: r.holes.map(Xt)
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
function kn(r) {
|
|
3520
|
+
return {
|
|
3521
|
+
type: "DIAGRAM",
|
|
3522
|
+
figures: r.figures.map(Qe)
|
|
3523
|
+
};
|
|
3524
|
+
}
|
|
3525
|
+
function ye(r) {
|
|
3526
|
+
if (r instanceof At)
|
|
3527
|
+
return kn(r);
|
|
3528
|
+
if (r instanceof X)
|
|
3529
|
+
return Qe(r);
|
|
3530
|
+
if (r instanceof W)
|
|
3531
|
+
return Xt(r);
|
|
3532
|
+
if (r instanceof S || r instanceof A)
|
|
3533
|
+
return Ke(r);
|
|
3534
|
+
throw new Error("Unknown shape type");
|
|
3535
|
+
}
|
|
3536
|
+
class Rn {
|
|
3537
|
+
constructor() {
|
|
3538
|
+
this.ids = [], this.values = [], this.length = 0;
|
|
3539
|
+
}
|
|
3540
|
+
clear() {
|
|
3541
|
+
this.length = 0;
|
|
3542
|
+
}
|
|
3543
|
+
push(t, e) {
|
|
3544
|
+
let s = this.length++;
|
|
3545
|
+
for (; s > 0; ) {
|
|
3546
|
+
const n = s - 1 >> 1, o = this.values[n];
|
|
3547
|
+
if (e >= o)
|
|
3548
|
+
break;
|
|
3549
|
+
this.ids[s] = this.ids[n], this.values[s] = o, s = n;
|
|
3550
|
+
}
|
|
3551
|
+
this.ids[s] = t, this.values[s] = e;
|
|
3552
|
+
}
|
|
3553
|
+
pop() {
|
|
3554
|
+
if (this.length === 0)
|
|
3555
|
+
return;
|
|
3556
|
+
const t = this.ids[0];
|
|
3557
|
+
if (this.length--, this.length > 0) {
|
|
3558
|
+
const e = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], n = this.length >> 1;
|
|
3559
|
+
let o = 0;
|
|
3560
|
+
for (; o < n; ) {
|
|
3561
|
+
let i = (o << 1) + 1;
|
|
3562
|
+
const h = i + 1;
|
|
3563
|
+
let l = this.ids[i], a = this.values[i];
|
|
3564
|
+
const c = this.values[h];
|
|
3565
|
+
if (h < this.length && c < a && (i = h, l = this.ids[h], a = c), a >= s)
|
|
3566
|
+
break;
|
|
3567
|
+
this.ids[o] = l, this.values[o] = a, o = i;
|
|
3568
|
+
}
|
|
3569
|
+
this.ids[o] = e, this.values[o] = s;
|
|
3570
|
+
}
|
|
3571
|
+
return t;
|
|
3572
|
+
}
|
|
3573
|
+
peek() {
|
|
3574
|
+
if (this.length !== 0)
|
|
3575
|
+
return this.ids[0];
|
|
3576
|
+
}
|
|
3577
|
+
peekValue() {
|
|
3578
|
+
if (this.length !== 0)
|
|
3579
|
+
return this.values[0];
|
|
3580
|
+
}
|
|
3581
|
+
shrink() {
|
|
3582
|
+
this.ids.length = this.values.length = this.length;
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
const Me = [
|
|
3586
|
+
Int8Array,
|
|
3587
|
+
Uint8Array,
|
|
3588
|
+
Uint8ClampedArray,
|
|
3589
|
+
Int16Array,
|
|
3590
|
+
Uint16Array,
|
|
3591
|
+
Int32Array,
|
|
3592
|
+
Uint32Array,
|
|
3593
|
+
Float32Array,
|
|
3594
|
+
Float64Array
|
|
3595
|
+
], Ot = 3;
|
|
3596
|
+
class ee {
|
|
3597
|
+
static from(t) {
|
|
3598
|
+
if (!t || t.byteLength === void 0 || t.buffer)
|
|
3599
|
+
throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
|
|
3600
|
+
const [e, s] = new Uint8Array(t, 0, 2);
|
|
3601
|
+
if (e !== 251)
|
|
3602
|
+
throw new Error("Data does not appear to be in a Flatbush format.");
|
|
3603
|
+
if (s >> 4 !== Ot)
|
|
3604
|
+
throw new Error(`Got v${s >> 4} data when expected v${Ot}.`);
|
|
3605
|
+
const [n] = new Uint16Array(t, 2, 1), [o] = new Uint32Array(t, 4, 1);
|
|
3606
|
+
return new ee(o, n, Me[s & 15], void 0, t);
|
|
3607
|
+
}
|
|
3608
|
+
constructor(t, e = 16, s = Float64Array, n = ArrayBuffer, o) {
|
|
3609
|
+
if (t === void 0)
|
|
3610
|
+
throw new Error("Missing required argument: numItems.");
|
|
3611
|
+
if (isNaN(t) || t <= 0)
|
|
3612
|
+
throw new Error(`Unexpected numItems value: ${t}.`);
|
|
3613
|
+
this.numItems = +t, this.nodeSize = Math.min(Math.max(+e, 2), 65535);
|
|
3614
|
+
let i = t, h = i;
|
|
3615
|
+
this._levelBounds = [i * 4];
|
|
3616
|
+
do
|
|
3617
|
+
i = Math.ceil(i / this.nodeSize), h += i, this._levelBounds.push(h * 4);
|
|
3618
|
+
while (i !== 1);
|
|
3619
|
+
this.ArrayType = s || Float64Array, this.IndexArrayType = h < 16384 ? Uint16Array : Uint32Array;
|
|
3620
|
+
const l = Me.indexOf(this.ArrayType), a = h * 4 * this.ArrayType.BYTES_PER_ELEMENT;
|
|
3621
|
+
if (l < 0)
|
|
3622
|
+
throw new Error(`Unexpected typed array class: ${s}.`);
|
|
3623
|
+
o && o.byteLength !== void 0 && !o.buffer ? (this.data = o, this._boxes = new this.ArrayType(this.data, 8, h * 4), this._indices = new this.IndexArrayType(this.data, 8 + a, h), this._pos = h * 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 n(8 + a + h * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, h * 4), this._indices = new this.IndexArrayType(this.data, 8 + a, h), 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, (Ot << 4) + l]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = t), this._queue = new Rn();
|
|
3624
|
+
}
|
|
3625
|
+
add(t, e, s, n) {
|
|
3626
|
+
const o = this._pos >> 2, i = this._boxes;
|
|
3627
|
+
return this._indices[o] = o, i[this._pos++] = t, i[this._pos++] = e, i[this._pos++] = s, i[this._pos++] = n, t < this.minX && (this.minX = t), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), n > this.maxY && (this.maxY = n), o;
|
|
3628
|
+
}
|
|
3629
|
+
finish() {
|
|
3630
|
+
if (this._pos >> 2 !== this.numItems)
|
|
3631
|
+
throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
|
|
3632
|
+
const t = this._boxes;
|
|
3633
|
+
if (this.numItems <= this.nodeSize) {
|
|
3634
|
+
t[this._pos++] = this.minX, t[this._pos++] = this.minY, t[this._pos++] = this.maxX, t[this._pos++] = this.maxY;
|
|
3635
|
+
return;
|
|
3636
|
+
}
|
|
3637
|
+
const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, n = new Uint32Array(this.numItems), o = (1 << 16) - 1;
|
|
3638
|
+
for (let i = 0, h = 0; i < this.numItems; i++) {
|
|
3639
|
+
const l = t[h++], a = t[h++], c = t[h++], u = t[h++], m = Math.floor(o * ((l + c) / 2 - this.minX) / e), p = Math.floor(o * ((a + u) / 2 - this.minY) / s);
|
|
3640
|
+
n[i] = $n(m, p);
|
|
3641
|
+
}
|
|
3642
|
+
Wt(n, t, this._indices, 0, this.numItems - 1, this.nodeSize);
|
|
3643
|
+
for (let i = 0, h = 0; i < this._levelBounds.length - 1; i++) {
|
|
3644
|
+
const l = this._levelBounds[i];
|
|
3645
|
+
for (; h < l; ) {
|
|
3646
|
+
const a = h;
|
|
3647
|
+
let c = t[h++], u = t[h++], m = t[h++], p = t[h++];
|
|
3648
|
+
for (let g = 1; g < this.nodeSize && h < l; g++)
|
|
3649
|
+
c = Math.min(c, t[h++]), u = Math.min(u, t[h++]), m = Math.max(m, t[h++]), p = Math.max(p, t[h++]);
|
|
3650
|
+
this._indices[this._pos >> 2] = a, t[this._pos++] = c, t[this._pos++] = u, t[this._pos++] = m, t[this._pos++] = p;
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
search(t, e, s, n, o) {
|
|
3655
|
+
if (this._pos !== this._boxes.length)
|
|
3656
|
+
throw new Error("Data not yet indexed - call index.finish().");
|
|
3657
|
+
let i = this._boxes.length - 4;
|
|
3658
|
+
const h = [], l = [];
|
|
3659
|
+
for (; i !== void 0; ) {
|
|
3660
|
+
const a = Math.min(i + this.nodeSize * 4, Pe(i, this._levelBounds));
|
|
3661
|
+
for (let c = i; c < a; c += 4) {
|
|
3662
|
+
if (s < this._boxes[c] || n < this._boxes[c + 1] || t > this._boxes[c + 2] || e > this._boxes[c + 3])
|
|
3663
|
+
continue;
|
|
3664
|
+
const u = this._indices[c >> 2] | 0;
|
|
3665
|
+
i >= this.numItems * 4 ? h.push(u) : (o === void 0 || o(u)) && l.push(u);
|
|
3666
|
+
}
|
|
3667
|
+
i = h.pop();
|
|
3668
|
+
}
|
|
3669
|
+
return l;
|
|
3670
|
+
}
|
|
3671
|
+
neighbors(t, e, s = 1 / 0, n = 1 / 0, o) {
|
|
3672
|
+
if (this._pos !== this._boxes.length)
|
|
3673
|
+
throw new Error("Data not yet indexed - call index.finish().");
|
|
3674
|
+
let i = this._boxes.length - 4;
|
|
3675
|
+
const h = this._queue, l = [], a = n * n;
|
|
3676
|
+
for (; i !== void 0; ) {
|
|
3677
|
+
const c = Math.min(i + this.nodeSize * 4, Pe(i, this._levelBounds));
|
|
3678
|
+
for (let u = i; u < c; u += 4) {
|
|
3679
|
+
const m = this._indices[u >> 2] | 0, p = be(t, this._boxes[u], this._boxes[u + 2]), g = be(e, this._boxes[u + 1], this._boxes[u + 3]), d = p * p + g * g;
|
|
3680
|
+
i >= this.numItems * 4 ? h.push(m << 1, d) : (o === void 0 || o(m)) && h.push((m << 1) + 1, d);
|
|
3681
|
+
}
|
|
3682
|
+
for (; h.length && h.peek() & 1; )
|
|
3683
|
+
if (h.peekValue() > a || (l.push(h.pop() >> 1), l.length === s))
|
|
3684
|
+
return h.clear(), l;
|
|
3685
|
+
i = h.pop() >> 1;
|
|
3686
|
+
}
|
|
3687
|
+
return h.clear(), l;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
function be(r, t, e) {
|
|
3691
|
+
return r < t ? t - r : r <= e ? 0 : r - e;
|
|
3692
|
+
}
|
|
3693
|
+
function Pe(r, t) {
|
|
3694
|
+
let e = 0, s = t.length - 1;
|
|
3695
|
+
for (; e < s; ) {
|
|
3696
|
+
const n = e + s >> 1;
|
|
3697
|
+
t[n] > r ? s = n : e = n + 1;
|
|
3698
|
+
}
|
|
3699
|
+
return t[e];
|
|
3700
|
+
}
|
|
3701
|
+
function Wt(r, t, e, s, n, o) {
|
|
3702
|
+
if (Math.floor(s / o) >= Math.floor(n / o))
|
|
3703
|
+
return;
|
|
3704
|
+
const i = r[s + n >> 1];
|
|
3705
|
+
let h = s - 1, l = n + 1;
|
|
3706
|
+
for (; ; ) {
|
|
3707
|
+
do
|
|
3708
|
+
h++;
|
|
3709
|
+
while (r[h] < i);
|
|
3710
|
+
do
|
|
3711
|
+
l--;
|
|
3712
|
+
while (r[l] > i);
|
|
3713
|
+
if (h >= l)
|
|
3714
|
+
break;
|
|
3715
|
+
Tn(r, t, e, h, l);
|
|
3716
|
+
}
|
|
3717
|
+
Wt(r, t, e, s, l, o), Wt(r, t, e, l + 1, n, o);
|
|
3718
|
+
}
|
|
3719
|
+
function Tn(r, t, e, s, n) {
|
|
3720
|
+
const o = r[s];
|
|
3721
|
+
r[s] = r[n], r[n] = o;
|
|
3722
|
+
const i = 4 * s, h = 4 * n, l = t[i], a = t[i + 1], c = t[i + 2], u = t[i + 3];
|
|
3723
|
+
t[i] = t[h], t[i + 1] = t[h + 1], t[i + 2] = t[h + 2], t[i + 3] = t[h + 3], t[h] = l, t[h + 1] = a, t[h + 2] = c, t[h + 3] = u;
|
|
3724
|
+
const m = e[s];
|
|
3725
|
+
e[s] = e[n], e[n] = m;
|
|
3726
|
+
}
|
|
3727
|
+
function $n(r, t) {
|
|
3728
|
+
let e = r ^ t, s = 65535 ^ e, n = 65535 ^ (r | t), o = r & (t ^ 65535), i = e | s >> 1, h = e >> 1 ^ e, l = n >> 1 ^ s & o >> 1 ^ n, a = e & n >> 1 ^ o >> 1 ^ o;
|
|
3729
|
+
e = i, s = h, n = l, o = a, i = e & e >> 2 ^ s & s >> 2, h = e & s >> 2 ^ s & (e ^ s) >> 2, l ^= e & n >> 2 ^ s & o >> 2, a ^= s & n >> 2 ^ (e ^ s) & o >> 2, e = i, s = h, n = l, o = a, i = e & e >> 4 ^ s & s >> 4, h = e & s >> 4 ^ s & (e ^ s) >> 4, l ^= e & n >> 4 ^ s & o >> 4, a ^= s & n >> 4 ^ (e ^ s) & o >> 4, e = i, s = h, n = l, o = a, l ^= e & n >> 8 ^ s & o >> 8, a ^= s & n >> 8 ^ (e ^ s) & o >> 8, e = l ^ l >> 1, s = a ^ a >> 1;
|
|
3730
|
+
let c = r ^ t, u = s | 65535 ^ (c | e);
|
|
3731
|
+
return c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, u = (u | u << 8) & 16711935, u = (u | u << 4) & 252645135, u = (u | u << 2) & 858993459, u = (u | u << 1) & 1431655765, (u << 1 | c) >>> 0;
|
|
3732
|
+
}
|
|
3733
|
+
function Ze(r, t = 1e-7) {
|
|
3734
|
+
if (r.length === 0)
|
|
3735
|
+
return [];
|
|
3736
|
+
if (r.length === 1)
|
|
3737
|
+
return [r];
|
|
3738
|
+
const e = new ee(r.length);
|
|
3739
|
+
r.forEach((o) => {
|
|
3740
|
+
const [i, h] = o.firstPoint;
|
|
3741
|
+
e.add(i - t, h - t, i + t, h + t);
|
|
3742
|
+
}), e.finish();
|
|
3743
|
+
const s = [], n = /* @__PURE__ */ new Set();
|
|
3744
|
+
return r.forEach((o, i) => {
|
|
3745
|
+
if (n.has(i))
|
|
3746
|
+
return;
|
|
3747
|
+
const h = [o];
|
|
3748
|
+
let l = i;
|
|
3749
|
+
n.add(i);
|
|
3750
|
+
let a = r.length;
|
|
3751
|
+
for (; ; ) {
|
|
3752
|
+
if (a-- < 0)
|
|
3753
|
+
throw new Error("Infinite loop detected");
|
|
3754
|
+
const c = h[h.length - 1].lastPoint, [u, m] = c, p = e.search(
|
|
3755
|
+
u - t,
|
|
3756
|
+
m - t,
|
|
3757
|
+
u + t,
|
|
3758
|
+
m + t
|
|
3759
|
+
), g = (w) => Math.abs((l - w) % r.length), d = p.filter((w) => !n.has(w)).map((w) => [
|
|
3760
|
+
r[w],
|
|
3761
|
+
w,
|
|
3762
|
+
g(w)
|
|
3763
|
+
]).sort(([, , w], [, , y]) => g(w) - g(y));
|
|
3764
|
+
if (d.length === 0) {
|
|
3765
|
+
s.push(h);
|
|
3766
|
+
break;
|
|
3767
|
+
}
|
|
3768
|
+
const [M, f] = d[0];
|
|
3769
|
+
h.push(M), n.add(f), l = f;
|
|
3770
|
+
}
|
|
3771
|
+
}), s;
|
|
3772
|
+
}
|
|
3773
|
+
let X = class It extends lt {
|
|
3774
|
+
constructor(t, e = [], { ignoreChecks: s = !1 } = {}) {
|
|
3775
|
+
super(), s || _n(t, e), this.contour = t, this.holes = e;
|
|
3776
|
+
}
|
|
3777
|
+
get boundingBox() {
|
|
3778
|
+
return this.contour.boundingBox;
|
|
3779
|
+
}
|
|
3780
|
+
get isFull() {
|
|
3781
|
+
return this.holes.length === 0;
|
|
3782
|
+
}
|
|
3783
|
+
get allLoops() {
|
|
3784
|
+
return [this.contour, ...this.holes];
|
|
3785
|
+
}
|
|
3786
|
+
clone() {
|
|
3787
|
+
return new It(
|
|
3788
|
+
this.contour.clone(),
|
|
3789
|
+
this.holes.map((t) => t.clone())
|
|
3790
|
+
);
|
|
3791
|
+
}
|
|
3792
|
+
transform(t) {
|
|
3793
|
+
return new It(
|
|
3794
|
+
this.contour.transform(t),
|
|
3795
|
+
this.holes.map((e) => e.transform(t))
|
|
3796
|
+
);
|
|
3797
|
+
}
|
|
3798
|
+
contains(t) {
|
|
3799
|
+
return this.contour.contains(t) && !this.holes.some((e) => e.contains(t));
|
|
3800
|
+
}
|
|
3801
|
+
intersects(t) {
|
|
3802
|
+
return this.allLoops.some(
|
|
3803
|
+
(e) => t.allLoops.some((s) => e.intersects(s))
|
|
3804
|
+
);
|
|
3805
|
+
}
|
|
3806
|
+
overlappingStrands(t) {
|
|
3807
|
+
const e = t instanceof It ? t.allLoops : [t], s = this.allLoops.flatMap((n) => e.flatMap((o) => n.overlappingSegments(o)));
|
|
3808
|
+
return Ze(s).map((n) => new st(n));
|
|
3809
|
+
}
|
|
3810
|
+
};
|
|
3811
|
+
function _n(r, t = []) {
|
|
3812
|
+
if (!r)
|
|
3813
|
+
throw new Error("Figure must have a contour");
|
|
3814
|
+
for (const [e, s] of Dt([r, ...t]))
|
|
3815
|
+
if (e.intersects(s))
|
|
3816
|
+
throw new Error("Loops in a figure must not intersect");
|
|
3817
|
+
if (t.some(
|
|
3818
|
+
(e) => !r.contains(e.firstPoint) && !r.onStroke(e.firstPoint)
|
|
3819
|
+
))
|
|
3820
|
+
throw new Error("Holes must be inside the contour");
|
|
3821
|
+
for (const [e, s] of Dt(t))
|
|
3822
|
+
if (e.contains(s.firstPoint))
|
|
3823
|
+
throw console.error(ye(e), ye(s)), new Error("Holes must not be inside other holes");
|
|
3824
|
+
}
|
|
3825
|
+
const In = (r) => {
|
|
3826
|
+
const t = r.map((n, o) => r.slice(o + 1).map((i, h) => [h + o + 1, i]).filter(([, i]) => n.boundingBox.overlaps(i.boundingBox)).map(([i]) => i)), e = [], s = Array(t.length);
|
|
3827
|
+
return t.forEach((n, o) => {
|
|
3828
|
+
let i = s[o];
|
|
3829
|
+
i || (i = [], e.push(i)), i.push(r[o]), n.length && n.forEach((h) => {
|
|
3830
|
+
s[h] = i;
|
|
3831
|
+
});
|
|
3832
|
+
}), e;
|
|
3833
|
+
}, ts = (r) => r.map((t, e) => {
|
|
3834
|
+
const s = t.segments[0].midPoint, n = r.filter((o, i) => e === i ? !1 : o.contains(s));
|
|
3835
|
+
return {
|
|
3836
|
+
loop: t,
|
|
3837
|
+
isIn: n
|
|
3838
|
+
};
|
|
3839
|
+
}), Fn = (r, t) => r.flatMap(({ loop: e }) => se(
|
|
3840
|
+
t.filter(
|
|
3841
|
+
({ loop: s, isIn: n }) => s === e || n.indexOf(e) !== -1
|
|
3842
|
+
)
|
|
3843
|
+
)), Ln = (r, t) => {
|
|
3844
|
+
const e = t.filter(({ isIn: n }) => n.length <= 1), s = se(
|
|
3845
|
+
ts(r.map(({ loop: n }) => n))
|
|
3846
|
+
);
|
|
3847
|
+
return [e, ...s];
|
|
3848
|
+
}, se = (r) => {
|
|
3849
|
+
if (!r.length)
|
|
3850
|
+
return [];
|
|
3851
|
+
const t = r.filter(({ isIn: s }) => !s.length), e = r.filter(({ isIn: s }) => s.length > 1);
|
|
3852
|
+
return t.length === 1 && e.length === 0 ? [r] : t.length > 1 ? Fn(t, r) : Ln(e, r);
|
|
3853
|
+
};
|
|
3854
|
+
function bt(r) {
|
|
3855
|
+
return In(r).map(ts).flatMap(se).map((t) => {
|
|
3856
|
+
if (t.length === 1)
|
|
3857
|
+
return new X(t[0].loop);
|
|
3858
|
+
t.sort((n, o) => n.isIn.length - o.isIn.length);
|
|
3859
|
+
const [e, ...s] = t.map(({ loop: n }) => n);
|
|
3860
|
+
return new X(e, s);
|
|
3861
|
+
});
|
|
3862
|
+
}
|
|
3863
|
+
function Cn(r, t) {
|
|
3864
|
+
const e = [];
|
|
3865
|
+
for (const s of r)
|
|
3866
|
+
for (const n of t)
|
|
3867
|
+
e.push([s, n]);
|
|
3868
|
+
return e;
|
|
3869
|
+
}
|
|
3870
|
+
function* Gt(r, t, e) {
|
|
3871
|
+
const s = (i) => t.some((h) => b(h, i.lastPoint)), n = (i) => e.some((h) => i.isSame(h));
|
|
3872
|
+
let o = [];
|
|
3873
|
+
for (const i of r)
|
|
3874
|
+
s(i) ? (o.push(i), yield new st(o, { ignoreChecks: !0 }), o = []) : n(i) ? (o.length && (yield new st(o, { ignoreChecks: !0 }), o = []), yield new st([i], { ignoreChecks: !0 })) : o.push(i);
|
|
3875
|
+
o.length && (yield new st(o, { ignoreChecks: !0 }));
|
|
3876
|
+
}
|
|
3877
|
+
const xe = (r, t) => {
|
|
3878
|
+
const e = r.findIndex((n) => b(t, n.firstPoint)), s = r.slice(0, e);
|
|
3879
|
+
return r.slice(e).concat(s);
|
|
3880
|
+
}, Ee = (r, t) => {
|
|
3881
|
+
let e = r;
|
|
3882
|
+
const s = (i) => b(i.firstPoint, t.firstPoint) && b(i.lastPoint, t.lastPoint);
|
|
3883
|
+
let n = r.findIndex(s);
|
|
3884
|
+
if (n === -1) {
|
|
3885
|
+
const i = r.map((h) => h.reverse());
|
|
3886
|
+
if (i.reverse(), n = i.findIndex(s), n === -1)
|
|
3887
|
+
throw console.error(
|
|
3888
|
+
i.map((h) => h.repr),
|
|
3889
|
+
t.repr
|
|
3890
|
+
), new Error("Failed to rotate to segment start");
|
|
3891
|
+
e = i;
|
|
3892
|
+
}
|
|
3893
|
+
const o = e.slice(0, n);
|
|
3894
|
+
return e.slice(n).concat(o);
|
|
3895
|
+
};
|
|
3896
|
+
function Bn(r, t, e) {
|
|
3897
|
+
return r.filter((s) => {
|
|
3898
|
+
const n = t.filter((i) => b(i.firstPoint, s) || b(i.lastPoint, s));
|
|
3899
|
+
if (n.length % 2)
|
|
3900
|
+
throw new Error("Bug in the intersection algo on non crossing point");
|
|
3901
|
+
const o = n.map((i) => e.contains(i.midPoint));
|
|
3902
|
+
return !(o.every((i) => i) || !o.some((i) => i));
|
|
3903
|
+
});
|
|
3904
|
+
}
|
|
3905
|
+
function jn(r, t, e) {
|
|
3906
|
+
let s = [];
|
|
3907
|
+
const n = [], o = new Array(r.segments.length).fill(0).map(() => []), i = new Array(t.segments.length).fill(0).map(() => []);
|
|
3908
|
+
if (r.segments.forEach((m, p) => {
|
|
3909
|
+
t.segments.forEach((g, d) => {
|
|
3910
|
+
const { intersections: M, overlaps: f } = Et(
|
|
3911
|
+
m,
|
|
3912
|
+
g,
|
|
3913
|
+
e
|
|
3914
|
+
);
|
|
3915
|
+
s.push(...M), o[p].push(...M), i[d].push(...M), n.push(...f);
|
|
3916
|
+
const w = f.flatMap((y) => [
|
|
3917
|
+
y.firstPoint,
|
|
3918
|
+
y.lastPoint
|
|
3919
|
+
]);
|
|
3920
|
+
s.push(...w), o[p].push(...w), i[d].push(...w);
|
|
3921
|
+
});
|
|
3922
|
+
}), s = at(s, e), !s.length || s.length === 1)
|
|
3923
|
+
return null;
|
|
3924
|
+
const h = ([m, p]) => p.length ? m.splitAt(p) : [m];
|
|
3925
|
+
let l = et([r.segments, o]).flatMap(h), a = et([t.segments, i]).flatMap(h);
|
|
3926
|
+
if (s = Bn(
|
|
3927
|
+
s,
|
|
3928
|
+
l,
|
|
3929
|
+
t
|
|
3930
|
+
), !s.length && !n.length)
|
|
3931
|
+
return null;
|
|
3932
|
+
if (n.length) {
|
|
3933
|
+
const m = n[0];
|
|
3934
|
+
l = Ee(
|
|
3935
|
+
l,
|
|
3936
|
+
m
|
|
3937
|
+
), a = Ee(
|
|
3938
|
+
a,
|
|
3939
|
+
m
|
|
3940
|
+
);
|
|
3941
|
+
} else {
|
|
3942
|
+
const m = s[0];
|
|
3943
|
+
l = xe(l, m), a = xe(a, m);
|
|
3944
|
+
}
|
|
3945
|
+
let c = Array.from(
|
|
3946
|
+
Gt(
|
|
3947
|
+
l,
|
|
3948
|
+
s,
|
|
3949
|
+
n
|
|
3950
|
+
)
|
|
3951
|
+
), u = Array.from(
|
|
3952
|
+
Gt(
|
|
3953
|
+
a,
|
|
3954
|
+
s,
|
|
3955
|
+
n
|
|
3956
|
+
)
|
|
3957
|
+
);
|
|
3958
|
+
return (!b(
|
|
3959
|
+
u[0].lastPoint,
|
|
3960
|
+
c[0].lastPoint
|
|
3961
|
+
) || n.length > 0 && u[0].segmentsCount !== 1) && (u = u.map((m) => m.reverse()).reverse(), b(u[0].lastPoint, c[0].lastPoint) || (c = c.map((m) => m.reverse()).reverse())), et([c, u]).map(([m, p]) => m.segmentsCount === 1 && n.some((g) => m.segments[0].isSame(g)) ? [m, "same"] : [m, p]);
|
|
3962
|
+
}
|
|
3963
|
+
function ve(r) {
|
|
3964
|
+
let t = r[0];
|
|
3965
|
+
for (const e of r.slice(1))
|
|
3966
|
+
t = t.extend(e);
|
|
3967
|
+
if (!b(t.firstPoint, t.lastPoint))
|
|
3968
|
+
throw console.error(
|
|
3969
|
+
I(t.firstPoint),
|
|
3970
|
+
I(t.lastPoint)
|
|
3971
|
+
), new Error("Bug in the intersection algo on non closing strand");
|
|
3972
|
+
return new W(t.segments);
|
|
3973
|
+
}
|
|
3974
|
+
function Vn(r, t) {
|
|
3975
|
+
const e = et([
|
|
3976
|
+
t.slice(0, -1),
|
|
3977
|
+
t.slice(1)
|
|
3978
|
+
]).map(([n, o]) => ve(r.slice(n, o)));
|
|
3979
|
+
let s = r.slice(
|
|
3980
|
+
t[t.length - 1]
|
|
3981
|
+
);
|
|
3982
|
+
return t[0] !== 0 && (s = s.concat(r.slice(0, t[0]))), e.push(ve(s)), e;
|
|
3983
|
+
}
|
|
3984
|
+
function Nn(r) {
|
|
3985
|
+
if (!r.length)
|
|
3986
|
+
return [];
|
|
3987
|
+
const t = r.map((n) => n.firstPoint);
|
|
3988
|
+
let e = r.map((n) => n.lastPoint);
|
|
3989
|
+
e = e.slice(-1).concat(e.slice(0, -1));
|
|
3990
|
+
const s = et([t, e]).flatMap(
|
|
3991
|
+
([n, o], i) => b(n, o) ? [] : i
|
|
3992
|
+
);
|
|
3993
|
+
try {
|
|
3994
|
+
return Vn(r, s);
|
|
3995
|
+
} catch {
|
|
3996
|
+
return Ze(r.flatMap((n) => n.segments)).filter((n) => n.length > 1).filter((n) => b(n[0].firstPoint, n.at(-1).lastPoint)).map((n) => new W(n));
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
const Ae = (r, t) => {
|
|
4000
|
+
if (r.length === 0)
|
|
4001
|
+
return [t];
|
|
4002
|
+
const e = r.at(-1);
|
|
4003
|
+
return b(e.lastPoint, t.firstPoint) ? r.slice(0, -1).concat([e.extend(t)]) : b(e.lastPoint, t.lastPoint) ? r.slice(0, -1).concat([e.extend(t.reverse())]) : r.concat([t]);
|
|
4004
|
+
}, qn = (r, t) => r.length === 0 ? [t] : b(r[0].firstPoint, t.lastPoint) ? [t.extend(r[0])].concat(r.slice(1)) : [t].concat(r);
|
|
4005
|
+
function ne(r, t, {
|
|
4006
|
+
firstInside: e,
|
|
4007
|
+
secondInside: s
|
|
4008
|
+
}) {
|
|
4009
|
+
const n = jn(r, t);
|
|
4010
|
+
if (!n) {
|
|
4011
|
+
const l = r.segments[0].midPoint, a = t.contains(l), c = t.segments[0].midPoint, u = r.contains(c);
|
|
4012
|
+
return {
|
|
4013
|
+
identical: !1,
|
|
4014
|
+
firstCurveInSecond: a,
|
|
4015
|
+
secondCurveInFirst: u
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
if (n.every(([, l]) => l === "same"))
|
|
4019
|
+
return { identical: !0 };
|
|
4020
|
+
let o = null, i = null;
|
|
4021
|
+
const h = n.flatMap(([l, a]) => {
|
|
4022
|
+
let c = [], u = 0;
|
|
4023
|
+
if (a === "same")
|
|
4024
|
+
return i === 1 ? (i = 1, l) : i === 2 || i === 0 ? (i = null, []) : i === null ? (o ? o = o.extend(l) : o = l, []) : (console.error("weird situation"), []);
|
|
4025
|
+
const m = l.segments[0].midPoint, p = t.contains(m);
|
|
4026
|
+
(e === "keep" && p || e === "remove" && !p) && (u += 1, c = Ae(c, l));
|
|
4027
|
+
const g = a.segments[0].midPoint, d = r.contains(g);
|
|
4028
|
+
if (s === "keep" && d || s === "remove" && !d) {
|
|
4029
|
+
const M = a;
|
|
4030
|
+
u += 1, u === 2 && c.length ? (c = Ae(c, M), o = null) : c = [M];
|
|
4031
|
+
}
|
|
4032
|
+
return i === null && u === 1 && o && (c = qn(c, o)), u === 1 && (i = u, o = null), c.length ? c : (o = null, []);
|
|
4033
|
+
});
|
|
4034
|
+
return Nn(h);
|
|
4035
|
+
}
|
|
4036
|
+
const On = (r, t) => {
|
|
4037
|
+
const e = ne(r, t, {
|
|
4038
|
+
firstInside: "remove",
|
|
4039
|
+
secondInside: "remove"
|
|
4040
|
+
});
|
|
4041
|
+
return Array.isArray(e) ? e : e.identical ? [r] : e.firstCurveInSecond ? [t] : e.secondCurveInFirst ? [r] : [r, t];
|
|
4042
|
+
}, Bt = (r, t) => {
|
|
4043
|
+
const e = ne(r, t, {
|
|
4044
|
+
firstInside: "remove",
|
|
4045
|
+
secondInside: "keep"
|
|
4046
|
+
});
|
|
4047
|
+
return Array.isArray(e) ? e : e.identical ? [] : e.firstCurveInSecond ? [] : e.secondCurveInFirst ? [r, t] : [r];
|
|
4048
|
+
}, re = (r, t) => {
|
|
4049
|
+
const e = ne(r, t, {
|
|
4050
|
+
firstInside: "keep",
|
|
4051
|
+
secondInside: "keep"
|
|
4052
|
+
});
|
|
4053
|
+
return Array.isArray(e) ? e : e.identical ? [r] : e.firstCurveInSecond ? [r] : e.secondCurveInFirst ? [t] : [];
|
|
4054
|
+
};
|
|
4055
|
+
function zn(r) {
|
|
4056
|
+
const t = /* @__PURE__ */ new Map(), e = [];
|
|
4057
|
+
return r.forEach((s, n) => {
|
|
4058
|
+
let o;
|
|
4059
|
+
t.has(n) ? o = t.get(n) : (o = { current: [s], fusedWith: /* @__PURE__ */ new Set([n]) }, e.push(o)), r.slice(n + 1).forEach((i, h) => {
|
|
4060
|
+
const l = o.current, a = n + h + 1;
|
|
4061
|
+
if (o.fusedWith.has(a))
|
|
4062
|
+
return;
|
|
4063
|
+
let c = [i], u = !1;
|
|
4064
|
+
if (t.has(a) && (c = t.get(a).current, u = !0), !l.some(
|
|
4065
|
+
(p) => c.some((g) => p.intersects(g))
|
|
4066
|
+
))
|
|
4067
|
+
return;
|
|
4068
|
+
let m;
|
|
4069
|
+
l.length > 1 || c.length > 1 ? m = vt(l, c) : m = es(l[0], c[0]), o.fusedWith.add(a), o.current = m, u || t.set(a, o);
|
|
4070
|
+
});
|
|
4071
|
+
}), e.flatMap(({ current: s }) => s);
|
|
4072
|
+
}
|
|
4073
|
+
function es(r, t) {
|
|
4074
|
+
const e = On(r.contour, t.contour), s = t.holes.flatMap((i) => Bt(i, r.contour)), n = r.holes.flatMap((i) => Bt(i, t.contour)), o = Cn(r.holes, t.holes).flatMap(
|
|
4075
|
+
([i, h]) => re(i, h)
|
|
4076
|
+
);
|
|
4077
|
+
return bt([
|
|
4078
|
+
...e,
|
|
4079
|
+
...s,
|
|
4080
|
+
...n,
|
|
4081
|
+
...o
|
|
4082
|
+
]);
|
|
4083
|
+
}
|
|
4084
|
+
function jt(r, t) {
|
|
4085
|
+
if (r.isFull && t.isFull)
|
|
4086
|
+
return bt(Bt(r.contour, t.contour));
|
|
4087
|
+
if (r.isFull) {
|
|
4088
|
+
const s = Bt(r.contour, t.contour), n = t.holes.flatMap(
|
|
4089
|
+
(o) => re(o, r.contour)
|
|
4090
|
+
);
|
|
4091
|
+
return bt([...s, ...n]);
|
|
4092
|
+
} else if (t.isFull && !r.contour.intersects(t.contour))
|
|
4093
|
+
if (r.contour.contains(t.contour.firstPoint)) {
|
|
4094
|
+
const s = vt(
|
|
4095
|
+
r.holes.map((n) => new X(n)),
|
|
4096
|
+
[t]
|
|
4097
|
+
);
|
|
4098
|
+
return bt([
|
|
4099
|
+
r.contour,
|
|
4100
|
+
...s.flatMap((n) => n.allLoops)
|
|
4101
|
+
]);
|
|
4102
|
+
} else
|
|
4103
|
+
return [r];
|
|
4104
|
+
let e = jt(new X(r.contour), t);
|
|
4105
|
+
return r.holes.forEach((s) => {
|
|
4106
|
+
e = e.flatMap((n) => jt(n, new X(s)));
|
|
4107
|
+
}), e;
|
|
4108
|
+
}
|
|
4109
|
+
function Un(r, t) {
|
|
4110
|
+
const e = re(r.contour, t.contour);
|
|
4111
|
+
if (!e.length)
|
|
4112
|
+
return [];
|
|
4113
|
+
let s = bt(e);
|
|
4114
|
+
return s = wt(
|
|
4115
|
+
s,
|
|
4116
|
+
r.holes.map((n) => new X(n))
|
|
4117
|
+
), wt(
|
|
4118
|
+
s,
|
|
4119
|
+
t.holes.map((n) => new X(n))
|
|
4120
|
+
);
|
|
4121
|
+
}
|
|
4122
|
+
function vt(r, t) {
|
|
4123
|
+
if (!r.length)
|
|
4124
|
+
return t;
|
|
4125
|
+
if (!t.length)
|
|
4126
|
+
return r;
|
|
4127
|
+
if (r.length === 1 && t.length > 1 || t.length === 1 && r.length > 1)
|
|
4128
|
+
return zn([...r, ...t]);
|
|
4129
|
+
if (r.length > 1 && t.length > 1) {
|
|
4130
|
+
let e = vt([r[0]], t);
|
|
4131
|
+
return r.slice(1).forEach((s) => {
|
|
4132
|
+
e = vt([s], e);
|
|
4133
|
+
}), e;
|
|
4134
|
+
}
|
|
4135
|
+
return r.length === 1 && t.length === 1 ? es(r[0], t[0]) : [];
|
|
4136
|
+
}
|
|
4137
|
+
function wt(r, t) {
|
|
4138
|
+
if (!r.length)
|
|
4139
|
+
return [];
|
|
4140
|
+
if (!t.length)
|
|
4141
|
+
return r;
|
|
4142
|
+
if (r.length === 1 && t.length === 1)
|
|
4143
|
+
return jt(r[0], t[0]);
|
|
4144
|
+
if (r.length > 1)
|
|
4145
|
+
return r.flatMap((s) => wt([s], t));
|
|
4146
|
+
let e = jt(r[0], t[0]);
|
|
4147
|
+
return t.slice(1).forEach((s) => {
|
|
4148
|
+
e = wt(e, [s]);
|
|
4149
|
+
}), e;
|
|
4150
|
+
}
|
|
4151
|
+
function Ht(r, t) {
|
|
4152
|
+
return !r.length || !t.length ? [] : r.length === 1 && t.length === 1 ? Un(r[0], t[0]) : r.length > 1 ? r.flatMap((e) => Ht([e], t)) : t.flatMap((e) => Ht(r, [e]));
|
|
4153
|
+
}
|
|
4154
|
+
let At = class nt extends lt {
|
|
4155
|
+
constructor(t = [], { ignoreChecks: e = !1 } = {}) {
|
|
4156
|
+
super(), this._boundingBox = null, e || Yn(t), this.figures = t;
|
|
4157
|
+
}
|
|
4158
|
+
get isEmpty() {
|
|
4159
|
+
return this.figures.length === 0;
|
|
4160
|
+
}
|
|
4161
|
+
get boundingBox() {
|
|
4162
|
+
if (this.isEmpty)
|
|
4163
|
+
return new ht();
|
|
4164
|
+
if (this._boundingBox === null) {
|
|
4165
|
+
let t = this.figures[0].boundingBox;
|
|
4166
|
+
for (const e of this.figures.slice(1))
|
|
4167
|
+
t = t.merge(e.boundingBox);
|
|
4168
|
+
this._boundingBox = t;
|
|
4169
|
+
}
|
|
4170
|
+
return this._boundingBox;
|
|
4171
|
+
}
|
|
4172
|
+
clone() {
|
|
4173
|
+
return new nt(this.figures.map((t) => t.clone()));
|
|
4174
|
+
}
|
|
4175
|
+
transform(t) {
|
|
4176
|
+
return new nt(this.figures.map((e) => e.transform(t)));
|
|
4177
|
+
}
|
|
4178
|
+
contains(t) {
|
|
4179
|
+
return this.figures.some((e) => e.contains(t));
|
|
4180
|
+
}
|
|
4181
|
+
intersects(t) {
|
|
4182
|
+
return this.figures.some(
|
|
4183
|
+
(e) => t.figures.some((s) => e.intersects(s))
|
|
4184
|
+
);
|
|
4185
|
+
}
|
|
4186
|
+
overlappingStrands(t) {
|
|
4187
|
+
return this.figures.flatMap((e) => t instanceof nt ? t.figures.flatMap(
|
|
4188
|
+
(s) => e.overlappingStrands(s)
|
|
4189
|
+
) : e.overlappingStrands(t));
|
|
4190
|
+
}
|
|
4191
|
+
fuse(t) {
|
|
4192
|
+
return new nt(vt(this.figures, t.figures));
|
|
4193
|
+
}
|
|
4194
|
+
cut(t) {
|
|
4195
|
+
return new nt(wt(this.figures, t.figures));
|
|
4196
|
+
}
|
|
4197
|
+
intersect(t) {
|
|
4198
|
+
return new nt(Ht(this.figures, t.figures));
|
|
4199
|
+
}
|
|
4200
|
+
};
|
|
4201
|
+
function Yn(r) {
|
|
4202
|
+
for (const [t, e] of Dt(r))
|
|
4203
|
+
if (t.intersects(e))
|
|
4204
|
+
throw new Error("Diagram figures must not intersect");
|
|
4205
|
+
}
|
|
4206
|
+
class Jt {
|
|
4207
|
+
constructor(t, e) {
|
|
4208
|
+
this.firstPoint = t, this.lastPoint = e;
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
function Se(r, t) {
|
|
4212
|
+
if (r instanceof A)
|
|
4213
|
+
return Dn(r, t);
|
|
4214
|
+
if (r instanceof S)
|
|
4215
|
+
return Xn(r, t);
|
|
4216
|
+
throw new Error("Not implemented");
|
|
4217
|
+
}
|
|
4218
|
+
function Dn(r, t) {
|
|
4219
|
+
const { firstPoint: e, lastPoint: s } = r, n = r.normalVector;
|
|
4220
|
+
return new A(
|
|
4221
|
+
_(e, L(n, t)),
|
|
4222
|
+
_(s, L(n, t))
|
|
4223
|
+
);
|
|
4224
|
+
}
|
|
4225
|
+
function Xn(r, t) {
|
|
4226
|
+
const e = _(
|
|
4227
|
+
r.firstPoint,
|
|
4228
|
+
L(z(r.tangentAtFirstPoint), t)
|
|
4229
|
+
), s = _(
|
|
4230
|
+
r.lastPoint,
|
|
4231
|
+
L(z(r.tangentAtLastPoint), t)
|
|
4232
|
+
), n = t * (r.clockwise ? 1 : -1);
|
|
4233
|
+
return r.radius + n < r.precision ? new Jt(e, s) : new S(e, s, r.center, r.clockwise);
|
|
4234
|
+
}
|
|
4235
|
+
function ss(r, t, e) {
|
|
4236
|
+
const s = it(
|
|
4237
|
+
r.tangentAtLastPoint,
|
|
4238
|
+
t.tangentAtFirstPoint
|
|
4239
|
+
);
|
|
4240
|
+
if (Math.abs(s) < 1e-10)
|
|
4241
|
+
return null;
|
|
4242
|
+
const n = s > 0 ? 1 : -1, o = Math.abs(e) * n, i = Se(r, o), h = Se(t, o);
|
|
4243
|
+
if (i instanceof Jt || h instanceof Jt)
|
|
4244
|
+
return null;
|
|
4245
|
+
let l;
|
|
4246
|
+
try {
|
|
4247
|
+
l = bn(i, h, 1e-9).at(-1);
|
|
4248
|
+
} catch {
|
|
4249
|
+
return null;
|
|
4250
|
+
}
|
|
4251
|
+
if (!l)
|
|
4252
|
+
return null;
|
|
4253
|
+
const a = l, c = (p, g) => {
|
|
4254
|
+
const d = g.tangentAt(a), M = Mt(d), f = _(a, L(M, o));
|
|
4255
|
+
return p.splitAt(f);
|
|
4256
|
+
}, [u] = c(r, i), [, m] = c(t, h);
|
|
4257
|
+
return { first: u, second: m, center: a };
|
|
4258
|
+
}
|
|
4259
|
+
function ke(r, t, e) {
|
|
4260
|
+
const s = ss(r, t, e);
|
|
4261
|
+
if (!s)
|
|
4262
|
+
return console.warn(
|
|
4263
|
+
"Cannot fillet between segments",
|
|
4264
|
+
r.repr,
|
|
4265
|
+
t.repr
|
|
4266
|
+
), [r, t];
|
|
4267
|
+
const { first: n, second: o } = s;
|
|
4268
|
+
return [
|
|
4269
|
+
n,
|
|
4270
|
+
Ne(n.lastPoint, o.firstPoint, n.tangentAtLastPoint),
|
|
4271
|
+
o
|
|
4272
|
+
];
|
|
4273
|
+
}
|
|
4274
|
+
function Re(r, t, e) {
|
|
4275
|
+
const s = ss(r, t, e);
|
|
4276
|
+
if (!s)
|
|
4277
|
+
return console.warn(
|
|
4278
|
+
"Cannot chamfer between segments",
|
|
4279
|
+
r.repr,
|
|
4280
|
+
t.repr
|
|
4281
|
+
), [r, t];
|
|
4282
|
+
const { first: n, second: o } = s;
|
|
4283
|
+
return [n, new A(n.lastPoint, o.firstPoint), o];
|
|
4284
|
+
}
|
|
4285
|
+
function Te(r, { ignoreChecks: t = !1 } = {}) {
|
|
4286
|
+
return new At([new X(new W([...r], { ignoreChecks: t }))]);
|
|
4287
|
+
}
|
|
4288
|
+
let Wn = class {
|
|
4289
|
+
constructor(t = [0, 0]) {
|
|
4290
|
+
this.pointer = t, this.firstPoint = t, this.pendingSegments = [], this._nextCorner = null;
|
|
4291
|
+
}
|
|
4292
|
+
movePointerTo(t) {
|
|
4293
|
+
if (this.pendingSegments.length)
|
|
4294
|
+
throw new Error(
|
|
4295
|
+
"You can only move the pointer if there is no segment defined"
|
|
4296
|
+
);
|
|
4297
|
+
return this.pointer = t, this.firstPoint = t, this;
|
|
4298
|
+
}
|
|
4299
|
+
saveSegment(t) {
|
|
4300
|
+
if (b(t.firstPoint, t.lastPoint))
|
|
4301
|
+
throw new Error(`Segment has no length, ${t.repr}`);
|
|
4302
|
+
if (!this._nextCorner)
|
|
4303
|
+
return this.pendingSegments.push(t), this;
|
|
4304
|
+
const e = this.pendingSegments.pop();
|
|
4305
|
+
if (!e)
|
|
4306
|
+
throw new Error("bug in the custom corner algorithm");
|
|
4307
|
+
const s = this._nextCorner.mode === "chamfer" ? Re : ke;
|
|
4308
|
+
return this.pendingSegments.push(
|
|
4309
|
+
...s(e, t, this._nextCorner.radius)
|
|
4310
|
+
), this._nextCorner = null, this;
|
|
4311
|
+
}
|
|
4312
|
+
lineTo(t) {
|
|
4313
|
+
const e = new A(this.pointer, t);
|
|
4314
|
+
return this.pointer = t, this.saveSegment(e);
|
|
4315
|
+
}
|
|
4316
|
+
line(t, e) {
|
|
4317
|
+
return this.lineTo([this.pointer[0] + t, this.pointer[1] + e]);
|
|
4318
|
+
}
|
|
4319
|
+
vLine(t) {
|
|
4320
|
+
return this.line(0, t);
|
|
4321
|
+
}
|
|
4322
|
+
hLine(t) {
|
|
4323
|
+
return this.line(t, 0);
|
|
4324
|
+
}
|
|
4325
|
+
vLineTo(t) {
|
|
4326
|
+
return this.lineTo([this.pointer[0], t]);
|
|
4327
|
+
}
|
|
4328
|
+
hLineTo(t) {
|
|
4329
|
+
return this.lineTo([t, this.pointer[1]]);
|
|
4330
|
+
}
|
|
4331
|
+
polarLineTo([t, e]) {
|
|
4332
|
+
const s = e * Pt, n = rt(t, s);
|
|
4333
|
+
return this.lineTo(n);
|
|
4334
|
+
}
|
|
4335
|
+
polarLine(t, e) {
|
|
4336
|
+
const s = e * Pt, [n, o] = rt(t, s);
|
|
4337
|
+
return this.line(n, o);
|
|
4338
|
+
}
|
|
4339
|
+
tangentLine(t) {
|
|
4340
|
+
const e = this.pendingSegments.at(-1);
|
|
4341
|
+
if (!e)
|
|
4342
|
+
throw new Error("You need a previous segment to sketch a tangent line");
|
|
4343
|
+
const [s, n] = e.tangentAtLastPoint;
|
|
4344
|
+
return this.line(s * t, n * t);
|
|
4345
|
+
}
|
|
4346
|
+
threePointsArcTo(t, e) {
|
|
4347
|
+
return this.saveSegment(Ts(this.pointer, e, t)), this.pointer = t, this;
|
|
4348
|
+
}
|
|
4349
|
+
threePointsArc(t, e, s, n) {
|
|
4350
|
+
const [o, i] = this.pointer;
|
|
4351
|
+
return this.threePointsArcTo(
|
|
4352
|
+
[o + t, i + e],
|
|
4353
|
+
[o + s, i + n]
|
|
4354
|
+
);
|
|
4355
|
+
}
|
|
4356
|
+
sagittaArcTo(t, e) {
|
|
4357
|
+
if (!e)
|
|
4358
|
+
return this.lineTo(t);
|
|
4359
|
+
const s = new A(this.pointer, t), n = z(s.tangentAtFirstPoint), o = _(s.midPoint, L(n, e));
|
|
4360
|
+
return this.threePointsArcTo(t, o);
|
|
4361
|
+
}
|
|
4362
|
+
sagittaArc(t, e, s) {
|
|
4363
|
+
return this.sagittaArcTo(
|
|
4364
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
4365
|
+
s
|
|
4366
|
+
);
|
|
4367
|
+
}
|
|
4368
|
+
vSagittaArc(t, e) {
|
|
4369
|
+
return this.sagittaArc(0, t, e);
|
|
4370
|
+
}
|
|
4371
|
+
hSagittaArc(t, e) {
|
|
4372
|
+
return this.sagittaArc(t, 0, e);
|
|
4373
|
+
}
|
|
4374
|
+
bulgeArcTo(t, e) {
|
|
4375
|
+
if (!e)
|
|
4376
|
+
return this.lineTo(t);
|
|
4377
|
+
const s = B(this.pointer, t) / 2, n = -e * s;
|
|
4378
|
+
return this.sagittaArcTo(t, n);
|
|
4379
|
+
}
|
|
4380
|
+
bulgeArc(t, e, s) {
|
|
4381
|
+
return this.bulgeArcTo(
|
|
4382
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
4383
|
+
s
|
|
4384
|
+
);
|
|
4385
|
+
}
|
|
4386
|
+
vBulgeArc(t, e) {
|
|
4387
|
+
return this.bulgeArc(0, t, e);
|
|
4388
|
+
}
|
|
4389
|
+
hBulgeArc(t, e) {
|
|
4390
|
+
return this.bulgeArc(t, 0, e);
|
|
4391
|
+
}
|
|
4392
|
+
tangentArcTo(t, e) {
|
|
4393
|
+
const s = this.pendingSegments.at(-1);
|
|
4394
|
+
if (!s)
|
|
4395
|
+
throw new Error("You need a previous curve to sketch a tangent arc");
|
|
4396
|
+
return this.saveSegment(
|
|
4397
|
+
Ne(
|
|
4398
|
+
this.pointer,
|
|
4399
|
+
t,
|
|
4400
|
+
e ?? s.tangentAtLastPoint
|
|
4401
|
+
)
|
|
4402
|
+
), this.pointer = t, this;
|
|
4403
|
+
}
|
|
4404
|
+
tangentArc(t, e, s) {
|
|
4405
|
+
const [n, o] = this.pointer;
|
|
4406
|
+
return this.tangentArcTo([t + n, e + o], s);
|
|
4407
|
+
}
|
|
4408
|
+
ellipseTo(t, e, s, n, o, i) {
|
|
4409
|
+
return this.saveSegment(
|
|
4410
|
+
Fs(this.pointer, t, e, s, n, o, i)
|
|
4411
|
+
), this.pointer = t, this;
|
|
4412
|
+
}
|
|
4413
|
+
ellipse(t, e, s, n, o, i, h) {
|
|
4414
|
+
return this.ellipseTo(
|
|
4415
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
4416
|
+
s,
|
|
4417
|
+
n,
|
|
4418
|
+
o,
|
|
4419
|
+
i,
|
|
4420
|
+
h
|
|
4421
|
+
);
|
|
4422
|
+
}
|
|
4423
|
+
halfEllipseTo(t, e) {
|
|
4424
|
+
const [s, n] = je(V(t, this.pointer));
|
|
4425
|
+
return this.ellipseTo(
|
|
4426
|
+
t,
|
|
4427
|
+
s / 2,
|
|
4428
|
+
Math.abs(e),
|
|
4429
|
+
n * Qt,
|
|
4430
|
+
!0,
|
|
4431
|
+
e > 0
|
|
4432
|
+
);
|
|
4433
|
+
}
|
|
4434
|
+
halfEllipse(t, e, s) {
|
|
4435
|
+
return this.halfEllipseTo(
|
|
4436
|
+
[t + this.pointer[0], e + this.pointer[1]],
|
|
4437
|
+
s
|
|
4438
|
+
);
|
|
4439
|
+
}
|
|
4440
|
+
customCorner(t, e = "fillet") {
|
|
4441
|
+
if (!this.pendingSegments.length)
|
|
4442
|
+
throw new Error("You need a segment defined to fillet the angle");
|
|
4443
|
+
return t ? (this._nextCorner = { mode: e, radius: t }, this) : this;
|
|
4444
|
+
}
|
|
4445
|
+
_customCornerLastWithFirst(t, e = "fillet") {
|
|
4446
|
+
if (!t)
|
|
4447
|
+
return;
|
|
4448
|
+
const s = this.pendingSegments.pop(), n = this.pendingSegments.shift();
|
|
4449
|
+
if (!s || !n)
|
|
4450
|
+
throw new Error("Not enough curves to close and fillet");
|
|
4451
|
+
const o = e === "chamfer" ? Re : ke;
|
|
4452
|
+
this.pendingSegments.push(...o(s, n, t));
|
|
4453
|
+
}
|
|
4454
|
+
close(t = !1) {
|
|
4455
|
+
if (!this.pendingSegments.length)
|
|
4456
|
+
throw new Error("No segments to close");
|
|
4457
|
+
const e = this.pendingSegments[0], s = this.pendingSegments.at(-1);
|
|
4458
|
+
return b(e.firstPoint, s.lastPoint) || this.lineTo(e.firstPoint), this._nextCorner !== null && (this._customCornerLastWithFirst(
|
|
4459
|
+
this._nextCorner.radius,
|
|
4460
|
+
this._nextCorner.mode
|
|
4461
|
+
), this._nextCorner = null), Te(this.pendingSegments, { ignoreChecks: t });
|
|
4462
|
+
}
|
|
4463
|
+
closeWithMirror(t = !1) {
|
|
4464
|
+
if (!this.pendingSegments.length)
|
|
4465
|
+
throw new Error("No segments to close");
|
|
4466
|
+
const e = this.pendingSegments[0], s = this.pendingSegments.at(-1), n = V(
|
|
4467
|
+
s.lastPoint,
|
|
4468
|
+
e.firstPoint
|
|
4469
|
+
), o = new q().mirrorLine(
|
|
4470
|
+
n,
|
|
4471
|
+
e.firstPoint
|
|
4472
|
+
), i = this.pendingSegments.map(
|
|
4473
|
+
(h) => h.transform(o).reverse()
|
|
4474
|
+
);
|
|
4475
|
+
return i.reverse(), Te(
|
|
4476
|
+
[...this.pendingSegments, ...i],
|
|
4477
|
+
{ ignoreChecks: t }
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
asStrand() {
|
|
4481
|
+
return new st([...this.pendingSegments]);
|
|
4482
|
+
}
|
|
4483
|
+
};
|
|
4484
|
+
function ns(r = [0, 0]) {
|
|
4485
|
+
return new Wn(r);
|
|
4486
|
+
}
|
|
4487
|
+
function $e(r) {
|
|
4488
|
+
if (r instanceof X)
|
|
4489
|
+
return [r];
|
|
4490
|
+
if (r instanceof W)
|
|
4491
|
+
return [new X(r)];
|
|
4492
|
+
if (r instanceof At)
|
|
4493
|
+
return r.figures;
|
|
4494
|
+
throw new Error("Unknown shape");
|
|
4495
|
+
}
|
|
4496
|
+
function rs(r, t, e = 1e-9) {
|
|
4497
|
+
let s = [];
|
|
4498
|
+
const n = [], o = new Array(t.segments.length).fill(0).map(() => []);
|
|
4499
|
+
t.segments.forEach((h, l) => {
|
|
4500
|
+
r.segments.forEach((a) => {
|
|
4501
|
+
const { intersections: c, overlaps: u } = Et(
|
|
4502
|
+
h,
|
|
4503
|
+
a,
|
|
4504
|
+
e
|
|
4505
|
+
);
|
|
4506
|
+
s.push(...c), o[l].push(...c), n.push(...u);
|
|
4507
|
+
const m = u.flatMap((p) => [
|
|
4508
|
+
p.firstPoint,
|
|
4509
|
+
p.lastPoint
|
|
4510
|
+
]);
|
|
4511
|
+
s.push(...m), o[l].push(...m);
|
|
4512
|
+
});
|
|
4513
|
+
}), s = at(s, e);
|
|
4514
|
+
const i = et([t.segments, o]).flatMap(([h, l]) => l.length ? h.splitAt(l) : [h]);
|
|
4515
|
+
return Array.from(
|
|
4516
|
+
Gt(
|
|
4517
|
+
i,
|
|
4518
|
+
s,
|
|
4519
|
+
n
|
|
4520
|
+
)
|
|
4521
|
+
);
|
|
4522
|
+
}
|
|
4523
|
+
function os(r, t, e = !1) {
|
|
4524
|
+
return rs(t, r).filter((s) => {
|
|
4525
|
+
const n = s.segments[0].midPoint;
|
|
4526
|
+
return t.onStroke(n) ? !e : !t.contains(n);
|
|
4527
|
+
});
|
|
4528
|
+
}
|
|
4529
|
+
function Gn(r, t, e = !1) {
|
|
4530
|
+
return rs(t, r).filter((s) => {
|
|
4531
|
+
const n = s.segments[0].midPoint;
|
|
4532
|
+
return t.onStroke(n) ? !e : t.contains(n);
|
|
4533
|
+
});
|
|
4534
|
+
}
|
|
4535
|
+
function _e(r, t, e = !1) {
|
|
4536
|
+
const s = os(
|
|
4537
|
+
r,
|
|
4538
|
+
t.contour,
|
|
4539
|
+
e
|
|
4540
|
+
), n = t.holes.flatMap(
|
|
4541
|
+
(o) => Gn(r, o, e)
|
|
4542
|
+
);
|
|
4543
|
+
return [...s, ...n];
|
|
4544
|
+
}
|
|
4545
|
+
function Hn(r, t) {
|
|
4546
|
+
return new At(
|
|
4547
|
+
wt($e(r), $e(t))
|
|
4548
|
+
);
|
|
4549
|
+
}
|
|
4550
|
+
function zt(r, t, e = !0) {
|
|
4551
|
+
if (t instanceof W)
|
|
4552
|
+
return os(r, t, e);
|
|
4553
|
+
if (t instanceof X)
|
|
4554
|
+
return _e(r, t, e);
|
|
4555
|
+
let s = [new st([...r.segments])];
|
|
4556
|
+
return t.figures.forEach((n) => {
|
|
4557
|
+
s = s.flatMap((o) => _e(o, n, e));
|
|
4558
|
+
}), s;
|
|
4559
|
+
}
|
|
4560
|
+
function oe(r) {
|
|
4561
|
+
if (r instanceof A)
|
|
4562
|
+
return `L ${r.lastPoint.join(" ")}`;
|
|
4563
|
+
if (r instanceof S)
|
|
4564
|
+
return `A ${r.radius} ${r.radius} 0 ${r.angularLength > Math.PI ? "1" : "0"} ${r.clockwise ? "0" : "1"} ${r.lastPoint.join(" ")}`;
|
|
4565
|
+
if (r instanceof O)
|
|
4566
|
+
return `A ${r.majorRadius} ${r.minorRadius} ${r.tiltAngle * Qt} ${r.deltaAngle > Math.PI ? "1" : "0"} ${r.clockwise ? "0" : "1"} ${r.lastPoint.join(" ")}`;
|
|
4567
|
+
throw new Error("Unknown segment type");
|
|
4568
|
+
}
|
|
4569
|
+
function is(r) {
|
|
4570
|
+
const t = `M ${r.firstPoint.join(" ")}`, e = r.segments.map(oe).join(" ");
|
|
4571
|
+
return `${t} ${e} Z`;
|
|
4572
|
+
}
|
|
4573
|
+
function hs(r) {
|
|
4574
|
+
return `<path d="${r.allLoops.map(is).join(" ")}" />`;
|
|
4575
|
+
}
|
|
4576
|
+
function Jn(r) {
|
|
4577
|
+
return `<g>
|
|
4578
|
+
${r.figures.map(hs).join(`
|
|
4579
|
+
`)}
|
|
4580
|
+
</g>`;
|
|
4581
|
+
}
|
|
4582
|
+
function Kn(r) {
|
|
4583
|
+
const t = `M ${r.firstPoint.join(" ")}`, e = r.segments.map(oe).join(" ");
|
|
4584
|
+
return `${t} ${e}`;
|
|
4585
|
+
}
|
|
4586
|
+
function Qn(r, t = 1) {
|
|
4587
|
+
const e = r.xMin - t, s = r.yMin - t;
|
|
4588
|
+
return `${e} ${s} ${r.width + 2 * t} ${r.height + 2 * t}`;
|
|
4589
|
+
}
|
|
4590
|
+
function Ie(r, t, e = 1, s) {
|
|
4591
|
+
const n = Qn(t, e), o = s ? `width="${t.width + 2 * e}${s}" height="${t.height + 2 * e}${s}"` : "";
|
|
4592
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
4593
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${n}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${o}>
|
|
4594
|
+
${r}
|
|
4595
|
+
</svg>`;
|
|
4596
|
+
}
|
|
4597
|
+
function Fe(r) {
|
|
4598
|
+
if (r instanceof At)
|
|
4599
|
+
return Jn(r);
|
|
4600
|
+
if (r instanceof X)
|
|
4601
|
+
return hs(r);
|
|
4602
|
+
if (r instanceof W)
|
|
4603
|
+
return `<path d="${is(r)}" />`;
|
|
4604
|
+
if (r instanceof st)
|
|
4605
|
+
return `<path d="${Kn(r)}" />`;
|
|
4606
|
+
if (r instanceof S || r instanceof A || r instanceof O)
|
|
4607
|
+
return `<path d="${`M ${r.firstPoint.join(" ")}`} ${oe(
|
|
4608
|
+
r
|
|
4609
|
+
)}" />`;
|
|
4610
|
+
throw new Error("Unknown shape type");
|
|
4611
|
+
}
|
|
4612
|
+
const Le = (r) => "shape" in r ? r.shape : r, Ce = (r, t) => {
|
|
4613
|
+
if (!("shape" in r))
|
|
4614
|
+
return t;
|
|
4615
|
+
const { color: e } = r;
|
|
4616
|
+
return e ? `<g stroke="${e}">${t}</g>` : t;
|
|
4617
|
+
};
|
|
4618
|
+
function Zn(r, {
|
|
4619
|
+
margin: t = 1,
|
|
4620
|
+
unit: e = null
|
|
4621
|
+
} = {}) {
|
|
4622
|
+
if (Array.isArray(r)) {
|
|
4623
|
+
const n = r.map((h) => Le(h).mirror()), o = n.map((h, l) => Ce(r[l], Fe(h))).join(`
|
|
4624
|
+
`), i = n.slice(1).reduce((h, l) => h.merge(l.boundingBox), n[0].boundingBox);
|
|
4625
|
+
return Ie(o, i, t, e);
|
|
4626
|
+
}
|
|
4627
|
+
const s = Le(r).mirror();
|
|
4628
|
+
return Ie(
|
|
4629
|
+
Ce(r, Fe(s)),
|
|
4630
|
+
s.boundingBox,
|
|
4631
|
+
t,
|
|
4632
|
+
e
|
|
4633
|
+
);
|
|
4634
|
+
}
|
|
4635
|
+
class yt extends lt {
|
|
4636
|
+
constructor(t, {
|
|
4637
|
+
cutLines: e = [],
|
|
4638
|
+
foldLines: s = [],
|
|
4639
|
+
foldLinesForwards: n = [],
|
|
4640
|
+
foldLinesBackwards: o = []
|
|
4641
|
+
} = {}) {
|
|
4642
|
+
super(), this.body = t, this.cutLines = [...e], this.foldLinesBackwards = [...s, ...o], this.foldLinesForwards = [...n];
|
|
4643
|
+
}
|
|
4644
|
+
get foldLines() {
|
|
4645
|
+
return [...this.foldLinesForwards, ...this.foldLinesBackwards];
|
|
4646
|
+
}
|
|
4647
|
+
clone() {
|
|
4648
|
+
return new yt(this.body, {
|
|
4649
|
+
cutLines: [...this.cutLines],
|
|
4650
|
+
foldLinesForwards: [...this.foldLinesForwards],
|
|
4651
|
+
foldLinesBackwards: [...this.foldLinesBackwards]
|
|
4652
|
+
});
|
|
4653
|
+
}
|
|
4654
|
+
addCutLine(t) {
|
|
4655
|
+
return this.cutLines.push(t), this;
|
|
4656
|
+
}
|
|
4657
|
+
addFoldLine(t, e = "backwards") {
|
|
4658
|
+
e === "forwards" ? this.foldLinesForwards.push(t) : this.foldLinesBackwards.push(t);
|
|
4659
|
+
}
|
|
4660
|
+
fuseFold(t, e = "backwards") {
|
|
4661
|
+
const s = t instanceof yt ? t.body : t, n = this.body.overlappingStrands(s);
|
|
4662
|
+
return e === "forwards" ? this.foldLinesForwards.push(...n) : this.foldLinesBackwards.push(...n), this.fuseBody(t), this;
|
|
4663
|
+
}
|
|
4664
|
+
fuseBody(t) {
|
|
4665
|
+
let e;
|
|
4666
|
+
return t instanceof yt ? (e = t.body, this.cutLines.push(...t.cutLines), this.foldLinesForwards.push(...t.foldLinesForwards), this.foldLinesBackwards.push(...t.foldLinesBackwards)) : e = t, this.body = this.body.fuse(e), this;
|
|
4667
|
+
}
|
|
4668
|
+
cutShape(t) {
|
|
4669
|
+
return this.body = Hn(this.body, t), this.cutLines = this.cutLines.flatMap(
|
|
4670
|
+
(e) => zt(e, t, !0)
|
|
4671
|
+
), this.eraseFolds(t), this;
|
|
4672
|
+
}
|
|
4673
|
+
eraseFolds(t) {
|
|
4674
|
+
this.foldLinesBackwards = this.foldLinesBackwards.flatMap(
|
|
4675
|
+
(e) => zt(e, t, !0)
|
|
4676
|
+
), this.foldLinesForwards = this.foldLinesForwards.flatMap(
|
|
4677
|
+
(e) => zt(e, t, !0)
|
|
4678
|
+
);
|
|
4679
|
+
}
|
|
4680
|
+
transform(t) {
|
|
4681
|
+
return new yt(this.body.transform(t), {
|
|
4682
|
+
cutLines: this.cutLines.map((s) => s.transform(t)),
|
|
4683
|
+
foldLinesForwards: this.foldLinesForwards.map(
|
|
4684
|
+
(s) => s.transform(t)
|
|
4685
|
+
),
|
|
4686
|
+
foldLinesBackwards: this.foldLinesBackwards.map(
|
|
4687
|
+
(s) => s.transform(t)
|
|
4688
|
+
)
|
|
4689
|
+
});
|
|
4690
|
+
}
|
|
4691
|
+
asSVG() {
|
|
4692
|
+
const t = [];
|
|
4693
|
+
return this.body && t.push({ shape: this.body, color: "red" }), this.cutLines.length && this.cutLines.map((e) => t.push({ shape: e, color: "red" })), this.foldLinesBackwards.length && this.foldLinesBackwards.map(
|
|
4694
|
+
(e) => t.push({ shape: e, color: "green" })
|
|
4695
|
+
), this.foldLinesForwards.length && this.foldLinesForwards.map(
|
|
4696
|
+
(e) => t.push({ shape: e, color: "blue" })
|
|
4697
|
+
), Zn(t, { unit: "mm" });
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
function ie(r, t, {
|
|
4701
|
+
fillet: e = 1,
|
|
4702
|
+
contraction: s = 1,
|
|
4703
|
+
contractionMode: n = "rounded",
|
|
4704
|
+
contractionLeft: o,
|
|
4705
|
+
contractionRight: i,
|
|
4706
|
+
leftContractionMode: h,
|
|
4707
|
+
rightContractionMode: l
|
|
4708
|
+
} = {}) {
|
|
4709
|
+
const a = o ?? s, c = i ?? s, u = ns([-r / 2, 0]).hLine(r);
|
|
4710
|
+
return c ? (l ?? n) === "rounded" ? (u.tangentArc(-c, c, [-1, 0]), u.vLine(t - c)) : u.line(-c, t) : u.vLine(t), u.customCorner(e), u.hLine(-r + a + c), u.customCorner(e), a ? (h ?? n) === "rounded" ? (u.vLine(-t + a), u.tangentArcTo([-r / 2, 0])) : u.lineTo([-r / 2, 0]) : u.vLine(-t), u.close();
|
|
4711
|
+
}
|
|
4712
|
+
function tr(r, t, e = {}) {
|
|
4713
|
+
return ie(r, t, e);
|
|
4714
|
+
}
|
|
4715
|
+
function er(r, t, e = {}) {
|
|
4716
|
+
return ie(r, t, e).mirror("x");
|
|
4717
|
+
}
|
|
4718
|
+
function as(r, t, {
|
|
4719
|
+
contractionTop: e,
|
|
4720
|
+
contractionBottom: s,
|
|
4721
|
+
topContractionMode: n,
|
|
4722
|
+
bottomContractionMode: o,
|
|
4723
|
+
...i
|
|
4724
|
+
} = {}) {
|
|
4725
|
+
return ie(r, t, {
|
|
4726
|
+
contractionLeft: e,
|
|
4727
|
+
contractionRight: s,
|
|
4728
|
+
leftContractionMode: n,
|
|
4729
|
+
rightContractionMode: o,
|
|
4730
|
+
...i
|
|
4731
|
+
}).rotate(90);
|
|
4732
|
+
}
|
|
4733
|
+
function sr(r, t, e = {}) {
|
|
4734
|
+
return as(r, t, e).mirror("y");
|
|
4735
|
+
}
|
|
4736
|
+
const or = {
|
|
4737
|
+
right: sr,
|
|
4738
|
+
left: as,
|
|
4739
|
+
top: tr,
|
|
4740
|
+
bottom: er
|
|
4741
|
+
}, Be = (r, t) => ns([-r / 2, 0]).line(t, -t).hLine(r - 2 * t).line(t, t);
|
|
4742
|
+
class Kt extends lt {
|
|
4743
|
+
constructor(t, e = 0.2) {
|
|
4744
|
+
if (super(), typeof t != "number") {
|
|
4745
|
+
this.cut = t.cut, this.unfold = t.unfold, this.bump = t.bump;
|
|
4746
|
+
return;
|
|
4747
|
+
}
|
|
4748
|
+
const s = Be(t, e * 2.5);
|
|
4749
|
+
this.cut = s.asStrand(), this.unfold = s.close(), this.bump = Be(t - 5 * e, 5 * e).close().mirror("x");
|
|
4750
|
+
}
|
|
4751
|
+
clone() {
|
|
4752
|
+
return new Kt(this);
|
|
4753
|
+
}
|
|
4754
|
+
transform(t) {
|
|
4755
|
+
return new Kt({
|
|
4756
|
+
cut: this.cut.transform(t),
|
|
4757
|
+
unfold: this.unfold.transform(t),
|
|
4758
|
+
bump: this.bump.transform(t)
|
|
4759
|
+
});
|
|
4760
|
+
}
|
|
4761
|
+
makeCut(t) {
|
|
4762
|
+
t.eraseFolds(this.unfold), t.addCutLine(this.cut);
|
|
4763
|
+
}
|
|
4764
|
+
fuseBump(t) {
|
|
4765
|
+
t.fuseBody(this.bump);
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
class qt extends lt {
|
|
4769
|
+
constructor(t) {
|
|
4770
|
+
super(), this.points = t, this.points = t;
|
|
4771
|
+
}
|
|
4772
|
+
transform(t) {
|
|
4773
|
+
return new qt(this.points.map(t.transform));
|
|
4774
|
+
}
|
|
4775
|
+
distribute(t) {
|
|
4776
|
+
return this.points.map((e) => t.translateTo(e));
|
|
4777
|
+
}
|
|
4778
|
+
cloneDistribute(t) {
|
|
4779
|
+
return this.points.map((e) => t.clone().translateTo(e));
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
function ir(r, t, e = 3, s = 0) {
|
|
4783
|
+
if (r <= t * 2)
|
|
4784
|
+
throw new Error("totalWidth must be greater than twice the objectWidth");
|
|
4785
|
+
const n = Math.max(
|
|
4786
|
+
Math.floor((r - 2 * s) / (t * (e + 1))),
|
|
4787
|
+
2
|
|
4788
|
+
), i = (r - 2 * s - n * t) / (n - 1), h = [];
|
|
4789
|
+
for (let l = 0; l < n; l++)
|
|
4790
|
+
h.push(
|
|
4791
|
+
s + l * (t + i) - r / 2 + t / 2
|
|
4792
|
+
);
|
|
4793
|
+
return new qt(h.map((l) => [l, 0]));
|
|
4794
|
+
}
|
|
4795
|
+
function hr(r, t, e = "x") {
|
|
4796
|
+
const s = r * (t - 1), n = [];
|
|
4797
|
+
for (let o = 0; o < t; o++)
|
|
4798
|
+
n.push(o * r - s / 2);
|
|
4799
|
+
return new qt(
|
|
4800
|
+
n.map((o) => e.toLowerCase() === "x" ? [o, 0] : [0, o])
|
|
4801
|
+
);
|
|
4802
|
+
}
|
|
4803
|
+
export {
|
|
4804
|
+
yt as Dieline,
|
|
4805
|
+
Kt as FoldLockBump,
|
|
4806
|
+
er as bottomFlap,
|
|
4807
|
+
or as drawFlaps,
|
|
4808
|
+
as as leftFlap,
|
|
4809
|
+
ir as linearDistribution,
|
|
4810
|
+
hr as linearSpread,
|
|
4811
|
+
sr as rightFlap,
|
|
4812
|
+
tr as topFlap
|
|
4813
|
+
};
|
|
4814
|
+
//# sourceMappingURL=dielines.js.map
|