Files
superGeometry 03ed32c740 Abuse sweep: typos, nonsense values, damaged files, messy sketches
- 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>
2026-11-09 16:28:44 +02:00

40 lines
3.0 KiB
TypeScript

// Run: npx tsx tests/limits.test.ts
// Values a person might type by mistake: each step stops at once with a
// message that says what is wrong (or works), never a freeze or a mystery.
import opencascade from "replicad-opencascadejs";
import { setOC } from "replicad";
import { regenerate } from "../src/kernel/engine";
setOC(await (opencascade as unknown as () => Promise<any>)());
const XY = { origin: [0, 0, 0], xDir: [1, 0, 0], normal: [0, 0, 1] };
const FRONT = { origin: [0, 0, 0], xDir: [1, 0, 0], normal: [0, -1, 0] };
const sk = (id: string, entities: any[], plane: any = XY) => ({ id, name: id, type: "sketch", plane, entities, constraints: [] });
const box = [sk("s", [{ id: "r", kind: "rect", center: [0, 0], w: 40, h: 30, rotation: 0 }]), { id: "b", name: "Extrude 01", type: "extrude", source: { kind: "profile", sketch: "s", regions: [{ c: [0, 0], a: 1200 }] }, distance: 20, mode: "new" }];
const cyl = [sk("c", [{ id: "k", kind: "circle", center: [0, 0], radius: 10 }]), { id: "y", name: "Extrude 01", type: "extrude", source: { kind: "profile", sketch: "c", regions: [{ c: [0, 0], a: 314.159 }] }, distance: 30, mode: "new" }];
const side = { body: "y", center: [0, 0, 15], normal: [-1, 0, 0], area: 1884.955592153876 };
const T = (op: any) => ({ id: "t", name: "T", type: "transform", bodies: ["b"], copy: false, op });
const rev = (cx: number) => [sk("s", [{ id: "r", kind: "rect", center: [cx, 5], w: 10, h: 10, rotation: 0 }], FRONT), { id: "v", name: "R", type: "revolve", source: { kind: "profile", sketch: "s", regions: [{ c: [cx, 5], a: 100 }] }, axis: { origin: [0, 0, 0], dir: [0, 0, 1] }, angle: 360, mode: "new" }];
// [name, steps, the message wanted (a part of it), or "" for "works"]
const cases: [string, any[], string][] = [
["pattern of 30000 (a typo for 30)", [...box, T({ kind: "linear", dir: [1, 0, 0], spacing: 50, count: 30000 })], "too many"],
["pattern spacing 0", [...box, T({ kind: "linear", dir: [1, 0, 0], spacing: 0, count: 5 })], "spacing is zero"],
["circular pattern angle 0", [...box, T({ kind: "circular", axis: { origin: [0, 0, 0], dir: [0, 0, 1] }, count: 4, angle: 0 })], "angle is zero"],
["pattern of 5 works", [...box, T({ kind: "linear", dir: [1, 0, 0], spacing: 50, count: 5 })], ""],
["revolve across the axis", rev(0), "crosses the axis"],
["revolve touching the axis works", rev(5), ""],
["thread pitch 0.05", [...cyl, { id: "th", name: "Th", type: "thread", face: side, pitch: 0.05 }], "too fine"],
["thread pitch 0", [...cyl, { id: "th", name: "Th", type: "thread", face: side, pitch: 0 }], "more than 0"],
];
let failed = 0;
for (const [name, feats, want] of cases) {
const t0 = performance.now();
const r: any = await regenerate(feats as any);
const msg = r.errors.map((e: any) => e.message).join("; ");
const ok = (want ? msg.toLowerCase().includes(want) : !msg) && performance.now() - t0 < 5000;
if (!ok) failed++;
console.log(ok ? "ok " : "FAIL", name, msg ? `- "${msg}"` : "", `${Math.round(performance.now() - t0)}ms`);
}
process.exit(failed ? 1 : 0);