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): refresh body rays when cameras change

Rudy Celekli865f3066c467
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..2eb093d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Projection ray regressions
+ run: node --test scripts/audit-projection.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..81e4887 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 ray casts now refresh body camera coefficients when the projection direction changes, so repeated builds retain the correct depth order.
+
- `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..9c1504a 100644
--- a/kit/audit.mjs
+++ b/kit/audit.mjs
@@ -324,9 +324,9 @@ function tubeDistance(shape, p, segments) {
function bodyDepth(shape, c, V, eps) {
const { F, poly } = shape;
- if (!shape._f) {
+ if (!shape._f || shape._f.view.some((value, index) => value !== V[index])) {
const s = poly.map(([value]) => value);
- shape._f = { aV: dot3(F.a, V), uV: dot3(F.u, V), vV: dot3(F.v, V), s0: Math.min(...s), s1: Math.max(...s), rm: Math.max(...poly.map(([, r]) => r)) };
+ shape._f = { view: [...V], aV: dot3(F.a, V), uV: dot3(F.u, V), vV: dot3(F.v, V), s0: Math.min(...s), s1: Math.max(...s), rm: Math.max(...poly.map(([, r]) => r)) };
}
const { aV, uV, vV, s0, s1, rm } = shape._f;
const q = [c[0] - F.o[0], c[1] - F.o[1], c[2] - F.o[2]];
diff --git a/scripts/audit-projection.test.mjs b/scripts/audit-projection.test.mjs
new file mode 100644
index 0000000..bbe13af
--- /dev/null
+++ b/scripts/audit-projection.test.mjs
@@ -0,0 +1,36 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import * as A from "../kit/audit.mjs";
+const projection = (azimuth, elevation, scale = 1) => ({ origin: [0, 0], scale, azimuth, elevation });
+const options = { step: 0.5, tolerance: 0.1, least: 0.25 };
+const fixture = () => [{ name: "body", key: 0, shapes: [A.cylinder(0, 0, 2, 0, 10)] }, { name: "probe", key: 0, shapes: [A.ball([1.5, 0, 5], 1)] }];
+for (const [name, before, after] of [
+ ["azimuth reversal", projection(45, 30), projection(180, 30)],
+ ["elevation change", projection(45, 30), projection(45, 60)],
+ ["side view to oblique", projection(0, 0), projection(45, 30)],
+]) test(`reused body ray geometry matches a fresh build after ${name}`, () => {
+ const items = fixture();
+ A.overlapsOf(items, before, options);
+ const reused = A.overlapsOf(items, after, options);
+ const fresh = A.overlapsOf(fixture(), after, options);
+ assert.equal(fresh.pairs.length, 1);
+ assert.deepEqual(reused, fresh);
+});
+test("azimuth reversal retains the physically nearer body in the key solver", () => {
+ const items = fixture();
+ A.overlapsOf(items, projection(45, 30), options);
+ const solved = A.orderKeys(items, A.overlapsOf(items, projection(180, 30), options));
+ assert.equal(solved.cycles.length, 0);
+ assert.ok(solved.keys[0] > solved.keys[1]);
+});
+test("repeated identical projections keep identical depth results", () => {
+ const items = fixture(); const P = projection(45, 30);
+ const first = A.overlapsOf(items, P, options);
+ assert.equal(first.pairs.length, 1);
+ assert.deepEqual(A.overlapsOf(items, P, options), first);
+});
+test("scale and origin changes keep the unchanged camera direction valid", () => {
+ const items = fixture(); A.overlapsOf(items, projection(45, 30), options);
+ const P = { ...projection(45, 30, 2), origin: [20, 30] };
+ assert.deepEqual(A.overlapsOf(items, P, options), A.overlapsOf(fixture(), P, options));
+});