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.

turn-fidelity.mjs: transform upright prisms through their frame before k.extrude

Stephen Chengec5236524670
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c9e657..be24922 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha
### Fixed
+- `turn-fidelity.mjs` transforms upright prisms through their authoring frame `F` (`F.o`, `F.u`, `F.v` and downward `F.a`) before calling `k.extrude`, so `turn-check.mjs --fidelity` matches `T.prism` on upright frame-authored and vertically split prisms.
- `capture.mjs` waits for the page to load before it touches it, even with `--wait 0`, and gives up with an error when Chrome leaves a request unanswered for 60 s instead of hanging.
- `drive.mjs` `until` times a condition inside the page, so one that is already true passes however short the wait, even on a slow machine; a promise that never settles still times out.
- Start headless Chrome on Windows from an elevated terminal: `capture.mjs`, `drive.mjs` and `turn-check.mjs` pass `--do-not-de-elevate` there. Chrome otherwise relaunches itself without the elevation, the process the script started exits with code 0, and the check stops with `Chrome exited before startup: 0` while the relaunched browser stays running.
diff --git a/scripts/fidelity-cut.test.mjs b/scripts/fidelity-cut.test.mjs
index 04b5bd6..c3bf289 100644
--- a/scripts/fidelity-cut.test.mjs
+++ b/scripts/fidelity-cut.test.mjs
@@ -7,15 +7,19 @@ 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) {
+async function run(kind, split = false, open = false, corrupt = null, options = {}) {
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;
+ const origin = options.origin ?? [0, 0, 0];
+ const axis = options.axis ?? [0, 0, 1];
+ const polygon = options.polygon ?? [[-2, -2], [2, -2], [2, 2], [-2, 2]];
+ const cutPlane = options.cutPlane ?? { n: [0, 0, 1], d: 5 };
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;};` : ""}`);
+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(${JSON.stringify(origin)},${JSON.stringify(axis)});const base={name:'body',group,F,s0:0,s1:10};const part=${kind === "prism" ? `T.prism({...base,polygon:${JSON.stringify(polygon)}})` : `T.round({...base,r:2,fixed:false,ends:${open ? "['open','flat']" : "['flat','flat']"}})`};${split ? `T.split(part,${JSON.stringify(cutPlane)});` : ""}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 }); }
}
@@ -43,6 +47,18 @@ for (const kind of ["prism", "round"]) test(`actual fidelity CLI preserves an un
compared(result.stdout, kind);
if (kind === "prism") assert.match(result.stdout, /control .*fails as it should/);
});
+for (const split of [false, true]) test(`actual fidelity CLI transforms upright frame prism (${split ? "split along axis" : "unsplit"})`, async () => {
+ const result = await run("prism", split, false, null, { origin: [4, -3, 2], polygon: [[-3, -1], [3, -1], [3, 1], [-3, 1]], cutPlane: { n: [1, 0, 0], d: 4 } });
+ assert.match(result.stdout, /fidelity passed/);
+ compared(result.stdout, "prism");
+ assert.match(result.stdout, /control .*fails as it should/);
+});
+test("actual fidelity CLI transforms upright frame prism with downward axis", async () => {
+ const result = await run("prism", false, false, null, { origin: [4, -3, 12], axis: [0, 0, -1], polygon: [[-3, -1], [3, -1], [3, 1], [-3, 1]] });
+ assert.match(result.stdout, /fidelity passed/);
+ compared(result.stdout, "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) => {
diff --git a/scripts/turn-fidelity.mjs b/scripts/turn-fidelity.mjs
index ede1dee..fc49917 100644
--- a/scripts/turn-fidelity.mjs
+++ b/scripts/turn-fidelity.mjs
@@ -90,7 +90,8 @@ for (const theta of angles) {
const { F, ring, s0, s1 } = part.world;
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 pts = up ? ring.map(([x, y]) => G.add3(G.add3(F.o, G.mul3(F.a, F.a[2] < 0 ? s1 : s0)), G.add3(G.mul3(F.u, x), G.mul3(F.v, y)))) : null;
+ const kit = up ? k.extrude(pts.map(([x, y]) => [x, y]), pts[0][2], s1 - s0, Pk) : G.prismOf(F, ring, s0, s1, Pk);
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);