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-audit: sample clips through their final instant, not past it

Rudy Celekli78095a187c8b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c9e657..c6221d1 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
+- The 3D turn audit samples a clip through its last instant and never past it. A clip whose length was not a whole number of frames was sampled beyond its end, or stopped short of its final pose.
- `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/kit/turn-audit.mjs b/kit/turn-audit.mjs
index ee033a9..8434d97 100644
--- a/kit/turn-audit.mjs
+++ b/kit/turn-audit.mjs
@@ -308,10 +308,15 @@ function familiesOf(T, { sweep, clips }) {
return out;
}
-function samplesOf(family, frame) {
+export function samplesOf(family, frame) {
const xs = [];
- const count = Math.max(1, Math.round((family.to - family.from) / frame));
- for (let i = 0; i < count + (family.periodic ? 0 : 1); i++) xs.push(family.from + i * frame);
+ if (family.periodic) {
+ const count = Math.max(1, Math.round((family.to - family.from) / frame));
+ for (let i = 0; i < count; i++) xs.push(family.from + i * frame);
+ return xs;
+ }
+ const count = Math.max(0, Math.ceil((family.to - family.from) / frame - 1e-9));
+ for (let i = 0; i <= count; i++) xs.push(Math.min(family.to, family.from + i * frame));
return xs;
}
diff --git a/scripts/turn-audit-samples.test.mjs b/scripts/turn-audit-samples.test.mjs
new file mode 100644
index 0000000..52c2cc3
--- /dev/null
+++ b/scripts/turn-audit-samples.test.mjs
@@ -0,0 +1,26 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+import { samplesOf } from "../kit/turn-audit.mjs";
+const clip = (from, to) => ({ from, to, periodic: false });
+test("a clip is sampled through its final instant and never past it", () => {
+ for (const [from, to, frame] of [[0, 1, 0.4], [0, 1, 0.3], [0, 0.42, 1 / 60], [0.5, 1.01, 1 / 60], [0, 2.5, 4 / 60]]) {
+ const xs = samplesOf(clip(from, to), frame);
+ assert.equal(xs[0], from);
+ assert.equal(xs[xs.length - 1], to);
+ assert.ok(xs.every((x, i) => x >= from && x <= to && (i === 0 || x > xs[i - 1])), `${from}..${to} by ${frame}: ${xs}`);
+ assert.ok(xs.every((x, i) => i === 0 || x - xs[i - 1] <= frame + 1e-9));
+ }
+});
+test("a clip whose length is a whole number of frames keeps its frames", () => {
+ assert.deepEqual(samplesOf(clip(0, 1), 0.25), [0, 0.25, 0.5, 0.75, 1]);
+ assert.equal(samplesOf(clip(0, 1), 1 / 60).length, 61);
+ assert.equal(samplesOf(clip(0, 1.5), 1 / 60).length, 91);
+});
+test("an empty clip has a single sample", () => {
+ assert.deepEqual(samplesOf(clip(2, 2), 1 / 60), [2]);
+});
+test("a periodic sweep still stops one frame short of the repeat", () => {
+ const xs = samplesOf({ from: 0, to: 360, periodic: true }, 90);
+ assert.deepEqual(xs, [0, 90, 180, 270]);
+ assert.equal(samplesOf({ from: 0, to: 360, periodic: true }, 0.3).length, 1200);
+});