[K4] Merge: Zeichenbefehle im Kern (cmd_create/cmd_draw/cmd_solid), Gruppen-Zuordnung beim Zeichnen
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
92 files changed
+4169
-4754
No files matched your search
@@ -1,74 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { autoExteriorDimensions } from "./autoDimensions";
|
||||
import type { Opening, Project, Wall } from "../model/types";
|
||||
|
||||
// L-förmiger Grundriss aus 0.3-m-Wänden (Achsen): (0,0)→(10,0)→(10,6)→(4,6)→(4,9)→(0,9)→(0,0).
|
||||
const axis: [number, number][] = [[0, 0], [10, 0], [10, 6], [4, 6], [4, 9], [0, 9]];
|
||||
function project(openings: Opening[] = []): Project {
|
||||
const walls: Wall[] = axis.map(([x, y], i) => {
|
||||
const [x2, y2] = axis[(i + 1) % axis.length];
|
||||
return { id: `W${i}`, type: "wall", floorId: "eg", categoryCode: "20", start: { x, y }, end: { x: x2, y: y2 }, wallTypeId: "aw" } as Wall;
|
||||
});
|
||||
return {
|
||||
id: "t", name: "T", lineStyles: [], hatches: [], components: [{ id: "c", name: "C", color: "#ccc", hatchId: "none", joinPriority: 1 }],
|
||||
wallTypes: [{ id: "aw", name: "AW", layers: [{ componentId: "c", thickness: 0.3 }] }],
|
||||
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1, baseElevation: 0 }],
|
||||
layers: [], walls, openings, ceilings: [], stairs: [], rooms: [], drawings2d: [], context: [],
|
||||
} as unknown as Project;
|
||||
}
|
||||
const lengths = (pts: { x: number; y: number }[]) => pts.slice(1).map((p, i) => Math.hypot(p.x - pts[i].x, p.y - pts[i].y));
|
||||
const sum = (a: number[]) => a.reduce((s, v) => s + v, 0);
|
||||
|
||||
describe("automatische Aussenbemassung", () => {
|
||||
it("vier Seiten, Gesamtmass = Aussenmass", () => {
|
||||
const dims = autoExteriorDimensions(project(), "eg", "80");
|
||||
const totals = dims.filter((d) => d.chain === "total");
|
||||
expect(totals).toHaveLength(4);
|
||||
const byside = Object.fromEntries(totals.map((d) => [d.side, sum(lengths(d.drawing.geom.shape === "dimension" ? d.drawing.geom.pts : []))]));
|
||||
expect(byside.south).toBeCloseTo(10.3, 6);
|
||||
expect(byside.north).toBeCloseTo(10.3, 6);
|
||||
expect(byside.west).toBeCloseTo(9.3, 6);
|
||||
expect(byside.east).toBeCloseTo(9.3, 6);
|
||||
});
|
||||
it("Vor-/Rücksprung-Kette nur, wo die Seite gestuft ist (L: Nord und Ost)", () => {
|
||||
const dims = autoExteriorDimensions(project(), "eg", "80");
|
||||
const steps = dims.filter((d) => d.chain === "steps");
|
||||
expect(steps.map((d) => d.side).sort()).toEqual(["east", "north"]);
|
||||
const north = steps.find((d) => d.side === "north")!;
|
||||
const g = north.drawing.geom;
|
||||
expect(g.shape === "dimension" && lengths(g.pts).map((v) => +v.toFixed(3)).sort((a, b) => a - b)).toEqual([4.3, 6]);
|
||||
});
|
||||
it("Öffnungskette mit Leibungen, Abstand nach aussen positiv", () => {
|
||||
const o = { id: "F1", type: "opening", categoryCode: "21", kind: "window", hostWallId: "W0", position: 2, width: 1.5, height: 1.4, sillHeight: 0.9 } as Opening;
|
||||
const dims = autoExteriorDimensions(project([o]), "eg", "80");
|
||||
const south = dims.find((d) => d.side === "south" && d.chain === "openings")!;
|
||||
const g = south.drawing.geom;
|
||||
expect(g.shape).toBe("dimension");
|
||||
if (g.shape !== "dimension") return;
|
||||
expect(lengths(g.pts).length).toBe(3);
|
||||
expect(sum(lengths(g.pts))).toBeCloseTo(10.3, 6);
|
||||
expect(g.offset).toBeGreaterThan(0);
|
||||
// Masslinie liegt ausserhalb (südlich) des Gebäudes.
|
||||
const nx = -(g.pts[1].y - g.pts[0].y), ny = g.pts[1].x - g.pts[0].x;
|
||||
const len = Math.hypot(nx, ny);
|
||||
expect(g.pts[0].y + (ny / len) * g.offset).toBeLessThan(-0.15);
|
||||
expect(south.drawing.levelId).toBe("eg");
|
||||
expect(south.drawing.categoryCode).toBe("80");
|
||||
});
|
||||
it("ohne Wände nichts", () => {
|
||||
expect(autoExteriorDimensions({ ...project(), walls: [] }, "eg", "80")).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Planbegrenzung mit Bemassung", () => {
|
||||
it("umfasst die versetzte Masslinie samt Masszahl", async () => {
|
||||
const { generatePlan } = await import("../plan/generatePlan");
|
||||
const p = project();
|
||||
const dims = autoExteriorDimensions(p, "eg", "80");
|
||||
const withDims = { ...p, layers: [{ code: "80", name: "Mass", color: "#000", lw: 0.18, visible: true, locked: false }], drawings2d: dims.map((d) => d.drawing) } as Project;
|
||||
const b = generatePlan(withDims, "eg", new Set(["80"])).bounds;
|
||||
// Gesamtmass Süd liegt 2.4 m ausserhalb von y = -0.15.
|
||||
expect(b.minY).toBeLessThan(-0.15 - 2.4);
|
||||
expect(b.maxX).toBeGreaterThan(10.15 + 2.4);
|
||||
});
|
||||
});
|
||||
@@ -1,89 +0,0 @@
|
||||
// Automatische Aussenbemassung ([81]): je Gebäudeseite (Süd, Ost, Nord, West) bis zu drei
|
||||
// Massketten ausserhalb des Grundrisses, von innen nach aussen:
|
||||
// 1. Öffnungen — Gebäudeecken der Seite plus Leibungen der Fenster/Türen in Wänden dieser Seite,
|
||||
// 2. Vor-/Rücksprünge — die Ecken der nach dieser Seite schauenden Aussenkanten (nur bei Stufung),
|
||||
// 3. Gesamtmass.
|
||||
// Grundlage ist die vereinigte Grundfläche der Wände des Geschosses (an verbundenen Enden um die
|
||||
// halbe Dicke verlängert, damit Aussenecken voll sind). Nur achsparallele Kanten werden bemasst;
|
||||
// schiefe Wände fehlen in den Ketten. Ergebnis sind gewöhnliche Bemassungen (Drawing2D), danach
|
||||
// frei bearbeitbar.
|
||||
|
||||
import type { Drawing2D, Project, Wall } from "../model/types";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { openingJambs } from "./opening";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import { FlatReader, FlatWriter } from "./coreFlat";
|
||||
|
||||
export type DimSide = "south" | "east" | "north" | "west";
|
||||
export type DimChain = "openings" | "steps" | "total";
|
||||
|
||||
export interface AutoDimension {
|
||||
side: DimSide;
|
||||
chain: DimChain;
|
||||
drawing: Drawing2D;
|
||||
}
|
||||
|
||||
/** Reihenfolge wie im Rust-Kern (`auto_dimensions.rs`: SIDES, CHAIN_*). */
|
||||
const SIDES: DimSide[] = ["south", "east", "north", "west"];
|
||||
const CHAINS: DimChain[] = ["openings", "steps", "total"];
|
||||
|
||||
function thicknessOf(project: Project, w: Wall): number {
|
||||
try {
|
||||
return wallTypeThickness(getWallType(project, w));
|
||||
} catch {
|
||||
return 0.3; // verwaister Wandtyp
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt die Aussenbemassung eines Geschosses. `scaleDenominator` bestimmt den Abstand der
|
||||
* Ketten (Papier-mm → Modell-Meter), `categoryCode` die Ebene der neuen Bemassungen. Die Ketten
|
||||
* rechnet der Rust-Kern aus Wandachsen/-dicken und Öffnungs-Leibungen.
|
||||
*/
|
||||
export function autoExteriorDimensions(
|
||||
project: Project,
|
||||
floorId: string,
|
||||
categoryCode: string,
|
||||
scaleDenominator = 100,
|
||||
idPrefix = "autodim",
|
||||
): AutoDimension[] {
|
||||
const walls = project.walls.filter((w) => w.floorId === floorId);
|
||||
if (walls.length === 0) return [];
|
||||
const ww = new FlatWriter().num(walls.length);
|
||||
for (const w of walls) ww.num(w.start.x, w.start.y, w.end.x, w.end.y, thicknessOf(project, w));
|
||||
const index = new Map<string, number>();
|
||||
walls.forEach((w, i) => index.has(w.id) || index.set(w.id, i));
|
||||
const ow = new FlatWriter();
|
||||
const count = ow.slot();
|
||||
let nOpenings = 0;
|
||||
for (const o of project.openings ?? []) {
|
||||
const i = index.get(o.hostWallId);
|
||||
if (i === undefined) continue;
|
||||
const j = openingJambs(walls[i], o);
|
||||
if (!j) continue;
|
||||
ow.num(i, j.jambStart.x, j.jambStart.y, j.jambEnd.x, j.jambEnd.y);
|
||||
nOpenings++;
|
||||
}
|
||||
ow.set(count, nOpenings);
|
||||
|
||||
const rd = new FlatReader(core().autodim_chains(ww.done(), ow.done(), scaleDenominator));
|
||||
const out: AutoDimension[] = [];
|
||||
for (let n = rd.count(); n > 0; n--) {
|
||||
const side = SIDES[rd.num()];
|
||||
const chain = CHAINS[rd.num()];
|
||||
const offset = rd.num();
|
||||
const pts = rd.ring();
|
||||
out.push({
|
||||
side,
|
||||
chain,
|
||||
drawing: {
|
||||
id: `${idPrefix}-${floorId}-${side}-${chain}`,
|
||||
type: "drawing2d",
|
||||
levelId: floorId,
|
||||
categoryCode,
|
||||
geom: { shape: "dimension", pts, offset },
|
||||
} as Drawing2D,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -5,14 +5,10 @@
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
arcFromStartEndDirection,
|
||||
arcFromStartEndRadius,
|
||||
arcThroughPoints,
|
||||
bulgeArc,
|
||||
bulgeArcPoints,
|
||||
bulgePolylinePoints,
|
||||
bulgeFromSagittaPoint,
|
||||
bulgeThroughPoint,
|
||||
} from "./bulge";
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
@@ -83,194 +79,6 @@ describe("bulgeFromSagittaPoint — Umkehrung für die Griff-Interaktion", () =>
|
||||
});
|
||||
});
|
||||
|
||||
describe("bulgeThroughPoint — Drei-Punkt-Bogen (unabhängig vom Vorgänger-Segment)", () => {
|
||||
it("Halbkreis über der Sehne: Durchgangspunkt im Scheitel", () => {
|
||||
const b = bulgeThroughPoint({ x: 0, y: 0 }, { x: 2, y: 2 }, { x: 4, y: 0 });
|
||||
// Halbkreis → |bulge| = 1 (Δ = 180°, tan(45°) = 1); Wölbung nach +Y
|
||||
// liegt LINKS von a→b, also positiv.
|
||||
expect(b).toBeCloseTo(1, 9);
|
||||
});
|
||||
|
||||
it("Durchgangspunkt auf der anderen Seite kehrt das Vorzeichen um", () => {
|
||||
const b = bulgeThroughPoint({ x: 0, y: 0 }, { x: 2, y: -2 }, { x: 4, y: 0 });
|
||||
expect(b).toBeCloseTo(-1, 9);
|
||||
});
|
||||
|
||||
it("der erzeugte Bogen läuft tatsächlich durch den Durchgangspunkt", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const through = { x: 3, y: 1 };
|
||||
const bb = { x: 5, y: -2 };
|
||||
const bulge = bulgeThroughPoint(a, through, bb);
|
||||
const arc = bulgeArc(a, bb, bulge)!;
|
||||
// Der Durchgangspunkt liegt auf dem Kreis …
|
||||
expect(Math.hypot(through.x - arc.center.x, through.y - arc.center.y)).toBeCloseTo(arc.r, 9);
|
||||
// … und innerhalb der tatsächlich durchlaufenen Spanne.
|
||||
const TAU = Math.PI * 2;
|
||||
const norm = (x: number) => ((x % TAU) + TAU) % TAU;
|
||||
const rel = arc.sweep >= 0
|
||||
? norm(Math.atan2(through.y - arc.center.y, through.x - arc.center.x) - arc.a0)
|
||||
: norm(arc.a0 - Math.atan2(through.y - arc.center.y, through.x - arc.center.x));
|
||||
expect(rel).toBeLessThanOrEqual(Math.abs(arc.sweep) + 1e-9);
|
||||
});
|
||||
|
||||
it("kollineare Punkte → gerade (kein Kreis)", () => {
|
||||
expect(bulgeThroughPoint({ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 })).toBe(0);
|
||||
});
|
||||
|
||||
it("die Grösse hängt NUR von den drei Punkten ab (unabhängig vom Startpunkt der Kette)", () => {
|
||||
// Dieselbe relative Geometrie an anderer Stelle ⇒ identischer Bulge.
|
||||
const b1 = bulgeThroughPoint({ x: 0, y: 0 }, { x: 2, y: 1 }, { x: 4, y: 0 });
|
||||
const b2 = bulgeThroughPoint({ x: 100, y: 50 }, { x: 102, y: 51 }, { x: 104, y: 50 });
|
||||
expect(b2).toBeCloseTo(b1, 12);
|
||||
});
|
||||
});
|
||||
|
||||
describe("arcThroughPoints — Drei-Punkt-Bogen als {center,r,a0,a1} (commands/cmds/arc.ts)", () => {
|
||||
it("Viertelkreis (0°→90° via 45°) liefert Mittelpunkt/Radius/Winkel exakt", () => {
|
||||
const a = { x: 1, y: 0 };
|
||||
const through = { x: Math.SQRT1_2, y: Math.SQRT1_2 }; // 45°
|
||||
const b = { x: 0, y: 1 };
|
||||
const arc = arcThroughPoints(a, through, b)!;
|
||||
expect(arc).not.toBeNull();
|
||||
expect(arc.center.x).toBeCloseTo(0, 9);
|
||||
expect(arc.center.y).toBeCloseTo(0, 9);
|
||||
expect(arc.r).toBeCloseTo(1, 9);
|
||||
expect(arc.a0).toBeCloseTo(0, 9);
|
||||
expect(arc.a1).toBeCloseTo(Math.PI / 2, 9);
|
||||
});
|
||||
|
||||
it("a0/a1 laufen IMMER CCW und decken den Durchgangspunkt ab, unabhängig von der Klickreihenfolge (a,through,b) vs (b,through,a)", () => {
|
||||
const a = { x: 1, y: 0 };
|
||||
const through = { x: Math.SQRT1_2, y: Math.SQRT1_2 };
|
||||
const b = { x: 0, y: 1 };
|
||||
const forward = arcThroughPoints(a, through, b)!;
|
||||
const backward = arcThroughPoints(b, through, a)!;
|
||||
expect(backward.center.x).toBeCloseTo(forward.center.x, 9);
|
||||
expect(backward.center.y).toBeCloseTo(forward.center.y, 9);
|
||||
expect(backward.r).toBeCloseTo(forward.r, 9);
|
||||
expect(backward.a0).toBeCloseTo(forward.a0, 9);
|
||||
expect(backward.a1).toBeCloseTo(forward.a1, 9);
|
||||
});
|
||||
|
||||
it("Start/End/Durchgangspunkt liegen alle auf dem Kreis, Durchgangspunkt innerhalb [a0,a1]", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const through = { x: 3, y: 1 };
|
||||
const b = { x: 5, y: -2 };
|
||||
const arc = arcThroughPoints(a, through, b)!;
|
||||
const onCircle = (p: { x: number; y: number }) =>
|
||||
Math.hypot(p.x - arc.center.x, p.y - arc.center.y);
|
||||
expect(onCircle(a)).toBeCloseTo(arc.r, 9);
|
||||
expect(onCircle(b)).toBeCloseTo(arc.r, 9);
|
||||
expect(onCircle(through)).toBeCloseTo(arc.r, 9);
|
||||
const TAU = Math.PI * 2;
|
||||
const norm = (x: number) => ((x % TAU) + TAU) % TAU;
|
||||
const sweep = norm(arc.a1 - arc.a0);
|
||||
const toThrough = norm(Math.atan2(through.y - arc.center.y, through.x - arc.center.x) - arc.a0);
|
||||
expect(toThrough).toBeLessThanOrEqual(sweep + 1e-9);
|
||||
});
|
||||
|
||||
it("kollineare Punkte → null (kein Kreis)", () => {
|
||||
expect(arcThroughPoints({ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("arcFromStartEndRadius — Start/Ende/Radius (commands/cmds/arc.ts, dritte Methode)", () => {
|
||||
const onCircle = (arc: { center: Vec2; r: number }, p: Vec2) =>
|
||||
Math.hypot(p.x - arc.center.x, p.y - arc.center.y);
|
||||
const TAU = Math.PI * 2;
|
||||
const norm = (x: number) => ((x % TAU) + TAU) % TAU;
|
||||
|
||||
it("Halbkreis exakt bei r = halbe Sehnenlänge (Grenzfall)", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const b = { x: 4, y: 0 };
|
||||
const arc = arcFromStartEndRadius(a, b, 2, { x: 2, y: 5 })!;
|
||||
expect(arc).not.toBeNull();
|
||||
expect(arc.r).toBeCloseTo(2, 9);
|
||||
expect(onCircle(arc, a)).toBeCloseTo(2, 9);
|
||||
expect(onCircle(arc, b)).toBeCloseTo(2, 9);
|
||||
expect(norm(arc.a1 - arc.a0)).toBeCloseTo(Math.PI, 6); // exakt 180°
|
||||
});
|
||||
|
||||
it("wölbt sich zur cursor-nahen Seite (near oberhalb → Bogenscheitel oberhalb der Sehne)", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const b = { x: 4, y: 0 };
|
||||
const arc = arcFromStartEndRadius(a, b, 3, { x: 2, y: 5 })!;
|
||||
const mid = arc.a0 + norm(arc.a1 - arc.a0) / 2;
|
||||
const apex = { x: arc.center.x + arc.r * Math.cos(mid), y: arc.center.y + arc.r * Math.sin(mid) };
|
||||
expect(apex.y).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("wölbt sich zur ANDEREN Seite, wenn `near` unterhalb der Sehne liegt", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const b = { x: 4, y: 0 };
|
||||
const arc = arcFromStartEndRadius(a, b, 3, { x: 2, y: -5 })!;
|
||||
const mid = arc.a0 + norm(arc.a1 - arc.a0) / 2;
|
||||
const apex = { x: arc.center.x + arc.r * Math.cos(mid), y: arc.center.y + arc.r * Math.sin(mid) };
|
||||
expect(apex.y).toBeLessThan(0);
|
||||
});
|
||||
|
||||
it("liefert immer den KLEINEREN Bogen (Sehnenwinkel ≤ 180°)", () => {
|
||||
const a = { x: 0, y: 0 };
|
||||
const b = { x: 4, y: 0 };
|
||||
const arc = arcFromStartEndRadius(a, b, 10, { x: 2, y: 1 })!;
|
||||
expect(norm(arc.a1 - arc.a0)).toBeLessThanOrEqual(Math.PI + 1e-9);
|
||||
});
|
||||
|
||||
it("liefert null, wenn der Radius kleiner als die halbe Sehnenlänge ist", () => {
|
||||
expect(arcFromStartEndRadius({ x: 0, y: 0 }, { x: 4, y: 0 }, 1, { x: 2, y: 1 })).toBeNull();
|
||||
});
|
||||
|
||||
it("liefert null bei entarteter Sehne (a≈b)", () => {
|
||||
expect(arcFromStartEndRadius({ x: 1, y: 1 }, { x: 1, y: 1 }, 2, { x: 2, y: 2 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("arcFromStartEndDirection — Start/Ende/Tangentenrichtung (commands/cmds/arc.ts, vierte Methode)", () => {
|
||||
const onCircle = (arc: { center: Vec2; r: number }, p: Vec2) =>
|
||||
Math.hypot(p.x - arc.center.x, p.y - arc.center.y);
|
||||
|
||||
it("Viertelkreis: Tangente bei (1,0) nach +y führt zum Bogen bis (0,1)", () => {
|
||||
const a = { x: 1, y: 0 };
|
||||
const b = { x: 0, y: 1 };
|
||||
const dir = { x: 1, y: 1 }; // von a aus Richtung +y (tangential zum Einheitskreis bei a)
|
||||
const arc = arcFromStartEndDirection(a, b, dir)!;
|
||||
expect(arc).not.toBeNull();
|
||||
expect(arc.center.x).toBeCloseTo(0, 6);
|
||||
expect(arc.center.y).toBeCloseTo(0, 6);
|
||||
expect(arc.r).toBeCloseTo(1, 6);
|
||||
expect(onCircle(arc, a)).toBeCloseTo(1, 9);
|
||||
expect(onCircle(arc, b)).toBeCloseTo(1, 9);
|
||||
});
|
||||
|
||||
it("Bogen-Tangente bei a zeigt tatsächlich in Richtung `dir`, nicht rückwärts", () => {
|
||||
const a = { x: 1, y: 0 };
|
||||
const b = { x: 0, y: 1 };
|
||||
const dir = { x: 1, y: 1 };
|
||||
const arc = arcFromStartEndDirection(a, b, dir)!;
|
||||
// CCW-Tangente bei a0 (Ableitung von (cos,sin) nach wachsendem Winkel).
|
||||
const tangentCCW = { x: -Math.sin(arc.a0), y: Math.cos(arc.a0) };
|
||||
const wantedDir = { x: dir.x - a.x, y: dir.y - a.y };
|
||||
const dot = tangentCCW.x * wantedDir.x + tangentCCW.y * wantedDir.y;
|
||||
expect(dot).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("entgegengesetzte Tangentenrichtung liefert den KOMPLEMENTÄREN Bogen (gleicher Kreis, andere Seite)", () => {
|
||||
const a = { x: 1, y: 0 };
|
||||
const b = { x: 0, y: 1 };
|
||||
const forward = arcFromStartEndDirection(a, b, { x: 1, y: 1 })!;
|
||||
const backward = arcFromStartEndDirection(a, b, { x: 1, y: -1 })!;
|
||||
expect(backward.center.x).toBeCloseTo(forward.center.x, 6);
|
||||
expect(backward.center.y).toBeCloseTo(forward.center.y, 6);
|
||||
expect(backward.r).toBeCloseTo(forward.r, 6);
|
||||
// Unterschiedlicher Schwenk (a0/a1 vertauscht bzw. andere Bogenseite).
|
||||
expect(backward.a0).not.toBeCloseTo(forward.a0, 3);
|
||||
});
|
||||
|
||||
it("liefert null bei entarteter Tangentenrichtung (dir≈a)", () => {
|
||||
expect(arcFromStartEndDirection({ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 0, y: 0 })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("bulgePolylinePoints (ganze Polylinie auf einmal)", () => {
|
||||
const sq: Vec2[] = [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }, { x: 0, y: 2 }];
|
||||
|
||||
@@ -298,7 +106,6 @@ describe("bulgePolylinePoints (ganze Polylinie auf einmal)", () => {
|
||||
expect(bulgePolylinePoints([], undefined, true)).toEqual([]);
|
||||
expect(bulgePolylinePoints([{ x: NaN, y: 0 }, { x: 1, y: 0 }], [1], false)).toEqual([]);
|
||||
expect(bulgeArc({ x: NaN, y: 0 }, { x: 1, y: 0 }, 1)).toBeNull();
|
||||
expect(bulgeThroughPoint({ x: 0, y: 0 }, { x: NaN, y: 1 }, { x: 2, y: 0 })).toBe(0);
|
||||
expect(bulgeArcPoints({ x: 0, y: 0 }, { x: 1, y: 0 }, NaN)).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,51 +89,7 @@ export function bulgePointAt(a: Vec2, b: Vec2, bulge: number, t: number): Vec2 {
|
||||
return { x: r[0], y: r[1] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulge eines Kreisbogens, der von `a` über `through` nach `b` läuft — der klassische
|
||||
* Drei-Punkt-Bogen, nur von diesen drei Punkten abhängig (nicht vom vorherigen Segment).
|
||||
* Liegen die Punkte (nahezu) auf einer Geraden, gibt es keinen Kreis — dann 0.
|
||||
*/
|
||||
export function bulgeThroughPoint(a: Vec2, through: Vec2, b: Vec2): number {
|
||||
return core().bulge_through_point(a.x, a.y, through.x, through.y, b.x, b.y);
|
||||
}
|
||||
|
||||
/** Punkt auf einem Kreis (center, r) beim Winkel `a` (Radiant). */
|
||||
export function pointOnCircle(center: Vec2, r: number, a: number): Vec2 {
|
||||
return { x: center.x + r * Math.cos(a), y: center.y + r * Math.sin(a) };
|
||||
}
|
||||
|
||||
type ArcParams = { center: Vec2; r: number; a0: number; a1: number };
|
||||
|
||||
function toArcParams(r: Float64Array): ArcParams | null {
|
||||
if (r.length < 5) return null;
|
||||
return { center: { x: r[0], y: r[1] }, r: r[2], a0: r[3], a1: r[4] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Kreisbogen-Parameter durch drei Punkte `a`→`through`→`b`, direkt als `{center,r,a0,a1}`
|
||||
* für Werkzeuge, die einen eigenständigen `{shape:"arc"}` erzeugen (`commands/cmds/arc.ts`).
|
||||
* `a0`/`a1` sind IMMER so geordnet, dass der Bogen CCW von a0 nach a1 läuft. `null` bei
|
||||
* (nahezu) kollinearen Punkten.
|
||||
*/
|
||||
export function arcThroughPoints(a: Vec2, through: Vec2, b: Vec2): ArcParams | null {
|
||||
return toArcParams(core().arc_through_points(a.x, a.y, through.x, through.y, b.x, b.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kreisbogen durch zwei Endpunkte `a`→`b` mit vorgegebenem Radius `r` (Methode „Start-Ende-
|
||||
* Radius"). `near` (typischerweise der Cursor) wählt die Seite der Sehne; es entsteht immer der
|
||||
* KLEINERE der beiden möglichen Bögen (Sehnenwinkel ≤ 180°). `null`, wenn `r` kleiner als die
|
||||
* halbe Sehnenlänge ist oder die Sehne entartet.
|
||||
*/
|
||||
export function arcFromStartEndRadius(a: Vec2, b: Vec2, r: number, near: Vec2): ArcParams | null {
|
||||
return toArcParams(core().arc_from_start_end_radius(a.x, a.y, b.x, b.y, r, near.x, near.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kreisbogen durch `a`→`b`, bei `a` tangential zur Richtung `dir` (ein Punkt AUF dem
|
||||
* Tangentenstrahl). `null` bei entarteter Tangente oder wenn sie entlang der Sehne a-b zeigt.
|
||||
*/
|
||||
export function arcFromStartEndDirection(a: Vec2, b: Vec2, dir: Vec2): ArcParams | null {
|
||||
return toArcParams(core().arc_from_start_end_direction(a.x, a.y, b.x, b.y, dir.x, dir.y));
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
// Geometrie-Helfer für Decken (Slabs) — reine Funktionen über `Vec2`, kein
|
||||
// externer Kernel. Eine Decke ist ein GESCHLOSSENER Umriss (Polygon) plus eine
|
||||
// Dicke; diese Helfer normalisieren den Umriss, berechnen Fläche/Umriss-Prüfung
|
||||
// und liefern eine extrude-fertige Form. Baut auf kernel2d/model/geometry auf.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
import { signedArea, isCCW, vecEqual } from "./kernel2d";
|
||||
|
||||
/** Kleinste sinnvolle Deckenfläche (m²) — darunter gilt der Umriss als entartet. */
|
||||
export const MIN_CEILING_AREA = 1e-4;
|
||||
|
||||
/**
|
||||
* Normalisiert einen Deckenumriss:
|
||||
* • entfernt aufeinanderfolgende (nahezu) gleiche Punkte,
|
||||
* • entfernt einen schließenden Duplikat-Endpunkt (pts[last] == pts[0]),
|
||||
* • erzwingt CCW-Wicklung (positive Fläche) — konsistent für Plan-Füllung und
|
||||
* 3D-Extrusion.
|
||||
* Liefert `null`, wenn nach der Bereinigung < 3 Punkte übrig bleiben (kein
|
||||
* gültiges Polygon).
|
||||
*/
|
||||
export function normalizeOutline(pts: Vec2[]): Vec2[] | null {
|
||||
const clean: Vec2[] = [];
|
||||
for (const p of pts) {
|
||||
if (clean.length === 0 || !vecEqual(clean[clean.length - 1], p)) clean.push(p);
|
||||
}
|
||||
// Schließenden Duplikat-Endpunkt verwerfen.
|
||||
if (clean.length > 1 && vecEqual(clean[0], clean[clean.length - 1])) clean.pop();
|
||||
if (clean.length < 3) return null;
|
||||
// CCW erzwingen.
|
||||
return isCCW(clean) ? clean : clean.slice().reverse();
|
||||
}
|
||||
|
||||
/** Fläche eines Deckenumrisses in m² (immer positiv). */
|
||||
export function ceilingArea(pts: Vec2[]): number {
|
||||
return Math.abs(signedArea(pts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Punkt-in-Polygon-Test (Ray-Casting) für einen geschlossenen Umriss — dient dem
|
||||
* Body-Select einer Decke im Grundriss/3D. Randpunkte gelten als innen genug.
|
||||
*/
|
||||
export function pointInOutline(p: Vec2, outline: Vec2[]): boolean {
|
||||
let inside = false;
|
||||
const n = outline.length;
|
||||
for (let i = 0, j = n - 1; i < n; j = i++) {
|
||||
const a = outline[i];
|
||||
const b = outline[j];
|
||||
const intersect =
|
||||
a.y > p.y !== b.y > p.y &&
|
||||
p.x < ((b.x - a.x) * (p.y - a.y)) / (b.y - a.y || 1e-12) + a.x;
|
||||
if (intersect) inside = !inside;
|
||||
}
|
||||
return inside;
|
||||
}
|
||||
@@ -1,30 +1,5 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { ellipsePts, sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "./curves";
|
||||
|
||||
describe("ellipsePts", () => {
|
||||
it("liegt auf der Ellipse (rotation 0): Ost/Nord-Punkte bei rx/ry", () => {
|
||||
const pts = ellipsePts({ x: 0, y: 0 }, 4, 2, 0, 4);
|
||||
// t=0 → Ost (rx,0); t=π/2 → Nord (0,ry)
|
||||
expect(pts[0].x).toBeCloseTo(4, 6);
|
||||
expect(pts[0].y).toBeCloseTo(0, 6);
|
||||
expect(pts[1].x).toBeCloseTo(0, 6);
|
||||
expect(pts[1].y).toBeCloseTo(2, 6);
|
||||
});
|
||||
|
||||
it("Drehung um 90° vertauscht die Achsen", () => {
|
||||
const pts = ellipsePts({ x: 0, y: 0 }, 4, 2, Math.PI / 2, 4);
|
||||
// Der ehemalige Ost-Punkt (rx,0) liegt jetzt bei (0, rx).
|
||||
expect(pts[0].x).toBeCloseTo(0, 6);
|
||||
expect(pts[0].y).toBeCloseTo(4, 6);
|
||||
});
|
||||
|
||||
it("Mittelpunkt-Verschiebung wird respektiert", () => {
|
||||
const pts = ellipsePts({ x: 10, y: 5 }, 3, 3, 0, 8);
|
||||
for (const p of pts) {
|
||||
expect(Math.hypot(p.x - 10, p.y - 5)).toBeCloseTo(3, 6);
|
||||
}
|
||||
});
|
||||
});
|
||||
import { sampleBezierChain, sampleCatmullRom, sampleUniformBSpline } from "./curves";
|
||||
|
||||
describe("sampleBezierChain", () => {
|
||||
it("weniger als 4 Punkte: Rohpunkte unverändert (Gummiband-Vorschau)", () => {
|
||||
|
||||
@@ -22,17 +22,6 @@ function toFlat(pts: Vec2[]): Float64Array {
|
||||
return f;
|
||||
}
|
||||
|
||||
/** Punkte einer (ggf. gedrehten) Ellipse, N gleichverteilte Parameterschritte. */
|
||||
export function ellipsePts(
|
||||
center: Vec2,
|
||||
rx: number,
|
||||
ry: number,
|
||||
rotation: number,
|
||||
n = 64,
|
||||
): Vec2[] {
|
||||
return toPoints(core().curves_ellipse_flat(center.x, center.y, rx, ry, rotation, n));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tessellierte Punkte einer kubischen Bezier-Kette. `pts` folgt dem Muster
|
||||
* Anker·Griff·Griff·Anker·… (`pts.length` ≡ 1 mod 3). Mit weniger als 4
|
||||
|
||||
@@ -26,25 +26,8 @@ export function vecEqual(a: Vec2, b: Vec2, eps = EPS): boolean {
|
||||
return Math.abs(a.x - b.x) <= eps && Math.abs(a.y - b.y) <= eps;
|
||||
}
|
||||
|
||||
/** Kanten einer Polylinie als [from,to]-Paare (Schlusskante bei `closed`). */
|
||||
export function polylineEdges(pts: Vec2[], closed: boolean): [Vec2, Vec2][] {
|
||||
const out: [Vec2, Vec2][] = [];
|
||||
for (let i = 0; i < pts.length - 1; i++) out.push([pts[i], pts[i + 1]]);
|
||||
if (closed && pts.length > 2) out.push([pts[pts.length - 1], pts[0]]);
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── Kodierung ────────────────────────────────────────────────────────────────
|
||||
|
||||
function encPts(pts: Vec2[]): Float64Array {
|
||||
const out = new Float64Array(pts.length * 2);
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
out[2 * i] = pts[i].x;
|
||||
out[2 * i + 1] = pts[i].y;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function decPts(buf: Float64Array, from = 0, count = (buf.length - from) / 2): Vec2[] {
|
||||
const out: Vec2[] = [];
|
||||
for (let k = 0; k < count; k++) out.push({ x: buf[from + 2 * k], y: buf[from + 2 * k + 1] });
|
||||
@@ -53,21 +36,6 @@ function decPts(buf: Float64Array, from = 0, count = (buf.length - from) / 2): V
|
||||
|
||||
// ── Punkt/Strecke, Fläche ───────────────────────────────────────────────────
|
||||
|
||||
/** Abstand von p zur Strecke a→b. */
|
||||
export function pointSegmentDistance(p: Vec2, a: Vec2, b: Vec2): number {
|
||||
return core().k2_point_segment_distance(p.x, p.y, a.x, a.y, b.x, b.y);
|
||||
}
|
||||
|
||||
/** Vorzeichenbehaftete Polygonfläche (Shoelace); >0 = CCW, <0 = CW. */
|
||||
export function signedArea(pts: Vec2[]): number {
|
||||
return core().k2_signed_area(encPts(pts));
|
||||
}
|
||||
|
||||
/** Ob ein Polygonzug gegen den Uhrzeigersinn (CCW) gewickelt ist. */
|
||||
export function isCCW(pts: Vec2[]): boolean {
|
||||
return core().k2_is_ccw(encPts(pts));
|
||||
}
|
||||
|
||||
/** Schnittpunkte zweier Kreise (0/1/2 Punkte). */
|
||||
export function circleCircleIntersect(c1: Vec2, r1: number, c2: Vec2, r2: number): Vec2[] {
|
||||
return decPts(core().k2_circle_circle_intersect(c1.x, c1.y, r1, c2.x, c2.y, r2));
|
||||
@@ -75,59 +43,5 @@ export function circleCircleIntersect(c1: Vec2, r1: number, c2: Vec2, r2: number
|
||||
|
||||
// ── Offset ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Offset einer einzelnen Strecke um `d` (links positiv). */
|
||||
export function offsetSegment(a: Vec2, b: Vec2, d: number): [Vec2, Vec2] {
|
||||
const r = core().k2_offset_segment(a.x, a.y, b.x, b.y, d);
|
||||
return [{ x: r[0], y: r[1] }, { x: r[2], y: r[3] }];
|
||||
}
|
||||
|
||||
// ── Tangente-Tangente-Radius ────────────────────────────────────────────────
|
||||
|
||||
/** Ein Tangentialobjekt für `tangentCircleCenters`: Gerade (durch a/b, unendlich gedacht) oder Kreis. */
|
||||
export type TangentTarget = { kind: "line"; a: Vec2; b: Vec2 } | { kind: "circle"; center: Vec2; r: number };
|
||||
|
||||
function encTarget(t: TangentTarget): Float64Array {
|
||||
return t.kind === "line"
|
||||
? Float64Array.of(0, t.a.x, t.a.y, t.b.x, t.b.y)
|
||||
: Float64Array.of(1, t.center.x, t.center.y, t.r, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle Mittelpunkt-Kandidaten eines Kreises mit Radius `r`, der `t1` UND `t2` berührt
|
||||
* (TTR). Unsortiert/undedupliziert; der Aufrufer wählt über einen Referenzpunkt.
|
||||
*/
|
||||
export function tangentCircleCenters(t1: TangentTarget, t2: TangentTarget, r: number): Vec2[] {
|
||||
return decPts(core().k2_tangent_circle_centers(encTarget(t1), encTarget(t2), r));
|
||||
}
|
||||
|
||||
// ── Fillet / Fase ────────────────────────────────────────────────────────────
|
||||
|
||||
/** Ergebnis einer Eck-Verrundung. */
|
||||
export interface Fillet {
|
||||
center: Vec2;
|
||||
radius: number;
|
||||
/** Tangentenpunkt auf dem ersten Schenkel (corner→p1). */
|
||||
tangentA: Vec2;
|
||||
/** Tangentenpunkt auf dem zweiten Schenkel (corner→p2). */
|
||||
tangentB: Vec2;
|
||||
/** Bogen-Endwinkel in Radiant (für ein Arc-Primitiv). */
|
||||
startAngle: number;
|
||||
endAngle: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verrundet die Ecke bei `corner` (Schenkel corner→p1, corner→p2) mit Radius `r`; null bei
|
||||
* (nahezu) kollinearen oder zu kurzen Schenkeln.
|
||||
*/
|
||||
export function filletCorner(corner: Vec2, p1: Vec2, p2: Vec2, r: number): Fillet | null {
|
||||
const f = core().k2_fillet_corner(corner.x, corner.y, p1.x, p1.y, p2.x, p2.y, r);
|
||||
if (f.length !== 9) return null;
|
||||
return {
|
||||
center: { x: f[0], y: f[1] },
|
||||
radius: f[2],
|
||||
tangentA: { x: f[3], y: f[4] },
|
||||
tangentB: { x: f[5], y: f[6] },
|
||||
startAngle: f[7],
|
||||
endAngle: f[8],
|
||||
};
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
// Tests für `tangentCircleCenters` (Tangente-Tangente-Radius-Konstruktion),
|
||||
// getrennt von `kernel2d.parity.test.ts` (dort werden nur die bereits vor
|
||||
// dieser Session bestehenden Funktionen gegen die DXF-Referenzimplementierung
|
||||
// geprüft).
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { tangentCircleCenters, type TangentTarget } from "./kernel2d";
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
const dist = (a: Vec2, b: Vec2): number => Math.hypot(b.x - a.x, b.y - a.y);
|
||||
|
||||
/** Prüft, dass `center` mit Radius `r` tangential (Abstand == r) an `t` liegt. */
|
||||
function isTangent(center: Vec2, r: number, t: TangentTarget): boolean {
|
||||
if (t.kind === "line") {
|
||||
const dx = t.b.x - t.a.x, dy = t.b.y - t.a.y;
|
||||
const len = Math.hypot(dx, dy);
|
||||
const cross = ((center.x - t.a.x) * dy - (center.y - t.a.y) * dx) / len;
|
||||
return Math.abs(Math.abs(cross) - r) < 1e-6;
|
||||
}
|
||||
const d = dist(center, t.center);
|
||||
// Äussere ODER innere Berührung.
|
||||
return Math.abs(d - (t.r + r)) < 1e-6 || Math.abs(d - Math.abs(t.r - r)) < 1e-6;
|
||||
}
|
||||
|
||||
describe("tangentCircleCenters — zwei Geraden", () => {
|
||||
it("zwei senkrechte Geraden, Radius 2 → vier Kandidaten (je ein Quadrant)", () => {
|
||||
const l1: TangentTarget = { kind: "line", a: { x: -10, y: 0 }, b: { x: 10, y: 0 } }; // X-Achse
|
||||
const l2: TangentTarget = { kind: "line", a: { x: 0, y: -10 }, b: { x: 0, y: 10 } }; // Y-Achse
|
||||
const cands = tangentCircleCenters(l1, l2, 2);
|
||||
expect(cands.length).toBe(4);
|
||||
// Ein Kandidat pro Quadrant, jeweils bei (±2, ±2).
|
||||
const quadrants = [
|
||||
{ x: 2, y: 2 },
|
||||
{ x: 2, y: -2 },
|
||||
{ x: -2, y: 2 },
|
||||
{ x: -2, y: -2 },
|
||||
];
|
||||
for (const q of quadrants) {
|
||||
expect(cands.some((c) => dist(c, q) < 1e-9)).toBe(true);
|
||||
}
|
||||
for (const c of cands) {
|
||||
expect(isTangent(c, 2, l1)).toBe(true);
|
||||
expect(isTangent(c, 2, l2)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("parallele Geraden, Abstand ≠ 2*r → geometrisch unlösbar (ein Kreis tangential an beide Parallelen MUSS Durchmesser = Abstand haben), keine Kandidaten", () => {
|
||||
const l1: TangentTarget = { kind: "line", a: { x: 0, y: 0 }, b: { x: 10, y: 0 } };
|
||||
const l2: TangentTarget = { kind: "line", a: { x: 0, y: 4 }, b: { x: 10, y: 4 } };
|
||||
// Abstand 4, Zielradius 3 (Durchmesser 6 ≠ 4) → keine Lösung.
|
||||
expect(tangentCircleCenters(l1, l2, 3)).toEqual([]);
|
||||
});
|
||||
|
||||
it("parallele Geraden, Abstand GENAU 2*r → degenerierter Fall (unendlich viele Lösungen entlang der Linie): bekannte Einschränkung, liefert KEINE Kandidaten statt unendlich vieler", () => {
|
||||
const l1: TangentTarget = { kind: "line", a: { x: 0, y: 0 }, b: { x: 10, y: 0 } };
|
||||
const l2: TangentTarget = { kind: "line", a: { x: 0, y: 4 }, b: { x: 10, y: 4 } };
|
||||
// Abstand 4 = 2*r bei r=2 → jede x-Position auf y=2 wäre tangential an beide;
|
||||
// `tangentCircleCenters` schneidet nur Geraden-PAARE (lineIntersect scheitert
|
||||
// an zusammenfallenden/parallelen Geraden) und liefert hier bewusst nichts,
|
||||
// statt eine beliebige der unendlich vielen Lösungen zu erraten.
|
||||
expect(tangentCircleCenters(l1, l2, 2)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tangentCircleCenters — Gerade + Kreis", () => {
|
||||
it("X-Achse + Kreis (Mittelpunkt (0,6), r=3), Zielradius 2 → Kandidaten in der Lücke, tangential an beide", () => {
|
||||
// Lücke zwischen Achse und Kreis-Unterkante (y=3) ist 3 — bei Zielradius 2
|
||||
// (Durchmesser 4 > Lücke 3) passt ein Kreis, der beide von aussen berührt.
|
||||
const line: TangentTarget = { kind: "line", a: { x: -10, y: 0 }, b: { x: 10, y: 0 } };
|
||||
const circle: TangentTarget = { kind: "circle", center: { x: 0, y: 6 }, r: 3 };
|
||||
const cands = tangentCircleCenters(line, circle, 2);
|
||||
expect(cands.length).toBeGreaterThan(0);
|
||||
for (const c of cands) {
|
||||
expect(isTangent(c, 2, line)).toBe(true);
|
||||
expect(isTangent(c, 2, circle)).toBe(true);
|
||||
}
|
||||
// Erwartet (rechnerisch): (±3, 2) — tangential an y=0 (Abstand 2) und an
|
||||
// den Kreis (Abstand zu (0,6) = sqrt(9+16) = 5 = 3+2).
|
||||
expect(cands.some((c) => Math.abs(c.x - 3) < 1e-9 && Math.abs(c.y - 2) < 1e-9)).toBe(true);
|
||||
expect(cands.some((c) => Math.abs(c.x + 3) < 1e-9 && Math.abs(c.y - 2) < 1e-9)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tangentCircleCenters — zwei Kreise", () => {
|
||||
it("zwei getrennte Kreise, Zielradius verbindet beide von aussen (äussere Berührung)", () => {
|
||||
// Loci-Radien 2+8=10 je Seite, Mittelpunkt-Abstand 16 ≤ 10+10 → lösbar,
|
||||
// symmetrische Schnittpunkte bei (0, ±6) (10² = 8² + 6²).
|
||||
const c1: TangentTarget = { kind: "circle", center: { x: -8, y: 0 }, r: 2 };
|
||||
const c2: TangentTarget = { kind: "circle", center: { x: 8, y: 0 }, r: 2 };
|
||||
const cands = tangentCircleCenters(c1, c2, 8);
|
||||
expect(cands.length).toBeGreaterThan(0);
|
||||
for (const c of cands) {
|
||||
expect(isTangent(c, 8, c1)).toBe(true);
|
||||
expect(isTangent(c, 8, c2)).toBe(true);
|
||||
}
|
||||
// Symmetrische Konfiguration: je ein Kandidat oberhalb/unterhalb der X-Achse bei x≈0.
|
||||
expect(cands.some((c) => Math.abs(c.x) < 1e-6 && Math.abs(c.y - 6) < 1e-9)).toBe(true);
|
||||
expect(cands.some((c) => Math.abs(c.x) < 1e-6 && Math.abs(c.y + 6) < 1e-9)).toBe(true);
|
||||
});
|
||||
|
||||
it("ein kleiner Kreis INNERHALB eines grossen → innere Berührung liefert Kandidaten", () => {
|
||||
const outer: TangentTarget = { kind: "circle", center: { x: 0, y: 0 }, r: 10 };
|
||||
const inner: TangentTarget = { kind: "circle", center: { x: 3, y: 0 }, r: 2 };
|
||||
// Zielkreis mit r=4, tangential von innen an `outer` und von aussen an `inner`.
|
||||
const cands = tangentCircleCenters(outer, inner, 4);
|
||||
expect(cands.length).toBeGreaterThan(0);
|
||||
for (const c of cands) {
|
||||
expect(isTangent(c, 4, outer)).toBe(true);
|
||||
expect(isTangent(c, 4, inner)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("konzentrische Kreise gleichen Radius (innere Loci kollabieren) → keine Endlosschleife, endliches Ergebnis", () => {
|
||||
const c1: TangentTarget = { kind: "circle", center: { x: 0, y: 0 }, r: 5 };
|
||||
const c2: TangentTarget = { kind: "circle", center: { x: 0, y: 0 }, r: 5 };
|
||||
const cands = tangentCircleCenters(c1, c2, 2);
|
||||
// Konzentrisch → circleCircleIntersect liefert für die äussere Loci-Kombination
|
||||
// nichts (gleicher Mittelpunkt, `d < EPS`); Funktion muss dennoch sauber terminieren.
|
||||
expect(Array.isArray(cands)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1,48 +0,0 @@
|
||||
// Geometrie-Helfer für Öffnungen (Fenster/Türen) — reine Funktionen, die eine
|
||||
// `Opening` relativ zu ihrer Wirts-Wand in konkrete Welt-Geometrie auflösen:
|
||||
// • die Öffnungs-Lücke entlang der Wandachse (from/to in Metern), die Pfosten.
|
||||
// (Die vertikale Lage rechnet der Kern: `model3d.rs`/`plan/section.rs`, UK/OK der Wand: `model/helpers.rs::heights`.)
|
||||
//
|
||||
// Da JEDE Größe aus der aktuellen Wandachse (`wall.start`/`wall.end`) abgeleitet
|
||||
// wird, folgt eine Öffnung ihrer Wand automatisch, sobald die Wand bewegt wird —
|
||||
// es gibt keine eingebackenen Weltkoordinaten.
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Vec2, Wall } from "../model/types";
|
||||
import { along } from "../model/geometry";
|
||||
|
||||
/** Achslänge einer Wand (Meter). */
|
||||
export function wallAxisLength(wall: Wall): number {
|
||||
return Math.hypot(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnungs-Intervall entlang der Wandachse (from..to in Metern), auf die
|
||||
* Achslänge geklemmt. Liefert null, wenn das Intervall entartet (Breite ≤ 0 oder
|
||||
* vollständig außerhalb der Achse).
|
||||
*/
|
||||
export function openingInterval(
|
||||
wall: Wall,
|
||||
o: Opening,
|
||||
): { from: number; to: number } | null {
|
||||
const axis = wallAxisLength(wall);
|
||||
const from = Math.max(0, Math.min(o.position, axis));
|
||||
const to = Math.max(from, Math.min(o.position + o.width, axis));
|
||||
if (to - from < 1e-4) return null;
|
||||
return { from, to };
|
||||
}
|
||||
|
||||
/** Die beiden Pfosten-Punkte (auf der Achse) einer Öffnung im Grundriss. */
|
||||
export function openingJambs(
|
||||
wall: Wall,
|
||||
o: Opening,
|
||||
): { jambStart: Vec2; jambEnd: Vec2 } | null {
|
||||
const iv = openingInterval(wall, o);
|
||||
if (!iv) return null;
|
||||
return {
|
||||
jambStart: along(wall.start, wall.end, iv.from),
|
||||
jambEnd: along(wall.start, wall.end, iv.to),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* `revisionCloudPts` — wandelt eine geklickte Punktfolge in eine
|
||||
* Beulen-Kontur (Revisionswolke) um.
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { revisionCloudPts, REVCLOUD_BULGE } from "./revisionCloud";
|
||||
import { bulgeArcPoints } from "./bulge";
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
describe("revisionCloudPts", () => {
|
||||
it("liefert null bei < 2 Punkten", () => {
|
||||
expect(revisionCloudPts([{ x: 0, y: 0 }], false, 0.3)).toBeNull();
|
||||
});
|
||||
|
||||
it("ein einzelnes offenes Segment wird in ~len/targetArcLen Beulen zerlegt", () => {
|
||||
const pts: Vec2[] = [{ x: 0, y: 0 }, { x: 3, y: 0 }];
|
||||
const res = revisionCloudPts(pts, false, 0.5)!;
|
||||
expect(res).not.toBeNull();
|
||||
// 3m Länge / 0.5m Ziel-Bogenlänge ≈ 6 Beulen.
|
||||
expect(res.bulge.length).toBe(6);
|
||||
expect(res.bulge.every((b) => b === REVCLOUD_BULGE)).toBe(true);
|
||||
// Erster und letzter Punkt der expandierten Kontur = Start/Ende der Eingabe.
|
||||
expect(res.pts[0]).toEqual({ x: 0, y: 0 });
|
||||
expect(res.pts[res.pts.length - 1]).toEqual({ x: 3, y: 0 });
|
||||
});
|
||||
|
||||
it("mehrere Segmente werden nahtlos aneinandergehängt (keine doppelten Zwischenpunkte)", () => {
|
||||
const pts: Vec2[] = [{ x: 0, y: 0 }, { x: 2, y: 0 }, { x: 2, y: 2 }];
|
||||
const res = revisionCloudPts(pts, false, 1)!;
|
||||
// Der mittlere Eingabepunkt (2,0) muss GENAU EINMAL in der expandierten
|
||||
// Kontur vorkommen (nicht doppelt vom Ende des ersten UND Anfang des
|
||||
// zweiten Segments).
|
||||
const occurrences = res.pts.filter((p) => p.x === 2 && p.y === 0).length;
|
||||
expect(occurrences).toBe(1);
|
||||
});
|
||||
|
||||
it("geschlossene Kontur: kein doppelter Schlusspunkt", () => {
|
||||
const pts: Vec2[] = [{ x: 0, y: 0 }, { x: 4, y: 0 }, { x: 4, y: 4 }, { x: 0, y: 4 }];
|
||||
const res = revisionCloudPts(pts, true, 1)!;
|
||||
// Der letzte Punkt der expandierten Kontur darf NICHT (0,0) sein (das
|
||||
// wäre der Startpunkt erneut) — der Ring schliesst sich implizit über
|
||||
// die geschlossene Interpretation, nicht über einen doppelten Punkt.
|
||||
const last = res.pts[res.pts.length - 1];
|
||||
expect(last).not.toEqual({ x: 0, y: 0 });
|
||||
// Bulge-Array hat genau so viele Einträge wie Punkte (Schluss-Segment
|
||||
// pts[last]→pts[0] eingerechnet, wie bei jeder geschlossenen Polylinie).
|
||||
expect(res.bulge.length).toBe(res.pts.length);
|
||||
});
|
||||
|
||||
it("jede Beule liegt exakt auf einem Kreisbogen mit dem erwarteten bulge (Rückwärtsprobe)", () => {
|
||||
const pts: Vec2[] = [{ x: 0, y: 0 }, { x: 2, y: 0 }];
|
||||
const res = revisionCloudPts(pts, false, 1)!;
|
||||
// Genau 2 Beulen bei 2m/1m Ziel-Länge.
|
||||
expect(res.pts.length).toBe(3); // Start + 2 Zwischenpunkte
|
||||
for (let i = 0; i < res.pts.length - 1; i++) {
|
||||
const arcPts = bulgeArcPoints(res.pts[i], res.pts[i + 1], res.bulge[i]);
|
||||
// Ein echter Bogen (bulge≠0) tesselliert zu MEHR als 2 Punkten.
|
||||
expect(arcPts.length).toBeGreaterThan(2);
|
||||
}
|
||||
});
|
||||
|
||||
it("sehr kurzes Segment (kürzer als die Ziel-Bogenlänge) ergibt genau EINE Beule", () => {
|
||||
const pts: Vec2[] = [{ x: 0, y: 0 }, { x: 0.1, y: 0 }];
|
||||
const res = revisionCloudPts(pts, false, 1)!;
|
||||
expect(res.bulge.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,86 +0,0 @@
|
||||
// Revisionswolke (Nutzer-Wunsch: „Keine Revisionswolken/Markup-Werkzeuge") —
|
||||
// wandelt eine geklickte (Polylinien-artige) Punktfolge in eine „ausgebeulte"
|
||||
// Kontur um: jedes gerade Segment zwischen zwei aufeinanderfolgenden Punkten
|
||||
// wird in mehrere gleich lange Teilstücke zerlegt, die JEWEILS als
|
||||
// Kreisbogen („Beule") statt als Gerade gezeichnet werden — die klassische
|
||||
// CAD-Revisionswolke.
|
||||
//
|
||||
// Bewusst KEIN neuer Shape-Typ: das Ergebnis ist eine ganz normale
|
||||
// `Drawing2DGeom["polyline"]` mit `bulge` (DXF-Konvention, s. `bulge.ts`) —
|
||||
// erbt dadurch Rendering/Snapping/Griffe/Export/Transformieren komplett vom
|
||||
// bereits vorhandenen Polylinien-Pfad, exakt wie bei `polygon.ts`/den
|
||||
// gerundeten Ecken von `rect.ts`.
|
||||
//
|
||||
// Alle Beulen bulgen in die GLEICHE Richtung relativ zur jeweiligen
|
||||
// Segment-Zeichenrichtung (positives `bulge` = links von a→b, s. bulge.ts) —
|
||||
// bei einem GEGEN den Uhrzeigersinn geklickten geschlossenen Zug zeigen sie
|
||||
// dadurch nach AUSSEN (die übliche Optik). Die Umlaufrichtung wird bewusst
|
||||
// NICHT automatisch erkannt/korrigiert (eigener, grösserer Scope) — zeichnet
|
||||
// der Nutzer im Uhrzeigersinn, zeigen die Beulen nach innen; einfach in der
|
||||
// anderen Richtung klicken behebt das.
|
||||
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
const EPS = 1e-9;
|
||||
/** Höchstzahl Beulen je Segment (praktische Wolken haben < 100). */
|
||||
const MAX_BUMPS_PER_SEGMENT = 2000;
|
||||
|
||||
/**
|
||||
* `bulge`-Wert EINER Beule — `tan(Δ/4)` für einen Öffnungswinkel Δ ≈ 100°
|
||||
* (Δ = 4·atan(0.42)): sichtbar, aber nicht übertrieben rund — der übliche
|
||||
* REVCLOUD-Look.
|
||||
*/
|
||||
export const REVCLOUD_BULGE = 0.42;
|
||||
|
||||
const dist = (a: Vec2, b: Vec2): number => Math.hypot(b.x - a.x, b.y - a.y);
|
||||
const lerp = (a: Vec2, b: Vec2, t: number): Vec2 => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
|
||||
|
||||
/**
|
||||
* Zerlegt EIN gerades Segment a→b in `n` gleich lange Beulen (Ziel-Bogenlänge
|
||||
* `targetArcLen`, mindestens 1 Beule). Liefert die neuen Zwischenpunkte OHNE
|
||||
* den Startpunkt `a` (der gehört dem Aufrufer/vorherigen Segment) UND die
|
||||
* `n` Bulge-Werte für die `n` neuen Teilsegmente.
|
||||
*/
|
||||
function expandSegment(a: Vec2, b: Vec2, targetArcLen: number): { pts: Vec2[]; bulge: number[] } {
|
||||
const len = dist(a, b);
|
||||
if (!Number.isFinite(len) || len < EPS) return { pts: [], bulge: [] };
|
||||
// Obergrenze gegen Unsinn-Eingaben (winzige Bogenlänge, riesige Strecke): sonst Speicher-Explosion.
|
||||
const n = Math.min(MAX_BUMPS_PER_SEGMENT, Math.max(1, Math.round(len / Math.max(targetArcLen, EPS))));
|
||||
const pts: Vec2[] = [];
|
||||
const bulge: number[] = [];
|
||||
for (let i = 1; i <= n; i++) {
|
||||
pts.push(lerp(a, b, i / n));
|
||||
bulge.push(REVCLOUD_BULGE);
|
||||
}
|
||||
return { pts, bulge };
|
||||
}
|
||||
|
||||
/**
|
||||
* Wandelt eine geklickte Punktfolge (offen ODER geschlossen) in die volle
|
||||
* Revisionswolken-Kontur um: alle geraden Segmente (inkl. Schluss-Segment bei
|
||||
* `closed`) werden zu Beulen-Ketten der Ziel-Bogenlänge `targetArcLen`
|
||||
* expandiert. Liefert `null` bei < 2 Punkten (nichts zu zeichnen).
|
||||
*/
|
||||
export function revisionCloudPts(
|
||||
points: Vec2[],
|
||||
closed: boolean,
|
||||
targetArcLen: number,
|
||||
): { pts: Vec2[]; bulge: number[] } | null {
|
||||
if (points.length < 2 || !Number.isFinite(targetArcLen) || targetArcLen <= 0) return null;
|
||||
const segCount = closed ? points.length : points.length - 1;
|
||||
const outPts: Vec2[] = [points[0]];
|
||||
const outBulge: number[] = [];
|
||||
for (let s = 0; s < segCount; s++) {
|
||||
const a = points[s];
|
||||
const b = points[(s + 1) % points.length];
|
||||
const { pts, bulge } = expandSegment(a, b, targetArcLen);
|
||||
outPts.push(...pts);
|
||||
outBulge.push(...bulge);
|
||||
}
|
||||
// Geschlossen: das letzte expandierte Segment endet exakt am Startpunkt
|
||||
// (points[0]) — der doppelte Schlusspunkt fällt weg (der Ring schliesst
|
||||
// sich implizit über `closed:true`, wie bei jeder anderen Polylinie).
|
||||
if (closed) outPts.pop();
|
||||
if (outPts.length < 2) return null;
|
||||
return { pts: outPts, bulge: outBulge };
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
// Kantenliste rechnet der Kern, Test in `state/selectionInfo.test.ts`).
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
import { removeRoofHole, setRoofEdge } from "./roofEdges";
|
||||
|
||||
const rect = (x: number, y: number, w: number, h: number): Vec2[] => [
|
||||
{ x, y },
|
||||
@@ -45,14 +45,6 @@ describe("setRoofEdge", () => {
|
||||
});
|
||||
|
||||
describe("Höfe", () => {
|
||||
it("Hof hinzufügen: Ring bleibt, ungültige (ausserhalb, Pult) wirken nicht", () => {
|
||||
const r = roof();
|
||||
expect(roofHoleWorks(r, court)).toBe(true);
|
||||
expect(roofHoleWorks(r, rect(10, 2, 4, 4))).toBe(false);
|
||||
expect(roofHoleWorks(roof({ shape: "pult" }), court)).toBe(false);
|
||||
const p = addRoofHole(r, court);
|
||||
expect(p.holes).toEqual([court]);
|
||||
});
|
||||
|
||||
it("Hof entfernen nimmt seine Kantenneigungen mit; Indizes der übrigen Höfe rücken nach", () => {
|
||||
const h2 = rect(1, 1, 1, 1);
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): Typen der Kantenliste (gerechnet im Kern, `selection_info.rs`),
|
||||
// Änderungen als Teilobjekt (`Partial<Roof>`, für `updateRoof`/`patchItem` — ein Undo-Schritt) und
|
||||
// die Prüfung, ob ein Hof wirkt. Die Geometrie selbst rechnet der Rust-Kern (`roof.rs`).
|
||||
// Änderungen als Teilobjekt (`Partial<Roof>`, für `updateRoof`/`patchItem` — ein Undo-Schritt). Höfe
|
||||
// legt der Befehl im Kern an (`cmd_solid.rs`, samt Prüfung am Skelett); die Geometrie rechnet `roof.rs`.
|
||||
//
|
||||
// Kantennummerierung wie `Roof.edgePitchDeg`: erst die Kanten von `outline` (Kante i = Punkt i →
|
||||
// i+1), dann die der `holes` Ring für Ring. Eintrag `null` = Giebel, Zahl ≥ 0 = Neigung, negativ
|
||||
// (oder fehlend) = Standard.
|
||||
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
import { roofGeometry } from "./roof";
|
||||
|
||||
/** Vorgabe einer Kante. */
|
||||
export type EdgeSpec = { kind: "default" } | { kind: "gable" } | { kind: "pitch"; deg: number };
|
||||
@@ -50,19 +49,6 @@ export function setRoofEdge(roof: Roof, index: number, spec: EdgeSpec): Pick<Roo
|
||||
return { edgePitchDeg: normalized(values) };
|
||||
}
|
||||
|
||||
/** Wirkt ein Hof `ring` an diesem Dach? Der Kern verwirft Höfe, die nicht ganz im Umriss liegen, sich
|
||||
* schneiden oder bei einer Dachform ohne Höfe (Pult) — dann liefert er keinen Hof-Traufring. */
|
||||
export function roofHoleWorks(roof: Roof, ring: Vec2[]): boolean {
|
||||
if (ring.length < 3) return false;
|
||||
const probe: Roof = { ...roof, holes: [...(roof.holes ?? []), ring] };
|
||||
return roofGeometry(probe, 0).eavesHoles.length === (probe.holes?.length ?? 0);
|
||||
}
|
||||
|
||||
/** Teilobjekt für `updateRoof`: Hof anhängen (seine Kanten folgen mit Standard-Neigung). */
|
||||
export function addRoofHole(roof: Roof, ring: Vec2[]): Pick<Roof, "holes"> {
|
||||
return { holes: [...(roof.holes ?? []), ring.map((p) => ({ x: p.x, y: p.y }))] };
|
||||
}
|
||||
|
||||
/** Teilobjekt für `updateRoof`: Hof `k` entfernen samt seinen Kantenneigungen. */
|
||||
export function removeRoofHole(roof: Roof, k: number): Pick<Roof, "holes" | "edgePitchDeg"> {
|
||||
const holes = roof.holes ?? [];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Vec2 } from "../model/types";
|
||||
import { detectRooms, roomFromPointInside, roomFromPointInsideFaces, type WallSegment } from "./roomBoundary";
|
||||
import { detectRooms, type WallSegment } from "./roomBoundary";
|
||||
|
||||
const P = (x: number, y: number): Vec2 => ({ x, y });
|
||||
const area = (pts: Vec2[]): number => {
|
||||
@@ -58,24 +58,3 @@ describe("detectRooms", () => {
|
||||
expect(detectRooms(box(5, 4), { gapTol: Number.NaN })).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("roomFromPointInside", () => {
|
||||
const walls = [...box(6, 4), { a: P(3, 0), b: P(3, 4), thickness: 0.2 }];
|
||||
|
||||
it("liefert die kleinste umgebende Zelle", () => {
|
||||
const r = roomFromPointInside(P(1.5, 2), walls);
|
||||
expect(r).not.toBeNull();
|
||||
expect(area(r!)).toBeCloseTo(2.8 * 3.8, 9);
|
||||
});
|
||||
|
||||
it("ausserhalb: null", () => {
|
||||
expect(roomFromPointInside(P(10, 10), walls)).toBeNull();
|
||||
expect(roomFromPointInside(P(Number.NaN, 1), walls)).toBeNull();
|
||||
});
|
||||
|
||||
it("auf Wandflächen: ohne Offset", () => {
|
||||
const faces = box(4, 3).map(({ a, b }) => ({ a, b }));
|
||||
expect(area(roomFromPointInsideFaces(P(2, 1), faces)!)).toBeCloseTo(12, 9);
|
||||
expect(roomFromPointInsideFaces(P(9, 9), faces)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
// Raum-Erkennung — geschlossene Raum-Umrisse aus Wandsegmenten ableiten.
|
||||
//
|
||||
// Fassade über den Rust-Kern (`src-tauri/core/src/room_boundary.rs`, Bindungen `web/room_boundary.rs`;
|
||||
// die Rechnung steht in `kernel2d`: `detect_rooms`, `room_from_point_inside`,
|
||||
// `room_from_point_inside_faces`). Wände gehen flach hinüber, Umrisse kommen flach zurück.
|
||||
// die Rechnung steht in `kernel2d`: `detect_rooms`). Wände gehen flach hinüber, Umrisse kommen flach
|
||||
// zurück. Der Klick-in-Raum des Raum-Befehls rechnet direkt im Kern (`cmd_create.rs`).
|
||||
//
|
||||
// Verfahren (Rust): planare Anordnung der Wand-MITTELLINIEN (Schnitte an Kreuzungen, Lücken ≤ `gapTol`
|
||||
// per Endpunkt-Snapping geschlossen), minimale Maschen über „next edge counter-clockwise"
|
||||
@@ -13,8 +13,6 @@
|
||||
// als geschlossen modelliert werden.
|
||||
//
|
||||
// detectRooms(walls) alle Räume (lichte Innenkonturen, CCW)
|
||||
// roomFromPointInside(point, walls) Klick-in-Raum: kleinste Masche um den Punkt, oder null
|
||||
// roomFromPointInsideFaces(point, faces) dasselbe auf fertigen Wand-Innenflächen (ohne Offset)
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md). Einheit: METER.
|
||||
|
||||
@@ -43,12 +41,6 @@ export interface DetectRoomsOptions {
|
||||
offsetToInner?: boolean;
|
||||
}
|
||||
|
||||
/** Eine Wand-Innenfläche (Face) als gerichtete/ungerichtete Strecke. */
|
||||
export interface WallFace {
|
||||
a: Vec2;
|
||||
b: Vec2;
|
||||
}
|
||||
|
||||
/** `[n, (ax, ay, bx, by, dicke)…]`. */
|
||||
function encodeWalls(walls: WallSegment[]): Float64Array {
|
||||
const out = new Float64Array(1 + 5 * walls.length);
|
||||
@@ -57,19 +49,6 @@ function encodeWalls(walls: WallSegment[]): Float64Array {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `[n, (ax, ay, bx, by)…]`. */
|
||||
function encodeFaces(faces: WallFace[]): Float64Array {
|
||||
const out = new Float64Array(1 + 4 * faces.length);
|
||||
out[0] = faces.length;
|
||||
faces.forEach((f, i) => out.set([f.a.x, f.a.y, f.b.x, f.b.y], 1 + 4 * i));
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `[nPkt, x, y, …]` → Umriss, leer → null. */
|
||||
function decodeRing(buf: Float64Array): Vec2[] | null {
|
||||
return buf.length ? new FlatReader(buf).ring() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erkennt geschlossene Räume aus einer Menge von Wandsegmenten (Mittellinien
|
||||
* mit Dicke). Liefert die lichten Innen-Umrisse (Vec2[] je Raum), CCW orientiert.
|
||||
@@ -87,27 +66,3 @@ export function detectRooms(walls: WallSegment[], options: DetectRoomsOptions =
|
||||
for (let n = r.count(); n > 0; n--) rooms.push(r.ring());
|
||||
return rooms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Klick-in-Raum-Fallback: findet die Masche, die den Saatpunkt einschliesst, und
|
||||
* gibt ihren lichten Innen-Umriss zurück (oder null, wenn der Punkt in keiner
|
||||
* geschlossenen Zelle liegt). Wählt die Masche mit kleinster Fläche, die den Punkt
|
||||
* enthält (die unmittelbar umgebende Zelle statt einer grösseren umschliessenden).
|
||||
*/
|
||||
export function roomFromPointInside(
|
||||
point: Vec2,
|
||||
walls: WallSegment[],
|
||||
options: DetectRoomsOptions = {},
|
||||
): Vec2[] | null {
|
||||
return decodeRing(
|
||||
core().room_from_point(point.x, point.y, encodeWalls(walls), options.gapTol ?? 0.05, options.offsetToInner ?? true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variante des Klick-Tracers auf bereits berechneten Wand-INNENFLÄCHEN: die Strecken
|
||||
* bilden schon die lichten Wandseiten, kein Innen-Offset.
|
||||
*/
|
||||
export function roomFromPointInsideFaces(point: Vec2, wallFaces: WallFace[], gapTol = 0.05): Vec2[] | null {
|
||||
return decodeRing(core().room_from_point_faces(point.x, point.y, encodeFaces(wallFaces), gapTol));
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
* `geometry/stair.ts` — Fassade über den Rust-Kern: Form-Prüfungen für gerade/L/Wendel,
|
||||
* Referenz, Schnitt, Rahmen und Unsinn-Eingaben (Rust-Tests decken die Mathematik je Fall ab).
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { defaultStepCount, stairCut, stairGeometry, stairOutline } from "./stair";
|
||||
import type { Stair } from "../model/types";
|
||||
|
||||
const base: Stair = {
|
||||
id: "s", type: "stair", floorId: "eg", categoryCode: "40", shape: "straight",
|
||||
start: { x: 0, y: 0 }, dir: { x: 1, y: 0 }, runLength: 3, width: 1.2, stepCount: 16,
|
||||
};
|
||||
|
||||
describe("stairGeometry", () => {
|
||||
it("gerade: 16 Tritte, Setzstufe, Lauflinie, Pfeil nach oben", () => {
|
||||
const g = stairGeometry(base, 2.8);
|
||||
expect(g.treads).toHaveLength(16);
|
||||
expect(g.riserHeight).toBeCloseTo(0.175, 12);
|
||||
expect(g.landing).toBeNull();
|
||||
expect(g.treads[15].topRise).toBeCloseTo(2.8, 12);
|
||||
expect(g.arrow.head[1]).toEqual(g.runLine[1]);
|
||||
expect(stairGeometry({ ...base, up: false }, 2.8).arrow.head[1]).toEqual(g.runLine[0]);
|
||||
});
|
||||
|
||||
it("L: Podest + zweiter Lauf, turn dreht die Richtung", () => {
|
||||
const l: Stair = { ...base, shape: "L", run2Length: 2 };
|
||||
const g = stairGeometry(l, 2.8);
|
||||
expect(g.treads).toHaveLength(15);
|
||||
expect(g.landing).toHaveLength(4);
|
||||
expect(g.runLine[2].y).toBeGreaterThan(1);
|
||||
expect(stairGeometry({ ...l, turn: -1 }, 2.8).runLine[2].y).toBeLessThan(-1);
|
||||
});
|
||||
|
||||
it("Wendel: Keile, Auge mit 12 Punkten, Lauflinie als Bogen", () => {
|
||||
const sp: Stair = { ...base, shape: "spiral", center: { x: 0, y: 0 }, start: { x: 1, y: 0 }, radius: 1, stepCount: 12 };
|
||||
const g = stairGeometry(sp, 2.4);
|
||||
expect(g.treads).toHaveLength(12);
|
||||
expect(g.landing).toHaveLength(12);
|
||||
expect(g.runLine).toHaveLength(13);
|
||||
});
|
||||
|
||||
it("Referenz links versetzt die Achse eine halbe Breite auf die Mitte", () => {
|
||||
const g = stairGeometry({ ...base, referenz: "links" }, 2.8);
|
||||
expect(g.treads[0].pts[0].y).toBeCloseTo(0, 12);
|
||||
expect(g.treads[0].pts[3].y).toBeCloseTo(-1.2, 12);
|
||||
expect(stairOutline({ ...base, referenz: "rechts" }, 0).polygon![0].y).toBeCloseTo(1.2, 12);
|
||||
});
|
||||
|
||||
it("Unsinn (NaN, 0 Stufen) liefert leere bzw. Mindest-Geometrie ohne Fehler", () => {
|
||||
expect(stairGeometry({ ...base, width: NaN }, 2.8).treads).toEqual([]);
|
||||
expect(stairGeometry(base, NaN).treads).toEqual([]);
|
||||
expect(stairGeometry({ ...base, stepCount: 0 }, 2.8).treads).toHaveLength(2);
|
||||
expect(stairOutline({ ...base, runLength: NaN }, 0)).toEqual({ polygon: null, spiral: null });
|
||||
});
|
||||
});
|
||||
|
||||
describe("stairCut / defaultStepCount", () => {
|
||||
it("Schnitt teilt die Tritte und legt eine Doppel-Bruchlinie", () => {
|
||||
const g = stairGeometry(base, 2.8);
|
||||
const c = stairCut(g, 1.0);
|
||||
expect(c.belowIndices).toEqual([0, 1, 2, 3, 4]);
|
||||
expect(c.aboveIndices).toHaveLength(11);
|
||||
expect(c.breakLine).toHaveLength(2);
|
||||
expect(stairCut(g, 99).breakLine).toBeNull();
|
||||
expect(stairCut(stairGeometry(base, NaN), 1)).toEqual({ belowIndices: [], aboveIndices: [], breakLine: null });
|
||||
});
|
||||
|
||||
it("Vorgabe-Stufenzahl: Steighöhe 0.17, gedeckelt durch die Lauflänge, mind. 2", () => {
|
||||
expect(defaultStepCount(2.8, 10)).toBe(16);
|
||||
expect(defaultStepCount(2.8, 3)).toBe(13);
|
||||
expect(defaultStepCount(0.1, 0)).toBe(2);
|
||||
});
|
||||
});
|
||||
+13
-168
@@ -1,18 +1,7 @@
|
||||
// Geometrie-Helfer für Treppen (Stairs) — Fassade über den Rust-Kern
|
||||
// (`src-tauri/kernel2d/src/lib.rs`: `stair_geometry`, `stair_outline`, `stair_cut`, `stair_bbox`;
|
||||
// Bindungen `src-tauri/core/src/web/stair.rs`, Kodierung `src-tauri/core/src/stair.rs`).
|
||||
// Aus einer `Stair` (gerade/L/Wendel) werden abgeleitet:
|
||||
// • die Tritt-Rechtecke im Grundriss (jeweils mit ihrer Z-Höhe der Setzstufe),
|
||||
// • das Zwischenpodest-Polygon (L / Wendel-Auge),
|
||||
// • die Lauflinie (Polyline) + der Auf-/Abpfeil,
|
||||
// • die Schnittposition (welche Tritte unter/über der Grundriss-Schnitthöhe
|
||||
// liegen → im Plan durchgezogen vs. gestrichelt) samt SIA-Bruchlinie,
|
||||
// • die Plan-Aussenlinie (`stairOutline`).
|
||||
//
|
||||
// Die 3D-Darstellung baut aus denselben Tritt-Rechtecken + Setzstufen-Höhen die
|
||||
// Stufenboxen (siehe `plan/toWalls3d/stairs.ts`). So bleiben Plan und 3D konsistent
|
||||
// aus EINER Quelle abgeleitet. Referenz (links/mitte/rechts): die gespeicherte Achse wird im
|
||||
// Kern auf die visuelle Treppen-MITTE versetzt, Lauflinie samt Pfeil liegen stets auf der Mitte.
|
||||
// Geometrie-Helfer für Treppen (Stairs) — Fassade über den Rust-Kern (`src-tauri/kernel2d/src/lib.rs`:
|
||||
// `stair_outline`; Bindung `src-tauri/core/src/web/stair.rs`, Kodierung `src-tauri/core/src/stair.rs`):
|
||||
// die Plan-Aussenlinie (`stairOutline`, Fang). Tritte, Podest, Lauflinie und Schnitt rechnet der Kern
|
||||
// direkt (Plan, 3D, Zeichenbefehl `cmd_create.rs`).
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch.
|
||||
|
||||
@@ -22,48 +11,17 @@ import { core } from "../engine/coreWasm";
|
||||
export const IDEAL_TREAD = 0.29;
|
||||
export const MIN_STEPS = 2;
|
||||
|
||||
/**
|
||||
* Sinnvolle Default-Stufenzahl aus Steighöhe + verfügbarer Lauflänge: möglichst
|
||||
* nahe an der idealen Steigungshöhe, gedeckelt durch die Lauflänge (min.
|
||||
* Auftritt ~0.24 m). Immer ≥ MIN_STEPS.
|
||||
*/
|
||||
export function defaultStepCount(totalRise: number, runLength: number): number {
|
||||
return core().stair_default_step_count(totalRise, runLength);
|
||||
}
|
||||
|
||||
/** Ein Tritt im Grundriss (Rechteck-Polygon) samt Setzstufen-Z (Oberkante). */
|
||||
export interface TreadRect {
|
||||
/** Vier Eckpunkte (CCW), Grundriss-Meter. */
|
||||
pts: Vec2[];
|
||||
/** Index der Stufe (0 = unterste). */
|
||||
index: number;
|
||||
/** Oberkante dieses Tritts relativ zur Treppen-UK (Meter). */
|
||||
topRise: number;
|
||||
/** Unterkante-Höhe (Setzstufe darunter) relativ zur UK (Meter). */
|
||||
baseRise: number;
|
||||
}
|
||||
|
||||
/** Vollständige, abgeleitete Treppengeometrie (Plan + 3D + Schnitt). */
|
||||
export interface StairGeometry {
|
||||
/** Alle Tritt-Rechtecke (untere → obere Stufe). */
|
||||
treads: TreadRect[];
|
||||
/** Zwischenpodest-Polygon (L/Wendel) oder null (gerade). */
|
||||
landing: Vec2[] | null;
|
||||
/** Setzstufen-Höhe (Meter). */
|
||||
riserHeight: number;
|
||||
/** Auftrittstiefe (Meter) des geraden Laufs. */
|
||||
treadDepth: number;
|
||||
/** Lauflinie als Polyline (Meter) — Mitte des Laufs, Start → Austritt. */
|
||||
runLine: Vec2[];
|
||||
/** Auf-/Abpfeil-Geometrie (Schaft + zwei Spitzenflügel). */
|
||||
arrow: { shaft: [Vec2, Vec2]; head: [Vec2, Vec2, Vec2] };
|
||||
/** Gesamt-Steighöhe (Meter). */
|
||||
totalRise: number;
|
||||
}
|
||||
|
||||
const FORM = { straight: 0, L: 1, spiral: 2 } as const;
|
||||
const REFERENZ = { mitte: 0, links: 1, rechts: 2 } as const;
|
||||
|
||||
const pt = (f: Float64Array, i: number): Vec2 => ({ x: f[i], y: f[i + 1] });
|
||||
|
||||
function ptsAt(f: Float64Array, i: number, n: number): Vec2[] {
|
||||
const out: Vec2[] = new Array(n);
|
||||
for (let k = 0; k < n; k++) out[k] = pt(f, i + 2 * k);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Treppen-Parameter als 16 Zahlen (Aufbau: `src-tauri/core/src/stair.rs`); fehlend = NaN. */
|
||||
export function encodeStair(s: Stair): Float64Array {
|
||||
const n = (v: number | undefined) => (v === undefined ? Number.NaN : v);
|
||||
@@ -84,119 +42,6 @@ export function encodeStair(s: Stair): Float64Array {
|
||||
);
|
||||
}
|
||||
|
||||
const pt = (f: Float64Array, i: number): Vec2 => ({ x: f[i], y: f[i + 1] });
|
||||
|
||||
function ptsAt(f: Float64Array, i: number, n: number): Vec2[] {
|
||||
const out: Vec2[] = new Array(n);
|
||||
for (let k = 0; k < n; k++) out[k] = pt(f, i + 2 * k);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Flache Treppengeometrie (Aufbau: `stair.rs`) → Objekt; leer (Unsinn-Eingabe) → leere Geometrie. */
|
||||
function decodeGeometry(f: Float64Array): StairGeometry {
|
||||
if (f.length < 4) {
|
||||
const z = { x: 0, y: 0 };
|
||||
return {
|
||||
treads: [], landing: null, riserHeight: 0, treadDepth: 0, runLine: [],
|
||||
arrow: { shaft: [z, z], head: [z, z, z] }, totalRise: 0,
|
||||
};
|
||||
}
|
||||
const nTreads = f[3];
|
||||
let i = 4;
|
||||
const treads: TreadRect[] = [];
|
||||
for (let t = 0; t < nTreads; t++, i += 11) {
|
||||
treads.push({ index: f[i], topRise: f[i + 1], baseRise: f[i + 2], pts: ptsAt(f, i + 3, 4) });
|
||||
}
|
||||
const nl = f[i++];
|
||||
let landing: Vec2[] | null = null;
|
||||
if (nl >= 0) {
|
||||
landing = ptsAt(f, i, nl);
|
||||
i += 2 * nl;
|
||||
}
|
||||
const nRun = f[i++];
|
||||
const runLine = ptsAt(f, i, nRun);
|
||||
i += 2 * nRun;
|
||||
const a = ptsAt(f, i, 5);
|
||||
return {
|
||||
treads,
|
||||
landing,
|
||||
riserHeight: f[0],
|
||||
treadDepth: f[1],
|
||||
runLine,
|
||||
arrow: { shaft: [a[0], a[1]], head: [a[2], a[3], a[4]] },
|
||||
totalRise: f[2],
|
||||
};
|
||||
}
|
||||
|
||||
/** Geometrie → flacher Puffer (gleicher Aufbau wie die Ausgabe von `stair_geometry_flat`). */
|
||||
function encodeGeometry(g: StairGeometry): Float64Array {
|
||||
const out: number[] = [g.riserHeight, g.treadDepth, g.totalRise, g.treads.length];
|
||||
const push = (p: Vec2) => out.push(p.x, p.y);
|
||||
for (const t of g.treads) {
|
||||
out.push(t.index, t.topRise, t.baseRise);
|
||||
t.pts.forEach(push);
|
||||
}
|
||||
if (g.landing) {
|
||||
out.push(g.landing.length);
|
||||
g.landing.forEach(push);
|
||||
} else out.push(-1);
|
||||
out.push(g.runLine.length);
|
||||
g.runLine.forEach(push);
|
||||
push(g.arrow.shaft[0]);
|
||||
push(g.arrow.shaft[1]);
|
||||
g.arrow.head.forEach(push);
|
||||
return Float64Array.from(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Leitet die vollständige Geometrie einer Treppe ab. `totalRise` MUSS vom
|
||||
* Aufrufer aufgelöst übergeben werden (Geschosshöhe-Default liegt im Kern,
|
||||
* `stair_vertical_extent` in `model/helpers.rs`), damit dieses Modul modellfrei bleibt.
|
||||
*/
|
||||
export function stairGeometry(stair: Stair, totalRise: number): StairGeometry {
|
||||
return decodeGeometry(core().stair_geometry_flat(encodeStair(stair), totalRise));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schnitt-Aufteilung im Grundriss: DOSSIER schneidet die Treppe auf `cutRise`
|
||||
* (Schnitthöhe über OKFF). Tritte mit Oberkante ≤ cutRise werden durchgezogen
|
||||
* gezeichnet (unterhalb der Schnittebene), darüberliegende gestrichelt (oberhalb,
|
||||
* verdeckt). Der ERSTE Tritt oberhalb markiert die SIA-Bruchlinie (diagonaler
|
||||
* Doppelstrich über die Laufbreite).
|
||||
*/
|
||||
export interface StairCut {
|
||||
/** Indizes der Tritte UNTER der Schnittebene (durchgezogen). */
|
||||
belowIndices: number[];
|
||||
/** Indizes der Tritte ÜBER der Schnittebene (gestrichelt/verdeckt). */
|
||||
aboveIndices: number[];
|
||||
/** Bruchlinie (SIA): zwei parallele Diagonalstriche über die Laufbreite. */
|
||||
breakLine: [Vec2, Vec2][] | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bestimmt die Schnittaufteilung. `cutRise` = Schnitthöhe über der Treppen-UK.
|
||||
* Findet den ersten Tritt, dessen Oberkante die Schnittebene überschreitet, und
|
||||
* legt dort die Bruchlinie quer über den Lauf.
|
||||
*/
|
||||
export function stairCut(geo: StairGeometry, cutRise: number): StairCut {
|
||||
const f = core().stair_cut_flat(encodeGeometry(geo), cutRise);
|
||||
if (f.length < 3) return { belowIndices: [], aboveIndices: [], breakLine: null };
|
||||
let i = 0;
|
||||
const nBelow = f[i++];
|
||||
const belowIndices = Array.from(f.subarray(i, i + nBelow));
|
||||
i += nBelow;
|
||||
const nAbove = f[i++];
|
||||
const aboveIndices = Array.from(f.subarray(i, i + nAbove));
|
||||
i += nAbove;
|
||||
const nBreak = f[i++];
|
||||
let breakLine: [Vec2, Vec2][] | null = null;
|
||||
if (nBreak > 0) {
|
||||
breakLine = [];
|
||||
for (let k = 0; k < nBreak; k++, i += 4) breakLine.push([pt(f, i), pt(f, i + 2)]);
|
||||
}
|
||||
return { belowIndices, aboveIndices, breakLine };
|
||||
}
|
||||
|
||||
/**
|
||||
* Spiral-Outline: Innenbogen + Aussenbogen + zwei radiale Schliesslinien.
|
||||
* Die Bögen werden als Kreisbogen-Parameter geliefert (cx/cy/r/a0/a1), die
|
||||
@@ -221,7 +66,7 @@ export function stairOutline(
|
||||
stair: Stair,
|
||||
totalRise: number,
|
||||
): { polygon: Vec2[] | null; spiral: SpiralOutlineSegments | null } {
|
||||
void totalRise; // Signatur-Konsistenz mit stairGeometry; derzeit ungenutzt
|
||||
void totalRise; // Signatur-Konsistenz; derzeit ungenutzt
|
||||
const f = core().stair_outline_flat(encodeStair(stair));
|
||||
if (f.length === 0) return { polygon: null, spiral: null };
|
||||
if (f[0] === 0) return { polygon: ptsAt(f, 2, f[1]), spiral: null };
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { stairOutline, stairGeometry } from "./stair";
|
||||
import { stairOutline } from "./stair";
|
||||
import type { Stair, Vec2 } from "../model/types";
|
||||
|
||||
/** Einfache Distanz-Funktion. */
|
||||
@@ -187,25 +187,3 @@ describe("stairOutline — Referenz links/mitte/rechts (Item 4)", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("stairGeometry — Lauflinie bleibt visuell zentriert (Item 4)", () => {
|
||||
const totalRise = 3.0;
|
||||
const links = stairGeometry({ ...geradeStair, referenz: "links" }, totalRise);
|
||||
const mitte = stairGeometry({ ...geradeStair, referenz: "mitte" }, totalRise);
|
||||
|
||||
it("Lauflinie liegt auf der Treppen-Mitte, nicht auf der Referenzkante (y=0)", () => {
|
||||
// Bei referenz=links liegt die Mitte bei y = −width/2 = −0.6.
|
||||
for (const p of links.runLine) {
|
||||
expect(p.y).toBeCloseTo(-geradeStair.width / 2, 5);
|
||||
}
|
||||
// Bei mitte liegt die Lauflinie auf y=0 (Achse = Mitte).
|
||||
for (const p of mitte.runLine) {
|
||||
expect(p.y).toBeCloseTo(0, 5);
|
||||
}
|
||||
});
|
||||
|
||||
it("Tritte sind bei referenz=links um −width/2 versetzt", () => {
|
||||
const dy = links.treads[0].pts[0].y - mitte.treads[0].pts[0].y;
|
||||
expect(dy).toBeCloseTo(-geradeStair.width / 2, 5);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user