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): detect sliding rod penetration

Rudy Celekli9375e986a9d9
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..8a5c0eb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -57,6 +57,9 @@ jobs:
node examples/raptor-engine/build.mjs
node examples/raptor-engine/build.mjs --light
+ - name: Sliding solid clearance regressions
+ run: node --test scripts/audit-slide-clearance.test.mjs
+
- name: Committed pages are unchanged
run: |
git status --short
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..487ad99 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 clearances check sliding rods whose drawn reach changes, even when their stretching geometry leaves no relative translation to a stationary obstacle.
+
- `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..2c6ab72 100644
--- a/kit/audit.mjs
+++ b/kit/audit.mjs
@@ -1563,7 +1563,13 @@ export function selfOverlaps(items, P, { entries: given = null, fold = 0.25, lea
}
export function solidClearances(solids, { state, sunk = 0.5, spacing = 0.6, cell = 4 } = {}) {
- const list = solids.filter((shape) => shape.kind !== "tube").map((shape) => (shape.slide && state !== undefined && shape.move ? { ...moved(shape, offsetOf(shape, state)), move: undefined } : shape));
+ const stretched = new Set();
+ const list = solids.filter((shape) => shape.kind !== "tube").map((shape) => {
+ if (!(shape.slide && state !== undefined && shape.move)) return shape;
+ const next = { ...moved(shape, offsetOf(shape, state)), move: undefined };
+ if (next.slide.to !== shape.slide.to) stretched.add(next);
+ return next;
+ });
if (!solidClearances.cache) solidClearances.cache = new WeakMap();
const cache = solidClearances.cache;
const gridOf = (shape) => {
@@ -1601,7 +1607,7 @@ export function solidClearances(solids, { state, sunk = 0.5, spacing = 0.6, cell
for (let a = 0; a < list.length; a++)
for (let b = a + 1; b < list.length; b++) {
const rel = sub3(offsets[a], offsets[b]);
- if (Math.abs(rel[0]) + Math.abs(rel[1]) + Math.abs(rel[2]) < 1e-6) continue;
+ if (Math.abs(rel[0]) + Math.abs(rel[1]) + Math.abs(rel[2]) < 1e-6 && !stretched.has(list[a]) && !stretched.has(list[b])) continue;
const box = { min: [0, 1, 2].map((i) => Math.max(bounds[a].min[i] + rel[i], bounds[b].min[i])), max: [0, 1, 2].map((i) => Math.min(bounds[a].max[i] + rel[i], bounds[b].max[i])) };
if (box.min.some((v, i) => v > box.max[i] - sunk)) continue;
if (seatedOn(list[a], list[b]) || seatedOn(list[b], list[a])) continue;
diff --git a/scripts/audit-slide-clearance.test.mjs b/scripts/audit-slide-clearance.test.mjs
new file mode 100644
index 0000000..a41b680
--- /dev/null
+++ b/scripts/audit-slide-clearance.test.mjs
@@ -0,0 +1,58 @@
+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: 45, elevation: 30 };
+const F = G.frameAlong([0, 0, 0], [0, 0, 1]);
+function scene(axis = [0, 0, 1]) {
+ const frame = G.frameAlong([0, 0, 0], axis);
+ const move = G.mul3(axis, 8);
+ const rod = A.slide(frame, 0, 2, 1, { name: "piston", move, piece: "piston" });
+ const obstacle = A.disc(frame, 6, 8, 2, { name: "obstacle" });
+ const drawn = G.rodOut(frame, 0, 2, 1, P, { stroke: 8 });
+ assert.equal(drawn.reach, 10);
+ assert.ok(drawn.paths.fill.length > 0 && drawn.clip.length > 0);
+ return { rod, obstacle, frame };
+}
+for (const axis of [[0, 0, 1], [1, 0, 0]]) test(`native solid clearance checks an extending rod along ${axis}`, () => {
+ const { rod, obstacle, frame } = scene(axis);
+ const state = { label: "stroke", shares: { piston: 1 } };
+ const posed = A.moved(rod, A.offsetOf(rod, state));
+ const inside = G.add3(frame.o, G.mul3(frame.a, 7));
+ assert.equal(posed.slide.to, 10);
+ assert.ok(A.sdf(posed, inside) < -0.9 && A.sdf(obstacle, inside) < -0.9);
+ const result = A.solidClearances([rod, obstacle], { state, spacing: 0.2, sunk: 0.2 });
+ assert.equal(result.length, 1);
+ assert.equal(result[0].tube, "piston");
+ assert.equal(result[0].other, "obstacle");
+ assert.equal(result[0].state, "stroke");
+ assert.ok(result[0].clearance < -0.9);
+});
+test("native recorder audit reports an extending rod with a stationary obstacle in either input order", () => {
+ const { rod, obstacle } = scene();
+ for (const shapes of [[rod, obstacle], [obstacle, rod]]) {
+ const R = A.recorder(P, { order: ["piston"] });
+ for (const shape of shapes) R.solid(shape);
+ const result = A.audit(R, P, { frames: [], apart: true });
+ assert.equal(result.apart.length, 1);
+ assert.ok(result.apart[0].clearance <= -0.5);
+ assert.ok(A.failures(result) > 0);
+ }
+});
+test("native solid clearance preserves rest, intermediate and retracted rod controls", () => {
+ const { rod, obstacle } = scene();
+ for (const state of [0, 0.4, -0.1]) assert.deepEqual(A.solidClearances([rod, obstacle], { state, spacing: 0.2, sunk: 0.2 }), []);
+});
+test("native solid clearance preserves translated solid penetration detection", () => {
+ const { obstacle } = scene();
+ const moving = A.ball([0, 0, 1], 1, { name: "moving", move: [0, 0, 6] });
+ const result = A.solidClearances([moving, obstacle], { state: 1, spacing: 0.2, sunk: 0.2 });
+ assert.equal(result.length, 1);
+ assert.ok(result[0].clearance < -0.9);
+});
+test("native sliding clearance preserves a seated host exemption", () => {
+ const { rod, obstacle } = scene();
+ rod.seated = true;
+ rod.cut = obstacle;
+ assert.deepEqual(A.solidClearances([rod, obstacle], { state: 1, spacing: 0.2, sunk: 0.2 }), []);
+});