8de2367a0c
== 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>
146 lines
9.8 KiB
TypeScript
146 lines
9.8 KiB
TypeScript
// Run: npx tsx tests/phonestand.test.ts [out.json] - a phone stand, with the
|
|
// tools the other build tests leave out: a back leaning at 75° on a plane
|
|
// through the base's back edge at an angle; a lip along the front, its
|
|
// line drawn parallel to the front edge (Offset Edge) and the strip raised
|
|
// (Offset Face); a cable hole cut through the tilted back; the lip's top
|
|
// edges chamfered and the back's top rounded. Each held to its size and
|
|
// soundness.
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { after, bodies, check, circle, done, health, line, near, rect, sketch, XY } from "./kit";
|
|
import { getOC, makeBox, type Shape3D } from "replicad";
|
|
import { measureVolume } from "../src/kernel/ocFree";
|
|
import { arrangement, regionRef } from "../src/sketch/regions";
|
|
import { solve } from "../src/sketch/constraints";
|
|
import type { EdgeRef, Feature, PlaneDef, SketchEntity, Vec3 } from "../src/doc/types";
|
|
|
|
const vol = (s: Shape3D) => Math.abs(measureVolume(s));
|
|
const stand0 = () => bodies().get("Stand") as Shape3D;
|
|
/** Solids in the stand (one: not two pieces meeting at an edge). */
|
|
const solids = () => countSolids(stand0());
|
|
function countSolids(s: Shape3D): number {
|
|
const oc = getOC();
|
|
const ex = new oc.TopExp_Explorer(s.wrapped, oc.TopAbs_ShapeEnum.TopAbs_SOLID, oc.TopAbs_ShapeEnum.TopAbs_SHAPE);
|
|
let n = 0;
|
|
for (; ex.More(); ex.Next()) n++;
|
|
ex.delete();
|
|
return n;
|
|
}
|
|
const W = 80, D = 70, T = 8, ANG = 75, BACK = 6, TALL = 90, LIP = 12, LIPH = 10;
|
|
const rad = (ANG * Math.PI) / 180;
|
|
const profileOf = (sk: string, es: SketchEntity[]) => ({ kind: "profile" as const, sketch: sk, regions: arrangement(es).regions.map(regionRef) });
|
|
const edgeOf = (body: string, pick: (mid: Vec3, dir: Vec3) => boolean): EdgeRef => {
|
|
const e = (bodies().get(body) as Shape3D).edges.find((e) => pick(e.pointAt(0.5).toTuple() as Vec3, e.tangentAt(0.5).normalized().toTuple() as Vec3));
|
|
if (!e) throw new Error("no such edge");
|
|
return { body, mid: e.pointAt(0.5).toTuple() as Vec3, dir: e.tangentAt(0.5).toTuple() as Vec3, length: e.length };
|
|
};
|
|
|
|
// ------------------------------------------------------------------ the base
|
|
const baseEs = [rect("b", -W / 2, 0, W / 2, D)];
|
|
const steps: Feature[] = [sketch("Base", XY(), baseEs), { id: "Stand", name: "Stand", type: "extrude", source: profileOf("Base", baseEs), distance: T, mode: "new" } as Feature];
|
|
let { errors } = await after(steps);
|
|
check("the base: no errors", !errors.length, errors);
|
|
const vBase = vol(bodies().get("Stand") as Shape3D);
|
|
check("the base: 80 x 70 x 8", near(vBase, W * D * T, 1e-6), vBase);
|
|
|
|
// ------------------------------------------------------------------ the back
|
|
// A plane through the base's top back edge, 75° up from the top, leaning back
|
|
// (its up direction away from the front); on it, the back 80 wide, from 3
|
|
// below the edge (down into the base's corner, to hold on to it) to 90 up,
|
|
// pulled 6 thick towards the front. (Only touching the base along the edge,
|
|
// a join made two solids meeting at an edge - and called them sound.)
|
|
const up: Vec3 = [0, Math.cos(rad), Math.sin(rad)];
|
|
const tilted: PlaneDef = { origin: [0, D, T], xDir: [1, 0, 0], normal: [0, -Math.sin(rad), Math.cos(rad)] };
|
|
const backEs = [rect("k", -W / 2, -3, W / 2, TALL)];
|
|
steps.push(
|
|
{ id: "Tilt", name: "Plane", type: "plane", kind: "angle", plane: tilted, offset: 0 } as Feature,
|
|
sketch("Back", tilted, backEs),
|
|
{ id: "BackUp", name: "Extrude", type: "extrude", source: profileOf("Back", backEs), distance: BACK, mode: "join", target: "Stand" } as Feature,
|
|
);
|
|
({ errors } = await after(steps));
|
|
check("the back: no errors", !errors.length, errors);
|
|
let stand = bodies().get("Stand") as Shape3D;
|
|
const vBack = vol(stand) - vBase;
|
|
// (A slab 80 x 93 x 6, less the wedge of it down in the base.)
|
|
check("the back: a slab 80 x 93 x 6 joined on (a little of it in the base)", vBack < W * 93 * BACK && vBack > W * 93 * BACK - W * 3 * BACK && bodies().size === 1 && (stand0() as any).wrapped && solids() === 1, [vBack, solids()]);
|
|
const [, [, by1, bz1]] = stand.boundingBox.bounds;
|
|
check("the back: leaning back 75° (its top 90 up the slope)", near(bz1, T + TALL * up[2] + BACK * Math.cos(rad), 0.01) && near(by1, D + TALL * up[1], 0.01), stand.boundingBox.bounds);
|
|
|
|
// Only touching (the back from the edge up, not into the base): joined in
|
|
// name, two pieces by any printer - said, and not sound.
|
|
{
|
|
const touchEs = [rect("k", -W / 2, 0, W / 2, TALL)];
|
|
const { r } = await after([...steps.slice(0, 3), sketch("Touch", tilted, touchEs), { id: "BackUp", name: "Extrude", type: "extrude", source: profileOf("Touch", touchEs), distance: BACK, mode: "join", target: "Stand" } as Feature]);
|
|
const h = health(stand0(), "Stand");
|
|
check("only touching along an edge: said, and not sound", !!r.notes?.some((n) => /only touches the body along an edge/.test(n.message)) && !h.healthy && h.pinched > 0, [r.notes, h.pinched, h.solids]);
|
|
}
|
|
// A rectangle's height typed 93 (from 90, dimensioned): exactly 93, not 92.999999999999.
|
|
{
|
|
const res = solve([{ id: "q", kind: "rect", center: [0, 45], w: 80, h: 90, rotation: 0 } as SketchEntity], [{ id: "d1", type: "dim", curves: ["q"], prop: "w", value: 80 }, { id: "d2", type: "dim", curves: ["q"], prop: "h", value: 93 }] as any);
|
|
check("a height typed 93 comes out exactly 93", (res.entities[0] as any).h === 93 && (res.entities[0] as any).w === 80, (res.entities[0] as any).h);
|
|
}
|
|
|
|
// ------------------------------------------------------------------ the lip
|
|
// A line on the top 12 in from the front edge, and the strip in front of it raised 10.
|
|
const lipEs = [rect("l", -W / 2, 0, W / 2, LIP)];
|
|
steps.push(sketch("Lip line", XY(T), lipEs), { id: "Lip", name: "Offset Face", type: "extrude", source: profileOf("Lip line", lipEs), distance: LIPH, mode: "join", target: "Stand" } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the lip: no errors", !errors.length, errors);
|
|
stand = bodies().get("Stand") as Shape3D;
|
|
const vLip = vol(stand) - vBase - vBack;
|
|
check("the lip: 80 x 12 x 10", near(vLip, W * LIP * LIPH, 1e-3), vLip);
|
|
|
|
// ------------------------------------------------------------- the cable hole
|
|
// A circle 8 round on the back's face, 30 up it, cut through the back.
|
|
const holeEs = [circle("h", 0, 30, 8)];
|
|
steps.push(sketch("Hole", tilted, holeEs), { id: "Cable", name: "Extrude", type: "extrude", source: profileOf("Hole", holeEs), distance: 1, extent: "through", mode: "cut", target: "Stand" } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the hole: no errors", !errors.length, errors);
|
|
stand = bodies().get("Stand") as Shape3D;
|
|
const vHole = vBase + vBack + vLip - vol(stand);
|
|
check("the hole: 8 round through the 6 thick back", near(vHole, Math.PI * 64 * BACK, 0.5), vHole);
|
|
|
|
// ---------------------------------------------------------------- the edges
|
|
// The lip's two top edges chamfered 2; the back's top edge (the front one) rounded 3.
|
|
const lipTop = (y: number) => edgeOf("Stand", (m, d) => near(m[2], T + LIPH, 1e-3) && near(m[1], y, 1e-3) && Math.abs(d[0]) > 0.99);
|
|
steps.push({ id: "LipEdges", name: "Chamfer", type: "chamfer", edges: [lipTop(0), lipTop(LIP)], radius: 2 } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the lip's edges: chamfered, no errors", !errors.length, errors);
|
|
stand = bodies().get("Stand") as Shape3D;
|
|
const vCham = vol(stand);
|
|
check("the lip's edges: two corners 2 x 2 off, 80 long", near(vBase + vBack + vLip - vHole - vCham, 2 * 2 * 2 * 0.5 * W, 0.5), vBase + vBack + vLip - vHole - vCham);
|
|
const topFront: Vec3 = [0, D + TALL * up[1] - BACK * Math.sin(rad), T + TALL * up[2] + BACK * Math.cos(rad)];
|
|
steps.push({ id: "TopRound", name: "Fillet", type: "fillet", edges: [edgeOf("Stand", (m, d) => Math.hypot(m[0] - topFront[0], m[1] - topFront[1], m[2] - topFront[2]) < 1e-3 && Math.abs(d[0]) > 0.99)], radius: 3 } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the back's top: rounded, no errors", !errors.length, errors);
|
|
stand = bodies().get("Stand") as Shape3D;
|
|
const vRound = vol(stand);
|
|
check("the back's top: a round 3 off along it (80 long)", near(vCham - vRound, (1 - Math.PI / 4) * 9 * W, 0.5), vCham - vRound);
|
|
|
|
const h = health(stand, "Stand");
|
|
check("the stand: sound, one body", h.healthy && bodies().size === 1, h.healthy ? `${Math.round(h.volume)} mm³` : h);
|
|
const codeVol = vol(stand);
|
|
console.log("base", vBase, "back", vBack.toFixed(1), "lip", vLip.toFixed(1), "hole", vHole.toFixed(1), "final", codeVol.toFixed(1));
|
|
|
|
// ------------------------------------------------- the stand built by hand
|
|
// On a phone-sized screen (tests/fixtures/phonestand-hand.json): the base
|
|
// typed, a Plane at Angle through its top back edge (105°, leaning back), the
|
|
// back drawn on it and pulled 6 - first only touching the base (it said so:
|
|
// "only touches the body along an edge"), then its rectangle typed 93 high
|
|
// and moved 1.5 down into the base; Offset Edge 12 in from the front edge on
|
|
// the top and the strip raised 10; a circle on the back's face cut through
|
|
// all; the lip's top edges chamfered 2 and the back's top rounded 3. It comes
|
|
// out the same.
|
|
{
|
|
const hand = JSON.parse(readFileSync(new URL("./fixtures/phonestand-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 stand (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)}`);
|
|
const hb = H[0]?.boundingBox.bounds;
|
|
check("by hand: the same box", !!hb && hb.flat().every((x, i) => near(x, stand.boundingBox.bounds.flat()[i], 1e-3)), [hb, stand.boundingBox.bounds]);
|
|
}
|
|
|
|
if (process.argv[2]) writeFileSync(process.argv[2], JSON.stringify({ format: "super", version: 2, name: "Phone stand", features: steps }));
|
|
done();
|