Files
superGeometry 8de2367a0c Stress tests: a phone stand, an ice cube tray, a headphone hook, a spanner, a planter, a door handle
== A phone stand (plane at angle, offset edge, through-all cut) ==

A phone stand built by code and by hand on a phone, the two matching:
a base, a back leaning at 75 degrees on a plane through its top edge, a
lip raised from an Offset Edge line, a cable hole cut through all, the
lip chamfered and the back's top rounded. What it turned up:

- A join that only touches along an edge (the back stood on the base's
  edge) made two solids meeting at an edge and was called sound. Health
  now counts pinched edges (more than two faces round them) and such a
  body is not healthy; the join says "only touches the body along an
  edge" and to let them overlap.
- A rectangle's height typed 93 came out 92.999999999999 (the solver's
  float noise, shown, saved and built). Values a hair off a clean one
  are put on it when the constraints stay as well met.
- Cut with Through all on a sketch on a face went out into the air and
  cut nothing: with no way picked yet, a through-all cut now goes into
  the body (Flip direction still turns it).
- Once a chamfer's preview showed, its edge was gone from the view, so
  tapping it again could not un-pick it: a tap near a picked edge's own
  line now drops it.

== An ice cube tray (draft, two-way pattern, shell, lettering) ==

An ice cube tray built by code and by hand on a phone, the two the same:
one pocket pulled down with a 6 degree draft as a body of its own,
patterned four along and two across, all eight subtracted from the
block, the block shelled from below (walls 2 thick round every pocket),
the rim rounded, ICE typed on the front and raised. What it turned up:

- Subtract's clearance box sat between the first two bodies: over the
  middle of the tray, on the pockets still to be tapped, and a tap meant
  for one opened its number pad over half the tray. It moves down the
  screen, clear of the bodies.
- With many bodies taken away, the signs (to swap the bodies round)
  were pushed aside onto bodies still to be tapped, and a tap meant for
  a pocket swapped the tray out. Past two, only the first keeps a sign.
- A pattern running, its first body picked, the view's taps go to its
  direction: four pockets to pattern across could only be had by
  starting again from Items. Now a body tapped in Items joins the
  running pattern (or leaves it).

== A headphone hook (symmetric, up to a plane, thread) ==

A headphone hook built by code and by hand on a phone, the two the
same to the face: a C clamp pulled Symmetric, an arm pulled Up to a
plane 50 out, a lip raised and rounded, a screw hole cut up through the
jaw and threaded M7. What it turned up:

- With Symmetric on, the box still read Distance, and 30 typed for a
  clamp 30 wide made it 30 each way, 60 in all. The box reads "Each
  side" and the hint says to type half the whole width.
- Up to a plane with the distance box left at 0: Done did nothing.
  The distance only has to be set when the ends are a distance.
- Fillet: tapping a picked edge to drop it took the picked edge even
  when the tap was on another edge nearer; now the nearer real edge
  wins.
- The radius dot catches taps for some 40 px round it, so an edge
  near it could not be picked or dropped. A tap on it that doesn't
  move, away from the dot itself, now goes to the model.

== A spanner (pieces pulled up at once, polygon, corner rounds) ==

A spanner built by code and by hand on a phone, the two the same to the
face: two circles and a bar pulled up 6 as one, an open jaw cut through
all, a hexagon 10 across flats cut through the ring end, the inside
corners rounded and the hexagon chamfered. What it turned up:

- New project kept the last project's view: left looking up from below,
  a tap meant for the top picked the bottom face. A new project starts
  from the default view.
- Through all with Auto, on a sketch on a body's face, went up off the
  face: a tower 354 high was added instead of the jaw cut. Auto on a
  body's face now goes into it, as a cut does.
- The Polygon's Values only took a radius to a corner: a hex 10 across
  its flats meant typing 5.7735. It takes Across flats too, kept as the
  radius dimension that makes it.

== A planter (loft square to round, shell, circular sketch pattern) ==

A planter built by code and by hand on a phone, the two the same to the
face: lofted from a square foot to a round mouth on an Offset Plane,
shelled open at the mouth, four drain holes (one circle, patterned round
in the sketch) cut through the floor, the rim rounded. What it turned up:

- The loft leaves the mouth's circle in five pieces, where the square's
  corners run up to it. A tap on the rim picked one quarter, and its
  fillet could not be made ("would damage the body"). A tap on a piece
  of a circle now takes the whole circle, and a tap drops it whole.

== A door handle (sweep along line, arc, line; sketch mirror; countersinks) ==

A lever door handle built by code and by hand on a phone, the two the
same to the face: a plate with rounded corners, two screw holes (one
circle mirrored in the sketch) cut through and countersunk, a round bar
swept up from the plate along a line, a centre arc and a line, its end
rounded. What it turned up:

- Mirror (Copy) applied on the first tap on the axis, but kept the shape
  picked and its card still read "Apply (1)", so a second tap made the
  same copy again, on top of the first. A mirrored copy now lets go of
  the shape, and a copy exactly on a curve already there is not made
  ("Those copies are there already").

Health: a body where more than two faces meet on one edge (pieces
touching only along a line) is no longer called clean. The drill's
housing halves have one such seam each, where the grip runs into the
wall and the inside and outside meet; the drill test allows that one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 20:54:00 +02:00

103 lines
7.8 KiB
TypeScript

// Run: npx tsx tests/doorhandle.test.ts [out.json] - a lever door handle: a
// plate with its corners rounded; two screw holes (one drawn, mirrored in the
// sketch) cut through and countersunk; the lever a round bar swept from the
// plate up, round a bend and out along a line and an arc drawn on the side
// plane; its far end rounded. Each step held to its size and soundness.
import { readFileSync, writeFileSync } from "node:fs";
import type { Shape3D } from "replicad";
import { after, bodies, check, circle, done, health, line, near, rect, sketch, XY, YZ } from "./kit";
import { measureVolume } from "../src/kernel/ocFree";
import { arrangement, regionRef } from "../src/sketch/regions";
import type { EdgeRef, Feature, SketchEntity, Vec3 } from "../src/doc/types";
const vol = (s: Shape3D) => Math.abs(measureVolume(s));
const body = (id: string) => bodies().get(id) as Shape3D;
const profileOf = (sk: string, es: SketchEntity[]) => ({ kind: "profile" as const, sketch: sk, regions: arrangement(es).regions.map(regionRef) });
const unit = (v: number[]): Vec3 => { const l = Math.hypot(v[0], v[1], v[2]) || 1; return [v[0] / l, v[1] / l, v[2] / l]; };
const edgesOf = (id: string, test: (m: Vec3, d: Vec3, len: number) => boolean): EdgeRef[] =>
body(id).edges.filter((e) => test(e.pointAt(0.5).toTuple() as Vec3, unit(e.tangentAt(0.5).toTuple()), e.length)).map((e) => ({ body: id, mid: e.pointAt(0.5).toTuple() as Vec3, dir: e.tangentAt(0.5).toTuple() as Vec3, length: e.length }));
const W = 30, L = 100, T = 6, CORNER = 5; // the plate
const HOLE = 2.5, HY = 38, SINK = 1.5; // the screw holes
const BAR = 7, AY = 20, Z0 = T, UP = 30, BEND = 15, OUT = 110; // the lever: a bar 14 across, from the plate's top at y 20 up to 30, a bend of 15, out to y 110
const ROUND = 3;
// ------------------------------------------------------------------ the plate
const plateEs = [rect("p", -W / 2, -L / 2, W / 2, L / 2)];
const steps: Feature[] = [sketch("Plate", XY(), plateEs), { id: "Handle", name: "Handle", type: "extrude", source: profileOf("Plate", plateEs), distance: T, mode: "new" } as Feature];
let { errors } = await after(steps);
check("the plate: no errors", !errors.length, errors);
const corners = edgesOf("Handle", (m, d) => Math.abs(d[2]) > 0.99 && near(Math.abs(m[0]), W / 2) && near(Math.abs(m[1]), L / 2));
steps.push({ id: "Corners", name: "Fillet", type: "fillet", edges: corners, radius: CORNER } as Feature);
({ errors } = await after(steps));
const vPlate = vol(body("Handle"));
check("the plate: 30 x 100 x 6, four corners rounded 5", !errors.length && corners.length === 4 && near(vPlate, (W * L - 4 * (1 - Math.PI / 4) * CORNER * CORNER) * T, 1e-6), [errors, corners.length, vPlate]);
// ----------------------------------------------------------------- the holes
// One circle, and its mirror over the plate's middle; cut through all from the top.
const holeEs = [circle("h1", 0, HY, HOLE), circle("h2", 0, -HY, HOLE)];
steps.push(sketch("Screws", XY(T), holeEs), { id: "Holes", name: "Extrude", type: "extrude", source: profileOf("Screws", holeEs), distance: -1, extent: "through", mode: "auto", target: "Handle" } as Feature);
({ errors } = await after(steps));
const vHoles = vol(body("Handle"));
check("the holes: two, 5 round, through the plate", !errors.length && near(vPlate - vHoles, 2 * Math.PI * HOLE * HOLE * T, 1e-6), [errors, vPlate - vHoles]);
// Countersunk: their top edges chamfered 1.5.
const tops = edgesOf("Handle", (m) => near(m[2], T) && near(Math.hypot(m[0], Math.abs(m[1]) - HY), HOLE, 1e-3));
steps.push({ id: "Sinks", name: "Chamfer", type: "chamfer", edges: tops, radius: SINK } as Feature);
({ errors } = await after(steps));
const vSink = vol(body("Handle"));
// A cone's ring round each: π·h·(R² + R·r + r²)/3 less the hole's cylinder there.
const ring = (Math.PI * SINK * ((HOLE + SINK) ** 2 + (HOLE + SINK) * HOLE + HOLE * HOLE)) / 3 - Math.PI * HOLE * HOLE * SINK;
check("the countersinks: both, 1.5 down", !errors.length && tops.length >= 2 && near(vHoles - vSink, 2 * ring, 1e-3), [errors, tops.length, vHoles - vSink, 2 * ring]);
// ----------------------------------------------------------------- the lever
// The path on the side plane (y across, z up): up from the plate's top, a bend, out along; the bar's circle on the top.
const pathEs = [line("p1", [AY, Z0], [AY, UP]), { id: "p2", kind: "arc", a: [AY, UP], m: [AY + BEND - BEND * Math.SQRT1_2, UP + BEND * Math.SQRT1_2], b: [AY + BEND, UP + BEND] } as SketchEntity, line("p3", [AY + BEND, UP + BEND], [OUT, UP + BEND])];
const barEs = [circle("b", 0, AY, BAR)];
steps.push(
sketch("Path", YZ(), pathEs),
sketch("Bar", XY(Z0), barEs),
{ id: "Lever", name: "Sweep", type: "sweep", source: profileOf("Bar", barEs), path: { kind: "sketch", sketch: "Path", entities: ["p1", "p2", "p3"] }, mode: "join", target: "Handle" } as Feature,
);
({ errors } = await after(steps));
check("the lever: no errors, one body", !errors.length && bodies().size === 1, errors);
const vLever = vol(body("Handle"));
const pathLen = UP - Z0 + (Math.PI / 2) * BEND + (OUT - AY - BEND);
check("the lever: a bar 14 across along the path", near(vLever - vSink, Math.PI * BAR * BAR * (pathLen - (T - Z0)), 1e-3), [vLever - vSink, Math.PI * BAR * BAR * (pathLen - (T - Z0))]);
const [, [, y1, z1]] = body("Handle").boundingBox.bounds;
check("the lever: out to 110, its top 52 up", near(y1, OUT, 1e-3) && near(z1, UP + BEND + BAR, 1e-3), body("Handle").boundingBox.bounds);
// ---------------------------------------------------------------- the end
const end = edgesOf("Handle", (m, _d, len) => near(m[1], OUT, 1e-3) && near(len, 2 * Math.PI * BAR, 1e-3));
steps.push({ id: "End", name: "Fillet", type: "fillet", edges: end, radius: ROUND } as Feature);
({ errors } = await after(steps));
const vEnd = vol(body("Handle"));
check("the end: rounded 3, a little off", !errors.length && end.length === 1 && vEnd < vLever && vLever - vEnd < 2 * Math.PI * BAR * ROUND * ROUND, [errors, end.length, vLever - vEnd]);
const h = health(body("Handle"), "Handle");
check("the handle: sound, one body", h.healthy && bodies().size === 1, h.healthy ? `${Math.round(h.volume)} mm³` : h);
const codeVol = vol(body("Handle"));
const codeFaces = body("Handle").faces.length;
const codeBox = body("Handle").boundingBox.bounds;
console.log("plate", vPlate.toFixed(1), "holes", vHoles.toFixed(1), "sinks", vSink.toFixed(1), "lever", vLever.toFixed(1), "final", codeVol.toFixed(1), "faces", codeFaces);
// ---------------------------------------------- the handle built by hand
// On a phone-sized screen (tests/fixtures/doorhandle-hand.json): the plate
// typed and pulled up 6, its corners picked from two sides and rounded 5; on
// its top one circle, Mirror (Copy) across the X axis - a second tap on the
// axis made the same copy again on top of it, before - both cut Through all
// and countersunk 1.5; on the side plane a line, a centre arc and a line,
// typed; the bar's circle on the top, swept along them (Auto joined it); its
// end rounded 3. It comes out the same.
{
const hand = JSON.parse(readFileSync(new URL("./fixtures/doorhandle-hand.json", import.meta.url), "utf8")).features as Feature[];
const { errors } = await after(hand);
check("by hand: no errors", errors.length === 0, errors);
const H = [...bodies().values()].map((s) => s as Shape3D);
check("by hand: one body, sound", H.length === 1 && health(H[0], "hand").healthy, H.length);
check("by hand: the same handle (to 0.1 %)", H.length === 1 && Math.abs(vol(H[0]) - codeVol) < codeVol * 1e-3, `${H[0] ? vol(H[0]).toFixed(1) : "-"} / ${codeVol.toFixed(1)}`);
check("by hand: as many faces, the same box", H[0]?.faces.length === codeFaces && H[0].boundingBox.bounds.flat().every((x, i) => near(x, codeBox.flat()[i], 1e-3)), [H[0]?.faces.length, codeFaces, H[0]?.boundingBox.bounds]);
}
if (process.argv[2]) writeFileSync(process.argv[2], JSON.stringify({ format: "super", version: 2, name: "Door handle", features: steps }));
done();