Files
superGeometry a2cfe76a3f Linked copies and patterns; Fill Pattern in sketches; freeform solids get every body tool; the right column's buttons lit and its windows clear of everything; More reordered with switches; the grid's size live; Draw turns Line on; the line as wide as its buttons (asked for, nine points: "make sure even the buttons on the middle right (fit, shaders, settings) show when something is opened. like the ones on the middle left ... when a window opens from those, to not override anything else (should be dynamic) ... In More, move Help above Feedback, move Update under Install App, and make the two buttons (guide text and offline mode) have a toggle icon ... Rename About supergeometry.app to only About ... the lock grid size should change on the fly when i zoom ... when i click draw, line should be automatically selected (but the window with different line types should open normally) ... if i copy a body, i have the option to link it, but that doesnt do anything ... whatever change i do to any copy of that body or the original, it should also change the other ones exactly the same. we should also have this in patterns ... a new tool in sketch mode named fill pattern ... when i double click a freeform body, i want the edit freeform button there ... a freeform body that is finished should be treated like a regular body ... on desktop, in sketch mode ... the bar should be wider to fit all the buttons without having to scroll on it").
- Linked bodies. A copy (Move/Rotate, Mirror, Scale with Copy on) or a pattern made with Link on, and what it was made from, are a group: a step that changes one of them - an edge rounded, a hole cut, something joined on - changes every other the same way, each where it stands (turned, mirrored). Moving or turning one only moves that one, and it still follows; one deleted leaves the others; a linked copy of a linked copy is of the same group. Both patterns have a Link switch now. (Link only did anything for freeform copies before.) tests/linked.test.ts, 17 checks.
- Fill Pattern, a sketch tool under Draw: tap inside a closed shape and it is filled with Lines, Crossed lines, Zigzag or Waves from edge to edge (ending exactly on the shape's edge, stopping at holes), or with Dots, a Honeycomb, Squares or Diamonds kept wholly inside it; Spacing (or the Gap between shapes), Size and Angle set, shown as they change. The strips and cells are shapes of the sketch: extruded or cut, a texture. A filled shape tapped again: its pattern changed or removed. The pattern is kept with the sketch and made again when the sketch's curves change (a rectangle made taller: 9 cells became 43). Too fine a spacing (thousands of curves) is refused in plain words. tests/fillpattern.test.ts, 28 checks.
- A freeform solid that is finished is a body like any other: its faces, edges and corners have every tool a body's have (they were held to Move, Mirror, Pattern and Delete Body), its edges their dot, its corners their gimbal and Move Vertex. Only a freeform left as an open surface keeps its own few. Edit Freeform is beside a freeform body double tapped - also after other steps were done on it - and in History.
- The right column: Shaded and Settings are lit while their window is open, as the three at the left are while they are on. Their windows (Units & grid and the others too) are placed in the room there is - under the top bar, the view cube, Items and History, over the line, undo / redo and the guide text - on every screen, and scroll inside when longer; on a phone on its side, beside the view cube. (They came down over the line on a phone.)
- More: Update under Install app; Guide text and Offline mode each with a switch (they said On / Off in words); Help above Feedback; About.
- Units & grid open, not locked: the size said on Lock grid size, in the box and in the note follows the zoom as it changes.
- A sketch's Draw opened with no tool on: Line is on and the list stays open - a tap on the grid draws, a tap in the list takes another tool.
- The line at the bottom is as wide as what is on it, up to all the room between undo and the right edge (it stopped at 980): a sketch's picked line or shape has all its sizes and buttons in view on a wide screen.
In the app: the nine tried - the windows at 390 x 800, 844 x 390, 768 x 1024 and a desk screen (nothing over anything); a rectangle filled with lines, then a honeycomb, then made taller; a circle filled with waves; a freeform box double tapped, a corner, a face and an edge of it picked; a pattern's Link switch; a sketch's line and rectangle picked on a 1577 wide screen (the line 1050 and 1115 wide, nothing to slide).
Tests: all 178 test files pass (mouse.test.ts's 30 s limit on a shell was missed once with five running at a time: 39 of 39 run alone).

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

123 lines
9.8 KiB
TypeScript

// Run: npx tsx tests/fillpattern.test.ts
// Fill Pattern: a closed shape of a sketch filled with lines from edge to edge, or with small shapes inside it.
// The lines end exactly on the shape's edge (so the strips between them are closed shapes to extrude), stay out of
// holes, follow the shape when it changes - and the engine builds solids from what they make.
import { after, bodies, check, done, health, near, sketch, volume, XY, circle, rect } from "./kit";
import { FILL_KINDS, FILL_MOST, fillCurves, fillOf, fillRegion, refill, withoutFills } from "../src/sketch/fill";
import { arrangement, regionRef } from "../src/sketch/regions";
import { entityCorners, entityPrims, evalPrim } from "../src/sketch/curves";
import type { Feature, SketchEntity, SketchFill, Vec2 } from "../src/doc/types";
import type { Shape3D } from "replicad";
const R = [rect("r", 0, 0, 40, 20)];
const fill = (kind: SketchFill["kind"], extra: Partial<SketchFill> = {}): SketchFill => ({ id: "f1", at: [20, 10], kind, spacing: 5, angle: 0, size: 4, ...extra });
const ends = (e: SketchEntity): Vec2[] => entityPrims(e).flatMap((p) => [evalPrim(p, 0), evalPrim(p, 1)]);
const onRect = (p: Vec2, w = 40, h = 20) => (Math.abs(p[0]) < 1e-7 || Math.abs(p[0] - w) < 1e-7 || Math.abs(p[1]) < 1e-7 || Math.abs(p[1] - h) < 1e-7) && p[0] > -1e-7 && p[0] < w + 1e-7 && p[1] > -1e-7 && p[1] < h + 1e-7;
const inRect = (p: Vec2, w = 40, h = 20) => p[0] > -1e-7 && p[0] < w + 1e-7 && p[1] > -1e-7 && p[1] < h + 1e-7;
check("a point in the rectangle is in a closed shape; one outside is in none", !!fillRegion(R, [20, 10]) && !fillRegion(R, [50, 10]));
// ---- lines
{
const got = fillCurves(R, fill("lines"))!;
const ys = got.curves.map((e) => (e as { a: Vec2 }).a[1]).sort((a, b) => a - b);
check("lines 5 apart in a 40 x 20 rectangle: three, at 5, 10 and 15, each from edge to edge", got.curves.length === 3 && ys.join() === "5,10,15" && got.curves.every((e) => e.kind === "line" && ends(e).every((p) => onRect(p))), JSON.stringify(got.curves.map((e) => ends(e))));
check(" named for their fill", got.curves.every((e) => fillOf(e.id) === "f1"));
const arr = arrangement([...R, ...got.curves]);
check(" the rectangle is four strips now, 200 mm² each", arr.regions.length === 4 && arr.regions.every((r) => near(r.area, 200, 1e-6)), arr.regions.map((r) => r.area.toFixed(2)).join());
const wide = fillCurves(R, fill("lines", { spacing: 2 }))!;
check(" 2 apart: nine", wide.curves.length === 9);
const slant = fillCurves(R, fill("lines", { angle: 45 }))!;
check(" at 45 degrees: every end on the rectangle's edge, each line at 45", slant.curves.length > 5 && slant.curves.every((e) => ends(e).every((p) => onRect(p)) && near(Math.abs(((e as { b: Vec2 }).b[1] - (e as { a: Vec2 }).a[1]) / ((e as { b: Vec2 }).b[0] - (e as { a: Vec2 }).a[0])), 1, 1e-9)), `${slant.curves.length} lines`);
}
// ---- crossed lines
{
const got = fillCurves(R, fill("cross"))!;
const arr = arrangement([...R, ...got.curves]);
check("crossed lines 5 apart: three one way, seven the other, 32 squares of 25 mm²", got.curves.length === 10 && arr.regions.length === 32 && arr.regions.every((r) => near(r.area, 25, 1e-6)), `${got.curves.length} lines, ${arr.regions.length} regions`);
}
// ---- in a circle: the ends on the circle exactly
{
const C = [circle("c", 0, 0, 10)];
const got = fillCurves(C, fill("lines", { at: [0, 0], spacing: 3, angle: 30 }))!;
const worst = Math.max(...got.curves.flatMap((e) => ends(e).map((p) => Math.abs(Math.hypot(p[0], p[1]) - 10))));
check("lines in a circle: every end on the circle (to a millionth of a mm)", got.curves.length === 7 && worst < 1e-6, `${got.curves.length} lines, worst ${worst.toExponential(1)}`);
check(" and the circle is eight closed pieces", arrangement([...C, ...got.curves]).regions.length === 8);
}
// ---- a shape with a hole: the lines stop at the hole
{
const H = [...R, circle("h", 20, 10, 4)];
const got = fillCurves(H, fill("lines", { at: [5, 10] }))!;
const mid = got.curves.filter((e) => near((e as { a: Vec2 }).a[1], 10, 1e-9));
check("a rectangle with a round hole: the middle line is two, stopping at the hole (x 16 and 24)", got.curves.length === 4 && mid.length === 2 && mid.flatMap(ends).map((p) => +p[0].toFixed(6)).sort((a, b) => a - b).join() === "0,16,24,40", JSON.stringify(mid.map(ends)));
check(" a point in the hole fills the hole, not the plate", fillRegion(H, [20, 10])!.area < 60);
}
// ---- zigzag and waves: edge to edge, and closed strips between rows
for (const kind of ["zigzag", "waves"] as const) {
const got = fillCurves(R, fill(kind, { spacing: 6, size: 4 }))!;
const all = got.curves.flatMap(ends);
const arr = arrangement([...R, ...got.curves]);
check(`${kind}: every piece inside, its loose ends on the edge, the rectangle in closed strips`, got.curves.length > 20 && all.every((p) => inRect(p)) && all.filter((p) => onRect(p)).length >= 6 && arr.regions.length >= 4 && near(arr.regions.reduce((s, r) => s + r.area, 0), 800, 1e-3), `${got.curves.length} pieces, ${arr.regions.length} regions, ${arr.regions.reduce((s, r) => s + r.area, 0).toFixed(3)} mm²`);
}
// ---- shapes: all wholly inside, the gap as asked
{
const dots = fillCurves(R, fill("dots", { size: 4, spacing: 2 }))!;
const cs = dots.curves.map((e) => (e as { center: Vec2 }).center);
let least = Infinity;
for (let i = 0; i < cs.length; i++) for (let j = i + 1; j < cs.length; j++) least = Math.min(least, Math.hypot(cs[i][0] - cs[j][0], cs[i][1] - cs[j][1]));
check("dots 4 across, 2 between: all inside the rectangle, none nearer another than 2", dots.curves.length >= 15 && dots.curves.every((e) => e.kind === "circle" && cs.every((c) => c[0] >= 2 - 1e-9 && c[0] <= 38 + 1e-9 && c[1] >= 2 - 1e-9 && c[1] <= 18 + 1e-9)) && near(least, 6, 1e-9), `${dots.curves.length} dots, nearest centres ${least.toFixed(4)}`);
for (const kind of ["hex", "squares", "diamonds"] as const) {
const got = fillCurves(R, fill(kind, { size: 4, spacing: 1.5 }))!;
const corners = got.curves.flatMap((e) => entityCorners(e as Extract<SketchEntity, { kind: "polygon" }>));
const arr = arrangement([...R, ...got.curves]);
check(`${kind}: all inside, each a closed shape of its own (${got.curves.length})`, got.curves.length >= 8 && corners.every((p) => inRect(p)) && arr.regions.length === got.curves.length + 1, `${arr.regions.length} regions`);
}
const sq = fillCurves(R, fill("squares", { size: 4, spacing: 1 }))!;
const first = entityCorners(sq.curves[0] as Extract<SketchEntity, { kind: "polygon" }>);
check(" squares 4 a side", near(Math.hypot(first[1][0] - first[0][0], first[1][1] - first[0][1]), 4, 1e-9));
const hx = fillCurves(R, fill("hex", { size: 4, spacing: 1 }))!;
const hc = entityCorners(hx.curves[0] as Extract<SketchEntity, { kind: "polygon" }>);
check(" a honeycomb cell 4 across its flats", near(Math.hypot(hc[0][0] - hc[2][0], hc[0][1] - hc[2][1]), 4, 1e-9), Math.hypot(hc[0][0] - hc[2][0], hc[0][1] - hc[2][1]).toFixed(4));
}
// ---- far too many: none made, and said
{
const got = fillCurves(R, fill("lines", { spacing: 0.001 }))!;
check("lines a thousandth apart: none made (too many)", !!got.tooMany && !got.curves.length);
const most = fillCurves(R, fill("dots", { size: 0.05, spacing: 0.05 }))!;
check("dots a twentieth across: none made (too many)", !!most.tooMany && most.curves.length <= FILL_MOST);
}
// ---- the shape changes: the pattern follows
{
const f = fill("lines");
const before = refill(R, [f]);
const bigger = refill([rect("r", 0, 0, 60, 30), ...before.filter((e) => e.id !== "r")], [f]);
const lines = bigger.filter((e) => fillOf(e.id) === "f1");
check("the rectangle made 60 x 30: five lines now, each 60 long", withoutFills(bigger).length === 1 && lines.length === 5 && lines.every((e) => ends(e).every((p) => onRect(p, 60, 30))), `${lines.length} lines`);
check("the fill taken away: its lines go", refill(bigger, []).length === 1);
const gone = refill(before.filter((e) => e.id !== "r"), [f]);
check("the shape itself deleted: the lines it had stay as they were", gone.length === 3);
check("every kind is offered once", new Set(FILL_KINDS.map((k) => k.id)).size === 8);
}
// ---- the engine: the strips are shapes to extrude
{
const f = fill("lines");
const ents = refill(R, [f]);
const sk = { ...sketch("S", XY(), ents), fills: [f] } as Feature;
const regions = arrangement(ents).regions.map(regionRef);
const every = { id: "E", name: "E", type: "extrude", source: { kind: "profile", sketch: "S", regions }, distance: 3, mode: "new" } as unknown as Feature;
const r = await after([sk, every]);
const vol = [...bodies().values()].reduce((s, b) => s + volume(b as Shape3D), 0);
check("all four strips extruded 3: 2400 mm³, sound", !r.errors.length && near(vol, 2400, 1e-3) && [...bodies().values()].every((b) => health(b as Shape3D).healthy), `${vol.toFixed(2)} ${r.errors.join("; ")}`);
const two = { ...every, source: { kind: "profile", sketch: "S", regions: regions.filter((_, i) => i % 2 === 0) } } as unknown as Feature;
const r2 = await after([sk, two]);
const v2 = [...bodies().values()].reduce((s, b) => s + volume(b as Shape3D), 0);
check("every other strip: two ribs, 1200 mm³", !r2.errors.length && near(v2, 1200, 1e-3), `${v2.toFixed(2)} ${r2.errors.join("; ")}`);
const hexes = refill(R, [fill("hex", { size: 4, spacing: 1.5 })]);
const cells = arrangement(hexes).regions.filter((x) => x.area < 100).map(regionRef);
const r3 = await after([{ ...sketch("S", XY(), hexes) } as Feature, { ...every, source: { kind: "profile", sketch: "S", regions: cells } } as unknown as Feature]);
const v3 = [...bodies().values()].reduce((s, b) => s + volume(b as Shape3D), 0);
const cell = (Math.sqrt(3) / 2) * 16;
check("a honeycomb's cells extruded 3: each cell's area times 3", !r3.errors.length && near(v3, cells.length * cell * 3, 1e-2), `${cells.length} cells, ${v3.toFixed(2)} for ${(cells.length * cell * 3).toFixed(2)} ${r3.errors.join("; ")}`);
}
done();