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): key clearance caches by sampling options
Rudy Celeklib4739497eb25
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bf7b18d..6829403 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -25,6 +25,9 @@ jobs:with:node-version: 22+ - name: Audit cache regressions+ run: node --test scripts/audit-cache.test.mjs+- name: Dial indicatorrun: |node examples/dial-indicator/build.mjsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8152ae2..e91cd0e 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+- Solid clearance audits rebuild cached surface grids when sampling spacing or cell size changes.+- `examples/test-rig/` drew its glass button dark in the light theme. `stretch.css` now has light values for its own colours.### Changeddiff --git a/kit/audit.mjs b/kit/audit.mjsindex f52d06c..1c0f220 100644--- a/kit/audit.mjs+++ b/kit/audit.mjs@@ -1567,7 +1567,10 @@ export function solidClearances(solids, { state, sunk = 0.5, spacing = 0.6, cellif (!solidClearances.cache) solidClearances.cache = new WeakMap();const cache = solidClearances.cache;const gridOf = (shape) => {- let grid = cache.get(shape);+ let samples = cache.get(shape);+ if (!samples) cache.set(shape, samples = new Map());+ const key = `${spacing}:${cell}`;+ let grid = samples.get(key);if (grid) return grid;grid = new Map();for (const p of surfaceOf(shape, spacing)) {@@ -1575,7 +1578,7 @@ export function solidClearances(solids, { state, sunk = 0.5, spacing = 0.6, cellif (!grid.has(key)) grid.set(key, []);grid.get(key).push(p);}- cache.set(shape, grid);+ samples.set(key, grid);return grid;};const pointsIn = (shape, box) => {diff --git a/scripts/audit-cache.test.mjs b/scripts/audit-cache.test.mjsnew file mode 100644index 0000000..62488ab--- /dev/null+++ b/scripts/audit-cache.test.mjs@@ -0,0 +1,37 @@+import assert from "node:assert/strict";+import test from "node:test";+import * as A from "../kit/audit.mjs";++function fixture(move = [1, 0, 0]) {+ return [+ A.box([0, 0, 0], [2, 2, 2], { name: "moving", move, piece: "moving" }),+ A.box([1.7, 0.6, 0.6], [2.2, 1.4, 1.4], { name: "fixed" }),+ ];+}+const inspect = (shapes, options = {}) => A.solidClearances(shapes, { state: 1, sunk: 0.05, ...options });+test("rebuilds the surface grid when the opted-in cell size changes", () => {+ const shapes = fixture();+ assert.equal(inspect(shapes, { cell: 0.1 }).length, 1);+ const cached = inspect(shapes);+ const fresh = inspect(fixture());+ assert.equal(cached.length, 1);+ assert.deepEqual(cached, fresh);+ assert.ok(Math.abs(cached[0].clearance + 0.8) < 1e-12);+});+test("refines surface samples when the opted-in spacing changes", () => {+ const shapes = fixture(); inspect(shapes, { spacing: 2 });+ const refined = inspect(shapes, { spacing: 0.1 });+ const fresh = inspect(fixture(), { spacing: 0.1 });+ assert.deepEqual(refined, fresh);+ assert.ok(Math.abs(refined[0].clearance + 0.8) < 1e-12);+});+test("preserves repeated default audits of the same moving overlap", () => {+ const shapes = fixture(); const first = inspect(shapes);+ assert.equal(first.length, 1); assert.deepEqual(inspect(shapes), first);+});+test("keeps a separated motion clear across sampling options", () => {+ const shapes = fixture([-1, 0, 0]);+ assert.deepEqual(inspect(shapes, { cell: 0.1 }), []);+ assert.deepEqual(inspect(shapes), []);+ assert.deepEqual(inspect(shapes, { spacing: 0.1 }), []);+});