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>
96 lines
6.8 KiB
TypeScript
96 lines
6.8 KiB
TypeScript
// Run: npx tsx tests/planter.test.ts [out.json] - a planter pot: lofted from
|
|
// a square foot to a round mouth, shelled open at the top, four drain holes
|
|
// through its floor (one circle, patterned round the middle in the sketch),
|
|
// the mouth's outer edge rounded. Each step held to its size and soundness.
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { measureArea, type Face, type Shape3D } from "replicad";
|
|
import { after, bodies, check, circle, done, health, near, rect, sketch, XY } from "./kit";
|
|
import { measureVolume } from "../src/kernel/ocFree";
|
|
import { arrangement, regionRef } from "../src/sketch/regions";
|
|
import type { EdgeRef, FaceRef, 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 faceOf = (id: string, pick: (f: Face) => boolean): FaceRef => {
|
|
const f = body(id).faces.find(pick);
|
|
if (!f) throw new Error("no such face");
|
|
return { body: id, center: f.center.toTuple() as Vec3, normal: f.normalAt().toTuple() as Vec3, area: measureArea(f) };
|
|
};
|
|
|
|
const FOOT = 60, MOUTH = 40, H = 80, WALL = 2, HOLE = 3, AT = 16, ROUND = 0.8;
|
|
|
|
// ------------------------------------------------------------------ the pot
|
|
// A square 60 on the floor, a circle 80 across 80 up: lofted between.
|
|
const footEs = [rect("f", -FOOT / 2, -FOOT / 2, FOOT / 2, FOOT / 2)];
|
|
const mouthEs = [circle("m", 0, 0, MOUTH)];
|
|
const steps: Feature[] = [
|
|
sketch("Foot", XY(), footEs),
|
|
sketch("Mouth", XY(H), mouthEs),
|
|
{ id: "Pot", name: "Loft", type: "loft", sections: [profileOf("Foot", footEs), profileOf("Mouth", mouthEs)], ruled: false, mode: "new" } as Feature,
|
|
];
|
|
let { errors } = await after(steps);
|
|
check("the pot: no errors, one body", !errors.length && bodies().size === 1, errors);
|
|
const vPot = vol(body("Pot"));
|
|
// (Between the square's prism and the circle's: the sections' areas, 3600 and 5026.5, 80 apart.)
|
|
check("the pot: between the foot's and the mouth's prisms", vPot > FOOT * FOOT * H && vPot < Math.PI * MOUTH * MOUTH * H, vPot);
|
|
const [[x0, , z0], [x1, , z1]] = body("Pot").boundingBox.bounds;
|
|
check("the pot: 80 high, 80 across at the top", near(z0, 0, 1e-6) && near(z1, H, 1e-6) && near(x1 - x0, 2 * MOUTH, 0.01), body("Pot").boundingBox.bounds);
|
|
|
|
// ---------------------------------------------------------------- the shell
|
|
const mouthFace = faceOf("Pot", (f) => near(f.center.z, H, 1e-6) && f.normalAt().z > 0.99);
|
|
steps.push({ id: "Hollow", name: "Shell", type: "shell", body: "Pot", faces: [mouthFace], thickness: WALL } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the shell: no errors", !errors.length, errors);
|
|
const vShell = vol(body("Pot"));
|
|
// The floor alone is 60 x 60 x 2; the walls about 2 thick round 80 high.
|
|
check("the shell: hollow, walls about 2 thick (the floor and the walls)", vShell > FOOT * FOOT * WALL + 4 * FOOT * WALL * H * 0.9 && vShell < FOOT * FOOT * WALL + 2 * Math.PI * MOUTH * WALL * H * 1.2, vShell);
|
|
check("the shell: open at the top, sound", health(body("Pot"), "p").healthy, health(body("Pot"), "p"));
|
|
|
|
// ----------------------------------------------------------- the drain holes
|
|
// One circle 16 out, patterned four round the middle (in the sketch), cut through the floor.
|
|
const holeEs = [0, 1, 2, 3].map((i) => circle(`h${i}`, AT * Math.cos((i * Math.PI) / 2), AT * Math.sin((i * Math.PI) / 2), HOLE));
|
|
steps.push(sketch("Drain", XY(), holeEs), { id: "Holes", name: "Extrude", type: "extrude", source: profileOf("Drain", holeEs), distance: WALL, mode: "cut", target: "Pot" } as Feature);
|
|
({ errors } = await after(steps));
|
|
check("the holes: no errors", !errors.length, errors);
|
|
const vHoles = vol(body("Pot"));
|
|
check("the holes: four, 6 round, through the 2 thick floor", near(vShell - vHoles, 4 * Math.PI * HOLE * HOLE * WALL, 1e-3), vShell - vHoles);
|
|
|
|
// ----------------------------------------------------------------- the rim
|
|
// The mouth's outer edge (a circle 40 round, 80 up) rounded 0.8.
|
|
const rimEdge = body("Pot").edges.filter((e) => near(e.pointAt(0.5).z, H, 1e-6) && near(Math.hypot(e.pointAt(0.5).x, e.pointAt(0.5).y), MOUTH, 1e-3));
|
|
const rim: EdgeRef[] = rimEdge.map((e) => ({ body: "Pot", mid: e.pointAt(0.5).toTuple() as Vec3, dir: e.tangentAt(0.5).toTuple() as Vec3, length: e.length }));
|
|
steps.push({ id: "Rim", name: "Fillet", type: "fillet", edges: rim, radius: ROUND } as Feature);
|
|
({ errors } = await after(steps));
|
|
// (The loft splits the mouth's circle where the square's corners run up to it: five pieces, all of them.)
|
|
check("the rim: rounded all round, no errors", !errors.length && rim.length >= 1 && near(rim.reduce((a, e) => a + e.length, 0), 2 * Math.PI * MOUTH, 1e-3), [errors, rim.length]);
|
|
const vRim = vol(body("Pot"));
|
|
check("the rim: a little off round it", vRim < vHoles && vHoles - vRim < 2 * Math.PI * MOUTH * ROUND * ROUND, vHoles - vRim);
|
|
|
|
const h = health(body("Pot"), "Pot");
|
|
check("the planter: sound, one body", h.healthy && bodies().size === 1, h.healthy ? `${Math.round(h.volume)} mm³` : h);
|
|
const codeVol = vol(body("Pot"));
|
|
const codeFaces = body("Pot").faces.length;
|
|
const codeBox = body("Pot").boundingBox.bounds;
|
|
console.log("pot", vPot.toFixed(1), "shell", vShell.toFixed(1), "holes", vHoles.toFixed(1), "final", codeVol.toFixed(1), "faces", codeFaces);
|
|
|
|
// ------------------------------------------------ the planter built by hand
|
|
// On a phone-sized screen (tests/fixtures/planter-hand.json): the square typed
|
|
// on the floor, an Offset Plane 80 up and the circle on it, the two lofted;
|
|
// the mouth tapped and shelled 2; on the underside one circle, Pattern
|
|
// (tapped again for Circular) four round the middle, cut Through all with
|
|
// Auto; the rim tapped once and rounded 0.8 (a quarter of it alone, before:
|
|
// "would damage the body"). It comes out the same.
|
|
{
|
|
const hand = JSON.parse(readFileSync(new URL("./fixtures/planter-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 planter (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: "Planter", features: steps }));
|
|
done();
|