Offset Face on a sweep's end around a bend, tilting a shell's rim, a fillet ending on a moved face; About without the GitHub button
- Offset Face on a sweep's end, pushed in again and again (a user's S-curve tube, 19 pushes): pushes on the bend failed. The end's plane cuts an S-shaped path in more than one place and only the first crossing was tried; and the disc cut along the path was far wider than the tube, so on a tight bend it folded over itself ("could not compute") or bit into the tube's next turn ("break into pieces"). The crossing at the face is taken, and the disc is just wider than the tube. The 19 pushes rebuild in 3.6 s (17 s). Test: tests/sweeppushes.test.ts
- Move Face tilting the rim a Shell leaves round its opening (a flat face with a hole) failed at any angle: its region was cut into 11 cells by every neighbour's surface, and joining them failed. Now its outline's region less its hole's. Test: tests/rimtilt.test.ts
- A fillet that ends on a face being moved, and can't be taken off alone (one link of a fillet chain): its cylinder was carried on as an endless one, which carved a groove and left a scrap of the old face standing (the stray-cylinder bug). It now carries on along its own corner, between the two faces it rounds, and ends on the moved face. Test: tests/movefillet.test.ts (a user's part)
- About: no "On GitHub" button
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+27
-28
@@ -1354,33 +1354,30 @@ function trimSweepEnd(body: Shape3D, F: Face, by: number, ctx: Ctx): Shape3D | n
|
||||
const c = F.center.toTuple() as Vec3;
|
||||
for (const spine of ctx.sweeps.values()) {
|
||||
const all = wirePoints(spine);
|
||||
// Every place the path passes through F's plane heading out through F
|
||||
// (the end itself, or where an earlier push left it): the one at F. On an
|
||||
// S-bend the plane cuts the path elsewhere too.
|
||||
const side = (p: Vec3) => dot(sub(p, origin), normal);
|
||||
const tolPlane = size * 0.05 + 1e-6;
|
||||
let best: { pts: Vec3[]; out: Vec3; d: number } | null = null;
|
||||
for (const way of [all, [...all].reverse()]) {
|
||||
// Walking in from this end of the path: where it crosses F's plane (the
|
||||
// end itself, or where an earlier push left the end), heading out
|
||||
// through F there, close to it.
|
||||
const side = (p: Vec3) => dot(sub(p, origin), normal);
|
||||
const tolPlane = size * 0.05 + 1e-6;
|
||||
let k = -1;
|
||||
for (let j = 0; j < way.length - 1; j++) {
|
||||
if (side(way[j]) >= -tolPlane && side(way[j + 1]) < side(way[j])) {
|
||||
if (side(way[j + 1]) <= tolPlane) {
|
||||
k = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (let k = 0; k < way.length - 1; k++) {
|
||||
const a0 = side(way[k]);
|
||||
const a1 = side(way[k + 1]);
|
||||
if (!(a0 >= -tolPlane && a1 < a0 && a1 <= tolPlane)) continue;
|
||||
const out = norm(sub(way[k], way[k + 1]));
|
||||
if (Math.abs(dot(out, normal)) < 0.98) continue;
|
||||
// (The sweep turns its profile square to the path: a profile drawn a
|
||||
// little off square ends on a plane a hair off the path's end.)
|
||||
const t0 = a0 <= tolPlane && k === 0 ? 0 : Math.min(1, Math.max(0, a0 / (a0 - a1)));
|
||||
const q = add(way[k], scale(sub(way[k + 1], way[k]), t0));
|
||||
const d = dist(q, c);
|
||||
if (d <= size && (!best || d < best.d)) best = { pts: [q, ...way.slice(k + 1)], out, d };
|
||||
}
|
||||
if (k < 0) continue;
|
||||
const a0 = side(way[k]);
|
||||
const a1 = side(way[k + 1]);
|
||||
// (The sweep turns its profile square to the path: a profile drawn a
|
||||
// little off square ends on a plane a hair off the path's end.)
|
||||
const t0 = a0 <= tolPlane && a0 >= -tolPlane && k === 0 ? 0 : Math.min(1, Math.max(0, a0 / (a0 - a1)));
|
||||
const q = add(way[k], scale(sub(way[k + 1], way[k]), t0));
|
||||
const pts = [q, ...way.slice(k + 1)];
|
||||
}
|
||||
if (best) {
|
||||
const { pts, out } = best;
|
||||
const p0 = pts[0];
|
||||
const out = norm(sub(way[k], way[k + 1]));
|
||||
if (Math.abs(dot(out, normal)) < 0.98) continue;
|
||||
if (dist(p0, c) > size) continue;
|
||||
// The piece of path to take off: from the end, `by` along it.
|
||||
const piece: Vec3[] = [p0];
|
||||
let run = 0;
|
||||
@@ -1399,11 +1396,13 @@ function trimSweepEnd(body: Shape3D, F: Face, by: number, ctx: Ctx): Shape3D | n
|
||||
if (run < by - 1e-9 || i >= pts.length - 1) throw new Error("That's as long as the sweep's whole path or more - it would remove it");
|
||||
// Straight line pieces stay a line; a curve is fitted through its points.
|
||||
const straight = piece.every((p) => len(sub(sub(p, p0), scale(norm(sub(piece[piece.length - 1], p0)), dot(sub(p, p0), norm(sub(piece[piece.length - 1], p0)))))) < size * 1e-6);
|
||||
const reach = size * 0.05 + 1e-3;
|
||||
const start = add(p0, scale(out, reach));
|
||||
const curve = straight || piece.length < 4 ? makeLine(p0, piece[piece.length - 1]) : makeBSplineApproximation(piece, { tolerance: size * 1e-6 + 1e-7, degMax: 5, degMin: 2 });
|
||||
const lead = size * 0.05 + 1e-3;
|
||||
const start = add(p0, scale(out, lead));
|
||||
const curve = straight || piece.length < 4 ? makeLine(p0, piece[piece.length - 1]) : makeBSplineApproximation(piece, { tolerance: size * 1e-4 + 1e-6, degMax: 5, degMin: 2 });
|
||||
const path = assembleWire([makeLine(start, p0), curve]);
|
||||
const r = dist(p0, c) + size;
|
||||
let reach0 = 0;
|
||||
for (const e of F.edges) for (let j = 0; j <= 16; j++) reach0 = Math.max(reach0, dist(e.pointAt(j / 16).toTuple() as Vec3, p0));
|
||||
const r = reach0 * 1.1 + size * 0.02;
|
||||
const disc = assembleWire([makeCircle(r, start, scale(out, -1))]);
|
||||
const cutter = genericSweep(disc, path, { frenet: false, transitionMode: "round" }) as Shape3D;
|
||||
const result = fuzzyBoolean("cut", body, cutter);
|
||||
|
||||
+106
-3
@@ -6,7 +6,7 @@
|
||||
// the body is on (planes → half-spaces, cylinders → infinite cylinders). Changing
|
||||
// F then only means adding/removing the right slab of E.
|
||||
|
||||
import { assembleWire, basicFaceExtrusion, getOC, loft, makeBSplineApproximation, makeCylinder, makeLine, makePolygon, makeSphere, measureArea, measureVolume, cast, Vector, type Face, type Shape3D } from "replicad";
|
||||
import { assembleWire, basicFaceExtrusion, getOC, loft, makeFace, makeBSplineApproximation, makeCylinder, makeLine, makePolygon, makeSphere, measureArea, measureVolume, cast, Vector, type Face, type Shape3D } from "replicad";
|
||||
import type { PlaneDef, Vec3 } from "../doc/types";
|
||||
import { add, cross, dist, dot, len, norm, scale, sub, xDirFor } from "../geom";
|
||||
import { subShapes } from "./health";
|
||||
@@ -127,6 +127,22 @@ function infiniteCylinder(cy: Cyl, r: number, L0: number): Shape3D {
|
||||
return makeCylinder(r, 2 * L, sub(cy.c, scale(cy.a, L)), cy.a) as Shape3D;
|
||||
}
|
||||
|
||||
/**
|
||||
* g, a round face next to flat face F, is a convex fillet that ends on F
|
||||
* (its axis runs through F, and it rounds the edge between two flat faces it
|
||||
* is tangent to): those two faces' planes, outward. Null otherwise.
|
||||
*/
|
||||
function filletEnding(body: Shape3D, F: Face, g: Face, cy: Cyl): [PlaneDef, PlaneDef] | null {
|
||||
if (Math.abs(dot(cy.a, planeOf(F).normal)) < 0.05) return null;
|
||||
const tol = sizeOf(body) * 1e-7;
|
||||
const sup = neighbours(body, g).filter((h) => h.geomType === "PLANE" && !h.isSame(F) && tangentTo(cy, planeOf(h), tol));
|
||||
if (sup.length !== 2) return null;
|
||||
const pls = sup.map((h) => planeOf(h)) as [PlaneDef, PlaneDef];
|
||||
// Convex: the axis lies inside the material, behind both faces.
|
||||
if (!pls.every((pl) => dot(sub(cy.c, pl.origin), pl.normal) < 0)) return null;
|
||||
return pls;
|
||||
}
|
||||
|
||||
/** Faces sharing an edge with F. */
|
||||
function neighbours(body: Shape3D, F: Face): Face[] {
|
||||
const edges = F.edges;
|
||||
@@ -138,12 +154,16 @@ function neighbours(body: Shape3D, F: Face): Face[] {
|
||||
* that contains `q` (a point just inside the body under F). Bounded by a box.
|
||||
*/
|
||||
export function extendedRegion(body: Shape3D, F: Face, q: Vec3, L: number): Shape3D {
|
||||
return regionAround(body, F, neighbours(body, F), q, L);
|
||||
}
|
||||
|
||||
/** As extendedRegion, bounded by the given faces round F (those along one of its outlines). */
|
||||
function regionAround(body: Shape3D, F: Face, nb: Face[], q: Vec3, L: number): Shape3D {
|
||||
const c = body.boundingBox.center as Vec3;
|
||||
// Bounding box, bigger than the other tools so no faces coincide with theirs.
|
||||
const big = () => halfSpace({ origin: sub(c, [0, 0, 1.5 * L]), xDir: [1, 0, 0], normal: [0, 0, 1] }, 3 * L);
|
||||
const keep: Shape3D[] = [];
|
||||
const remove: Shape3D[] = [];
|
||||
const nb = neighbours(body, F);
|
||||
for (const g of nb) {
|
||||
if (g.geomType === "PLANE") {
|
||||
const { origin: p, normal: n } = planeOf(g);
|
||||
@@ -153,6 +173,19 @@ export function extendedRegion(body: Shape3D, F: Face, q: Vec3, L: number): Shap
|
||||
} else if (g.geomType === "CYLINDRE") {
|
||||
const cy = cylinderOf(g);
|
||||
if (!cy) continue;
|
||||
// A rounded edge (a fillet) that ends on F: it carries on along itself,
|
||||
// between the two faces it rounds - not as an endless cylinder, which
|
||||
// carved a groove into the body and left a scrap of the old face standing.
|
||||
const corner = F.geomType === "PLANE" ? filletEnding(body, F, g, cy) : null;
|
||||
if (corner) {
|
||||
for (const pl of corner) {
|
||||
if (nb.some((x) => x.geomType === "PLANE" && Math.abs(dot(planeOf(x).normal, pl.normal)) > 1 - 1e-9 && Math.abs(dot(sub(planeOf(x).origin, pl.origin), pl.normal)) < 1e-6)) continue;
|
||||
keep.push(halfSpace({ origin: pl.origin, normal: scale(pl.normal, -1), xDir: xDirFor(scale(pl.normal, -1)) }, L));
|
||||
}
|
||||
const wedge = halfSpace({ origin: cy.c, normal: corner[0].normal, xDir: xDirFor(corner[0].normal) }, L).intersect(halfSpace({ origin: cy.c, normal: corner[1].normal, xDir: xDirFor(corner[1].normal) }, L));
|
||||
remove.push(wedge.cut(infiniteCylinder(cy, cy.r, L)));
|
||||
continue;
|
||||
}
|
||||
const rel = sub(q, cy.c);
|
||||
const radial = len(sub(rel, scale(cy.a, dot(rel, cy.a))));
|
||||
(radial < cy.r ? keep : remove).push(infiniteCylinder(cy, cy.r, L));
|
||||
@@ -338,6 +371,8 @@ function faceColumn(body: Shape3D, F: Face, L: number): Shape3D {
|
||||
const lift = sizeOf(body) * 1e-3;
|
||||
const q0 = sub(p, scale(n, lift));
|
||||
if (F.geomType === "PLANE" && convexFace(F)) return extendedRegion(body, F, q0, L);
|
||||
const holed = F.geomType === "PLANE" ? framedColumn(body, F, n, lift, L) : null;
|
||||
if (holed) return holed;
|
||||
const tol = sizeOf(body) * 1e-6;
|
||||
const sides = neighbours(body, F).map((g): ((q: Vec3) => number) | null => {
|
||||
if (g.geomType === "PLANE") {
|
||||
@@ -386,11 +421,79 @@ function faceColumn(body: Shape3D, F: Face, L: number): Shape3D {
|
||||
let E: Shape3D | null = null;
|
||||
for (const q of cells.values()) {
|
||||
const c = extendedRegion(body, F, q, L);
|
||||
E = E ? E.fuse(c) : c;
|
||||
E = E ? fuseCells(E, c) : c;
|
||||
}
|
||||
return E!;
|
||||
}
|
||||
|
||||
/**
|
||||
* A flat face with holes whose outline and holes are each convex (a rim left
|
||||
* round an opening, a plate with a window): the space its outline's
|
||||
* neighbours enclose, less the space each hole's neighbours enclose. Null for
|
||||
* any other face. (Cutting it into cells by every neighbour's surface and
|
||||
* joining them again failed on such a rim.)
|
||||
*/
|
||||
function framedColumn(body: Shape3D, F: Face, n: Vec3, lift: number, L: number): Shape3D | null {
|
||||
const holes = F.clone().innerWires();
|
||||
if (!holes.length) return null;
|
||||
const outer = F.clone().outerWire();
|
||||
const wireFace = (w: typeof outer): Face | null => {
|
||||
try {
|
||||
return makeFace(w);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
const loops = [outer, ...holes].map((w) => ({ w, f: wireFace(w) }));
|
||||
if (loops.some((l) => !l.f || !convexFace(l.f))) return null;
|
||||
const all = neighbours(body, F);
|
||||
const along = (w: typeof outer) => all.filter((g) => g.edges.some((e) => w.edges.some((we) => we.isSame(e))));
|
||||
// A point inside a convex loop, just under F.
|
||||
const inside = (w: typeof outer): Vec3 => {
|
||||
const pts = w.edges.flatMap((e) => [0, 0.5].map((t) => tup(e.pointAt(t))));
|
||||
const m = scale(pts.reduce((a, b) => add(a, b), [0, 0, 0] as Vec3), 1 / pts.length);
|
||||
return sub(m, scale(n, lift));
|
||||
};
|
||||
try {
|
||||
let E = regionAround(body, F, along(outer), inside(outer), L);
|
||||
for (const h of holes) E = E.cut(regionAround(body, F, along(h), inside(h), L));
|
||||
return isEmpty(E) ? null : E;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Two of a face's cells joined. They meet face to face, and the plain join
|
||||
* can fail on that (a U-shaped rim across a shell's walls): then once more
|
||||
* with a small tolerance, which lets the shared faces be one.
|
||||
*/
|
||||
function fuseCells(a: Shape3D, b: Shape3D): Shape3D {
|
||||
try {
|
||||
return a.fuse(b);
|
||||
} catch (err) {
|
||||
const oc = getOC();
|
||||
const algo = new oc.BRepAlgoAPI_Fuse();
|
||||
const args = new oc.NCollection_List_TopoDS_Shape();
|
||||
const tools = new oc.NCollection_List_TopoDS_Shape();
|
||||
try {
|
||||
args.Append(a.wrapped);
|
||||
tools.Append(b.wrapped);
|
||||
algo.SetArguments(args);
|
||||
algo.SetTools(tools);
|
||||
algo.SetFuzzyValue(Math.max(1e-7, Math.max(sizeOf(a), sizeOf(b)) * 1e-6));
|
||||
algo.SetNonDestructive(true);
|
||||
algo.Build(new oc.Message_ProgressRange());
|
||||
if (!algo.IsDone()) throw err;
|
||||
return cast(algo.Shape()) as Shape3D;
|
||||
} finally {
|
||||
algo.delete();
|
||||
args.delete();
|
||||
tools.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Does a flat face's outline turn the same way at every corner (no inward corners, no holes)? */
|
||||
export function convexFace(F: Face): boolean {
|
||||
if (F.clone().innerWires().length) return false;
|
||||
|
||||
+1
-5
@@ -111,15 +111,11 @@ export function showAbout(): void {
|
||||
const box = el("div", "dialog about");
|
||||
const head = el("div", "library-head");
|
||||
head.append(el("div", "panel-title", "About supergeometry.app"));
|
||||
const gh = el("a", "text-btn", "On GitHub");
|
||||
gh.href = REPO;
|
||||
gh.target = "_blank";
|
||||
gh.rel = "noopener";
|
||||
const closeBtn = el("button", "icon-btn library-close");
|
||||
closeBtn.type = "button";
|
||||
closeBtn.title = "Close";
|
||||
closeBtn.innerHTML = icons.close;
|
||||
head.append(gh, closeBtn);
|
||||
head.append(closeBtn);
|
||||
const body = el("div", "about-body");
|
||||
body.innerHTML = render(aboutText());
|
||||
// The Contents links scroll within the window.
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"format":"super","version":2,"name":"Untitled","features":[{"id":"sketch-mw569tes-9eqj","name":"Sketch 01","type":"sketch","plane":{"origin":[0,0,0],"xDir":[1,0,0],"normal":[0,-1,0]},"entities":[{"id":"5ludb8xt","kind":"line","a":[-10,0],"b":[-9.999999999999996,50]},{"id":"mk28wv3v","kind":"line","a":[-9.999999999999996,50],"b":[-60,50.00000000000001]},{"id":"qjpky46f","kind":"line","a":[-60,50.00000000000001],"b":[-60,0]},{"id":"87e4ry1k","kind":"line","a":[-60,0],"b":[-10,0]}],"constraints":[{"id":"u8afcwye","type":"vertical","curves":["5ludb8xt"]},{"id":"pnmx28tq","type":"coincident","pts":[{"e":"5ludb8xt","p":"b"},{"e":"mk28wv3v","p":"a"}]},{"id":"laf2pdi3","type":"horizontal","curves":["mk28wv3v"]},{"id":"tzgx1ui7","type":"coincident","pts":[{"e":"mk28wv3v","p":"b"},{"e":"qjpky46f","p":"a"}]},{"id":"ng4u1dih","type":"vertical","curves":["qjpky46f"]},{"id":"9w5fe9ad","type":"coincident","pts":[{"e":"qjpky46f","p":"b"},{"e":"87e4ry1k","p":"a"}]},{"id":"muii5bt2","type":"coincident","pts":[{"e":"87e4ry1k","p":"b"},{"e":"5ludb8xt","p":"a"}]},{"id":"d0rnci4s","type":"horizontal","curves":["87e4ry1k"]}],"log":[{"op":"Line","n":4}]},{"id":"extrude-mw56abf8-v8l2","name":"Extrude 01","type":"extrude","source":{"kind":"profile","sketch":"sketch-mw569tes-9eqj","regions":[{"c":[-35,25.000000000000004],"a":2500.0000000000005}]},"distance":33.5,"mode":"auto"},{"id":"moveFace-mw56ait0-ryuw","name":"Move Face 01","type":"moveFace","face":{"body":"extrude-mw56abf8-v8l2","center":[-9.999999999999998,-16.75,25],"normal":[1,0,-7.105427357601002e-17],"area":1675},"translate":[0,0,0],"rotate":{"origin":[-9.999999999999998,-16.75,25],"axis":[0,1,0],"angle":-30}},{"id":"moveFace-mw56apcg-u2z5","name":"Move Face 02","type":"moveFace","face":{"body":"extrude-mw56abf8-v8l2","center":[-34.30555555555555,-33.5,22.594373878376565],"normal":[0,-1,0],"area":2500.000000000001},"translate":[0,0,0],"rotate":{"origin":[-34.30555555555555,-33.5,22.594373878376565],"axis":[1,0,0],"angle":30}},{"id":"moveFace-mw56ay0f-5jhf","name":"Move Edge 01","type":"moveFace","edge":{"body":"extrude-mw56abf8-v8l2","mid":[-42.21687836487031,0,50.00000000000001],"dir":[-1,0,1.4210854715202004e-16],"length":35.56624327025938},"translate":[0,18.5,0]},{"id":"fillet-mw56b1ly-gl90","name":"Fillet 01","type":"fillet","edges":[{"body":"extrude-mw56abf8-v8l2","mid":[-24.43375672974063,-15.411322809314754,50.00000000000001],"dir":[-2.6191205359177573e-16,-1,2.0952964287342059e-16],"length":67.82264561862951}],"radius":5},{"id":"moveFace-mw56bndt-p9vl","name":"Move Face 03","type":"moveFace","face":{"body":"extrude-mw56abf8-v8l2","center":[-34.31070177796434,8.354569335452299,22.579917122844055],"normal":[0,0.9378618426812279,-0.3470088817920542],"area":2664.2050022174662},"translate":[0,0,0],"rotate":{"origin":[-34.31070177796434,8.354569335452299,22.579917122844055],"axis":[-1,0,0],"angle":12}},{"id":"fillet-mw56bw0o-4v3o","name":"Fillet 02","type":"fillet","edges":[{"body":"extrude-mw56abf8-v8l2","mid":[-9.27831216351296,9.094392904224886,23.749999999999996],"dir":[-0.43855660750047387,0.48028367458274124,0.7596023261858635],"length":62.532720559859705},{"body":"extrude-mw56abf8-v8l2","mid":[-24.82050807568875,25.26827360128725,49.33012701892219],"dir":[-0.8257432937451457,0.3014365888760406,0.4767431129252887],"length":5.529472582131915},{"body":"extrude-mw56abf8-v8l2","mid":[-43.66025403784439,25.6918229319893,50],"dir":[-1,0,0],"length":32.67949192431128}],"radius":3},{"id":"moveFace-mw56c27p-5oqy","name":"Move Face 04","type":"moveFace","face":{"body":"extrude-mw56abf8-v8l2","center":[-35.92141430595347,7.092617452310803,20.584051686023404],"normal":[0,0.8452201078962631,-0.5344183466235317],"area":2520.8994263543664},"translate":[0,0,0],"rotate":{"origin":[-35.92141430595347,7.092617452310803,20.584051686023404],"axis":[-1,0,0],"angle":-48}},{"id":"moveFace-mw6q8oo5-balt","name":"Move Face 05","type":"moveFace","face":{"body":"extrude-mw56abf8-v8l2","center":[-59.99999999999999,-12.45599336973517,30.573464678026944],"normal":[-1,0,0],"area":2231.9488897382917},"translate":[0,0,0],"rotate":{"origin":[-59.99999999999999,-12.45599336973517,30.573464678026944],"axis":[0,-1,0],"angle":-18}}],"variables":[],"views":[],"units":"mm","hidden":["sketch-mw569tes-9eqj"],"pins":[],"names":{}}
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,36 @@
|
||||
// Run: npx tsx tests/movefillet.test.ts - a user's part (tests/fixtures/
|
||||
// movefillet.json): a box with faces tilted, an edge moved, a fillet and a
|
||||
// chain of R3 fillets, then the left wall tilted 18° (Move Face 05). The R3
|
||||
// fillet ends on that wall and can't be taken off alone (it's one link of a
|
||||
// chain), so the wall's region was made with the fillet's cylinder as an
|
||||
// endless one: it carved a groove and left a scrap of the old wall standing
|
||||
// (12 faces: an inside-out cylinder and a 28 mm² patch at x = -60). Now the
|
||||
// fillet carries on along its own corner and simply ends on the tilted wall.
|
||||
import opencascade from "replicad-opencascadejs";
|
||||
import { measureArea, setOC } from "replicad";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { debugBodies, regenerate } from "../src/kernel/engine";
|
||||
import { healthOf, isHealthy } from "../src/kernel/repair";
|
||||
|
||||
setOC(await (opencascade as unknown as () => Promise<any>)());
|
||||
let failed = 0;
|
||||
const check = (name: string, ok: boolean, info = "") => {
|
||||
if (!ok) failed++;
|
||||
console.log(ok ? "ok " : "FAIL", name, info);
|
||||
};
|
||||
const doc = JSON.parse(readFileSync(new URL("./fixtures/movefillet.json", import.meta.url), "utf8"));
|
||||
const B = "extrude-mw56abf8-v8l2";
|
||||
const r: any = await regenerate(doc.features);
|
||||
const name = (id: string) => doc.features.find((f: any) => f.id === id)?.name;
|
||||
check("only Move Face 04 is refused (a fillet chain runs along that face), with a clear reason", r.errors.length === 1 && name(r.errors[0].featureId) === "Move Face 04" && /fillet/.test(r.errors[0].message), r.errors.map((e: any) => `${name(e.featureId)}: ${e.message}`).join("; "));
|
||||
const s = debugBodies().get(B)!;
|
||||
check("one clean solid", isHealthy(healthOf(s)));
|
||||
const n = (f: any) => f.normalAt().toTuple();
|
||||
const oldWall = s.faces.filter((f) => f.geomType === "PLANE" && Math.abs(n(f)[0] + 1) < 1e-6);
|
||||
check("no scrap of the old left wall left standing", oldWall.length === 0, oldWall.map((f) => measureArea(f).toFixed(1)).join(", "));
|
||||
const wall = s.faces.filter((f) => f.geomType === "PLANE" && Math.abs(n(f)[0] + Math.cos(Math.PI / 10)) < 1e-6 && Math.abs(n(f)[2] - Math.sin(Math.PI / 10)) < 1e-6);
|
||||
check("the left wall is one face, tilted 18°", wall.length === 1, wall.map((f) => measureArea(f).toFixed(1)).join(", "));
|
||||
const cyl = s.faces.filter((f) => f.geomType === "CYLINDRE");
|
||||
check("the same three rounded faces as before the tilt (no groove)", s.faces.length === 10 && cyl.length === 3, `${s.faces.length} faces, round: ${cyl.map((f) => measureArea(f).toFixed(1)).join(", ")}`);
|
||||
console.log(failed ? `${failed} FAILED` : "all passed");
|
||||
process.exit(failed ? 1 : 0);
|
||||
@@ -0,0 +1,45 @@
|
||||
// Run: npx tsx tests/rimtilt.test.ts - Move Face tilting the rim a Shell
|
||||
// leaves round its opening (a user's box: filleted, chamfered, shelled open on
|
||||
// the chamfer, the rim pushed in twice). The rim is a flat face with a hole;
|
||||
// tilting it failed at any angle (its region was cut into 11 cells by every
|
||||
// neighbour's surface, and joining them failed). Now: its outline's region
|
||||
// less its hole's.
|
||||
import opencascade from "replicad-opencascadejs";
|
||||
import { measureArea, measureVolume, setOC } from "replicad";
|
||||
import { debugBodies, regenerate } from "../src/kernel/engine";
|
||||
import { healthOf, isHealthy } from "../src/kernel/repair";
|
||||
|
||||
setOC(await (opencascade as unknown as () => Promise<any>)());
|
||||
let failed = 0;
|
||||
const check = (name: string, ok: boolean, info = "") => {
|
||||
if (!ok) failed++;
|
||||
console.log(ok ? "ok " : "FAIL", name, info);
|
||||
};
|
||||
const rect = { id: "sk", name: "Sketch 01", type: "sketch", plane: { origin: [0, 0, 0], xDir: [0, 1, 0], normal: [1, 0, 0] }, entities: [{ id: "r", kind: "rect", center: [20, 25], w: 40, h: 50, rotation: 0 }] };
|
||||
const B = "box";
|
||||
const s2 = Math.SQRT1_2;
|
||||
const base: any[] = [
|
||||
rect,
|
||||
{ id: B, name: "Extrude 01", type: "extrude", source: { kind: "profile", sketch: "sk", regions: [{ c: [20, 25], a: 2000 }] }, distance: 28, mode: "auto" },
|
||||
{ id: "f1", name: "Fillet 01", type: "fillet", edges: [{ body: B, mid: [14, 40, 50], dir: [1, 0, 0], length: 28 }], radius: 20 },
|
||||
{ id: "c1", name: "Chamfer 01", type: "chamfer", edges: [{ body: B, mid: [14, 0, 50], dir: [1, 0, 0], length: 28 }], radius: 14 },
|
||||
{ id: "s1", name: "Shell 01", type: "shell", body: B, faces: [{ body: B, center: [14, 7, 43], normal: [0, -s2, s2], area: 554.37 }], thickness: 5 },
|
||||
{ id: "o1", name: "Offset Face 01", type: "extrude", source: { kind: "face", face: { body: B, center: [14, 7, 43], normal: [0, -s2, s2], area: 452.548 } }, distance: -3, mode: "auto", target: B },
|
||||
{ id: "o2", name: "Offset Face 02", type: "extrude", source: { kind: "face", face: { body: B, center: [14, 9.1213, 40.8787], normal: [0, -s2, s2], area: 512.548 } }, distance: -9, mode: "auto", target: B },
|
||||
];
|
||||
const rim = { body: B, center: [14, 13.960626616153542, 32.99006386767639], normal: [0, -s2, s2], area: 632.652 };
|
||||
await regenerate(base);
|
||||
const v0 = Math.abs(measureVolume(debugBodies().get(B)!));
|
||||
for (const angle of [14, -10, 3]) {
|
||||
const r: any = await regenerate([...base, { id: "m1", name: "Move Face 01", type: "moveFace", face: rim, translate: [0, 0, 0], rotate: { origin: rim.center, axis: [1, 0, 0], angle } }]);
|
||||
const s = debugBodies().get(B)!;
|
||||
const a = (angle * Math.PI) / 180;
|
||||
const want = [0, -s2 * Math.cos(a) - s2 * Math.sin(a), -s2 * Math.sin(a) + s2 * Math.cos(a)];
|
||||
const tilted = s.faces.filter((f) => f.geomType === "PLANE" && f.normalAt().toTuple().every((x, i) => Math.abs(x - want[i]) < 1e-6));
|
||||
const v = Math.abs(measureVolume(s));
|
||||
check(`rim tilted ${angle}°: builds, one clean solid`, !r.errors.length && isHealthy(healthOf(s)), r.errors.map((e: any) => e.message).join("; "));
|
||||
check("…the rim is one face at the new angle, still with its opening", tilted.length === 1 && tilted[0].clone().innerWires().length === 1, tilted.map((f) => measureArea(f).toFixed(1)).join(", "));
|
||||
check("…the walls just follow (volume within 10%)", Math.abs(v - v0) < v0 * 0.1, `${v0.toFixed(0)} → ${v.toFixed(0)}`);
|
||||
}
|
||||
console.log(failed ? `${failed} FAILED` : "all passed");
|
||||
process.exit(failed ? 1 : 0);
|
||||
@@ -0,0 +1,54 @@
|
||||
// Run: npx tsx tests/sweeppushes.test.ts - a user's S-curve tube whose ends
|
||||
// were pushed in again and again (Offset Face on a sweep's end, 19 times;
|
||||
// tests/fixtures/sweeppushes.json). Pushes on the bend failed: the end's plane
|
||||
// cuts an S-shaped path in more than one place and only the first was tried,
|
||||
// and the cutting disc was far wider than the tube (on a tight bend it folded
|
||||
// over itself, or bit into the tube's next turn: "break into pieces").
|
||||
import opencascade from "replicad-opencascadejs";
|
||||
import { measureArea, measureVolume, setOC } from "replicad";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { debugBodies, regenerate } from "../src/kernel/engine";
|
||||
import { healthOf, isHealthy } from "../src/kernel/repair";
|
||||
|
||||
setOC(await (opencascade as unknown as () => Promise<any>)());
|
||||
let failed = 0;
|
||||
const check = (name: string, ok: boolean, info = "") => {
|
||||
if (!ok) failed++;
|
||||
console.log(ok ? "ok " : "FAIL", name, info);
|
||||
};
|
||||
const doc = JSON.parse(readFileSync(new URL("./fixtures/sweeppushes.json", import.meta.url), "utf8"));
|
||||
const BODY = "sweep-mw6p7ni3-sy2n";
|
||||
const A = Math.PI * 2.5 * 2.5;
|
||||
const name = (id: string) => doc.features.find((f: any) => f.id === id)?.name;
|
||||
const tube = () => {
|
||||
const s = debugBodies().get(BODY)!;
|
||||
const ends = s.faces.filter((f) => f.geomType === "PLANE");
|
||||
return { s, length: Math.abs(measureVolume(s)) / A, round: ends.length === 2 && ends.every((f) => Math.abs(measureArea(f) - A) < A * 2e-3), ends: ends.map((f) => measureArea(f).toFixed(2)).join(", ") };
|
||||
};
|
||||
|
||||
// As the user saw it: the pushes that failed then (11, 12, 18, 20) left out.
|
||||
{
|
||||
const skip = new Set(["Offset Face 11", "Offset Face 12", "Offset Face 18", "Offset Face 20"]);
|
||||
const r: any = await regenerate(doc.features.filter((f: any) => !skip.has(f.name)));
|
||||
const t = tube();
|
||||
check("as the user built it: every push builds", !r.errors.length, r.errors.map((e: any) => `${name(e.featureId)}: ${e.message}`).join("; "));
|
||||
check("…one clean tube, both ends round", isHealthy(healthOf(t.s)) && t.round, `${t.length.toFixed(2)} long; ends ${t.ends}`);
|
||||
}
|
||||
|
||||
// Everything: 11 and 12 build now; by 18 the tube is shorter than the push (an honest error).
|
||||
{
|
||||
const t0 = performance.now();
|
||||
const r: any = await regenerate(doc.features);
|
||||
const ms = performance.now() - t0;
|
||||
const failedNames = r.errors.map((e: any) => name(e.featureId));
|
||||
check("all on: Offset Face 11 and 12 build (they're on the bend)", !failedNames.includes("Offset Face 11") && !failedNames.includes("Offset Face 12"), failedNames.join(", "));
|
||||
check("…no kernel failures, only pushes past what's left", r.errors.every((e: any) => /remove/.test(e.message)), r.errors.map((e: any) => `${name(e.featureId)}: ${e.message}`).join("; "));
|
||||
check("…19 pushes rebuild in reasonable time", ms < 12000, `${Math.round(ms)} ms`);
|
||||
const upto = doc.features.slice(0, doc.features.findIndex((f: any) => f.name === "Offset Face 17") + 1);
|
||||
await regenerate(upto);
|
||||
const t = tube();
|
||||
check("…up to 17 the tube is 3 mm long (18 pushes 6.4)", t.length < 6.4 && t.round, `${t.length.toFixed(2)}; ends ${t.ends}`);
|
||||
}
|
||||
|
||||
console.log(failed ? `${failed} FAILED` : "all passed");
|
||||
process.exit(failed ? 1 : 0);
|
||||
Reference in New Issue
Block a user