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

41 lines
2.9 KiB
TypeScript

// Run: npx tsx tests/pushfollows.test.ts - a face pushed out (or tilted about
// a line in it) after an earlier step tilted it, then that earlier tilt
// changed: the push stays a push, square to the face as it is now (it was
// taken for a slide: a sheared move, or "Sliding or turning a face within its
// plane..." on a body with a round face); the tilt stays a tilt. The earlier
// tilt turned to 0 or switched off: the push still finds its face.
import { after, bodies, check, done, near, rect, circle, sketch, XY, profile, health } from "./kit";
import { measureVolume, type Shape3D } from "replicad";
import type { Feature, Vec3 } from "../src/doc/types";
const D = (a: number) => (a * Math.PI) / 180;
const P = 3; // the push
for (const hole of [false, true]) {
const es = [rect("r", 0, 0, 40, 30), ...(hole ? [circle("h", 15, 15, 4)] : [])];
const v0 = (hole ? 1200 - Math.PI * 16 : 1200) * 20;
const base: Feature[] = [sketch("s", XY(), es), { id: "b", name: "Block", type: "extrude", source: profile("s", es, (rs) => rs.filter((r) => r.a > 500)), distance: 20, mode: "new" } as Feature];
const tilt = (a: number): Feature => ({ id: "t", name: "Tilt", type: "moveFace", face: { body: "b", center: [40, 15, 10], normal: [1, 0, 0], area: 600 }, translate: [0, 0, 0], rotate: { origin: [40, 15, 10], axis: [0, 0, 1], angle: a } }) as Feature;
// Made after a 5° tilt, from the face as it was then.
const n5: Vec3 = [Math.cos(D(5)), Math.sin(D(5)), 0];
const ref = { body: "b", center: [40, 15, 10] as Vec3, normal: n5, area: 600 / Math.cos(D(5)), step: "t" };
const push: Feature = { id: "p", name: "Push", type: "moveFace", face: ref, translate: [P * n5[0], P * n5[1], 0] } as Feature;
const lean: Feature = { id: "l", name: "Lean", type: "moveFace", face: ref, translate: [0, 0, 0], rotate: { origin: [40, 15, 10], axis: [-n5[1], n5[0], 0], angle: 4 } } as Feature;
const w = hole ? "with a hole" : "plain";
for (const a of [5, 8, -3, 0, "off"] as const) {
const t = a === "off" ? { ...tilt(5), suppressed: true } : tilt(a);
const ang = a === "off" ? 0 : a;
let { errors } = await after([...base, t, push]);
let b = bodies().get("b") as Shape3D;
let v = b ? Math.abs(measureVolume(b)) : NaN;
check(`${w}, first tilt ${a}: the push adds its face times ${P}`, !errors.length && near(v - v0, (P * 600) / Math.cos(D(ang)), 1e-6), [errors, v - v0]);
await after([...base, t]);
const x0 = (bodies().get("b") as Shape3D).boundingBox.bounds[1][0];
({ errors } = await after([...base, t, lean]));
b = bodies().get("b") as Shape3D;
v = b ? Math.abs(measureVolume(b)) : NaN;
const out = b ? b.boundingBox.bounds[1][0] - x0 : NaN;
check(`${w}, first tilt ${a}: the lean about its middle line keeps the volume, its top edge out`, !errors.length && near(v, v0, 1e-6) && near(out, 10 * Math.tan(D(4)) * Math.cos(D(ang)), 0.05) && health(b).healthy, [errors, v - v0, out]);
}
}
done();