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): let large depth graphs converge

Rudy Celeklib406d13f813e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..b0d6779 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Depth key convergence regressions
+ run: node --test scripts/audit-order-convergence.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..6db0068 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
+- Depth-key solving now allows large acyclic figures to converge beyond 400 rounds and avoids choosing a cycle victim from an empty set of violated rules.
+
- `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..a2f82f9 100644
--- a/kit/audit.mjs
+++ b/kit/audit.mjs
@@ -669,7 +669,7 @@ export function orderKeys(items, overlaps, { gap = 0.02, rounds = 0 } = {}) {
}
}
const rules = [...strongest.values()];
- const limit = rounds || Math.min(items.length + 1, 400);
+ const limit = rounds || items.length + 1;
const dropped = [];
let keys = start.slice();
let active = rules.slice();
@@ -705,7 +705,9 @@ export function orderKeys(items, overlaps, { gap = 0.02, rounds = 0 } = {}) {
walk = by[walk].back;
} while (walk !== node && loop.length <= items.length);
}
- const victim = (loop.length ? loop : active.filter((rule) => keys[rule.front] - keys[rule.back] < rule.need - 1e-9)).reduce((low, rule) => (rule.weight < low.weight ? rule : low));
+ const candidates = loop.length ? loop : active.filter((rule) => keys[rule.front] - keys[rule.back] < rule.need - 1e-9);
+ if (!candidates.length) break;
+ const victim = candidates.reduce((low, rule) => (rule.weight < low.weight ? rule : low));
dropped.push(victim);
active = active.filter((rule) => rule !== victim);
}
diff --git a/scripts/audit-order-convergence.test.mjs b/scripts/audit-order-convergence.test.mjs
new file mode 100644
index 0000000..2bbcf6c
--- /dev/null
+++ b/scripts/audit-order-convergence.test.mjs
@@ -0,0 +1,55 @@
+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 P = { origin: [0, 0], scale: 1, azimuth: 0, elevation: 0 };
+const cam = A.cameraBasis(P);
+const at = (screen, depth) => G.add3(G.mul3(cam.R, screen), G.mul3(cam.V, depth));
+const inspect = (items) => A.overlapsOf(items, P, { step: 0.25, tolerance: 0.01, least: 0.01 });
+const chain = (count) => Array.from({ length: count }, (_, i) => ({ name: `ball${i}`, key: 0, shapes: [A.ball(at(i * 1.5, -i * 0.5), 1)] }));
+const assertRules = (overlaps, solved) => {
+ for (const pair of overlaps.pairs) {
+ const front = pair.front[0].area >= overlaps.least ? pair.a : pair.b;
+ const back = front === pair.a ? pair.b : pair.a;
+ assert.ok(solved.keys[front] - solved.keys[back] >= 0.02 - 1e-9);
+ }
+};
+test("a 410-part acyclic drawn overlap chain converges without losing constraints", () => {
+ const items = chain(410); const overlaps = inspect(items);
+ assert.equal(overlaps.pairs.length, 409);
+ assert.ok(overlaps.pairs.every((p) => p.front[0].area >= overlaps.least && p.front[1].area < overlaps.least));
+ const solved = A.orderKeys(items, overlaps);
+ assert.deepEqual(solved.dropped, []);
+ assert.deepEqual(solved.cycles, []);
+ assertRules(overlaps, solved);
+});
+test("an explicit final-round budget does not invent a victim once all rules are satisfied", () => {
+ const items = chain(10); const overlaps = inspect(items);
+ const solved = A.orderKeys(items, overlaps, { rounds: 9 });
+ assert.deepEqual(solved.dropped, []);
+ assertRules(overlaps, solved);
+});
+test("small acyclic figures preserve the existing zero-drop solution", () => {
+ const items = chain(10); const overlaps = inspect(items); const solved = A.orderKeys(items, overlaps);
+ assert.deepEqual(solved.dropped, []);
+ assertRules(overlaps, solved);
+ assert.ok(Math.abs(solved.keys[0] - 0.18) < 1e-12);
+});
+test("an actual three-item geometric cycle still drops its weakest conflicting rule", () => {
+ const items = [
+ { name: "a", key: 0, shapes: [A.ball(at(0, 3), 1), A.ball(at(20, 0), 1)] },
+ { name: "b", key: 0, shapes: [A.ball(at(0, 0), 1), A.ball(at(10, 3), 1)] },
+ { name: "c", key: 0, shapes: [A.ball(at(10, 0), 1), A.ball(at(20, 3), 1)] },
+ ];
+ const overlaps = inspect(items); assert.equal(overlaps.pairs.length, 3);
+ const solved = A.orderKeys(items, overlaps);
+ assert.equal(solved.rules, 3);
+ assert.equal(solved.dropped.length, 1);
+ assert.equal(solved.cycles.length, 0);
+ for (const pair of overlaps.pairs) {
+ const front = pair.front[0].area >= overlaps.least ? pair.a : pair.b;
+ const back = front === pair.a ? pair.b : pair.a;
+ if (solved.dropped.some((rule) => rule.front === front && rule.back === back)) continue;
+ assert.ok(solved.keys[front] - solved.keys[back] >= 0.02 - 1e-9);
+ }
+});