Files
supergeometry.app/tests/threadclearance.test.ts
superGeometry 2433833eef A thread's clearance on a bolt with a head; a lifted spline split keeps its heights; printing a drawing from a phone; STEP files of several solids, tested (asked for: "ok do all you can" - of the list of what to test next: undo inside each tool, 3D splines beyond Sweep, picking with every tool, thread clearance on awkward bolts, STEP files of several bodies, Print / PDF of drawings).
- Thread clearance. A bolt with a head, cut from a block with a clearance: the hole's thread ran into the bolt's (0.027 off it, not the 0.2 asked). The thread put back on the grown body was measured from that body's own round face, whose centre and direction are the kernel's choice and differ from the bolt's: the turns started somewhere else. It is measured from the first thread's own point and axis now, over its own stretch. The grooves are filled back in by taking the threaded stretch out and putting a clean ring in (filling them one by one left edges the kernel could not grow). tests/threadclearance.test.ts, 13 checks: the plain bolt at 0.1, 0.2, 0.4; a headed bolt; its head chamfered after the thread; a rod cut by a threaded nut; clearance taken from the bolt, and from both - each the gap asked (0.1998 to 0.2000).
- A spline with points off the plane, split or trimmed: its pieces keep their heights (they fell flat on the plane). A loft along a lifted spline as its guide: tested. tests/spline3d.test.ts, 22 checks.
- Print / PDF of a drawing, of all drawings, and of the Technical Sheet: the page was put back the moment print() returned. On a phone it returns at once, before the preview has drawn anything - a blank page, or the app. It is put back when printing is over.
- tests/stepimport.test.ts, 12 checks: a STEP of four solids (two touching, one sunk in another) comes in as four bodies, each its size, sound; the same file in metres and in inches; Windows line ends; one then moved, one cut by another, one deleted; two files in one project; forty solids; a file cut short, not STEP, empty - said in plain words. Nothing to fix.
In the app: undo and redo inside Offset Face, Extrude, Fillet, Chamfer, Shell, Move/Rotate Face, Edge and Body, Scale, both patterns, Thread, Subtract, Revolve - each step back in turn, nothing to fix; every tool started from every kind of pick (216 starts): none failed to open, no errors; Print / PDF pressed with the print window held: the sheet (420 x 297) in the page until printing is over, then gone, twice in a row the same.
Tests: threadclearance 13, thread, clearance 32, spline3d 22, sketchtools, exports 25, projectlean 29, stepimport 12, drawing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 17:29:38 +02:00

89 lines
6.7 KiB
TypeScript

// Run: npx tsx tests/threadclearance.test.ts
// A threaded bolt subtracted from a block with a clearance: a threaded hole a little bigger than the bolt all
// round, so the printed bolt turns in it. (It failed every time: "Couldn't keep 0.2 mm clear ...".)
import { after, bodies, block, check, cylinder, done, health, near, volume } from "./kit";
import { getOC, type Shape3D } from "replicad";
import type { Feature } from "../src/doc/types";
const oc = getOC();
const gap = (a: Shape3D, b: Shape3D) => {
const d = new oc.BRepExtrema_DistShapeShape(a.wrapped, b.wrapped);
try {
return d.IsDone() ? d.Value() : -1;
} finally {
d.delete();
}
};
// A block 30 x 30 x 12 and an M10 bolt shank (r 5, 24 long) standing through its middle.
const blockF = block("blk", 30, 30, 12);
const bolt = cylinder("bolt", 5, 24, 15, 15, -6);
const first = await after([...blockF, ...bolt]);
const side = first.r.bodies.find((b) => b.id === "bolt")!.faces.find((f) => f.type === "CYLINDRE")!;
const thread: Feature = { id: "thr", name: "Thread", type: "thread", face: { body: "bolt", center: side.center, normal: side.normal, area: side.area }, pitch: 1.5 } as Feature;
const cut = (extra: object): Feature => ({ id: "cut", name: "Subtract", type: "boolean", op: "subtract", target: "blk", tools: ["bolt"], keepTools: true, ...extra }) as Feature;
const B = (id: string) => bodies().get(id) as Shape3D;
let r = await after([...blockF, ...bolt, thread]);
const vBolt = volume(B("bolt"));
check("the bolt is threaded", !r.errors.length && health(B("bolt")).healthy && vBolt < Math.PI * 25 * 24, `${vBolt.toFixed(1)} ${r.errors.join("; ")}`);
r = await after([...blockF, ...bolt, thread, cut({})]);
const vTight = volume(B("blk"));
check("no clearance: a threaded hole the bolt's own size", !r.errors.length && health(B("blk")).healthy && near(gap(B("blk"), B("bolt")), 0, 1e-3), `${r.errors.join("; ")} gap ${gap(B("blk"), B("bolt")).toFixed(4)}`);
for (const c of [0.1, 0.2, 0.4]) {
const t0 = performance.now();
r = await after([...blockF, ...bolt, thread, cut({ clearance: c })]);
const ok = !r.errors.length && !!B("blk");
const g = ok ? gap(B("blk"), B("bolt")) : -1;
const v = ok ? volume(B("blk")) : 0;
// The hole is the thread that much bigger all round: nowhere nearer the bolt than the clearance (its sides and
// its crests at just that; its roots have more).
check(`clearance ${c}: the cut is made, sound, the bolt kept`, ok && health(B("blk")).healthy && near(volume(B("bolt")), vBolt, 1e-6), `${r.errors.join("; ")} ${Math.round(performance.now() - t0)} ms`);
check(`clearance ${c}: the hole stands ${c} off the bolt at its nearest, and is bigger than the tight one`, ok && g > c * 0.97 && g < c * 1.03 && v < vTight, `gap ${g.toFixed(4)}, block ${v.toFixed(1)} against ${vTight.toFixed(1)}`);
}
// A bolt with a head: the thread is on its shank only; the block is cut round shank and head alike.
{
const head = cylinder("head", 9, 6, 15, 15, 18);
const join: Feature = { id: "j", name: "Union", type: "boolean", op: "union", target: "bolt", tools: ["head"] } as Feature;
const tall = block("blk", 30, 30, 22);
const base = [...tall, ...bolt, ...head, join];
const r0 = await after(base);
const shank = r0.r.bodies.find((b) => b.id === "bolt")!.faces.find((f) => f.type === "CYLINDRE" && Math.abs((f.round?.r ?? 0) - 5) < 1e-6)!;
const th: Feature = { id: "thr", name: "Thread", type: "thread", face: { body: "bolt", center: shank.center, normal: shank.normal, area: shank.area }, pitch: 1.5 } as Feature;
const rr = await after([...base, th, cut({ clearance: 0.2 })]);
const okk = !rr.errors.length && !!B("blk");
check("a headed bolt, clearance 0.2: cut, sound, 0.2 off at its nearest", okk && health(B("blk")).healthy && near(gap(B("blk"), B("bolt")), 0.2, 0.01), `${rr.errors.join("; ")} gap ${okk ? gap(B("blk"), B("bolt")).toFixed(4) : "-"}`);
// Something done to the bolt after its thread (a chamfer on the head): it is no longer the thread's own result
// in every part, yet its thread is still there - cut the same way.
const top = rr.r.bodies.find((b) => b.id === "bolt")!;
const rim = top.edges.find((e) => e.type === "CIRCLE" && Math.abs(e.start[2] - 24) < 1e-6 && Math.abs(Math.hypot(e.start[0] - 15, e.start[1] - 15) - 9) < 1e-6)!;
const cham: Feature = { id: "ch", name: "Chamfer", type: "chamfer", edges: [{ body: "bolt", mid: rim.mid, dir: [0, 0, 1], length: rim.length }], radius: 1 } as unknown as Feature;
const r2 = await after([...base, th, cham, cut({ clearance: 0.2 })]);
const ok2 = !r2.errors.length && !!B("blk");
check("the same with the head chamfered after the thread: cut, or said why in plain words", ok2 ? health(B("blk")).healthy && gap(B("blk"), B("bolt")) > 0.15 : /clear|smaller/i.test(r2.errors.join()), `${r2.errors.join("; ")} gap ${ok2 ? gap(B("blk"), B("bolt")).toFixed(4) : "-"}`);
}
// A nut (a thread in a hole) used as the cutter of a rod standing in it: the rod gets the outside thread, 0.2 smaller.
{
const nut = block("nut", 24, 24, 8, [3, 3, 2]);
const hole = cylinder("pin", 4.25, 8, 15, 15, 2);
const bore: Feature = { id: "bore", name: "Subtract", type: "boolean", op: "subtract", target: "nut", tools: ["pin"] } as Feature;
const rod = cylinder("rod", 5, 14, 15, 15, -1);
const r0 = await after([...nut, ...hole, bore]);
const inner = r0.r.bodies.find((b) => b.id === "nut")!.faces.find((f) => f.type === "CYLINDRE")!;
const th: Feature = { id: "nt", name: "Thread", type: "thread", face: { body: "nut", center: inner.center, normal: inner.normal, area: inner.area }, pitch: 1.5 } as Feature;
const c: Feature = { id: "cut", name: "Subtract", type: "boolean", op: "subtract", target: "rod", tools: ["nut"], keepTools: true, clearance: 0.2 } as Feature;
const rr = await after([...nut, ...hole, bore, th, ...rod, c]);
const okk = !rr.errors.length && !!B("rod");
check("a rod cut by a threaded nut, clearance 0.2: made, sound, 0.2 off the nut at its nearest", okk && health(B("rod")).healthy && near(gap(B("rod"), B("nut")), 0.2, 0.01), `${rr.errors.join("; ")} gap ${okk ? gap(B("rod"), B("nut")).toFixed(4) : "-"}`);
}
// The clearance taken from the bolt instead of the block ("The others"), and shared between them ("All").
for (const from of ["tools", "all"] as const) {
r = await after([...blockF, ...bolt, thread, cut({ clearance: 0.2, cutFrom: from })]);
const okk = !r.errors.length && !!B("blk") && !!B("bolt");
check(`clearance 0.2 taken from ${from === "tools" ? "the bolt" : "both"}: made and 0.2 apart, or said why in plain words`, okk ? gap(B("blk"), B("bolt")) > 0.15 && gap(B("blk"), B("bolt")) < 0.25 : /clear|smaller|thread/i.test(r.errors.join()), `${r.errors.join("; ")} gap ${okk ? gap(B("blk"), B("bolt")).toFixed(4) : "-"}`);
}
done();