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(lines): sample SVG arc curves instead of chords

Rudy Celeklic61be458ff84
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf7b18d..6daa29e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -25,6 +25,9 @@ jobs:
with:
node-version: 22
+ - name: Arc line root regressions
+ run: node --test scripts/lines-arcs.test.mjs
+
- name: Dial indicator
run: |
node examples/dial-indicator/build.mjs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8152ae2..c2cbbf7 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
+- The line-end check now follows SVG arc curves instead of treating each arc as a straight chord.
+
- `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/scripts/line-ends.mjs b/scripts/line-ends.mjs
index 4f8a772..b35b3ff 100644
--- a/scripts/line-ends.mjs
+++ b/scripts/line-ends.mjs
@@ -95,7 +95,16 @@ function lineEnds({ select = null, tolerance = 1, root: rootSlack = 2, mark = 7,
const reflected = control ? [2 * x - control[0], 2 * y - control[1]] : [x, y];
quad(reflected[0], reflected[1], v[i] + ox(), v[i + 1] + oy());
}
- else if (C === "A") for (let i = 0; i + 6 < v.length; i += 7) push(v[i + 5] + ox(), v[i + 6] + oy());
+ else if (C === "A") {
+ const arc = document.createElementNS("http://www.w3.org/2000/svg", "path");
+ arc.setAttribute("d", `M${x} ${y}${command}${args}`);
+ const length = arc.getTotalLength();
+ const count = Math.max(8, Math.ceil(length / 2));
+ for (let index = 1; index <= count; index++) {
+ const point = arc.getPointAtLength(length * index / count);
+ push(point.x, point.y);
+ }
+ }
if (C !== "C" && C !== "S" && C !== "Q" && C !== "T") control = null;
}
return out;
diff --git a/scripts/lines-arcs.test.mjs b/scripts/lines-arcs.test.mjs
new file mode 100644
index 0000000..1092519
--- /dev/null
+++ b/scripts/lines-arcs.test.mjs
@@ -0,0 +1,50 @@
+import assert from "node:assert/strict";
+import { execFile } from "node:child_process";
+import { mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { promisify } from "node:util";
+import { fileURLToPath } from "node:url";
+import test from "node:test";
+
+const execute = promisify(execFile);
+const lines = fileURLToPath(new URL("lines.mjs", import.meta.url));
+
+async function check(arc, line) {
+ const directory = await mkdtemp(join(tmpdir(), "anatomy-lines-arcs-"));
+ try {
+ const page = join(directory, "figure.html");
+ await writeFile(page, `<!doctype html><div class="iso-plate"><svg width="200" height="100" viewBox="0 0 200 100"><path fill="none" stroke="black" d="${arc}"/><path class="iso-line" fill="none" stroke="black" d="${line}"/></svg></div>`);
+ try {
+ return { code: 0, ...await execute(process.execPath, [lines, page, "--wait", "0"], { timeout: 30000 }) };
+ } catch (error) {
+ return { code: error.code, stdout: error.stdout, stderr: error.stderr };
+ }
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+}
+
+test("the empty chord of an arc does not root a line", async () => {
+ const result = await check("M20 50A30 30 0 0 1 80 50", "M50 50L50 70");
+ assert.equal(result.code, 1);
+ assert.match(result.stdout, /line ends: 2 of 2/);
+});
+
+test("the actual middle of an arc roots a line", async () => {
+ const result = await check("M20 50A30 30 0 0 1 80 50", "M50 20L50 0");
+ assert.equal(result.code, 1);
+ assert.match(result.stdout, /line ends: 1 of 2/);
+});
+
+test("relative arcs retain their endpoint and curvature", async () => {
+ const result = await check("M20 50a30 30 0 0 1 60 0", "M50 20L50 0");
+ assert.equal(result.code, 1);
+ assert.match(result.stdout, /line ends: 1 of 2/);
+});
+
+test("arc endpoints preserve fully rooted lines", async () => {
+ const result = await check("M20 50A30 30 0 0 1 80 50", "M20 50L80 50");
+ assert.equal(result.code, 0);
+ assert.match(result.stdout, /line ends: 0/);
+});