Skip to content

An agent skill for creating detailed, interactive isometric illustrations of real-world machines and complex systems. Generates polished SVGs with optional WebGL shaders and 3D effects.

fix(audit): retain inflected profile curvature

Rudy Celeklid80ad505daf6
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..5e81041 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Inflected profile regressions
+ run: node --test scripts/audit-profile.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..a68b1c6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha
### Fixed
+- Audit profile tracing now checks quarter-span deviations, preserving inflected analytic and smooth profiles whose midpoint lies on their chord.
+
- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.
### Changed
diff --git a/kit/audit.mjs b/kit/audit.mjs
index f52d06c..6829473 100644
--- a/kit/audit.mjs
+++ b/kit/audit.mjs
@@ -19,7 +19,11 @@ export function traced(meridian, { radius = null, error = 0.02, depth = 6 } = {}
if (at) {
const split = (a, b, level) => {
const mid = (a + b) / 2;
- if (level >= depth || Math.abs(at(mid) - (at(a) + at(b)) / 2) <= error) return;
+ if (level >= depth) return;
+ const ra = at(a);
+ const rb = at(b);
+ const deviation = Math.max(...[0.25, 0.5, 0.75].map((t) => Math.abs(at(a + (b - a) * t) - (ra + (rb - ra) * t))));
+ if (deviation <= error) return;
split(a, mid, level + 1);
out.push([mid, at(mid)]);
split(mid, b, level + 1);
diff --git a/scripts/audit-profile.test.mjs b/scripts/audit-profile.test.mjs
new file mode 100644
index 0000000..7543bd1
--- /dev/null
+++ b/scripts/audit-profile.test.mjs
@@ -0,0 +1,41 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import * as A from "../kit/audit.mjs";
+import * as G from "../kit/lathe.mjs";
+const F = G.frameAlong([0, 0, 0], [0, 0, 1]);
+const radius = (s) => 2 + Math.sin(2 * Math.PI * s / 10);
+const slope = (s) => Math.cos(2 * Math.PI * s / 10) * 2 * Math.PI / 10;
+const profile = [[0, 2], [10, 2]];
+const radialAt = (points, s) => {
+ const index = points.findIndex((p) => p[0] >= s);
+ if (!index) return points[0][1];
+ const [a, ra] = points[index - 1]; const [b, rb] = points[index];
+ return ra + (rb - ra) * (s - a) / (b - a);
+};
+test("inflected analytic recording follows the actual band side geometry", () => {
+ const bands = G.bandsOf(profile, [], F, { origin: [0, 0], scale: 10 }, { radius, slope });
+ const recorded = A.traced(profile, { radius });
+ const actual = bands.sidesOf().points.flat();
+ const bulge = actual.filter((p) => Math.abs(p[2] - 2.5) < 1e-8);
+ assert.equal(bulge.length, 2);
+ for (const p of bulge) assert.ok(Math.abs(radialAt(recorded, p[2]) - Math.hypot(p[0], p[1])) <= 0.02);
+});
+test("analytic tracing keeps bulge points inside the recorded solid", () => {
+ assert.ok(A.sdf(A.solid(F, profile, { radius }), [0, 2.5, 2.5]) < 0);
+});
+test("analytic tracing keeps neck points outside the recorded solid", () => {
+ assert.ok(A.sdf(A.solid(F, profile, { radius }), [0, 1.5, 7.5]) > 0);
+});
+test("smooth Hermite inflection retains its quarter-span curvature", () => {
+ const knots = [[0, 2, 1], [1, 2, 1], [2, 3, 1], [3, 3, 1]];
+ const curve = G.profileCurve(knots);
+ assert.ok(Math.abs(radialAt(A.traced(knots), 1.25) - curve.radius(1.25)) <= 0.02);
+ assert.ok(Math.abs(radialAt(A.traced(knots), 1.75) - curve.radius(1.75)) <= 0.02);
+});
+test("constant and linear radius controls keep their exact two endpoints", () => {
+ assert.deepEqual(A.traced([[0, 2], [10, 2]], { radius: () => 2 }), [[0, 2], [10, 2]]);
+ assert.deepEqual(A.traced([[0, 1], [10, 3]], { radius: (s) => 1 + s / 5 }), [[0, 1], [10, 3]]);
+});
+test("explicit zero recursion depth retains the requested coarse profile", () => {
+ assert.deepEqual(A.traced(profile, { radius, depth: 0 }), profile);
+});