03ed32c740
- Pattern: up to 1000 copies (a typo like 30000 used to build them all, and again each time the project opened); spacing or angle 0 is refused instead of stacking every copy in one place. - Revolve: a shape across the axis says so (was "could not compute this"). - Thread: a pitch under 0.2 mm says it is too fine; a failed fine pitch says "try a coarser pitch", not "slightly different". - Value boxes: 5,5 (decimal comma), 5. and +5 are read; 1,000 is not guessed; "30 deg" works in angle boxes and as an angle variable; sizes over 1000 km are refused. Variables can't be named sin, pi, deg and the like. - Deleting a variable that steps use: they keep their sizes as plain numbers (every rebuild said "can't be evaluated"). - Imports: an empty, damaged or wrong STL/STEP is refused with the reason, not added as a failed step holding the broken file; a damaged or newer project file says so in words; reference images are kept at 2048 px (a 12 MB photo went into the project) and an unreadable one (HEIC) says why. - Sketch: a spline crossing itself (a hand-drawn loop past its start, a figure 8) is split where it crosses: it had no region to extrude. - Tests: limits, resize (a part's first sizes changed: every later step follows), self-crossing splines, the new value-box cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
3.2 KiB
TypeScript
48 lines
3.2 KiB
TypeScript
// Run: npx tsx tests/resize.test.ts
|
|
// A part made the usual way (box, rounded corners, a hole sketched on top,
|
|
// a chamfer, shelled from below), then its first sizes changed: every later
|
|
// step must follow - the same part as one whose picks were made at the new size.
|
|
import opencascade from "replicad-opencascadejs";
|
|
import { setOC, measureVolume } from "replicad";
|
|
import { debugBodies, regenerate } from "../src/kernel/engine";
|
|
import { resolveDoc } from "../src/doc/params";
|
|
setOC(await (opencascade as unknown as () => Promise<any>)());
|
|
|
|
const XY = { origin: [0, 0, 0], xDir: [1, 0, 0], normal: [0, 0, 1] };
|
|
function part(w: number, d: number, h: number, fresh = false) {
|
|
const W = fresh ? w : 40, D = fresh ? d : 30, H = fresh ? h : 20;
|
|
// Refs as they were picked on the 40 x 30 x 20 box (what the doc stores).
|
|
return {
|
|
variables: [],
|
|
features: [
|
|
{ id: "s", name: "Sketch 01", type: "sketch", plane: XY, entities: [{ id: "r", kind: "rect", center: [0, 0], w, h: d, rotation: 0 }], constraints: [] },
|
|
{ id: "b", name: "Extrude 01", type: "extrude", source: { kind: "profile", sketch: "s", regions: [{ c: [0, 0], a: 1200, k: ["r"], s: [2] }] }, distance: h, mode: "new" },
|
|
// fillet: the 4 vertical edges
|
|
{ id: "f", name: "Fillet 01", type: "fillet", radius: 3, edges: [[W / 2, D / 2], [-W / 2, D / 2], [W / 2, -D / 2], [-W / 2, -D / 2]].map(([x, y]) => ({ body: "b", mid: [x, y, H / 2], dir: [0, 0, 1], length: H })) },
|
|
// a hole sketched on the top face, cut through
|
|
{ id: "s2", name: "Sketch 02", type: "sketch", plane: { origin: [0, 0, H], xDir: [1, 0, 0], normal: [0, 0, 1] }, attachedTo: { body: "b", center: [0, 0, H], normal: [0, 0, 1], area: W * D - (4 - Math.PI) * 9 }, entities: [{ id: "c", kind: "circle", center: [0, 0], radius: 5 }], constraints: [] },
|
|
{ id: "e2", name: "Extrude 02", type: "extrude", source: { kind: "profile", sketch: "s2", regions: [{ c: [0, 0], a: 78.54, k: ["c"], s: [0.5] }] }, distance: -20, mode: "cut", target: "b" },
|
|
// chamfer the top outer rim (one of its straight edges)
|
|
{ id: "ch", name: "Chamfer 01", type: "chamfer", radius: 1, edges: [{ body: "b", mid: [0, -D / 2, H], dir: [1, 0, 0], length: W - 6 }] },
|
|
// shell from the bottom face
|
|
{ id: "sh", name: "Shell 01", type: "shell", body: "b", faces: [{ body: "b", center: [0, 0, 0], normal: [0, 0, -1], area: W * D - (4 - Math.PI) * 9 - 78.54 }], thickness: 1.5 },
|
|
],
|
|
};
|
|
}
|
|
|
|
let failed = 0;
|
|
for (const [w, d, h] of [[40, 30, 20], [60, 30, 20], [40, 50, 20], [40, 30, 35], [80, 60, 10], [24, 18, 20]]) {
|
|
const doc2: any = part(w, d, h, true);
|
|
await regenerate(doc2.features);
|
|
const want = Math.abs(measureVolume(debugBodies().get("b") as any)).toFixed(0);
|
|
const doc: any = part(w, d, h);
|
|
resolveDoc(doc);
|
|
const r: any = await regenerate(doc.features);
|
|
const b = debugBodies().get("b");
|
|
const got = b ? Math.abs(measureVolume(b as any)).toFixed(0) : "-";
|
|
const ok = !r.errors.length && got === want;
|
|
if (!ok) failed++;
|
|
console.log(ok ? "ok " : "FAIL", `${w}x${d}x${h}`.padEnd(10), "errors", JSON.stringify(r.errors.map((e: any) => `${e.featureId}: ${e.message}`)), "volume", got, "want", want);
|
|
}
|
|
process.exit(failed ? 1 : 0);
|