Files
DOSSIER/src/commands/cmds/solidbool.test.ts
T
Claude 45f98e2402 [115][G1][180] 3D: freie Körper aus den Kern-Netzen statt truck
Eine Quelle für die Geometrie freier Körper: 3D-Bild, Pick, Explosion,
Abzugskörper an Wänden/Decken und die Kennwerte der Objekt-Info nehmen
dieselben Kern-Netze (solid_mesh.rs, Manifold) wie Grundriss, Schnitt
und Ansicht.

- model3d/solids.rs: Teil solidMeshes (Owner::Solid für den
  Klassen-Filter, Farbe/Textur aus componentId, glatt schattiert),
  3D-Facettierung mindestens 48 je Vollkreis (Fugen unter dem
  15°-Kantenwinkel von render3d), Explosion hebt mit dem Geschoss.
- pick_solids: Dreiecke des Kern-Netzes statt Prisma-Näherung.
- solid_specs::void_meshes: Wand/Decke minus Abzugskörper im Kern
  (Teil voidMeshes) statt truck-Boolean in TS.
- Abfrage solidProps (Volumen, Oberfläche, Schwerpunkt) statt truck.
- Volle Verjüngung ergibt eine Pyramide (Netz-Spezifikation).
- Entfernt: toWalls3d/extrusions.ts, TRUCK_MESH_READY_EVENT,
  truck-Wrapper extrudePolygon/extrudeCircle/buildSolidMesh,
  needsBrepPath. truck bleibt für STEP und Kollisionsprüfung.
- Golden komplex-model3d: drei Körper neu im Modell.
2026-11-11 17:04:38 +00:00

50 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { sampleProject } from "../../model/sampleProject";
import type { ExtrudedSolid } from "../../model/types";
import { documentFor } from "../../core/document";
/** Boolesche Verknüpfung zweier Körper über den Befehl im Kern (`cmd_solid.rs`); null = kein Körper. */
function combineSolids(project: typeof sampleProject, a: ExtrudedSolid, b: ExtrudedSolid, op: string): ExtrudedSolid | null {
const p = { ...project, extrudedSolids: [a, b] };
const ops = documentFor(p).cmdOps({ cmd: "solidbool", a: a.id, b: b.id, op, stamp: "t", ctx: { level: "eg" } });
const add = ops.find((o) => o.kind === "add");
return add && add.kind === "add" ? (add.items[0] as unknown as ExtrudedSolid) : null;
}
const box = (id: string, x0: number, y0: number, x1: number, y1: number, h: number): ExtrudedSolid => ({
id,
type: "extrudedSolid", categoryCode: "20",
levelId: "eg",
points: [{ x: x0, y: y0 }, { x: x1, y: y0 }, { x: x1, y: y1 }, { x: x0, y: y1 }],
height: h,
});
describe("combineSolids", () => {
const a = box("a", 0, 0, 4, 4, 3);
const b = box("b", 2, 2, 6, 6, 2);
it("Vereinigung: Grundfläche = Hüll-Rechteck, Höhe = Maximum, Boolean-Spezifikation über beiden Operanden", () => {
const r = combineSolids(sampleProject, a, b, "union")!;
expect(r.height).toBe(3);
expect(r.points).toEqual([{ x: 0, y: 0 }, { x: 6, y: 0 }, { x: 6, y: 6 }, { x: 0, y: 6 }]);
expect(r.brep!.spec).toMatchObject({ kind: "boolean", op: "union", a: { kind: "extrude" }, b: { kind: "extrude" } });
expect(r.brep!.origin).toEqual(r.points[0]);
});
it("Differenz behält die Grundfläche des ersten Körpers, Durchschnitt die Überlappung", () => {
expect(combineSolids(sampleProject, a, b, "difference")!.points).toEqual(a.points);
const i = combineSolids(sampleProject, a, b, "intersection")!;
expect(i.points).toEqual([{ x: 2, y: 2 }, { x: 4, y: 2 }, { x: 4, y: 4 }, { x: 2, y: 4 }]);
expect(i.height).toBe(2);
});
it("Durchschnitt ohne Überlappung ergibt null", () => {
expect(combineSolids(sampleProject, a, box("c", 10, 10, 12, 12, 1), "intersection")).toBeNull();
});
it("[115] Pyramide (volle Verjüngung) ist als Netz ein gültiger Operand", () => {
const u = combineSolids(sampleProject, { ...a, taper: 1 }, b, "union");
expect(u?.brep?.spec).toMatchObject({ kind: "boolean", op: "union", a: { kind: "mesh" } });
});
});