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(turning): preserve authored rounds and ownership when splitting
Rudy Celekli2cb2cdc8b819
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bf7b18d..2b5f418 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -25,6 +25,9 @@ jobs:with:node-version: 22+ - name: Split ownership regressions+ run: node --test scripts/turn-split-owner.test.mjs+- name: Dial indicatorrun: |node examples/dial-indicator/build.mjsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8152ae2..b584e4b 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+- Splitting now accepts default fixed rounds and preserves explicit prism/round ownership, so a pipe fitting can be split without inventing collisions with its own pipe.+- `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/turn-build.mjs b/kit/turn-build.mjsindex b92c8cd..d47de83 100644--- a/kit/turn-build.mjs+++ b/kit/turn-build.mjs@@ -674,7 +674,7 @@ export function turning(P, { recorder = null, scale = 1 } = {}) {if (part.kind === "prism") {const { F, ring, s0, s1 } = part.world;const along = dot3(N, F.a);- const base = { name: part.name, group: part.group, layer: part.layer, tone: part.tone, crease: part.crease, lit: part.lit, material: part.material, details: { ...part.details }, bevel: part.spec.bevel };+ const base = { name: part.name, owner: part.owner, group: part.group, layer: part.layer, tone: part.tone, crease: part.crease, lit: part.lit, material: part.material, details: { ...part.details }, bevel: part.spec.bevel };let halves;if (Math.abs(Math.abs(along) - 1) < 1e-6) {const sCut = (d - dot3(N, F.o)) / along;@@ -713,8 +713,8 @@ export function turning(P, { recorder = null, scale = 1 } = {}) {drop(part);return made;}- if (part.kind === "round") {- const { F, s0, s1, r0, r1, ends } = part.world;+ if (part.kind === "round" || (part.kind === "fixed" && part.round)) {+ const { F, s0, s1, r0, r1, ends } = part.round ?? part.world;const along = dot3(N, F.a);if (Math.abs(Math.abs(along) - 1) > 1e-6) throw new Error(`turning: a round can only be split across its axis (${part.name})`);const sCut = (d - dot3(N, F.o)) / along;@@ -722,7 +722,7 @@ export function turning(P, { recorder = null, scale = 1 } = {}) {const rAt = r0 + ((r1 - r0) * (sCut - s0)) / (s1 - s0);part.dead = true;if (T.R) T.R.solids.splice(T.R.solids.indexOf(part.shapes[0]), 1);- const base = { group: part.group, layer: part.layer, tone: part.tone, crease: part.crease, lit: part.lit, material: part.material, F, fixed: false };+ const base = { owner: part.owner, group: part.group, layer: part.layer, tone: part.tone, crease: part.crease, lit: part.lit, material: part.material, F, fixed: false };const made = [T.round({ ...base, name: `${part.name}.a`, s0, s1: sCut, r: [r0, rAt], ends: [ends[0], "open"], details: part.details }),T.round({ ...base, name: `${part.name}.b`, s0: sCut, s1, r: [rAt, r1], ends: ["open", ends[1]] }),diff --git a/scripts/turn-split-owner.test.mjs b/scripts/turn-split-owner.test.mjsnew file mode 100644index 0000000..3b4697b--- /dev/null+++ b/scripts/turn-split-owner.test.mjs@@ -0,0 +1,62 @@+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";+import { turning } from "../kit/turn-build.mjs";+import { TURN } from "../kit/turn.mjs";+import { posed } from "../kit/turn-audit.mjs";+function fixture(kind, owner = "pipe") {+ const T = turning({ origin: [0, 0], scale: 1, azimuth: 45, elevation: 30 }); T.layer("all");+ const group = T.group("assembly", { turn: { pivot: [5, 2] } });+ const F = G.frameAlong([0, 0, 0], [0, 0, 1]);+ const base = { name: "ferrule", owner, group, F, s0: 0, s1: 10 };+ const part = kind === "prism" ? T.prism({ ...base, polygon: [[-2, -2], [2, -2], [2, 2], [-2, 2]] }) : T.round({ ...base, r: 2, ...(kind === "default round" ? {} : { fixed: false }) });+ const tube = A.tube([[0, 0, -2], [0, 0, 12]], 0.5, { name: "pipe", owner: "pipe" });+ return { T, part, tube };+}+for (const kind of ["prism", "round", "default round"]) test(`split ${kind} preserves explicit ownership and its pipe clearance`, () => {+ const { T, part, tube } = fixture(kind);+ assert.deepEqual(A.clearances([tube], part.shapes), []);+ const halves = T.split(part, { n: [0, 0, 1], d: 5 });+ assert.equal(halves.length, 2);+ assert.ok(halves.every((half) => half.owner === "pipe" && half.shapes.every((shape) => shape.owner === "pipe")));+ assert.deepEqual(A.clearances([tube], halves.flatMap((half) => half.shapes)), []);+ T.build();+ const scene = TURN.prepare(T.data, { unit: 1 });+ for (const angle of [0, 45, 90, 180]) {+ const cams = TURN.cams(scene, { assembly: angle });+ const group = T.groups[0];+ const pose = { R: cams[group.index].R, t: cams[group.index].t, origin: group.origin };+ const shapes = halves.flatMap((half) => half.shapes.map((shape) => posed(shape, pose)));+ const original = posed(part.shapes[0], pose);+ assert.deepEqual(A.clearances([posed(tube, pose)], shapes), []);+ for (const z of [2.5, 7.5]) {+ const a = angle * Math.PI / 180;+ const point = [5 - 4 * Math.cos(a) + 2 * Math.sin(a), 2 - 4 * Math.sin(a) - 2 * Math.cos(a), z];+ const distance = Math.min(...shapes.map((shape) => A.sdf(shape, point)));+ assert.ok(distance < 0);+ assert.ok(Math.abs(distance - A.sdf(original, point)) < 1e-8);+ }+ for (const run of scene.runs) {+ const frame = TURN.emit(run, cams[run.group], TURN.frame(run));+ assert.ok(frame.d.some((path) => typeof path === "string" && path.length));+ }+ }+});+test("an unrelated pipe still reports real penetration of split fittings", () => {+ for (const kind of ["prism", "round", "default round"]) {+ const { T, part, tube } = fixture(kind, "other");+ const halves = T.split(part, { n: [0, 0, 1], d: 5 });+ const failures = A.clearances([tube], halves.flatMap((half) => half.shapes));+ assert.equal(failures.length, 2);+ assert.ok(failures.every((failure) => failure.kind === "through" && failure.clearance < 0));+ }+});+test("unowned split parts retain normal collision checking", () => {+ for (const kind of ["prism", "round", "default round"]) {+ const { T, part, tube } = fixture(kind, null);+ const halves = T.split(part, { n: [0, 0, 1], d: 5 });+ assert.ok(halves.every((half) => !half.owner && half.shapes.every((shape) => !shape.owner)));+ assert.equal(A.clearances([tube], halves.flatMap((half) => half.shapes)).length, 2);+ }+});