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): use actual round-shape boundaries
Rudy Celeklib19e71d50f26
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bf7b18d..e2c0199 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -25,6 +25,9 @@ jobs:with:node-version: 22+ - name: Round line root regressions+ run: node --test scripts/lines-round.test.mjs+- name: Dial indicatorrun: |node examples/dial-indicator/build.mjsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8152ae2..3591210 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 uses ellipse boundaries and transformed circle boundaries, and treats hollow interiors as empty instead of solid dots.+- `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/scripts/line-ends.mjs b/scripts/line-ends.mjsindex 4f8a772..adce2cc 100644--- a/scripts/line-ends.mjs+++ b/scripts/line-ends.mjs@@ -139,10 +139,19 @@ function lineEnds({ select = null, tolerance = 1, root: rootSlack = 2, mark = 7,const filled = cs.fill !== "none" && Number(cs.fillOpacity) > 0.05;if (tag === "circle" || tag === "ellipse") {if (!stroked && !filled) continue;- const c = map([Number(el.getAttribute("cx") || 0), Number(el.getAttribute("cy") || 0)]);- const r = Number(el.getAttribute("r") || el.getAttribute("rx") || 0) * Math.hypot(ctm.a, ctm.b);- const entry = { el, kind: "dot", c, r };- for (let gx = Math.floor((c[0] - r) / cell); gx <= Math.floor((c[0] + r) / cell); gx++) for (let gy = Math.floor((c[1] - r) / cell); gy <= Math.floor((c[1] + r) / cell); gy++) add(gx, gy, entry);+ const cx = Number(el.getAttribute("cx") || 0);+ const cy = Number(el.getAttribute("cy") || 0);+ const rx = Number(el.getAttribute(tag === "circle" ? "r" : "rx") || 0);+ const ry = Number(el.getAttribute(tag === "circle" ? "r" : "ry") || 0);+ if (rx <= 0 || ry <= 0) continue;+ const points = Array.from({ length: 128 }, (_, index) => {+ const angle = index * Math.PI * 2 / 128;+ return map([cx + rx * Math.cos(angle), cy + ry * Math.sin(angle)]);+ });+ const entry = { el, kind: "round", points, cx, cy, rx, ry, filled };+ const xs = points.map(([x]) => x);+ const ys = points.map(([, y]) => y);+ for (let gx = Math.floor(Math.min(...xs) / cell); gx <= Math.floor(Math.max(...xs) / cell); gx++) for (let gy = Math.floor(Math.min(...ys) / cell); gy <= Math.floor(Math.max(...ys) / cell); gy++) add(gx, gy, entry);continue;}if (!stroked) continue;@@ -196,8 +205,11 @@ function lineEnds({ select = null, tolerance = 1, root: rootSlack = 2, mark = 7,for (let i = 1; i < own.length; i++) along.push(along[i - 1] + Math.hypot(own[i][0] - own[i - 1][0], own[i][1] - own[i - 1][1]));const total = along[along.length - 1];for (const entry of near(p, reach * 4)) {- if (entry.kind === "dot") {- best = Math.min(best, Math.max(0, Math.hypot(p[0] - entry.c[0], p[1] - entry.c[1]) - entry.r));+ if (entry.kind === "round") {+ const local = inverse(entry.el, p);+ const inside = ((local[0] - entry.cx) / entry.rx) ** 2 + ((local[1] - entry.cy) / entry.ry) ** 2 <= 1;+ if (entry.filled && inside) best = 0;+ else for (let index = 0; index < entry.points.length; index++) best = Math.min(best, segmentDistance(p, entry.points[index], entry.points[(index + 1) % entry.points.length]));continue;}if (entry.el === line.el && entry.sub === sub.index) {diff --git a/scripts/lines-round.test.mjs b/scripts/lines-round.test.mjsnew file mode 100644index 0000000..d451a5f--- /dev/null+++ b/scripts/lines-round.test.mjs@@ -0,0 +1,56 @@+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(shape, path) {+ const directory = await mkdtemp(join(tmpdir(), "anatomy-lines-round-"));+ 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">${shape}<path class="iso-line" fill="none" stroke="black" d="${path}"/></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("line ends above a flat ellipse are floating", async () => {+ const result = await check('<ellipse cx="50" cy="50" rx="40" ry="5" fill="black"/>', "M30 30L50 30");+ assert.equal(result.code, 1);+ assert.match(result.stdout, /line ends: 2 of 2/);+});++test("line ends inside an unfilled circle are floating", async () => {+ const result = await check('<circle cx="50" cy="50" r="40" fill="none" stroke="black"/>', "M30 50L50 50");+ assert.equal(result.code, 1);+ assert.match(result.stdout, /line ends: 2 of 2/);+});++test("line ends on ellipse rims remain rooted", async () => {+ const result = await check('<ellipse cx="50" cy="50" rx="40" ry="5" fill="none" stroke="black"/>', "M10 50L90 50");+ assert.equal(result.code, 0);+ assert.match(result.stdout, /line ends: 0/);+});++test("a nonuniformly scaled circle does not root nearby floating ends", async () => {+ const result = await check('<circle cx="25" cy="25" r="20" transform="scale(2,.25)" fill="black"/>', "M30 20L50 20");+ assert.equal(result.code, 1);+ assert.match(result.stdout, /line ends: 2 of 2/);+});++test("line ends inside a filled ellipse remain rooted", async () => {+ const result = await check('<ellipse cx="50" cy="50" rx="40" ry="5" fill="black"/>', "M30 50L50 50");+ assert.equal(result.code, 0);+ assert.match(result.stdout, /line ends: 0/);+});