[26][B2] Dach: Innenhöfe (Roof.holes) und Neigung je Kante (Roof.edgePitchDeg), Objekt-Info, Befehl Dachhof

Modell (Rust, ts-rs): Roof.holes (Ringe) und Roof.edgePitchDeg (je Umrisskante, dann Hofkanten;
null = Giebel, negativ = Standard, Feld fehlt = wie bisher). roof.rs: custom_roof rechnet über
weighted_roof (alle Ringe, Überstand je Kante, Hofringe schrumpfen); ungültige Höfe und Pult
fallen auf das bisherige Dach zurück. Dächer ohne die Felder bleiben bitgleich (CLI-SVG/IFC).
Plan: Hof als Loch der Dachfläche, Hofkanten als Traufe. 3D: Gehrung an Graten zwischen
verschieden geneigten Flächen (Dachschichten bleiben geschlossen).
UI: Kantenliste mit Neigung/Giebel im Objekt-Info, Hofliste mit Entfernen, Befehl "Dachhof".

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-29 01:29:15 +00:00
1 parent 775d756a6c
commit 0986a3ac7b
24 files changed
+1341 -41

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
/**
* `roofHoleCommand` — Innenhof per Klicks (≥ 3 Punkte Polygon, 2 Punkte + Enter Rechteck) im ersten
* Dach des aktiven Geschosses, in dem er wirkt; sonst bleibt das Projekt unverändert.
*/
import { describe, expect, it } from "vitest";
import { roofHoleCommand } from "./roofHole";
import type { CommandContext, CommandState, Project, Vec2 } from "../types";
const roof = (id: string, shape: "walm" | "pult", x0: number) => ({
id,
type: "roof" as const,
floorId: "eg",
categoryCode: "31",
outline: [
{ x: x0, y: 0 },
{ x: x0 + 12, y: 0 },
{ x: x0 + 12, y: 8 },
{ x: x0, y: 8 },
],
shape,
pitchDeg: 35,
overhang: 0,
ridgeAxis: "x" as const,
thickness: 0.2,
});
function project(shape: "walm" | "pult" = "walm"): Project {
return {
id: "t",
name: "T",
lineStyles: [],
hatches: [],
components: [],
wallTypes: [],
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 2.6, cutHeight: 1.0, baseElevation: 0 }],
layers: [{ code: "31", name: "Dächer", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
walls: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [],
context: [],
roofs: [roof("RF1", shape, 0)],
};
}
const ctxOf = (p: Project): CommandContext => ({
project: p,
level: p.drawingLevels[0],
defaultCategoryCode: "31",
activeLineStyleId: "solid",
activeWallTypeId: "aw",
lastPoint: null,
selection: { wallIds: [], drawingId: null },
});
/** Befehl mit Punkten füttern und mit Enter bestätigen; liefert das Ergebnis-Projekt. */
function run(p: Project, pts: Vec2[], confirm = true): Project {
const ctx = ctxOf(p);
let state: CommandState = roofHoleCommand.init();
let commit: ((q: Project) => Project) | undefined;
for (const point of pts) {
const [ns, res] = roofHoleCommand.onInput(state, { kind: "point", point }, ctx);
state = ns;
commit = res.commit ?? commit;
}
if (confirm && !commit) {
const [, res] = roofHoleCommand.onConfirm(state, ctx);
commit = res.commit;
}
return commit ? commit(p) : p;
}
describe("roofHoleCommand", () => {
it("zwei Punkte + Enter ergeben einen rechteckigen Hof", () => {
const p = project();
const q = run(p, [{ x: 4, y: 2 }, { x: 8, y: 6 }]);
expect(q.roofs![0].holes).toEqual([
[
{ x: 4, y: 2 },
{ x: 8, y: 2 },
{ x: 8, y: 6 },
{ x: 4, y: 6 },
],
]);
});
it("drei und mehr Punkte: Klick auf den Startpunkt schliesst das Polygon", () => {
const q = run(project(), [{ x: 3, y: 2 }, { x: 9, y: 2 }, { x: 6, y: 6 }, { x: 3, y: 2 }], false);
expect(q.roofs![0].holes).toHaveLength(1);
expect(q.roofs![0].holes![0]).toHaveLength(3);
});
it("Hof ausserhalb des Dachs oder bei Pultdach: Projekt unverändert", () => {
const p = project();
expect(run(p, [{ x: 20, y: 2 }, { x: 24, y: 6 }]).roofs![0].holes).toBeUndefined();
const pult = project("pult");
expect(run(pult, [{ x: 4, y: 2 }, { x: 8, y: 6 }]).roofs![0].holes).toBeUndefined();
});
it("Hof über den Umriss hinaus wird verworfen", () => {
expect(run(project(), [{ x: 10, y: 2 }, { x: 14, y: 6 }]).roofs![0].holes).toBeUndefined();
});
});
+145
View File
@@ -0,0 +1,145 @@
// Dachhof — Innenhof/Lichthof im Dach als Engine-Befehl: eine Kontur wird per Klicks gezeichnet und
// dem ERSTEN Dach des aktiven Geschosses hinzugefügt, in dem sie wirkt (ganz im Umriss, ohne
// Überschneidung, nicht bei Pultdach — das entscheidet der Rust-Kern, s. `roofHoleWorks`).
//
// Warum Zeichnen statt „aus gewählter Kontur": die Auswahl kennt immer nur ein Objekt, mit dem
// Dach gewählt wäre keine zweite Kontur wählbar; gezeichnet gibt es Fang auf Wände und Umriss,
// und der Ablauf entspricht Deckenloch/Decke. Zwei Punkte + Enter ergeben ein Rechteck.
//
// Schritte:
// 1) „Erster Punkt des Hofs:" → Punkt
// 2) „Nächster Punkt ( Schliessen Zurück ):" → Punkt … Schliessen per Klick auf den Startpunkt,
// Option „Schliessen" oder Enter (≥ 3 Punkte; bei genau 2 Punkten: Rechteck aus den Ecken).
import { addRoofHole, opsMutation, patchItem, pointInOutline, roofHoleWorks } from "../../core";
import type { CoreOp } from "../../core";
import type { Command, CommandContext, CommandResult, CommandState, CmdOption, DraftShape, Project, ToolDraft, Vec2 } from "../types";
const EPS = 1e-6;
const CLOSE_HIT = 0.08; // Modell-Meter: Klick nahe Startpunkt schliesst die Kontur
const dist = (a: Vec2, b: Vec2): number => Math.hypot(b.x - a.x, b.y - a.y);
/** Vier Ecken eines Rechtecks aus zwei Gegenecken. */
function rectCorners(a: Vec2, b: Vec2): Vec2[] {
const x0 = Math.min(a.x, b.x);
const x1 = Math.max(a.x, b.x);
const y0 = Math.min(a.y, b.y);
const y1 = Math.max(a.y, b.y);
return [
{ x: x0, y: y0 },
{ x: x1, y: y0 },
{ x: x1, y: y1 },
{ x: x0, y: y1 },
];
}
interface HoleIdle extends CommandState {
phase: "start";
}
interface HoleDrawing extends CommandState {
phase: "next";
points: Vec2[];
cursor: Vec2 | null;
}
type HoleState = HoleIdle | HoleDrawing;
const CLOSE: CmdOption = { id: "close", labelKey: "cmd.polyline.close" };
const UNDO: CmdOption = { id: "undo", labelKey: "cmd.polyline.undo" };
/** Vorschau: Kontur (ab 3 Punkten geschlossen) + Gummiband. */
function holeDraft(points: Vec2[], cursor: Vec2 | null): ToolDraft {
const pts = cursor ? [...points, cursor] : points;
const preview: DraftShape[] = [{ kind: "poly", pts, closed: pts.length >= 3 }];
const draft: ToolDraft = { preview, vertices: points };
const last = points[points.length - 1];
if (cursor && last && dist(last, cursor) >= EPS) draft.hud = { at: cursor, text: `${dist(last, cursor).toFixed(2)} m` };
return draft;
}
/** Aus den Klickpunkten die Hof-Kontur: ≥ 3 Punkte = Polygon, genau 2 = Rechteck. */
function ringOf(points: Vec2[]): Vec2[] | null {
if (points.length >= 3) return points;
if (points.length === 2) {
const [a, b] = points;
if (Math.abs(a.x - b.x) < 0.05 || Math.abs(a.y - b.y) < 0.05) return null;
return rectCorners(a, b);
}
return null;
}
/**
* Hängt den Hof an das erste Dach des aktiven Geschosses, in dem er wirkt. Ohne passendes Dach
* (Hof ausserhalb, schneidet den Umriss, Pultdach) bleibt das Projekt unverändert.
*/
function roofHoleOps(p: Project, points: Vec2[], ctx: CommandContext): CoreOp[] {
const ring = ringOf(points);
if (!ring) return [];
const host = (p.roofs ?? []).find((r) => r.floorId === ctx.level.id && r.outline.length >= 3 && ring.every((pt) => pointInOutline(pt, r.outline)) && roofHoleWorks(r, ring));
if (!host) return [];
return patchItem(p, "roofs", host.id, (r) => ({ ...r, ...addRoofHole(r, ring) }));
}
const idle = (): [CommandState, CommandResult] => [{ phase: "start", lastPoint: null } as HoleIdle, { draft: null, done: true }];
const finish = (points: Vec2[], ctx: CommandContext): [CommandState, CommandResult] => [
{ phase: "start", lastPoint: null } as HoleIdle,
{ draft: null, done: true, commit: opsMutation((p) => roofHoleOps(p, points, ctx)) },
];
export const roofHoleCommand: Command = {
name: "roofhole",
labelKey: "cmd.roofHole.label",
floorOnly: true,
prompt: (s) => ((s as HoleState).phase === "next" ? "cmd.roofHole.next" : "cmd.roofHole.start"),
accepts: (s) => ((s as HoleState).phase === "next" ? ["point", "option"] : ["point"]),
options: (s) => {
const ps = s as HoleState;
if (ps.phase !== "next") return [];
return ps.points.length >= 3 ? [CLOSE, UNDO] : [UNDO];
},
init: (): HoleIdle => ({ phase: "start", lastPoint: null }),
onInput: (state, input, ctx): [CommandState, CommandResult] => {
const s = state as HoleState;
if (input.kind === "option") {
if (s.phase !== "next") return [s, { draft: null }];
if (input.id === "undo") {
const pts = s.points.slice(0, -1);
if (pts.length === 0) return [{ phase: "start", lastPoint: null } as HoleIdle, { draft: null }];
const ns: HoleDrawing = { phase: "next", points: pts, cursor: s.cursor, lastPoint: pts[pts.length - 1] };
return [ns, { draft: holeDraft(pts, s.cursor) }];
}
if (input.id === "close" && s.points.length >= 3) return finish(s.points, ctx);
return [s, { draft: holeDraft(s.points, s.cursor) }];
}
if (input.kind !== "point") return [s, { draft: s.phase === "next" ? holeDraft(s.points, s.cursor) : null }];
const pt = input.point;
if (s.phase !== "next") {
const ns: HoleDrawing = { phase: "next", points: [pt], cursor: pt, lastPoint: pt };
return [ns, { draft: holeDraft([pt], pt) }];
}
// Klick nahe Startpunkt schliesst die Kontur.
if (s.points.length >= 3 && dist(s.points[0], pt) < CLOSE_HIT) return finish(s.points, ctx);
// Null-Strecke ignorieren.
if (dist(s.points[s.points.length - 1], pt) < EPS) return [s, { draft: holeDraft(s.points, s.cursor) }];
const points = [...s.points, pt];
const ns: HoleDrawing = { phase: "next", points, cursor: pt, lastPoint: pt };
return [ns, { draft: holeDraft(points, pt) }];
},
onMove: (state, point): [CommandState, CommandResult] => {
const s = state as HoleState;
if (s.phase !== "next") return [s, { draft: null }];
const ns: HoleDrawing = { ...s, cursor: point };
return [ns, { draft: holeDraft(s.points, point) }];
},
// Enter/Rechtsklick: ≥ 3 Punkte Polygon, 2 Punkte Rechteck.
onConfirm: (state, ctx): [CommandState, CommandResult] => {
const s = state as HoleState;
if (s.phase === "next" && s.points.length >= 2) return finish(s.points, ctx);
return idle();
},
onCancel: (): [CommandState, CommandResult] => idle(),
};