@weasel-js/geom 1.10.1 → 1.11.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 +9 -1
- package/dist/3d/index.d.ts +29 -2
- package/dist/3d/index.js +49 -1
- package/dist/3d/index.js.map +1 -1
- package/dist/booleans/index.d.ts +15 -10
- package/dist/booleans/index.js +306 -353
- package/dist/booleans/index.js.map +1 -1
- package/dist/{chunk-7WFFCHRL.js → chunk-6XSJY3TC.js} +6 -37
- package/dist/chunk-6XSJY3TC.js.map +1 -0
- package/dist/chunk-7KLJZFBY.js +573 -0
- package/dist/chunk-7KLJZFBY.js.map +1 -0
- package/dist/chunk-B53BERKG.js +386 -0
- package/dist/chunk-B53BERKG.js.map +1 -0
- package/dist/chunk-CE7IY7TB.js +104 -0
- package/dist/chunk-CE7IY7TB.js.map +1 -0
- package/dist/chunk-HGF5OVEN.js +129 -0
- package/dist/chunk-HGF5OVEN.js.map +1 -0
- package/dist/chunk-J2O2B54M.js +800 -0
- package/dist/chunk-J2O2B54M.js.map +1 -0
- package/dist/chunk-Q66NA2FU.js +174 -0
- package/dist/chunk-Q66NA2FU.js.map +1 -0
- package/dist/chunk-SASMXDBE.js +443 -0
- package/dist/chunk-SASMXDBE.js.map +1 -0
- package/dist/chunk-UI3FUWXM.js +533 -0
- package/dist/chunk-UI3FUWXM.js.map +1 -0
- package/dist/curvature-PkoLduGc.d.ts +454 -0
- package/dist/curves/index.d.ts +14 -5
- package/dist/curves/index.js +33 -111
- package/dist/curves/index.js.map +1 -1
- package/dist/index.d.ts +1468 -284
- package/dist/index.js +5450 -2672
- package/dist/index.js.map +1 -1
- package/dist/nd/index.d.ts +91 -27
- package/dist/nd/index.js +282 -0
- package/dist/nd/index.js.map +1 -1
- package/dist/path-BW8d_2RY.d.ts +157 -0
- package/dist/portCurve-C5HDWuuV.d.ts +30 -0
- package/dist/tessellate/index.d.ts +15 -4
- package/dist/tessellate/index.js +21 -277
- package/dist/tessellate/index.js.map +1 -1
- package/dist/warp/index.d.ts +252 -0
- package/dist/warp/index.js +1316 -0
- package/dist/warp/index.js.map +1 -0
- package/package.json +5 -1
- package/dist/chunk-7WFFCHRL.js.map +0 -1
- package/dist/chunk-IDXY2NCA.js +0 -177
- package/dist/chunk-IDXY2NCA.js.map +0 -1
- package/dist/chunk-NJ3IGAKR.js +0 -16
- package/dist/chunk-NJ3IGAKR.js.map +0 -1
- package/dist/chunk-OXH3NOXC.js +0 -62
- package/dist/chunk-OXH3NOXC.js.map +0 -1
- package/dist/chunk-URQMDR6Q.js +0 -80
- package/dist/chunk-URQMDR6Q.js.map +0 -1
- package/dist/cubicMath-BW-HJrCE.d.ts +0 -16
- package/dist/path-ljHxobyu.d.ts +0 -44
|
@@ -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,GAAA,CAAA,CAAM,KAAK,EAAA,IAAM,EAAA,GAAA,CAAM,EAAA,GAAK,EAAA,IAAM,EAAA,IAAM,EAAA;AAC3D,EAAA,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,CAAA,GAAI,IAAI,CAAA,GAAI,CAAA;AAC5B,EAAA,MAAM,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AA,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"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { nearestOnLine, nearestOnCubic } from './chunk-CE7IY7TB.js';
|
|
2
|
+
import { resolveCorners, fitCubicWithTangents } from './chunk-J2O2B54M.js';
|
|
3
|
+
import { forEachSegment, PATH_Z, PATH_Q, elevateQuadraticToCubic, cubicBounds, PATH_C, PATH_L, PATH_M } from './chunk-B53BERKG.js';
|
|
4
|
+
|
|
5
|
+
// src/paths/bounds.ts
|
|
6
|
+
function boundsOfPath(path) {
|
|
7
|
+
if (path.kind === "rect") return path;
|
|
8
|
+
const { commands, coords } = resolveCorners(path);
|
|
9
|
+
if (commands.length === 0) {
|
|
10
|
+
return { kind: "rect", x: 0, y: 0, width: 0, height: 0 };
|
|
11
|
+
}
|
|
12
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
13
|
+
let seen = false;
|
|
14
|
+
const include = (x, y) => {
|
|
15
|
+
if (x < minX) minX = x;
|
|
16
|
+
if (x > maxX) maxX = x;
|
|
17
|
+
if (y < minY) minY = y;
|
|
18
|
+
if (y > maxY) maxY = y;
|
|
19
|
+
seen = true;
|
|
20
|
+
};
|
|
21
|
+
forEachSegment(commands, coords, (cmd, ci, px, py) => {
|
|
22
|
+
switch (cmd) {
|
|
23
|
+
case PATH_M:
|
|
24
|
+
case PATH_L: {
|
|
25
|
+
include(coords[ci], coords[ci + 1]);
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case PATH_C: {
|
|
29
|
+
const [bMinX, bMinY, bMaxX, bMaxY] = cubicBounds(
|
|
30
|
+
px,
|
|
31
|
+
py,
|
|
32
|
+
coords[ci],
|
|
33
|
+
coords[ci + 1],
|
|
34
|
+
coords[ci + 2],
|
|
35
|
+
coords[ci + 3],
|
|
36
|
+
coords[ci + 4],
|
|
37
|
+
coords[ci + 5]
|
|
38
|
+
);
|
|
39
|
+
include(bMinX, bMinY);
|
|
40
|
+
include(bMaxX, bMaxY);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case PATH_Q: {
|
|
44
|
+
const qx2 = coords[ci + 2], qy2 = coords[ci + 3];
|
|
45
|
+
const [c1x, c1y, c2x, c2y] = elevateQuadraticToCubic(px, py, coords[ci], coords[ci + 1], qx2, qy2);
|
|
46
|
+
const [bMinX, bMinY, bMaxX, bMaxY] = cubicBounds(px, py, c1x, c1y, c2x, c2y, qx2, qy2);
|
|
47
|
+
include(bMinX, bMinY);
|
|
48
|
+
include(bMaxX, bMaxY);
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case PATH_Z:
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`boundsOfPath: unknown command ${cmd}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
if (!seen) return { kind: "rect", x: 0, y: 0, width: 0, height: 0 };
|
|
58
|
+
return { kind: "rect", x: minX, y: minY, width: maxX - minX, height: maxY - minY };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/paths/fitRun.ts
|
|
62
|
+
function keepCorner(to, from) {
|
|
63
|
+
if (from.corner) to.corner = { ...from.corner };
|
|
64
|
+
}
|
|
65
|
+
function fitPointRun(pts, tStart, tEnd, tol, out, closing) {
|
|
66
|
+
if (out.length === 0) out.push({ x: pts[0].x, y: pts[0].y });
|
|
67
|
+
const segs = [];
|
|
68
|
+
fitRecursive(pts, tStart, tEnd, tol, segs);
|
|
69
|
+
segs.forEach((seg, i) => {
|
|
70
|
+
const prev = out[out.length - 1];
|
|
71
|
+
if (seg.c1) prev.outHandle = seg.c1;
|
|
72
|
+
const isLast = i === segs.length - 1;
|
|
73
|
+
if (closing && isLast) {
|
|
74
|
+
if (seg.c2) out[0].inHandle = seg.c2;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
out.push(seg.c2 ? { x: seg.end.x, y: seg.end.y, inHandle: seg.c2 } : { x: seg.end.x, y: seg.end.y });
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function fitRecursive(pts, tStart, tEnd, tol, out) {
|
|
81
|
+
const a = pts[0];
|
|
82
|
+
const e = pts[pts.length - 1];
|
|
83
|
+
if (pts.length <= 2 || worstFromLine(pts, a, e).dist <= tol) {
|
|
84
|
+
out.push({ end: e });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const { cp1, cp2 } = fitCubicWithTangents(pts, tStart, tEnd);
|
|
88
|
+
const worst = worstFromCubic(pts, a, cp1, cp2, e);
|
|
89
|
+
if (worst.dist <= tol) {
|
|
90
|
+
out.push({ c1: cp1, c2: cp2, end: e });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const k = worst.index;
|
|
94
|
+
const center = unit(sub2(pts[k + 1], pts[k - 1]));
|
|
95
|
+
fitRecursive(pts.slice(0, k + 1), tStart, neg(center), tol, out);
|
|
96
|
+
fitRecursive(pts.slice(k), center, tEnd, tol, out);
|
|
97
|
+
}
|
|
98
|
+
function worstFromLine(pts, a, e) {
|
|
99
|
+
let index = 1, dist = 0;
|
|
100
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
101
|
+
const d = nearestOnLine(pts[i].x, pts[i].y, a.x, a.y, e.x, e.y).dist;
|
|
102
|
+
if (d > dist) {
|
|
103
|
+
dist = d;
|
|
104
|
+
index = i;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { index, dist };
|
|
108
|
+
}
|
|
109
|
+
function worstFromCubic(pts, a, c1, c2, e) {
|
|
110
|
+
let index = 1, dist = 0;
|
|
111
|
+
for (let i = 1; i < pts.length - 1; i++) {
|
|
112
|
+
const d = nearestOnCubic(pts[i].x, pts[i].y, a.x, a.y, c1.x, c1.y, c2.x, c2.y, e.x, e.y).dist;
|
|
113
|
+
if (d > dist) {
|
|
114
|
+
dist = d;
|
|
115
|
+
index = i;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { index, dist };
|
|
119
|
+
}
|
|
120
|
+
var sub2 = (p, q) => ({ x: p.x - q.x, y: p.y - q.y });
|
|
121
|
+
var neg = (p) => ({ x: -p.x, y: -p.y });
|
|
122
|
+
function unit(p) {
|
|
123
|
+
const len = Math.hypot(p.x, p.y);
|
|
124
|
+
return len === 0 ? { x: 0, y: 0 } : { x: p.x / len, y: p.y / len };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { boundsOfPath, fitPointRun, keepCorner };
|
|
128
|
+
//# sourceMappingURL=chunk-HGF5OVEN.js.map
|
|
129
|
+
//# sourceMappingURL=chunk-HGF5OVEN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/paths/bounds.ts","../src/paths/fitRun.ts"],"names":[],"mappings":";;;;;AAUO,SAAS,aAAa,IAAA,EAAsB;AACjD,EAAA,IAAI,IAAA,CAAK,IAAA,KAAS,MAAA,EAAQ,OAAO,IAAA;AAEjC,EAAA,MAAM,EAAE,QAAA,EAAU,MAAA,EAAO,GAAI,eAAe,IAAI,CAAA;AAChD,EAAA,IAAI,QAAA,CAAS,WAAW,CAAA,EAAG;AACzB,IAAA,OAAO,EAAE,IAAA,EAAM,MAAA,EAAQ,CAAA,EAAG,CAAA,EAAG,GAAG,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,MAAA,EAAQ,CAAA,EAAE;AAAA,EACzD;AAEA,EAAA,IAAI,OAAO,QAAA,EAAU,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AAA,OAAO,EAAE,OAAO,IAAA,EAAK;AACvB;AAEA,IAAM,IAAA,GAAO,CAAC,CAAA,EAAU,CAAA,MAAqB,EAAE,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,CAAA,CAAE,CAAA,EAAG,CAAA,EAAG,CAAA,CAAE,CAAA,GAAI,EAAE,CAAA,EAAE,CAAA;AAC1E,IAAM,GAAA,GAAM,CAAC,CAAA,MAAqB,EAAE,CAAA,EAAG,CAAC,CAAA,CAAE,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,CAAE,CAAA,EAAE,CAAA;AACrD,SAAS,KAAK,CAAA,EAAiB;AAC7B,EAAA,MAAM,MAAM,IAAA,CAAK,KAAA,CAAM,CAAA,CAAE,CAAA,EAAG,EAAE,CAAC,CAAA;AAC/B,EAAA,OAAO,QAAQ,CAAA,GAAI,EAAE,CAAA,EAAG,CAAA,EAAG,GAAG,CAAA,EAAE,GAAI,EAAE,CAAA,EAAG,EAAE,CAAA,GAAI,GAAA,EAAK,CAAA,EAAG,CAAA,CAAE,IAAI,GAAA,EAAI;AACnE","file":"chunk-HGF5OVEN.js","sourcesContent":["import { cubicBounds, elevateQuadraticToCubic } from '../curve';\nimport { forEachSegment, PATH_C, PATH_L, PATH_M, PATH_Q, PATH_Z } from '../commands';\nimport type { Path, RectPath } from '../path';\nimport { resolveCorners } from './corners';\n\n/**\n * AABB of a `Path`, returned as a `RectPath` for direct reuse with rect-fast-path machinery.\n * Control points are NOT included directly; they're used only to compute extrema that actually\n * lie on the curve. Corner shapes are bounded as they are drawn, expanded. Empty paths (no commands) return a zero-size rect anchored at the origin.\n */\nexport function boundsOfPath(path: Path): RectPath {\n if (path.kind === 'rect') return path;\n\n const { commands, coords } = resolveCorners(path);\n if (commands.length === 0) {\n return { kind: 'rect', x: 0, y: 0, width: 0, height: 0 };\n }\n\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n let seen = false;\n\n const include = (x: number, y: number) => {\n if (x < minX) minX = x;\n if (x > maxX) maxX = x;\n if (y < minY) minY = y;\n if (y > maxY) maxY = y;\n seen = true;\n };\n\n forEachSegment(commands, coords, (cmd, ci, px, py) => {\n switch (cmd) {\n case PATH_M:\n case PATH_L: {\n include(coords[ci], coords[ci + 1]);\n break;\n }\n case PATH_C: {\n const [bMinX, bMinY, bMaxX, bMaxY] = cubicBounds(\n px, py,\n coords[ci], coords[ci + 1],\n coords[ci + 2], coords[ci + 3],\n coords[ci + 4], coords[ci + 5],\n );\n include(bMinX, bMinY);\n include(bMaxX, bMaxY);\n break;\n }\n case PATH_Q: {\n const qx2 = coords[ci + 2], qy2 = coords[ci + 3];\n const [c1x, c1y, c2x, c2y] = elevateQuadraticToCubic(px, py, coords[ci], coords[ci + 1], qx2, qy2);\n const [bMinX, bMinY, bMaxX, bMaxY] = cubicBounds(px, py, c1x, c1y, c2x, c2y, qx2, qy2);\n include(bMinX, bMinY);\n include(bMaxX, bMaxY);\n break;\n }\n case PATH_Z:\n break;\n default:\n throw new Error(`boundsOfPath: unknown command ${cmd}`);\n }\n });\n\n if (!seen) return { kind: 'rect', x: 0, y: 0, width: 0, height: 0 };\n return { kind: 'rect', x: minX, y: minY, width: maxX - minX, height: maxY - minY };\n}\n\n","/**\n * Fitting a run of sampled points with as few cubics as hold it within a\n * tolerance, each held to the run's end tangents: the refit `simplifyPath`\n * and `warpPath` share.\n */\nimport { nearestOnCubic, nearestOnLine } from '../nearest';\nimport type { PenAnchor } from './anchors';\nimport type { Point } from './cubicMath';\nimport { fitCubicWithTangents } from './schneiderFit';\n\n/** Give `to`, an anchor a refit kept where `from` was, `from`'s corner spec. */\nexport function keepCorner(to: PenAnchor, from: PenAnchor): void {\n if (from.corner) to.corner = { ...from.corner };\n}\n\n/**\n * Fit `pts` with cubics held to the end tangents, splitting at the worst\n * sample until every sample is within `tol`, and append the anchors after the\n * first to `out` (the first too when `out` is empty). `closing` folds the\n * final anchor, which lands on the subpath's first, into that first one.\n */\nexport function fitPointRun(pts: Point[], tStart: Point, tEnd: Point, tol: number, out: PenAnchor[], closing: boolean): void {\n if (out.length === 0) out.push({ x: pts[0].x, y: pts[0].y });\n const segs: Array<{ c1?: Point; c2?: Point; end: Point }> = [];\n fitRecursive(pts, tStart, tEnd, tol, segs);\n segs.forEach((seg, i) => {\n const prev = out[out.length - 1];\n if (seg.c1) prev.outHandle = seg.c1;\n const isLast = i === segs.length - 1;\n if (closing && isLast) {\n if (seg.c2) out[0].inHandle = seg.c2;\n return;\n }\n out.push(seg.c2 ? { x: seg.end.x, y: seg.end.y, inHandle: seg.c2 } : { x: seg.end.x, y: seg.end.y });\n });\n}\n\nfunction fitRecursive(\n pts: Point[], tStart: Point, tEnd: Point, tol: number,\n out: Array<{ c1?: Point; c2?: Point; end: Point }>,\n): void {\n const a = pts[0];\n const e = pts[pts.length - 1];\n if (pts.length <= 2 || worstFromLine(pts, a, e).dist <= tol) {\n out.push({ end: e });\n return;\n }\n const { cp1, cp2 } = fitCubicWithTangents(pts, tStart, tEnd);\n const worst = worstFromCubic(pts, a, cp1, cp2, e);\n if (worst.dist <= tol) {\n out.push({ c1: cp1, c2: cp2, end: e });\n return;\n }\n const k = worst.index;\n const center = unit(sub2(pts[k + 1], pts[k - 1]));\n fitRecursive(pts.slice(0, k + 1), tStart, neg(center), tol, out);\n fitRecursive(pts.slice(k), center, tEnd, tol, out);\n}\n\nfunction worstFromLine(pts: Point[], a: Point, e: Point): { index: number; dist: number } {\n let index = 1, dist = 0;\n for (let i = 1; i < pts.length - 1; i++) {\n const d = nearestOnLine(pts[i].x, pts[i].y, a.x, a.y, e.x, e.y).dist;\n if (d > dist) { dist = d; index = i; }\n }\n return { index, dist };\n}\n\nfunction worstFromCubic(pts: Point[], a: Point, c1: Point, c2: Point, e: Point): { index: number; dist: number } {\n let index = 1, dist = 0;\n for (let i = 1; i < pts.length - 1; i++) {\n const d = nearestOnCubic(pts[i].x, pts[i].y, a.x, a.y, c1.x, c1.y, c2.x, c2.y, e.x, e.y).dist;\n if (d > dist) { dist = d; index = i; }\n }\n return { index, dist };\n}\n\nconst sub2 = (p: Point, q: Point): Point => ({ x: p.x - q.x, y: p.y - q.y });\nconst neg = (p: Point): Point => ({ x: -p.x, y: -p.y });\nfunction unit(p: Point): Point {\n const len = Math.hypot(p.x, p.y);\n return len === 0 ? { x: 0, y: 0 } : { x: p.x / len, y: p.y / len };\n}\n"]}
|