@weasel-js/geom 1.10.1 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +9 -1
  2. package/dist/3d/index.d.ts +29 -2
  3. package/dist/3d/index.js +49 -1
  4. package/dist/3d/index.js.map +1 -1
  5. package/dist/booleans/index.d.ts +18 -11
  6. package/dist/booleans/index.js +432 -352
  7. package/dist/booleans/index.js.map +1 -1
  8. package/dist/chunk-4Y67BZL5.js +573 -0
  9. package/dist/chunk-4Y67BZL5.js.map +1 -0
  10. package/dist/chunk-6FGQML7D.js +152 -0
  11. package/dist/chunk-6FGQML7D.js.map +1 -0
  12. package/dist/{chunk-7WFFCHRL.js → chunk-7F66PQCJ.js} +6 -37
  13. package/dist/chunk-7F66PQCJ.js.map +1 -0
  14. package/dist/chunk-B53BERKG.js +386 -0
  15. package/dist/chunk-B53BERKG.js.map +1 -0
  16. package/dist/chunk-CE7IY7TB.js +104 -0
  17. package/dist/chunk-CE7IY7TB.js.map +1 -0
  18. package/dist/chunk-EAKE3N7W.js +804 -0
  19. package/dist/chunk-EAKE3N7W.js.map +1 -0
  20. package/dist/chunk-LRVPK7HI.js +491 -0
  21. package/dist/chunk-LRVPK7HI.js.map +1 -0
  22. package/dist/chunk-Q66NA2FU.js +174 -0
  23. package/dist/chunk-Q66NA2FU.js.map +1 -0
  24. package/dist/chunk-UI3FUWXM.js +533 -0
  25. package/dist/chunk-UI3FUWXM.js.map +1 -0
  26. package/dist/curvature-PkoLduGc.d.ts +454 -0
  27. package/dist/curves/index.d.ts +14 -5
  28. package/dist/curves/index.js +33 -111
  29. package/dist/curves/index.js.map +1 -1
  30. package/dist/index.d.ts +1511 -283
  31. package/dist/index.js +5755 -2674
  32. package/dist/index.js.map +1 -1
  33. package/dist/nd/index.d.ts +92 -27
  34. package/dist/nd/index.js +297 -0
  35. package/dist/nd/index.js.map +1 -1
  36. package/dist/path-BW8d_2RY.d.ts +157 -0
  37. package/dist/portCurve-C5HDWuuV.d.ts +30 -0
  38. package/dist/tessellate/index.d.ts +15 -4
  39. package/dist/tessellate/index.js +21 -277
  40. package/dist/tessellate/index.js.map +1 -1
  41. package/dist/warp/index.d.ts +254 -0
  42. package/dist/warp/index.js +1448 -0
  43. package/dist/warp/index.js.map +1 -0
  44. package/package.json +5 -1
  45. package/dist/chunk-7WFFCHRL.js.map +0 -1
  46. package/dist/chunk-IDXY2NCA.js +0 -177
  47. package/dist/chunk-IDXY2NCA.js.map +0 -1
  48. package/dist/chunk-NJ3IGAKR.js +0 -16
  49. package/dist/chunk-NJ3IGAKR.js.map +0 -1
  50. package/dist/chunk-OXH3NOXC.js +0 -62
  51. package/dist/chunk-OXH3NOXC.js.map +0 -1
  52. package/dist/chunk-URQMDR6Q.js +0 -80
  53. package/dist/chunk-URQMDR6Q.js.map +0 -1
  54. package/dist/cubicMath-BW-HJrCE.d.ts +0 -16
  55. package/dist/path-ljHxobyu.d.ts +0 -44
@@ -0,0 +1,386 @@
1
+ // src/box.ts
2
+ function boundsOfCoords(coords) {
3
+ if (coords.length < 2) return null;
4
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
5
+ for (let i = 0; i + 1 < coords.length; i += 2) {
6
+ const x = coords[i], y = coords[i + 1];
7
+ if (x < minX) minX = x;
8
+ if (y < minY) minY = y;
9
+ if (x > maxX) maxX = x;
10
+ if (y > maxY) maxY = y;
11
+ }
12
+ return [minX, minY, maxX, maxY];
13
+ }
14
+ function unionBox(a, b) {
15
+ return [
16
+ Math.min(a[0], b[0]),
17
+ Math.min(a[1], b[1]),
18
+ Math.max(a[2], b[2]),
19
+ Math.max(a[3], b[3])
20
+ ];
21
+ }
22
+ function boxContainsPoint(b, x, y) {
23
+ return x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3];
24
+ }
25
+ function boxContainsBox(outer, inner) {
26
+ return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];
27
+ }
28
+ function rectToContour(x, y, w, h) {
29
+ return Float64Array.of(x, y, x + w, y, x + w, y + h, x, y + h);
30
+ }
31
+
32
+ // src/commands.ts
33
+ var PATH_COMMANDS = {
34
+ /** moveTo — opens a new subpath. */
35
+ M: { code: 0, coords: 2 },
36
+ /** Straight segment from the pen to the next coord pair. */
37
+ L: { code: 1, coords: 2 },
38
+ /** Cubic bezier: two control points then the endpoint. */
39
+ C: { code: 2, coords: 6 },
40
+ /** Quadratic bezier: one control point then the endpoint. */
41
+ Q: { code: 3, coords: 4 },
42
+ /** Close the current subpath back to its start. Consumes no coords and
43
+ * leaves the pen where it is. */
44
+ Z: { code: 4, coords: 0 }
45
+ };
46
+ var PATH_M = PATH_COMMANDS.M.code;
47
+ var PATH_L = PATH_COMMANDS.L.code;
48
+ var PATH_C = PATH_COMMANDS.C.code;
49
+ var PATH_Q = PATH_COMMANDS.Q.code;
50
+ var PATH_Z = PATH_COMMANDS.Z.code;
51
+ var PATH_CMD_LENGTHS = buildCmdLengths();
52
+ function buildCmdLengths() {
53
+ const lengths = [];
54
+ for (const { code, coords } of Object.values(PATH_COMMANDS)) lengths[code] = coords;
55
+ return lengths;
56
+ }
57
+ function pathCommandCoordCount(cmd) {
58
+ return PATH_CMD_LENGTHS[cmd];
59
+ }
60
+ function forEachSegment(commands, coords, visit) {
61
+ let ci = 0;
62
+ let px = 0, py = 0;
63
+ let startX = 0, startY = 0;
64
+ let open = false;
65
+ for (let i = 0; i < commands.length; i++) {
66
+ const cmd = commands[i];
67
+ const opens = !open && cmd !== PATH_M && cmd !== PATH_Z;
68
+ if (opens) {
69
+ startX = px;
70
+ startY = py;
71
+ }
72
+ open = cmd !== PATH_Z;
73
+ if (visit(cmd, ci, px, py, i, opens) === false) return;
74
+ const len = pathCommandCoordCount(cmd);
75
+ if (len === void 0) throw new Error(`forEachSegment: unknown command code ${cmd}`);
76
+ if (len > 0) {
77
+ px = coords[ci + len - 2];
78
+ py = coords[ci + len - 1];
79
+ ci += len;
80
+ if (cmd === PATH_M) {
81
+ startX = px;
82
+ startY = py;
83
+ }
84
+ } else if (cmd === PATH_Z) {
85
+ px = startX;
86
+ py = startY;
87
+ }
88
+ }
89
+ }
90
+
91
+ // src/curve.ts
92
+ function cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t) {
93
+ const u = 1 - t;
94
+ const a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;
95
+ return [
96
+ a * x0 + b * x1 + c * x2 + d * x3,
97
+ a * y0 + b * y1 + c * y2 + d * y3
98
+ ];
99
+ }
100
+ function elevateQuadraticToCubic(q0x, q0y, cx, cy, q1x, q1y) {
101
+ return [
102
+ q0x + 2 / 3 * (cx - q0x),
103
+ q0y + 2 / 3 * (cy - q0y),
104
+ q1x + 2 / 3 * (cx - q1x),
105
+ q1y + 2 / 3 * (cy - q1y)
106
+ ];
107
+ }
108
+ function cubicAxisExtremaTs(p0, p1, p2, p3) {
109
+ const a = -p0 + 3 * p1 - 3 * p2 + p3;
110
+ const b = 2 * (p0 - 2 * p1 + p2);
111
+ const c = -p0 + p1;
112
+ const ts = [];
113
+ const push = (t) => {
114
+ if (t > 0 && t < 1) ts.push(t);
115
+ };
116
+ if (Math.abs(a) < 1e-12) {
117
+ if (Math.abs(b) > 1e-12) push(-c / b);
118
+ } else {
119
+ const disc = b * b - 4 * a * c;
120
+ if (disc >= 0) {
121
+ const sq = Math.sqrt(disc);
122
+ push((-b + sq) / (2 * a));
123
+ push((-b - sq) / (2 * a));
124
+ }
125
+ }
126
+ return ts;
127
+ }
128
+ function cubicBounds(x0, y0, x1, y1, x2, y2, x3, y3) {
129
+ let minX = Math.min(x0, x3), maxX = Math.max(x0, x3);
130
+ let minY = Math.min(y0, y3), maxY = Math.max(y0, y3);
131
+ for (const t of cubicAxisExtremaTs(x0, x1, x2, x3)) {
132
+ const [ex] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);
133
+ if (ex < minX) minX = ex;
134
+ if (ex > maxX) maxX = ex;
135
+ }
136
+ for (const t of cubicAxisExtremaTs(y0, y1, y2, y3)) {
137
+ const [, ey] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);
138
+ if (ey < minY) minY = ey;
139
+ if (ey > maxY) maxY = ey;
140
+ }
141
+ return [minX, minY, maxX, maxY];
142
+ }
143
+ function quadraticEvalAt(x0, y0, x1, y1, x2, y2, t) {
144
+ const u = 1 - t;
145
+ const a = u * u, b = 2 * u * t, c = t * t;
146
+ return [a * x0 + b * x1 + c * x2, a * y0 + b * y1 + c * y2];
147
+ }
148
+ function splitCubicAt(x0, y0, x1, y1, x2, y2, x3, y3, t) {
149
+ const ax = x0 + (x1 - x0) * t, ay = y0 + (y1 - y0) * t;
150
+ const bx = x1 + (x2 - x1) * t, by = y1 + (y2 - y1) * t;
151
+ const cx = x2 + (x3 - x2) * t, cy = y2 + (y3 - y2) * t;
152
+ const dx = ax + (bx - ax) * t, dy = ay + (by - ay) * t;
153
+ const ex = bx + (cx - bx) * t, ey = by + (cy - by) * t;
154
+ const mx = dx + (ex - dx) * t, my = dy + (ey - dy) * t;
155
+ return [[x0, y0, ax, ay, dx, dy, mx, my], [mx, my, ex, ey, cx, cy, x3, y3]];
156
+ }
157
+ function splitQuadraticAt(x0, y0, x1, y1, x2, y2, t) {
158
+ const ax = x0 + (x1 - x0) * t, ay = y0 + (y1 - y0) * t;
159
+ const bx = x1 + (x2 - x1) * t, by = y1 + (y2 - y1) * t;
160
+ const mx = ax + (bx - ax) * t, my = ay + (by - ay) * t;
161
+ return [[x0, y0, ax, ay, mx, my], [mx, my, bx, by, x2, y2]];
162
+ }
163
+ function splitLineAt(x0, y0, x1, y1, t) {
164
+ const mx = x0 + (x1 - x0) * t, my = y0 + (y1 - y0) * t;
165
+ return [[x0, y0, mx, my], [mx, my, x1, y1]];
166
+ }
167
+
168
+ // src/paths/builder.ts
169
+ var PathBuilder = class _PathBuilder {
170
+ cmds = [];
171
+ xs = [];
172
+ fillRule = "nonzero";
173
+ /** Seed a builder with an existing `PolygonPath`. Useful for extending
174
+ * an in-flight path with another segment (e.g. appending a cubic to
175
+ * the end of a curve in response to a user action) without hand-
176
+ * reaching into the `commands` / `coords` typed arrays.
177
+ *
178
+ * ```ts
179
+ * const next = PathBuilder.fromPath(current).curveTo(...).build();
180
+ * ```
181
+ */
182
+ static fromPath(path) {
183
+ const b = new _PathBuilder();
184
+ b.cmds = Array.from(path.commands);
185
+ b.xs = Array.from(path.coords);
186
+ b.fillRule = path.fillRule;
187
+ return b;
188
+ }
189
+ setFillRule(rule) {
190
+ this.fillRule = rule;
191
+ return this;
192
+ }
193
+ moveTo(x, y) {
194
+ this.cmds.push(PATH_M);
195
+ this.xs.push(x, y);
196
+ return this;
197
+ }
198
+ lineTo(x, y) {
199
+ this.cmds.push(PATH_L);
200
+ this.xs.push(x, y);
201
+ return this;
202
+ }
203
+ /** Cubic bezier to (x, y) with control points (x1, y1) and (x2, y2). */
204
+ curveTo(x1, y1, x2, y2, x, y) {
205
+ this.cmds.push(PATH_C);
206
+ this.xs.push(x1, y1, x2, y2, x, y);
207
+ return this;
208
+ }
209
+ /** Quadratic bezier to (x, y) with control point (x1, y1). */
210
+ quadTo(x1, y1, x, y) {
211
+ this.cmds.push(PATH_Q);
212
+ this.xs.push(x1, y1, x, y);
213
+ return this;
214
+ }
215
+ close() {
216
+ this.cmds.push(PATH_Z);
217
+ return this;
218
+ }
219
+ build() {
220
+ return {
221
+ kind: "polygon",
222
+ commands: new Uint8Array(this.cmds),
223
+ coords: new Float32Array(this.xs),
224
+ fillRule: this.fillRule
225
+ };
226
+ }
227
+ };
228
+ function rectPath(x, y, width, height) {
229
+ return { kind: "rect", x, y, width, height };
230
+ }
231
+ function asPolygonPath(path) {
232
+ if (path.kind === "polygon") return path;
233
+ return {
234
+ kind: "polygon",
235
+ commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L, PATH_Z]),
236
+ coords: Float32Array.from(rectToContour(path.x, path.y, path.width, path.height)),
237
+ fillRule: "nonzero"
238
+ };
239
+ }
240
+ function polylineFromPoints(points) {
241
+ const b = new PathBuilder();
242
+ const first = points[0];
243
+ if (!first) return rectPath(0, 0, 0, 0);
244
+ b.moveTo(first.x, first.y);
245
+ for (let i = 1; i < points.length; i++) {
246
+ const p = points[i];
247
+ if (p) b.lineTo(p.x, p.y);
248
+ }
249
+ return b.build();
250
+ }
251
+ function polygonFromPoints(points, opts = {}) {
252
+ if (points.length === 0) {
253
+ return {
254
+ kind: "polygon",
255
+ commands: new Uint8Array(),
256
+ coords: new Float32Array(),
257
+ fillRule: opts.fillRule ?? "nonzero"
258
+ };
259
+ }
260
+ const b = new PathBuilder();
261
+ if (opts.fillRule) b.setFillRule(opts.fillRule);
262
+ b.moveTo(points[0].x, points[0].y);
263
+ for (let i = 1; i < points.length; i++) b.lineTo(points[i].x, points[i].y);
264
+ b.close();
265
+ return b.build();
266
+ }
267
+ var ELLIPSE_KAPPA = 0.5522847498307936;
268
+ function ellipsePath(bounds) {
269
+ const cx = bounds.x + bounds.width / 2;
270
+ const cy = bounds.y + bounds.height / 2;
271
+ const rx = bounds.width / 2;
272
+ const ry = bounds.height / 2;
273
+ const ox = rx * ELLIPSE_KAPPA;
274
+ const oy = ry * ELLIPSE_KAPPA;
275
+ const b = new PathBuilder();
276
+ b.moveTo(cx + rx, cy);
277
+ b.curveTo(cx + rx, cy + oy, cx + ox, cy + ry, cx, cy + ry);
278
+ b.curveTo(cx - ox, cy + ry, cx - rx, cy + oy, cx - rx, cy);
279
+ b.curveTo(cx - rx, cy - oy, cx - ox, cy - ry, cx, cy - ry);
280
+ b.curveTo(cx + ox, cy - ry, cx + rx, cy - oy, cx + rx, cy);
281
+ b.close();
282
+ return b.build();
283
+ }
284
+ function regularPolygonPath(center, radius, sides, rotation = 0) {
285
+ const b = new PathBuilder();
286
+ for (let i = 0; i < sides; i++) {
287
+ const a = rotation + i / sides * Math.PI * 2;
288
+ const x = center.x + radius * Math.cos(a);
289
+ const y = center.y + radius * Math.sin(a);
290
+ if (i === 0) b.moveTo(x, y);
291
+ else b.lineTo(x, y);
292
+ }
293
+ b.close();
294
+ return b.build();
295
+ }
296
+ function starPath(center, outerRadius, points = 5, innerRadius = outerRadius / 2, rotation = 0) {
297
+ const b = new PathBuilder();
298
+ const n = points * 2;
299
+ for (let i = 0; i < n; i++) {
300
+ const a = rotation + i / n * Math.PI * 2;
301
+ const r = i % 2 === 0 ? outerRadius : innerRadius;
302
+ const x = center.x + r * Math.cos(a);
303
+ const y = center.y + r * Math.sin(a);
304
+ if (i === 0) b.moveTo(x, y);
305
+ else b.lineTo(x, y);
306
+ }
307
+ b.close();
308
+ return b.build();
309
+ }
310
+ function linePath(a, b) {
311
+ const pb = new PathBuilder();
312
+ pb.moveTo(a.x, a.y);
313
+ pb.lineTo(b.x, b.y);
314
+ return pb.build();
315
+ }
316
+
317
+ // src/paths/cornerSpec.ts
318
+ function cornerAt(path, index) {
319
+ const spec = path.corners?.[index];
320
+ return spec && spec.radius > 0 ? spec : null;
321
+ }
322
+ function cornerSpecAt(path, index) {
323
+ return path.corners?.[index] ?? null;
324
+ }
325
+ function hasCorners(path) {
326
+ const corners = path.corners;
327
+ if (!corners) return false;
328
+ for (const c of corners) if (c && c.radius > 0) return true;
329
+ return false;
330
+ }
331
+ function compactCorners(corners) {
332
+ let end = corners.length;
333
+ while (end > 0 && !corners[end - 1]) end--;
334
+ if (end === 0) return void 0;
335
+ const out = new Array(end);
336
+ for (let i = 0; i < end; i++) out[i] = corners[i] ?? null;
337
+ return out;
338
+ }
339
+ function withoutCorners(path) {
340
+ if (path.corners === void 0) return path;
341
+ const { corners: _dropped, ...rest } = path;
342
+ return rest;
343
+ }
344
+ function withCorner(path, index, spec) {
345
+ const next = path.corners ? [...path.corners] : [];
346
+ while (next.length <= index) next.push(null);
347
+ next[index] = spec ? { shape: spec.shape, radius: Math.max(0, spec.radius) } : null;
348
+ const corners = compactCorners(next);
349
+ const bare = withoutCorners(path);
350
+ return corners ? { ...bare, corners } : bare;
351
+ }
352
+ function scaleCorners(path, factor) {
353
+ if (!path.corners || factor === 1) return path;
354
+ return {
355
+ ...path,
356
+ corners: path.corners.map((c) => c ? { shape: c.shape, radius: c.radius * factor } : null)
357
+ };
358
+ }
359
+ function lerpCorners(a, b, t) {
360
+ if (!a && !b) return void 0;
361
+ const n = Math.max(a?.length ?? 0, b?.length ?? 0);
362
+ const out = new Array(n);
363
+ for (let i = 0; i < n; i++) {
364
+ const ca = a?.[i] ?? null, cb = b?.[i] ?? null;
365
+ const either = ca ?? cb;
366
+ if (!either) out[i] = null;
367
+ else if (ca && cb && ca.shape !== cb.shape) out[i] = t < 0.5 ? ca : cb;
368
+ else out[i] = { shape: either.shape, radius: (ca?.radius ?? 0) + ((cb?.radius ?? 0) - (ca?.radius ?? 0)) * t };
369
+ }
370
+ return compactCorners(out);
371
+ }
372
+
373
+ // src/paths/cubicMath.ts
374
+ function cubicPointAt(p0, p1, p2, p3, t) {
375
+ const [x, y] = cubicEvalAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);
376
+ return { x, y };
377
+ }
378
+ function splitCubicAtT(p0, p1, p2, p3, t) {
379
+ const [l, r] = splitCubicAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);
380
+ const quad = (c) => [{ x: c[0], y: c[1] }, { x: c[2], y: c[3] }, { x: c[4], y: c[5] }, { x: c[6], y: c[7] }];
381
+ return { left: quad(l), right: quad(r) };
382
+ }
383
+
384
+ export { PATH_C, PATH_CMD_LENGTHS, PATH_COMMANDS, PATH_L, PATH_M, PATH_Q, PATH_Z, PathBuilder, asPolygonPath, boundsOfCoords, boxContainsBox, boxContainsPoint, compactCorners, cornerAt, cornerSpecAt, cubicAxisExtremaTs, cubicBounds, cubicEvalAt, cubicPointAt, elevateQuadraticToCubic, ellipsePath, forEachSegment, hasCorners, lerpCorners, linePath, pathCommandCoordCount, polygonFromPoints, polylineFromPoints, quadraticEvalAt, rectPath, rectToContour, regularPolygonPath, scaleCorners, splitCubicAt, splitCubicAtT, splitLineAt, splitQuadraticAt, starPath, unionBox, withCorner, withoutCorners };
385
+ //# sourceMappingURL=chunk-B53BERKG.js.map
386
+ //# sourceMappingURL=chunk-B53BERKG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/box.ts","../src/commands.ts","../src/curve.ts","../src/paths/builder.ts","../src/paths/cornerSpec.ts","../src/paths/cubicMath.ts"],"names":[],"mappings":";AAQO,SAAS,eAAe,MAAA,EAAuC;AACpE,EAAA,IAAI,MAAA,CAAO,MAAA,GAAS,CAAA,EAAG,OAAO,IAAA;AAC9B,EAAA,IAAI,OAAO,QAAA,EAAU,IAAA,GAAO,QAAA,EAAU,IAAA,GAAO,WAAW,IAAA,GAAO,CAAA,QAAA;AAC/D,EAAA,KAAA,IAAS,IAAI,CAAA,EAAG,CAAA,GAAI,IAAI,MAAA,CAAO,MAAA,EAAQ,KAAK,CAAA,EAAG;AAC7C,IAAA,MAAM,IAAI,MAAA,CAAO,CAAC,GAAG,CAAA,GAAI,MAAA,CAAO,IAAI,CAAC,CAAA;AACrC,IAAA,IAAI,CAAA,GAAI,MAAM,IAAA,GAAO,CAAA;AACrB,IAAA,IAAI,CAAA,GAAI,MAAM,IAAA,GAAO,CAAA;AACrB,IAAA,IAAI,CAAA,GAAI,MAAM,IAAA,GAAO,CAAA;AACrB,IAAA,IAAI,CAAA,GAAI,MAAM,IAAA,GAAO,CAAA;AAAA,EACvB;AACA,EAAA,OAAO,CAAC,IAAA,EAAM,IAAA,EAAM,IAAA,EAAM,IAAI,CAAA;AAChC;AAGO,SAAS,QAAA,CAAS,GAAQ,CAAA,EAAa;AAC5C,EAAA,OAAO;AAAA,IACL,KAAK,GAAA,CAAI,CAAA,CAAE,CAAC,CAAA,EAAG,CAAA,CAAE,CAAC,CAAC,CAAA;AAAA,IACnB,KAAK,GAAA,CAAI,CAAA,CAAE,CAAC,CAAA,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AAA,EAAG,EAAA,CAAG,GAAG,EAAA,CAAG,CAAA,EAAG,EAAA,CAAG,CAAA,EAAG,CAAC,CAAA;AAC5E,EAAA,OAAO,EAAE,GAAG,CAAA,EAAE;AAChB;AAIO,SAAS,aAAA,CACd,EAAA,EAAW,EAAA,EAAW,EAAA,EAAW,IACjC,CAAA,EAC6E;AAC7E,EAAA,MAAM,CAAC,GAAG,CAAC,CAAA,GAAI,aAAa,EAAA,CAAG,CAAA,EAAG,GAAG,CAAA,EAAG,EAAA,CAAG,GAAG,EAAA,CAAG,CAAA,EAAG,GAAG,CAAA,EAAG,EAAA,CAAG,GAAG,EAAA,CAAG,CAAA,EAAG,EAAA,CAAG,CAAA,EAAG,CAAC,CAAA;AAC7E,EAAA,MAAM,OAAO,CAAC,CAAA,KACZ,CAAC,EAAE,CAAA,EAAG,EAAE,CAAC,CAAA,EAAG,GAAG,CAAA,CAAE,CAAC,GAAE,EAAG,EAAE,GAAG,CAAA,CAAE,CAAC,GAAG,CAAA,EAAG,CAAA,CAAE,CAAC,CAAA,EAAE,EAAG,EAAE,CAAA,EAAG,CAAA,CAAE,CAAC,CAAA,EAAG,CAAA,EAAG,EAAE,CAAC,CAAA,IAAK,EAAE,CAAA,EAAG,EAAE,CAAC,CAAA,EAAG,GAAG,CAAA,CAAE,CAAC,GAAG,CAAA;AACzF,EAAA,OAAO,EAAE,MAAM,IAAA,CAAK,CAAC,GAAG,KAAA,EAAO,IAAA,CAAK,CAAC,CAAA,EAAE;AACzC","file":"chunk-B53BERKG.js","sourcesContent":["/** Axis-aligned box as [minX, minY, maxX, maxY]. */\nexport type Box = readonly [number, number, number, number];\n\n/** An axis-aligned rectangle in object form. `Box` is the tuple form; this is\n * the one that survives being read by a human. */\nexport interface Rect { x: number; y: number; width: number; height: number }\n\n/** Tight bounds of an interleaved coord stream, or null if empty. */\nexport function boundsOfCoords(coords: ArrayLike<number>): Box | null {\n if (coords.length < 2) return null;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (let i = 0; i + 1 < coords.length; i += 2) {\n const x = coords[i], y = coords[i + 1];\n if (x < minX) minX = x;\n if (y < minY) minY = y;\n if (x > maxX) maxX = x;\n if (y > maxY) maxY = y;\n }\n return [minX, minY, maxX, maxY];\n}\n\n/** Smallest box containing both inputs. */\nexport function unionBox(a: Box, b: Box): Box {\n return [\n Math.min(a[0], b[0]),\n Math.min(a[1], b[1]),\n Math.max(a[2], b[2]),\n Math.max(a[3], b[3]),\n ];\n}\n\n/** Inclusive point-in-box test. */\nexport function boxContainsPoint(b: Box, x: number, y: number): boolean {\n return x >= b[0] && x <= b[2] && y >= b[1] && y <= b[3];\n}\n\n/** Whether `outer` wholly holds `inner`, edges inclusive. Two boxes that merely\n * overlap answer false. */\nexport function boxContainsBox(outer: Box, inner: Box): boolean {\n return inner[0] >= outer[0] && inner[1] >= outer[1] && inner[2] <= outer[2] && inner[3] <= outer[3];\n}\n\n/** Interleaved corner ring for a rect at (x,y,w,h), wound clockwise from the\n * origin corner. The closing edge is implicit — the same unclosed shape\n * `pointInPolygon` takes, and what a repeated first vertex would leave as a\n * zero-length segment for anything that strokes it. */\nexport function rectToContour(x: number, y: number, w: number, h: number): Float64Array {\n return Float64Array.of(x, y, x + w, y, x + w, y + h, x, y + h);\n}\n","/**\n * SVG-style command-stream encoding — the kit's single declaration of the path\n * opcodes.\n *\n * The codes index a `Uint8Array` command stream whose coords live in a\n * parallel float array, so a code declared anywhere but `PATH_COMMANDS` makes\n * every walker that doesn't know it misread the coord stream from that command\n * on — silently, for every path.\n */\n\n/** Opcode table: command code and the float coords it consumes. */\nexport const PATH_COMMANDS = {\n /** moveTo — opens a new subpath. */\n M: { code: 0, coords: 2 },\n /** Straight segment from the pen to the next coord pair. */\n L: { code: 1, coords: 2 },\n /** Cubic bezier: two control points then the endpoint. */\n C: { code: 2, coords: 6 },\n /** Quadratic bezier: one control point then the endpoint. */\n Q: { code: 3, coords: 4 },\n /** Close the current subpath back to its start. Consumes no coords and\n * leaves the pen where it is. */\n Z: { code: 4, coords: 0 },\n} as const;\n\n/** Mnemonic of a declared command (`'M' | 'L' | …`). */\nexport type PathCommandName = keyof typeof PATH_COMMANDS;\n/** Numeric code of a declared command. */\nexport type PathCommandCode = (typeof PATH_COMMANDS)[PathCommandName]['code'];\n\n/** Command code of `M` (moveTo). */\nexport const PATH_M = PATH_COMMANDS.M.code;\n/** Command code of `L` (lineTo). */\nexport const PATH_L = PATH_COMMANDS.L.code;\n/** Command code of `C` (cubic bezier). */\nexport const PATH_C = PATH_COMMANDS.C.code;\n/** Command code of `Q` (quadratic bezier). */\nexport const PATH_Q = PATH_COMMANDS.Q.code;\n/** Command code of `Z` (close subpath). */\nexport const PATH_Z = PATH_COMMANDS.Z.code;\n\n/** Float coords consumed by each command, indexed by command code. */\nexport const PATH_CMD_LENGTHS: readonly number[] = buildCmdLengths();\n\nfunction buildCmdLengths(): number[] {\n const lengths: number[] = [];\n for (const { code, coords } of Object.values(PATH_COMMANDS)) lengths[code] = coords;\n return lengths;\n}\n\n/** Float coords consumed by the command with this code. */\nexport function pathCommandCoordCount(cmd: number): number {\n return PATH_CMD_LENGTHS[cmd];\n}\n\n/**\n * Visit each command with its coord offset and the pen position BEFORE the\n * command consumes its coords (the segment start). The callback stops the\n * walk by returning `false`. `Z` returns the pen to the subpath's opening `M`.\n *\n * A command following a `Z` without an intervening `M` opens a new subpath at\n * the pen, as does a drawing command no `M` precedes at all. The visitor is\n * told with `opensSubpath`, and has to start its contour at `(penX, penY)`\n * then: there is no `M` to do it.\n *\n * A code `PATH_COMMANDS` does not declare throws once the visitor has seen it.\n */\nexport function forEachSegment(\n commands: ArrayLike<number>,\n coords: ArrayLike<number>,\n visit: (\n cmd: number,\n coordIndex: number,\n penX: number,\n penY: number,\n commandIndex: number,\n opensSubpath: boolean,\n ) => void | boolean,\n): void {\n let ci = 0;\n let px = 0, py = 0;\n let startX = 0, startY = 0;\n let open = false;\n for (let i = 0; i < commands.length; i++) {\n const cmd = commands[i];\n const opens = !open && cmd !== PATH_M && cmd !== PATH_Z;\n if (opens) { startX = px; startY = py; }\n open = cmd !== PATH_Z;\n if (visit(cmd, ci, px, py, i, opens) === false) return;\n const len = pathCommandCoordCount(cmd);\n if (len === undefined) throw new Error(`forEachSegment: unknown command code ${cmd}`);\n if (len > 0) {\n px = coords[ci + len - 2];\n py = coords[ci + len - 1];\n ci += len;\n if (cmd === PATH_M) { startX = px; startY = py; }\n } else if (cmd === PATH_Z) {\n px = startX; py = startY;\n }\n }\n}\n","import type { Box } from './box';\n\n/** Cubic Bezier point at parameter t (de Casteljau / Bernstein form). */\nexport function cubicEvalAt(\n x0: number, y0: number, x1: number, y1: number,\n x2: number, y2: number, x3: number, y3: number, t: number,\n): [number, number] {\n const u = 1 - t;\n const a = u * u * u, b = 3 * u * u * t, c = 3 * u * t * t, d = t * t * t;\n return [\n a * x0 + b * x1 + c * x2 + d * x3,\n a * y0 + b * y1 + c * y2 + d * y3,\n ];\n}\n\n/**\n * Degree-elevate a quadratic (q0, ctrl, q1) to a cubic. Returns the two\n * cubic control points [c1x, c1y, c2x, c2y]; the cubic endpoints equal the\n * quadratic endpoints. c1 = q0 + 2/3(ctrl-q0), c2 = q1 + 2/3(ctrl-q1).\n */\nexport function elevateQuadraticToCubic(\n q0x: number, q0y: number, cx: number, cy: number, q1x: number, q1y: number,\n): [number, number, number, number] {\n return [\n q0x + (2 / 3) * (cx - q0x),\n q0y + (2 / 3) * (cy - q0y),\n q1x + (2 / 3) * (cx - q1x),\n q1y + (2 / 3) * (cy - q1y),\n ];\n}\n\n/** The parameters in (0, 1) where one coordinate of a cubic, with control\n * values `p0..p3`, turns: the roots of its derivative. */\nexport function cubicAxisExtremaTs(p0: number, p1: number, p2: number, p3: number): number[] {\n // B'(t)=0 → quadratic a t² + b t + c = 0 with:\n const a = -p0 + 3 * p1 - 3 * p2 + p3;\n const b = 2 * (p0 - 2 * p1 + p2);\n const c = -p0 + p1;\n const ts: number[] = [];\n const push = (t: number) => { if (t > 0 && t < 1) ts.push(t); };\n if (Math.abs(a) < 1e-12) {\n if (Math.abs(b) > 1e-12) push(-c / b);\n } else {\n const disc = b * b - 4 * a * c;\n if (disc >= 0) {\n const sq = Math.sqrt(disc);\n push((-b + sq) / (2 * a));\n push((-b - sq) / (2 * a));\n }\n }\n return ts;\n}\n\n/** Tight AABB of a cubic, evaluating only extrema that lie on the curve. */\nexport function cubicBounds(\n x0: number, y0: number, x1: number, y1: number,\n x2: number, y2: number, x3: number, y3: number,\n): Box {\n let minX = Math.min(x0, x3), maxX = Math.max(x0, x3);\n let minY = Math.min(y0, y3), maxY = Math.max(y0, y3);\n for (const t of cubicAxisExtremaTs(x0, x1, x2, x3)) {\n const [ex] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);\n if (ex < minX) minX = ex;\n if (ex > maxX) maxX = ex;\n }\n for (const t of cubicAxisExtremaTs(y0, y1, y2, y3)) {\n const [, ey] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);\n if (ey < minY) minY = ey;\n if (ey > maxY) maxY = ey;\n }\n return [minX, minY, maxX, maxY];\n}\n\n/** Quadratic Bezier point at parameter t (Bernstein form). */\nexport function quadraticEvalAt(\n x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, t: number,\n): [number, number] {\n const u = 1 - t;\n const a = u * u, b = 2 * u * t, c = t * t;\n return [a * x0 + b * x1 + c * x2, a * y0 + b * y1 + c * y2];\n}\n\n/** A line segment's coords: start, end. */\nexport type LineCoords = [number, number, number, number];\n/** A quadratic Bezier's coords: start, control, end. */\nexport type QuadraticCoords = [number, number, number, number, number, number];\n/** A cubic Bezier's coords: start, two controls, end. */\nexport type CubicCoords = [number, number, number, number, number, number, number, number];\n\n/**\n * Split a cubic at parameter t (de Casteljau). The two halves share the point\n * at t and together trace the original exactly. A t outside [0, 1] splits the\n * curve's polynomial extension.\n */\nexport function splitCubicAt(\n x0: number, y0: number, x1: number, y1: number,\n x2: number, y2: number, x3: number, y3: number, t: number,\n): [CubicCoords, CubicCoords] {\n const ax = x0 + (x1 - x0) * t, ay = y0 + (y1 - y0) * t;\n const bx = x1 + (x2 - x1) * t, by = y1 + (y2 - y1) * t;\n const cx = x2 + (x3 - x2) * t, cy = y2 + (y3 - y2) * t;\n const dx = ax + (bx - ax) * t, dy = ay + (by - ay) * t;\n const ex = bx + (cx - bx) * t, ey = by + (cy - by) * t;\n const mx = dx + (ex - dx) * t, my = dy + (ey - dy) * t;\n return [[x0, y0, ax, ay, dx, dy, mx, my], [mx, my, ex, ey, cx, cy, x3, y3]];\n}\n\n/** Split a quadratic at parameter t (de Casteljau). See {@link splitCubicAt}. */\nexport function splitQuadraticAt(\n x0: number, y0: number, x1: number, y1: number, x2: number, y2: number, t: number,\n): [QuadraticCoords, QuadraticCoords] {\n const ax = x0 + (x1 - x0) * t, ay = y0 + (y1 - y0) * t;\n const bx = x1 + (x2 - x1) * t, by = y1 + (y2 - y1) * t;\n const mx = ax + (bx - ax) * t, my = ay + (by - ay) * t;\n return [[x0, y0, ax, ay, mx, my], [mx, my, bx, by, x2, y2]];\n}\n\n/** Split a line segment at parameter t. See {@link splitCubicAt}. */\nexport function splitLineAt(\n x0: number, y0: number, x1: number, y1: number, t: number,\n): [LineCoords, LineCoords] {\n const mx = x0 + (x1 - x0) * t, my = y0 + (y1 - y0) * t;\n return [[x0, y0, mx, my], [mx, my, x1, y1]];\n}\n","/**\n * Fluent builder for `PolygonPath`. Hides the `Uint8Array` / `Float32Array`\n * encoding behind move/line/curve/close calls and a final `build()`. Use\n * this to construct paths in tests and demos; production callers that need\n * to mutate large paths in place should reach for the raw arrays directly.\n *\n * Numeric capacity grows by doubling — typical for amortized O(1) push.\n *\n * Also exposes `rectPath` / `polygonFromPoints` shortcuts for the common\n * cases. `rectPath` returns the lighter `RectPath` subtype, not a polygon.\n */\n\nimport { rectToContour } from '../box';\nimport { PATH_C, PATH_L, PATH_M, PATH_Q, PATH_Z } from '../commands';\nimport type { Path, PathFillRule, PolygonPath, RectPath } from '../path';\n\n/** Fluent builder for `PolygonPath`; hides the `Uint8Array`/`Float32Array` encoding behind move/line/curve/close calls. */\nexport class PathBuilder {\n private cmds: number[] = [];\n private xs: number[] = [];\n private fillRule: PathFillRule = 'nonzero';\n\n /** Seed a builder with an existing `PolygonPath`. Useful for extending\n * an in-flight path with another segment (e.g. appending a cubic to\n * the end of a curve in response to a user action) without hand-\n * reaching into the `commands` / `coords` typed arrays.\n *\n * ```ts\n * const next = PathBuilder.fromPath(current).curveTo(...).build();\n * ```\n */\n static fromPath(path: PolygonPath): PathBuilder {\n const b = new PathBuilder();\n b.cmds = Array.from(path.commands);\n b.xs = Array.from(path.coords);\n b.fillRule = path.fillRule;\n return b;\n }\n\n setFillRule(rule: PathFillRule): this {\n this.fillRule = rule;\n return this;\n }\n\n moveTo(x: number, y: number): this {\n this.cmds.push(PATH_M);\n this.xs.push(x, y);\n return this;\n }\n\n lineTo(x: number, y: number): this {\n this.cmds.push(PATH_L);\n this.xs.push(x, y);\n return this;\n }\n\n /** Cubic bezier to (x, y) with control points (x1, y1) and (x2, y2). */\n curveTo(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this {\n this.cmds.push(PATH_C);\n this.xs.push(x1, y1, x2, y2, x, y);\n return this;\n }\n\n /** Quadratic bezier to (x, y) with control point (x1, y1). */\n quadTo(x1: number, y1: number, x: number, y: number): this {\n this.cmds.push(PATH_Q);\n this.xs.push(x1, y1, x, y);\n return this;\n }\n\n close(): this {\n this.cmds.push(PATH_Z);\n return this;\n }\n\n build(): PolygonPath {\n return {\n kind: 'polygon',\n commands: new Uint8Array(this.cmds),\n coords: new Float32Array(this.xs),\n fillRule: this.fillRule,\n };\n }\n}\n\n/** Construct a `RectPath` (the fast-path subtype). */\nexport function rectPath(x: number, y: number, width: number, height: number): RectPath {\n return { kind: 'rect', x, y, width, height };\n}\n\n/** `path` as a command stream drawing the same outline. A rect becomes its four\n * corners clockwise from `(x, y)`, the order `countPathAnchors` numbers them in. */\nexport function asPolygonPath(path: Path): PolygonPath {\n if (path.kind === 'polygon') return path;\n return {\n kind: 'polygon',\n commands: new Uint8Array([PATH_M, PATH_L, PATH_L, PATH_L, PATH_Z]),\n coords: Float32Array.from(rectToContour(path.x, path.y, path.width, path.height)),\n fillRule: 'nonzero',\n };\n}\n\n/** Build an open polyline from a flat list of points — the same geometry as\n * {@link polygonFromPoints} without the closing edge. A freehand stroke and a\n * measurement line want this; a region wants the closed one. */\nexport function polylineFromPoints(\n points: readonly { x: number; y: number }[],\n): PolygonPath | RectPath {\n const b = new PathBuilder();\n const first = points[0];\n if (!first) return rectPath(0, 0, 0, 0);\n b.moveTo(first.x, first.y);\n for (let i = 1; i < points.length; i++) {\n const p = points[i];\n if (p) b.lineTo(p.x, p.y);\n }\n return b.build();\n}\n\n/** Build a closed polygon from a flat list of points. */\nexport function polygonFromPoints(\n points: readonly { x: number; y: number }[],\n opts: { fillRule?: PathFillRule } = {},\n): PolygonPath {\n if (points.length === 0) {\n return {\n kind: 'polygon',\n commands: new Uint8Array(),\n coords: new Float32Array(),\n fillRule: opts.fillRule ?? 'nonzero',\n };\n }\n const b = new PathBuilder();\n if (opts.fillRule) b.setFillRule(opts.fillRule);\n b.moveTo(points[0].x, points[0].y);\n for (let i = 1; i < points.length; i++) b.lineTo(points[i].x, points[i].y);\n b.close();\n return b.build();\n}\n\n/** Cubic-Bezier kappa for circular-quadrant approximation (<1% max error). */\nconst ELLIPSE_KAPPA = 0.5522847498307936;\n\n/** Closed ellipse inscribed in `bounds`, as a 4-cubic-Bezier `PolygonPath`.\n * Matches the geometry `useEllipseTool`'s overlay paints. */\nexport function ellipsePath(\n bounds: { x: number; y: number; width: number; height: number },\n): PolygonPath {\n const cx = bounds.x + bounds.width / 2;\n const cy = bounds.y + bounds.height / 2;\n const rx = bounds.width / 2;\n const ry = bounds.height / 2;\n const ox = rx * ELLIPSE_KAPPA;\n const oy = ry * ELLIPSE_KAPPA;\n const b = new PathBuilder();\n b.moveTo(cx + rx, cy);\n b.curveTo(cx + rx, cy + oy, cx + ox, cy + ry, cx, cy + ry);\n b.curveTo(cx - ox, cy + ry, cx - rx, cy + oy, cx - rx, cy);\n b.curveTo(cx - rx, cy - oy, cx - ox, cy - ry, cx, cy - ry);\n b.curveTo(cx + ox, cy - ry, cx + rx, cy - oy, cx + rx, cy);\n b.close();\n return b.build();\n}\n\n/** Closed regular n-gon centered at `center`, circumscribed by `radius`.\n * `rotation` is in radians; default 0 puts the first vertex on the +x axis. */\nexport function regularPolygonPath(\n center: { x: number; y: number },\n radius: number,\n sides: number,\n rotation = 0,\n): PolygonPath {\n const b = new PathBuilder();\n for (let i = 0; i < sides; i++) {\n const a = rotation + (i / sides) * Math.PI * 2;\n const x = center.x + radius * Math.cos(a);\n const y = center.y + radius * Math.sin(a);\n if (i === 0) b.moveTo(x, y); else b.lineTo(x, y);\n }\n b.close();\n return b.build();\n}\n\n/** Closed n-pointed star centered at `center`, alternating `outerRadius` and\n * `innerRadius` (default `outerRadius / 2`). `rotation` is in radians. */\nexport function starPath(\n center: { x: number; y: number },\n outerRadius: number,\n points = 5,\n innerRadius: number = outerRadius / 2,\n rotation = 0,\n): PolygonPath {\n const b = new PathBuilder();\n const n = points * 2;\n for (let i = 0; i < n; i++) {\n const a = rotation + (i / n) * Math.PI * 2;\n const r = i % 2 === 0 ? outerRadius : innerRadius;\n const x = center.x + r * Math.cos(a);\n const y = center.y + r * Math.sin(a);\n if (i === 0) b.moveTo(x, y); else b.lineTo(x, y);\n }\n b.close();\n return b.build();\n}\n\n/** Open 2-vertex polyline from `a` to `b` — strokeable, not fillable. */\nexport function linePath(\n a: { x: number; y: number },\n b: { x: number; y: number },\n): PolygonPath {\n const pb = new PathBuilder();\n pb.moveTo(a.x, a.y);\n pb.lineTo(b.x, b.y);\n return pb.build();\n}\n","/**\n * Per-anchor corner specs: the stored half of corner shapes. A path carries\n * them in `PolygonPath.corners`, indexed by flat anchor index, and every\n * reader of its geometry sees them expanded (`resolveCorners`).\n */\nimport type { PolygonPath } from '../path';\nimport type { CornerShape } from './cornerShape';\n\n/** The corner at one anchor: its shape, and its setback, how far along each\n * edge from the anchor the cut starts. A `round` corner between edges at a\n * right angle is a circle of that radius. */\nexport interface CornerSpec {\n shape: CornerShape;\n radius: number;\n}\n\n/** The corner cut at flat anchor `index`, or null. A zero radius cuts nothing. */\nexport function cornerAt(path: PolygonPath, index: number): CornerSpec | null {\n const spec = path.corners?.[index];\n return spec && spec.radius > 0 ? spec : null;\n}\n\n/** The spec stored at flat anchor `index`, radius zero included: a shape\n * picked before any radius is dragged out. */\nexport function cornerSpecAt(path: PolygonPath, index: number): CornerSpec | null {\n return path.corners?.[index] ?? null;\n}\n\n/** Whether any anchor of `path` carries a corner with a radius. */\nexport function hasCorners(path: { kind: string; corners?: PolygonPath['corners'] }): boolean {\n const corners = path.corners;\n if (!corners) return false;\n for (const c of corners) if (c && c.radius > 0) return true;\n return false;\n}\n\n/** `corners` without trailing empty slots, or undefined when none is left. */\nexport function compactCorners(\n corners: readonly (CornerSpec | null | undefined)[],\n): (CornerSpec | null)[] | undefined {\n let end = corners.length;\n while (end > 0 && !corners[end - 1]) end--;\n if (end === 0) return undefined;\n const out: (CornerSpec | null)[] = new Array(end);\n for (let i = 0; i < end; i++) out[i] = corners[i] ?? null;\n return out;\n}\n\n/** `path` without its corner specs: the bare anchors the specs decorate. */\nexport function withoutCorners(path: PolygonPath): PolygonPath {\n if (path.corners === undefined) return path;\n const { corners: _dropped, ...rest } = path;\n return rest;\n}\n\n/** `path` with the corner at flat anchor `index` set to `spec`, or cleared\n * when `spec` is null. A zero radius keeps the shape and cuts nothing.\n * Never mutates `path`. */\nexport function withCorner(path: PolygonPath, index: number, spec: CornerSpec | null): PolygonPath {\n const next: (CornerSpec | null)[] = path.corners ? [...path.corners] : [];\n while (next.length <= index) next.push(null);\n next[index] = spec ? { shape: spec.shape, radius: Math.max(0, spec.radius) } : null;\n const corners = compactCorners(next);\n const bare = withoutCorners(path);\n return corners ? { ...bare, corners } : bare;\n}\n\n/** `path` with every corner radius multiplied by `factor`, as a uniform\n * scale of its geometry would carry them. */\nexport function scaleCorners(path: PolygonPath, factor: number): PolygonPath {\n if (!path.corners || factor === 1) return path;\n return {\n ...path,\n corners: path.corners.map((c) => (c ? { shape: c.shape, radius: c.radius * factor } : null)),\n };\n}\n\n/**\n * The corners of a path `t` of the way from `a` to `b`, which share their\n * anchors. A corner whose shape both ends agree on, or that one end leaves\n * sharp, grows its radius between them; one whose shape changes takes the\n * nearer end's.\n */\nexport function lerpCorners(\n a: PolygonPath['corners'],\n b: PolygonPath['corners'],\n t: number,\n): (CornerSpec | null)[] | undefined {\n if (!a && !b) return undefined;\n const n = Math.max(a?.length ?? 0, b?.length ?? 0);\n const out: (CornerSpec | null)[] = new Array(n);\n for (let i = 0; i < n; i++) {\n const ca = a?.[i] ?? null, cb = b?.[i] ?? null;\n const either = ca ?? cb;\n if (!either) out[i] = null;\n else if (ca && cb && ca.shape !== cb.shape) out[i] = t < 0.5 ? ca : cb;\n else out[i] = { shape: either.shape, radius: (ca?.radius ?? 0) + ((cb?.radius ?? 0) - (ca?.radius ?? 0)) * t };\n }\n return compactCorners(out);\n}\n","import { cubicEvalAt, splitCubicAt, type CubicCoords } from '../curve';\n\n/** A 2D point, the shape the point-taking path helpers read and return. */\nexport interface Point { x: number; y: number; }\n\n/** Point on the cubic Bezier (p0, p1, p2, p3) at parameter t. The point-shaped\n * face of geom's `cubicEvalAt`. */\nexport function cubicPointAt(p0: Point, p1: Point, p2: Point, p3: Point, t: number): Point {\n const [x, y] = cubicEvalAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);\n return { x, y };\n}\n\n/** De Casteljau subdivision of a cubic at parameter t. The point-shaped face\n * of geom's `splitCubicAt`; `left[3]` and `right[0]` are the point at t. */\nexport function splitCubicAtT(\n p0: Point, p1: Point, p2: Point, p3: Point,\n t: number,\n): { left: [Point, Point, Point, Point]; right: [Point, Point, Point, Point] } {\n const [l, r] = splitCubicAt(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, t);\n const quad = (c: CubicCoords): [Point, Point, Point, Point] =>\n [{ x: c[0], y: c[1] }, { x: c[2], y: c[3] }, { x: c[4], y: c[5] }, { x: c[6], y: c[7] }];\n return { left: quad(l), right: quad(r) };\n}\n"]}
@@ -0,0 +1,104 @@
1
+ import { cubicEvalAt, elevateQuadraticToCubic, forEachSegment, PATH_M, PATH_L, PATH_Q, PATH_C, PATH_Z } from './chunk-B53BERKG.js';
2
+
3
+ // src/nearest.ts
4
+ function nearestOnLine(px, py, x0, y0, x1, y1) {
5
+ const vx = x1 - x0, vy = y1 - y0;
6
+ const vv = vx * vx + vy * vy;
7
+ let t = vv === 0 ? 0 : ((px - x0) * vx + (py - y0) * vy) / vv;
8
+ t = t < 0 ? 0 : t > 1 ? 1 : t;
9
+ const x = t === 1 ? x1 : x0 + t * vx;
10
+ const y = t === 1 ? y1 : y0 + t * vy;
11
+ return { x, y, t, dist: Math.hypot(px - x, py - y) };
12
+ }
13
+ var CUBIC_SAMPLES = 32;
14
+ var REFINE_ITERS = 40;
15
+ var T_EPS = 1e-14;
16
+ function nearestOnCubic(px, py, x0, y0, x1, y1, x2, y2, x3, y3) {
17
+ const ax = -x0 + 3 * x1 - 3 * x2 + x3, ay = -y0 + 3 * y1 - 3 * y2 + y3;
18
+ const bx = 3 * x0 - 6 * x1 + 3 * x2, by = 3 * y0 - 6 * y1 + 3 * y2;
19
+ const cx = 3 * (x1 - x0), cy = 3 * (y1 - y0);
20
+ const d2At = (t) => {
21
+ const [x4, y4] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);
22
+ return (x4 - px) ** 2 + (y4 - py) ** 2;
23
+ };
24
+ const d2s = [];
25
+ for (let k = 0; k <= CUBIC_SAMPLES; k++) d2s.push(d2At(k / CUBIC_SAMPLES));
26
+ let bestT = 0, bestD2 = d2s[0];
27
+ for (let k = 0; k <= CUBIC_SAMPLES; k++) {
28
+ const d = d2s[k];
29
+ const prev = k > 0 ? d2s[k - 1] : Infinity;
30
+ const next = k < CUBIC_SAMPLES ? d2s[k + 1] : Infinity;
31
+ if (!(d <= prev && d <= next)) continue;
32
+ let lo = Math.max(0, (k - 1) / CUBIC_SAMPLES);
33
+ let hi = Math.min(1, (k + 1) / CUBIC_SAMPLES);
34
+ let t = k / CUBIC_SAMPLES;
35
+ for (let i = 0; i < REFINE_ITERS; i++) {
36
+ const t2 = t * t;
37
+ const ex = ax * t2 * t + bx * t2 + cx * t + x0 - px;
38
+ const ey = ay * t2 * t + by * t2 + cy * t + y0 - py;
39
+ const dx = 3 * ax * t2 + 2 * bx * t + cx, dy = 3 * ay * t2 + 2 * by * t + cy;
40
+ const ddx = 6 * ax * t + 2 * bx, ddy = 6 * ay * t + 2 * by;
41
+ const g = ex * dx + ey * dy;
42
+ const gp = dx * dx + dy * dy + ex * ddx + ey * ddy;
43
+ if (g > 0) hi = t;
44
+ else if (g < 0) lo = t;
45
+ else break;
46
+ let tn = gp > 0 ? t - g / gp : NaN;
47
+ if (!(tn > lo && tn < hi)) tn = (lo + hi) / 2;
48
+ const step = Math.abs(tn - t);
49
+ t = tn;
50
+ if (step < T_EPS || hi - lo < T_EPS) break;
51
+ }
52
+ const refined = d2At(t);
53
+ const [tk, dk] = refined <= d ? [t, refined] : [k / CUBIC_SAMPLES, d];
54
+ if (dk < bestD2) {
55
+ bestD2 = dk;
56
+ bestT = tk;
57
+ }
58
+ }
59
+ const [x, y] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, bestT);
60
+ return { x, y, t: bestT, dist: Math.hypot(x - px, y - py) };
61
+ }
62
+ function nearestOnQuadratic(px, py, x0, y0, x1, y1, x2, y2) {
63
+ const [c1x, c1y, c2x, c2y] = elevateQuadraticToCubic(x0, y0, x1, y1, x2, y2);
64
+ return nearestOnCubic(px, py, x0, y0, c1x, c1y, c2x, c2y, x2, y2);
65
+ }
66
+ function nearestOnPath(commands, coords, px, py) {
67
+ let best = null;
68
+ let startX = 0, startY = 0;
69
+ forEachSegment(commands, coords, (cmd, ci, x0, y0, commandIndex) => {
70
+ let hit;
71
+ if (cmd === PATH_M) {
72
+ startX = coords[ci];
73
+ startY = coords[ci + 1];
74
+ return;
75
+ } else if (cmd === PATH_L) {
76
+ hit = nearestOnLine(px, py, x0, y0, coords[ci], coords[ci + 1]);
77
+ } else if (cmd === PATH_Q) {
78
+ hit = nearestOnQuadratic(px, py, x0, y0, coords[ci], coords[ci + 1], coords[ci + 2], coords[ci + 3]);
79
+ } else if (cmd === PATH_C) {
80
+ hit = nearestOnCubic(
81
+ px,
82
+ py,
83
+ x0,
84
+ y0,
85
+ coords[ci],
86
+ coords[ci + 1],
87
+ coords[ci + 2],
88
+ coords[ci + 3],
89
+ coords[ci + 4],
90
+ coords[ci + 5]
91
+ );
92
+ } else if (cmd === PATH_Z) {
93
+ hit = nearestOnLine(px, py, x0, y0, startX, startY);
94
+ } else {
95
+ throw new Error(`nearestOnPath: unknown command code ${cmd}`);
96
+ }
97
+ if (best === null || hit.dist < best.dist) best = { ...hit, commandIndex, coordIndex: ci };
98
+ });
99
+ return best;
100
+ }
101
+
102
+ export { nearestOnCubic, nearestOnLine, nearestOnPath, nearestOnQuadratic };
103
+ //# sourceMappingURL=chunk-CE7IY7TB.js.map
104
+ //# sourceMappingURL=chunk-CE7IY7TB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/nearest.ts"],"names":["x","y"],"mappings":";;;AA0BO,SAAS,cACd,EAAA,EAAY,EAAA,EAAY,EAAA,EAAY,EAAA,EAAY,IAAY,EAAA,EAC9C;AACd,EAAA,MAAM,EAAA,GAAK,EAAA,GAAK,EAAA,EAAI,EAAA,GAAK,EAAA,GAAK,EAAA;AAC9B,EAAA,MAAM,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA,GAAK,EAAA;AAC1B,EAAA,IAAI,CAAA,GAAI,OAAO,CAAA,GAAI,CAAA,G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K,CAAC,CAAA;AAAA,QAAG,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,QAAG,MAAA,CAAO,KAAK,CAAC;AAAA,OAC3F;AAAA,IACF,CAAA,MAAA,IAAW,QAAQ,MAAA,EAAQ;AACzB,MAAA,GAAA,GAAM,cAAc,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,EAAA,EAAI,QAAQ,MAAM,CAAA;AAAA,IACpD,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oCAAA,EAAuC,GAAG,CAAA,CAAE,CAAA;AAAA,IAC9D;AACA,IAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,GAAA,CAAI,IAAA,GAAO,IAAA,CAAK,IAAA,EAAM,IAAA,GAAO,EAAE,GAAG,GAAA,EAAK,YAAA,EAAc,UAAA,EAAY,EAAA,EAAG;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,IAAA;AACT","file":"chunk-CE7IY7TB.js","sourcesContent":["/**\n * Nearest point on a segment or a whole path to a probe point: where it is,\n * its curve parameter, and how far away it lies.\n */\nimport { cubicEvalAt, elevateQuadraticToCubic } from './curve';\nimport { forEachSegment, PATH_M, PATH_L, PATH_Q, PATH_C, PATH_Z } from './commands';\n\n/** The point on one segment nearest a probe. */\nexport interface CurveNearest {\n x: number;\n y: number;\n /** Curve parameter of the point, in [0, 1]. */\n t: number;\n /** Euclidean distance from the probe. */\n dist: number;\n}\n\n/** The point on a path nearest a probe, and the command whose segment holds it. */\nexport interface PathNearest extends CurveNearest {\n /** Index of the segment's command in the command stream (`L`, `Q`, `C` or `Z`). */\n commandIndex: number;\n /** Offset of that command's first coord; for a `Z`, where its coords would begin. */\n coordIndex: number;\n}\n\n/** Nearest point on segment (x0,y0)-(x1,y1) to (px,py). */\nexport function nearestOnLine(\n px: number, py: number, x0: number, y0: number, x1: number, y1: number,\n): CurveNearest {\n const vx = x1 - x0, vy = y1 - y0;\n const vv = vx * vx + vy * vy;\n let t = vv === 0 ? 0 : ((px - x0) * vx + (py - y0) * vy) / vv;\n t = t < 0 ? 0 : t > 1 ? 1 : t;\n const x = t === 1 ? x1 : x0 + t * vx;\n const y = t === 1 ? y1 : y0 + t * vy;\n return { x, y, t, dist: Math.hypot(px - x, py - y) };\n}\n\n/** Coarse samples per cubic. Each local minimum among them is refined, so this\n * only has to separate the distance function's minima (a cubic has at most\n * three), not locate them. */\nconst CUBIC_SAMPLES = 32;\nconst REFINE_ITERS = 40;\nconst T_EPS = 1e-14;\n\n/**\n * Nearest point on the cubic (x0,y0)…(x3,y3) to (px,py). Samples the curve,\n * then refines every sampled local minimum with bracketed Newton on the\n * distance derivative, so a loop or cusp cannot capture it in the wrong basin.\n */\nexport function nearestOnCubic(\n px: number, py: number,\n x0: number, y0: number, x1: number, y1: number,\n x2: number, y2: number, x3: number, y3: number,\n): CurveNearest {\n // Power basis B(t) = a t³ + b t² + c t + p0, for the derivatives.\n const ax = -x0 + 3 * x1 - 3 * x2 + x3, ay = -y0 + 3 * y1 - 3 * y2 + y3;\n const bx = 3 * x0 - 6 * x1 + 3 * x2, by = 3 * y0 - 6 * y1 + 3 * y2;\n const cx = 3 * (x1 - x0), cy = 3 * (y1 - y0);\n\n const d2At = (t: number): number => {\n const [x, y] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, t);\n return (x - px) ** 2 + (y - py) ** 2;\n };\n\n const d2s: number[] = [];\n for (let k = 0; k <= CUBIC_SAMPLES; k++) d2s.push(d2At(k / CUBIC_SAMPLES));\n\n let bestT = 0, bestD2 = d2s[0];\n for (let k = 0; k <= CUBIC_SAMPLES; k++) {\n const d = d2s[k];\n const prev = k > 0 ? d2s[k - 1] : Infinity;\n const next = k < CUBIC_SAMPLES ? d2s[k + 1] : Infinity;\n if (!(d <= prev && d <= next)) continue;\n\n let lo = Math.max(0, (k - 1) / CUBIC_SAMPLES);\n let hi = Math.min(1, (k + 1) / CUBIC_SAMPLES);\n let t = k / CUBIC_SAMPLES;\n for (let i = 0; i < REFINE_ITERS; i++) {\n const t2 = t * t;\n const ex = ax * t2 * t + bx * t2 + cx * t + x0 - px;\n const ey = ay * t2 * t + by * t2 + cy * t + y0 - py;\n const dx = 3 * ax * t2 + 2 * bx * t + cx, dy = 3 * ay * t2 + 2 * by * t + cy;\n const ddx = 6 * ax * t + 2 * bx, ddy = 6 * ay * t + 2 * by;\n // g = ½ d/dt |B - P|², zero at a critical point; its sign says which side the minimum is on.\n const g = ex * dx + ey * dy;\n const gp = dx * dx + dy * dy + ex * ddx + ey * ddy;\n if (g > 0) hi = t; else if (g < 0) lo = t; else break;\n let tn = gp > 0 ? t - g / gp : NaN;\n if (!(tn > lo && tn < hi)) tn = (lo + hi) / 2;\n const step = Math.abs(tn - t);\n t = tn;\n if (step < T_EPS || hi - lo < T_EPS) break;\n }\n const refined = d2At(t);\n const [tk, dk] = refined <= d ? [t, refined] : [k / CUBIC_SAMPLES, d];\n if (dk < bestD2) { bestD2 = dk; bestT = tk; }\n }\n\n const [x, y] = cubicEvalAt(x0, y0, x1, y1, x2, y2, x3, y3, bestT);\n return { x, y, t: bestT, dist: Math.hypot(x - px, y - py) };\n}\n\n/** Nearest point on the quadratic (x0,y0)(x1,y1)(x2,y2) to (px,py). */\nexport function nearestOnQuadratic(\n px: number, py: number,\n x0: number, y0: number, x1: number, y1: number, x2: number, y2: number,\n): CurveNearest {\n // Degree elevation keeps the parameterization, so t carries over unchanged.\n const [c1x, c1y, c2x, c2y] = elevateQuadraticToCubic(x0, y0, x1, y1, x2, y2);\n return nearestOnCubic(px, py, x0, y0, c1x, c1y, c2x, c2y, x2, y2);\n}\n\n/**\n * Nearest point on a command-stream path to (px,py), over every `L`, `Q`, `C`\n * and the closing edge each `Z` draws. The earliest segment wins a tie.\n * Returns `null` when the path has no segment, and throws on a command code\n * `PATH_COMMANDS` does not declare.\n */\nexport function nearestOnPath(\n commands: ArrayLike<number>,\n coords: ArrayLike<number>,\n px: number,\n py: number,\n): PathNearest | null {\n let best: PathNearest | null = null;\n let startX = 0, startY = 0;\n forEachSegment(commands, coords, (cmd, ci, x0, y0, commandIndex) => {\n let hit: CurveNearest;\n if (cmd === PATH_M) {\n startX = coords[ci]; startY = coords[ci + 1];\n return;\n } else if (cmd === PATH_L) {\n hit = nearestOnLine(px, py, x0, y0, coords[ci], coords[ci + 1]);\n } else if (cmd === PATH_Q) {\n hit = nearestOnQuadratic(px, py, x0, y0, coords[ci], coords[ci + 1], coords[ci + 2], coords[ci + 3]);\n } else if (cmd === PATH_C) {\n hit = nearestOnCubic(\n px, py, x0, y0,\n coords[ci], coords[ci + 1], coords[ci + 2], coords[ci + 3], coords[ci + 4], coords[ci + 5],\n );\n } else if (cmd === PATH_Z) {\n hit = nearestOnLine(px, py, x0, y0, startX, startY);\n } else {\n throw new Error(`nearestOnPath: unknown command code ${cmd}`);\n }\n if (best === null || hit.dist < best.dist) best = { ...hit, commandIndex, coordIndex: ci };\n });\n return best;\n}\n"]}