Files
superGeometry 4cbd0d044e Freeform: what was missing.
- Sharp edges. Edges picked are made sharp (Sharp edge; one edge: Sharp loop, the whole loop it is part of): the surface keeps a crease along them instead of rounding over - followed as an open border is, a corner where three or more meet, fading out where one ends in the middle. Smooth edge takes it off. Shown orange on the cage. Kept in the cage (cage.creases), so in the step, its edits, copies and moves; the editor's quick weights and the solid are made by the same rules (a box with every edge sharp is that box: 24,000 for 40 x 30 x 20). Tools that change the cage carry them: a loop cut across one leaves its two halves sharp, taken out again it is one; Add detail halves each; faces deleted keep what is still an edge.
- Remove edge loop: the loop an edge is part of taken out, the faces either side of it made one (it could only ever be added).
- A picked face is pushed or pulled by dragging the face itself, along its normal (several: their average) - as everything else on the model is dragged.
- Place at, beside Move / Turn / Scale: the picked points put where their middle is at the X, Y, Z typed (there were only distances to move by).
- Soft: a distance round the picked points within which the others follow a move, less the further off (1 beside, 0 at that distance) - a bump, not a spike. By the gimbal, by typed values, by a face dragged and by Place at; with Symmetry, mirrored too.
tests/creases.test.ts: 18 checks. In the app: a face dragged (1.9 out), points placed at Z 60 and X 5, one point raised 10 with Soft 25 (13 others followed, up to 5.1), a loop added and removed (56 points, 68, 56), an edge and a loop made sharp, undone and redone, saved and opened again still sharp; each finished as a closed solid. The other freeform tests as before: freeform 15, freeformedit 29, freeformtools 40, faceff 26, faceffmulti 7, hoseconnector 14, connect 107.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 01:39:04 +02:00

79 lines
5.4 KiB
TypeScript

// Run: npx tsx tests/creases.test.ts - sharp edges on a freeform cage: the
// surface keeps a crease along them. The quick weights the editor draws with
// give the same points as the rules applied in full; a box with every edge
// sharp is that box exactly; one loop sharp is a cylinder-like end; tools that
// change the cage carry the sharp edges along.
import { check, done, near, after, volume, health } from "./kit";
import { applyPlan, boxCage, carryCreases, cageEdges, insertEdgeLoop, limitPoints, refineCage, removeEdgeLoop, subdivide, subdivisionPlan, edgeLoopOf, deleteFaces, type Cage } from "../src/freeform/cage";
import type { Feature } from "../src/doc/types";
const same = (cage: Cage, levels = 3) => {
const s = subdivide(cage, levels);
const exact = limitPoints(s);
const quick = applyPlan(subdivisionPlan(cage, levels), cage.verts);
let worst = 0;
exact.forEach((p, i) => (worst = Math.max(worst, Math.abs(p[0] - quick[i * 3]), Math.abs(p[1] - quick[i * 3 + 1]), Math.abs(p[2] - quick[i * 3 + 2]))));
return { worst, n: exact.length, pts: exact };
};
const ff = (id: string, cage: Cage): Feature => ({ id, name: id, type: "freeform", cage }) as Feature;
// A box, one face a side: all twelve edges sharp.
const box = boxCage([40, 30, 20], 1);
const all: Cage = { ...box, creases: cageEdges(box) };
check("a box has twelve edges", all.creases!.length === 12, all.creases!.length);
const a = same(all);
check("quick and full agree (every edge sharp)", a.worst < 1e-5, a.worst);
const lo = [0, 1, 2].map((k) => Math.min(...a.pts.map((p) => p[k])));
const hi = [0, 1, 2].map((k) => Math.max(...a.pts.map((p) => p[k])));
check("... and the surface is the box itself", near(hi[0] - lo[0], 40, 1e-9) && near(hi[1] - lo[1], 30, 1e-9) && near(hi[2] - lo[2], 20, 1e-9), [lo, hi]);
{
const { body, err } = await after([ff("B", all)], "B");
check("made a solid: 40 x 30 x 20", !err && near(volume(body), 24000, 24), { err, v: volume(body) });
check("... closed and sound", !!body && health(body).healthy, body && health(body));
}
// No sharp edges: as it always was (rounded, smaller).
{
const s = same(box);
check("quick and full agree (none sharp)", s.worst < 1e-5, s.worst);
const { body } = await after([ff("R", box)], "R");
check("none sharp: a rounded lump, well under the box", volume(body) < 24000 * 0.75, volume(body));
}
// Only the top's four edges sharp: a flat top with a crisp rim, the bottom still round.
{
const fine = boxCage([40, 40, 40], 2);
const z = Math.max(...fine.verts.map((p) => p[2]));
const rim = cageEdges(fine).filter(([p, q]) => near(fine.verts[p][2], z) && near(fine.verts[q][2], z) && (near(Math.abs(fine.verts[p][0]), 20) || near(Math.abs(fine.verts[p][1]), 20)) && (near(Math.abs(fine.verts[q][0]), 20) || near(Math.abs(fine.verts[q][1]), 20)) && (near(fine.verts[p][0], fine.verts[q][0]) ? near(Math.abs(fine.verts[p][0]), 20) : near(Math.abs(fine.verts[p][1]), 20)));
const top: Cage = { ...fine, creases: rim };
check("the top's rim is eight edges", rim.length === 8, rim.length);
const s = same(top);
check("quick and full agree (a rim sharp)", s.worst < 1e-5, s.worst);
const { body: sharp, err } = await after([ff("T", top)], "T");
const { body: round } = await after([ff("T0", fine)], "T0");
check("a sharp rim: more of the box is kept than with none", !err && volume(sharp) > volume(round) * 1.03, { err, sharp: volume(sharp), round: volume(round) });
check("... closed and sound", !!sharp && health(sharp).healthy, sharp && health(sharp));
// The loop through one of its edges is the rim's side it is on... the whole loop of edges through it.
const loop = edgeLoopOf(top, rim[0][0], rim[0][1], true);
check("the loop through a rim edge can be followed", !!loop && loop.length >= 2, loop?.length);
// Tools carry them: a loop added across the rim cuts two of its edges - both halves stay sharp.
const side = cageEdges(top).find(([p, q]) => near(top.verts[p][0], top.verts[q][0]) && near(top.verts[p][1], top.verts[q][1]) && !near(top.verts[p][2], top.verts[q][2]))!;
const cut = insertEdgeLoop(top, side[0], side[1]);
check("a loop round the sides leaves the rim as it was", !!cut && (carryCreases(top, cut!).creases?.length ?? 0) === 8, cut && carryCreases(top, cut).creases?.length);
const across = insertEdgeLoop(top, rim[0][0], rim[0][1]);
const carried = across && carryCreases(top, across);
check("a loop across the rim: its two cut edges are four sharp halves (ten in all)", (carried?.creases?.length ?? 0) === 10, carried?.creases?.length);
check("... and quick and full still agree", !!carried && same(carried).worst < 1e-5, carried && same(carried).worst);
// Taken out again: eight.
const mid = carried!.verts.length - 1;
const loopEdge = cageEdges(carried!).find(([p, q]) => p >= top.verts.length && q >= top.verts.length)!;
const back = removeEdgeLoop(carried!, loopEdge[0], loopEdge[1]);
check("the loop taken out again: the rim's eight", !!back && (back!.creases?.length ?? 0) === 8, { n: back?.creases?.length, mid });
// Add detail: each sharp edge is two.
const fine2 = refineCage(top);
check("Add detail: sixteen sharp edges, the same shape", (fine2.creases?.length ?? 0) === 16, fine2.creases?.length);
// A face deleted: sharp edges that are still edges stay.
const less = deleteFaces(top, [0]);
check("a face deleted: the sharp edges still there are kept", (less.creases?.length ?? 0) >= 6, less.creases?.length);
}
done();