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(fidelity): honor intentional cut and open silhouettes

Rudy Celekli3d58415c078f
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..37e8b04 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,7 @@ jobs:
with:
node-version: 22
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
@@ -57,6 +58,9 @@ jobs:
node examples/raptor-engine/build.mjs
node examples/raptor-engine/build.mjs --light
+ - name: Cut silhouette fidelity regressions
+ run: node --test scripts/fidelity-cut.test.mjs
+
- name: Committed pages are unchanged
run: |
git status --short
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..93ad087 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
+- Native fidelity checks now compare complete filled silhouettes for cut parts and honor open round ends in the kit reference, preserving deliberately unstroked cut edges.
+
- `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/scripts/fidelity-cut.test.mjs b/scripts/fidelity-cut.test.mjs
new file mode 100644
index 0000000..04b5bd6
--- /dev/null
+++ b/scripts/fidelity-cut.test.mjs
@@ -0,0 +1,54 @@
+import assert from "node:assert/strict";
+import { execFile } from "node:child_process";
+import { mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+import { promisify } from "node:util";
+import { pathToFileURL } from "node:url";
+import test from "node:test";
+const execute = promisify(execFile);
+async function run(kind, split = false, open = false, corrupt = null) {
+ const directory = await mkdtemp(join(tmpdir(), "anatomy-fidelity-cut-"));
+ try {
+ const file = join(directory, "fixture.mjs");
+ const module = pathToFileURL(resolve("kit/turn-build.mjs")).href;
+ const frameModule = pathToFileURL(resolve("kit/lathe.mjs")).href;
+ const runtime = pathToFileURL(resolve("kit/turn.mjs")).href;
+ await writeFile(file, `import {turning} from ${JSON.stringify(module)};import * as G from ${JSON.stringify(frameModule)};
+export const P={origin:[0,0],scale:1,azimuth:45,elevation:30};export const T=turning(P);T.layer('parts');const group=T.group('assembly',{turn:{pivot:[5,2]}});const F=G.frameAlong([0,0,0],[0,0,1]);const base={name:'body',group,F,s0:0,s1:10};const part=${kind === "prism" ? "T.prism({...base,polygon:[[-2,-2],[2,-2],[2,2],[-2,2]]})" : `T.round({...base,r:2,fixed:false,ends:${open ? "['open','flat']" : "['flat','flat']"}})`};${split ? "T.split(part,{n:[0,0,1],d:5});" : ""}T.build();${corrupt ? `const {TURN}=await import(${JSON.stringify(runtime)});const emit=TURN.emit;TURN.emit=(run,cam,frame)=>{const f=emit(run,cam,frame);for(const role of ${JSON.stringify(corrupt === "edge" ? ["edge"] : corrupt === "fill" ? ["fill"] : ["fill", "edge"])})if(run.role[role]!==undefined)f.d[run.role[role]]=f.d[run.role[role]].replace(/-?\\d+(?:\\.\\d+)?/g,n=>String(Number(n)+20));return f;};` : ""}`);
+ return await execute(process.execPath, ["scripts/turn-check.mjs", file, "--fidelity", "--angles", "0,45,90,180"], { timeout: 30000 });
+ } finally { await rm(directory, { recursive: true, force: true }); }
+}
+function compared(stdout, kind) {
+ if (kind === "prism") assert.ok(Number(stdout.match(/over (\d+) faces/)[1]) > 0);
+ else {
+ assert.ok(Number(stdout.match(/rounds: (\d+) frames/)[1]) > 0);
+ assert.ok(Number(stdout.match(/of (\d+) interior cells/)[1]) > 0);
+ }
+}
+for (const kind of ["prism", "round"]) test(`actual fidelity CLI accepts split ${kind} with intentionally unstroked cuts`, async () => {
+ const result = await run(kind, true);
+ assert.match(result.stdout, /fidelity passed/);
+ compared(result.stdout, kind);
+ if (kind === "prism") assert.match(result.stdout, /control .*fails as it should/);
+});
+test("actual fidelity CLI honors an unsplit open round end", async () => {
+ const result = await run("round", false, true);
+ assert.match(result.stdout, /fidelity passed/);
+ compared(result.stdout, "round");
+});
+for (const kind of ["prism", "round"]) test(`actual fidelity CLI preserves an unsplit closed ${kind} control`, async () => {
+ const result = await run(kind);
+ assert.match(result.stdout, /fidelity passed/);
+ compared(result.stdout, kind);
+ if (kind === "prism") assert.match(result.stdout, /control .*fails as it should/);
+});
+for (const kind of ["prism", "round"]) for (const split of [false, true]) for (const fault of (split ? ["edge", "geometry", "fill"] : ["edge", "geometry"]))
+ test(`actual fidelity CLI detects ${fault} corruption of ${split ? "split" : "unsplit"} ${kind}`, async () => {
+ await assert.rejects(run(kind, split, false, fault), (error) => {
+ assert.equal(error.code, 1);
+ assert.match(error.stdout, /(?:prisms|rounds) FAILED/);
+ assert.match(error.stdout, /fidelity failed/);
+ return true;
+ });
+ });
diff --git a/scripts/turn-fidelity.mjs b/scripts/turn-fidelity.mjs
index 8e628a3..c50d998 100644
--- a/scripts/turn-fidelity.mjs
+++ b/scripts/turn-fidelity.mjs
@@ -91,9 +91,11 @@ for (const theta of angles) {
const up = run.up;
const Pk = planted ? { ...Pp, azimuth: Pp.azimuth - 2 } : Pp;
const kit = up ? k.extrude(ring, s0, s1 - s0, Pk) : G.prismOf(F, ring, s0, s1, Pk);
- const mine = subpaths(f.d[run.role.edge])[0].pts;
+ const cut = Boolean(part.spec.cuts?.length);
+ const mine = subpaths(f.d[run.role[cut ? "fill" : "edge"]])[0].pts;
const theirs = sh(subpaths(kit.fill)[0].pts);
- const ho = hausdorff(mine, theirs);
+ const visible = cut ? oneWay(subpaths(f.d[run.role.edge]).flatMap((path) => path.pts), theirs) : 0;
+ const ho = Math.max(hausdorff(mine, theirs), visible);
results.outline = Math.max(results.outline, ho);
if (ho > (worstAt[part.name]?.outline ?? -1)) worstAt[part.name] = { ...(worstAt[part.name] ?? {}), outline: ho, at: theta };
if (up) {
@@ -239,7 +241,7 @@ for (const theta of angles) {
ends = ["flat", "flat"];
profile = [[s0, r0], ...knots.slice(1, -1).map((sv) => [sv, curve.radius(sv), 1]), [s1, r1]];
} else ({ F, s0, s1, r0, r1, ends, profile } = part.world);
- const meridian = [[profile[0][0], 0], ...profile.filter((p) => p[1] > 1e-9), [profile[profile.length - 1][0], 0]];
+ const meridian = [...(ends[0] === "open" ? [] : [[profile[0][0], 0]]), ...profile.filter((p) => p[1] > 1e-9), ...(ends[1] === "open" ? [] : [[profile[profile.length - 1][0], 0]])];
const domed = ends.includes("dome");
const radius = (s) => {
if (ends[0] === "dome" && s < s0) return Math.sqrt(Math.max(0, r0 * r0 - (s - s0) ** 2));
@@ -262,11 +264,13 @@ for (const theta of angles) {
const kit = lathed ? G.lathe(meridian, F, Pp, { smooth: lathed }) : domed ? G.lathe(analytic, F, Pp, { smooth: { slope, radius } }) : G.lathe(meridian, F, Pp, { smooth: true });
const kitFine = lathed ? G.lathe(meridian, F, Pf, { smooth: lathed }) : domed ? G.lathe(analytic, F, Pf, { smooth: { slope, radius } }) : G.lathe(meridian, F, Pf, { smooth: true });
const sh = (pts) => pts.map(([x, y]) => [x + shift[0], y + shift[1]]);
- const mine = subpaths(f.d[run.role.edge])[0];
+ const cut = Boolean(part.spec.cuts?.length);
+ const mine = subpaths(f.d[run.role[cut ? "fill" : "edge"]])[0];
const theirs = sh(subpaths(kit.fill)[0]);
const fineRef = subpaths(kitFine.fill)[0].map(([x, y]) => [x / 10 + shift[0], y / 10 + shift[1]]);
const ho = hausdorff(mine, theirs);
- const hf = hausdorff(mine, fineRef);
+ const visible = cut ? subpaths(f.d[run.role.edge]).flat().reduce((worst, point) => Math.max(worst, distToPoly(point, fineRef)), 0) : 0;
+ const hf = Math.max(hausdorff(mine, fineRef), visible);
stats.outline = Math.max(stats.outline, ho);
stats.outlineFine = Math.max(stats.outlineFine, hf);
stats.parts++;