Files
superGeometry e2711937c3 Stress tests aimed elsewhere, and what they found. A fuzz of the rebuild: random steps added the way the app adds them (taps from the last rebuild), then an early size changed and back, each step switched off and deleted - built warm (results kept) and from nothing, the two the same, every time (30 seeds, 850 checks: the cache held). Its refused steps found the bugs. Edit Freeform steps had no test: now edits stacked, switched off, rolled back to, with a subtract and a linked copy between, each the same as the cage made that way straight away.
Fixed:
- A face pushed out after an earlier step tilted it, then that tilt changed: the push became a slide - a sheared move, or "Sliding or turning a face within its plane..." on a body with a round face. A move that was a push when made stays a push, square to the face as it is now; a tilt about a line in the face stays that.
- The earlier tilt turned to 0 or switched off: the push lost its face ("The face it was built on is gone"). When the step that made a face makes none now, the face that is plainly the same one (facing the same way, its middle where it was, much the same size) is taken.
- Move Face on a shape projected onto a face (Project as Edge) did nothing and said nothing: the faces round it lie in its plane. Pushed out it now raises it (a boss), in sinks it (a pocket), following the sketch when it moves or grows; tilting it says why it can't.
- Project as Edge from a sketch on a block's top split the bottom too, out of sight behind the block: a line running wholly inside the body was taken as seen.

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

45 lines
2.8 KiB
TypeScript

// Run: npx tsx tests/imprintpush.test.ts - a circle projected onto a block's
// top (Project as Edge), its disc then pushed with Move Face: up 4 it is a
// round boss, down 4 a round pocket (it did nothing at all - the faces round
// the disc lie in its plane, so moving the plane moved nothing - and said
// nothing). Then the circle moved and made bigger, the block made taller: the
// push follows. Tilting the disc says why it can't.
import { after, bodies, check, done, near, rect, circle, sketch, XY, profile, health } from "./kit";
import { measureVolume, type Shape3D } from "replicad";
import type { Feature } from "../src/doc/types";
const build = (H: number, cx: number, R: number, move: Partial<Feature>): Feature[] => {
const es = [rect("r", 0, 0, 40, 30)];
const ce = [circle("c", cx, 15, R)];
return [
sketch("s", XY(), es),
{ id: "b", name: "Block", type: "extrude", source: profile("s", es), distance: H, mode: "new" } as Feature,
sketch("k", XY(H), ce),
{ id: "i", name: "Project as Edge", type: "imprint", body: "b", source: profile("k", ce) } as Feature,
// The disc as tapped (on the first block, 20 high, the circle at 15 with radius 5).
{ id: "p", name: "Move Face", type: "moveFace", face: { body: "b", center: [15, 15, 20], normal: [0, 0, 1], area: Math.PI * 25, step: "b", curve: "cap:1@r:0" }, translate: [0, 0, 4], ...move } as Feature,
];
};
{
// Projected from above, the circle lands on the top only: the bottom (out
// of sight behind the block) stays whole.
const { r, errors } = await after(build(20, 15, 5, {}).slice(0, 4));
const faces = r.bodies[0].faces;
const bottom = faces.filter((f) => f.normal[2] < -0.99);
check("projected: the top split in two, the bottom whole", !errors.length && faces.length === 7 && bottom.length === 1 && near(bottom[0].area, 1200, 1e-6), faces.map((f) => [f.center, f.area]));
}
for (const d of [4, -4]) {
for (const [H, cx, R] of [[20, 15, 5], [20, 25, 5], [20, 15, 7], [26, 15, 5], [26, 25, 3]]) {
const { errors } = await after(build(H, cx, R, { translate: [0, 0, d] } as Partial<Feature>));
const b = bodies().get("b") as Shape3D;
const v = Math.abs(measureVolume(b));
const top = b.boundingBox.bounds[1][2];
check(`pushed ${d > 0 ? "up" : "down"} ${Math.abs(d)}, block ${H} high, circle at ${cx} radius ${R}: ${d > 0 ? "a boss" : "a pocket"}`, !errors.length && near(v - 1200 * H, Math.PI * R * R * d, 1e-6) && near(top, H + Math.max(d, 0), 1e-9) && health(b).healthy, [errors, v - 1200 * H, top]);
}
}
{
const { errors } = await after(build(20, 15, 5, { translate: [0, 0, 0], rotate: { origin: [15, 15, 20], axis: [1, 0, 0], angle: 10 } } as Partial<Feature>));
check("tilted: says it can only go straight out or in", errors.length === 1 && /pushed straight out or in/.test(errors[0]), errors);
}
done();