[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:
24 files changed
+1341
-41
No files matched your search
+29
-5
@@ -23,6 +23,8 @@ export interface RoofPlane {
|
||||
export interface RoofGeometry {
|
||||
/** Traufe-Umriss (Grundriss, inkl. Überstand) als geschlossener Ring. */
|
||||
eaves: Vec2[];
|
||||
/** Traufringe der Innenhöfe (`Roof.holes`, inkl. Überstand; der Hof schrumpft). */
|
||||
eavesHoles: Vec2[][];
|
||||
/** Firstlinie(n) im Grundriss (leer bei Flach/Zelt). */
|
||||
ridges: [Vec2, Vec2][];
|
||||
/** Gratlinien (Walm/Zelt: Ecke → First/Spitze). */
|
||||
@@ -74,7 +76,11 @@ const MANSARD_CODE = { giebel: 0, walm: 1, zelt: 2 } as const;
|
||||
|
||||
function encodeRoof(roof: Roof): Float64Array {
|
||||
const pts = roof.outline;
|
||||
const buf = new Float64Array(10 + 2 * pts.length);
|
||||
const holes = roof.holes ?? [];
|
||||
const edges = roof.edgePitchDeg;
|
||||
let size = 10 + 2 * pts.length + 1 + 1 + (edges ? edges.length : 0);
|
||||
for (const h of holes) size += 1 + 2 * h.length;
|
||||
const buf = new Float64Array(size);
|
||||
buf[0] = SHAPE_CODE[roof.shape] ?? 0;
|
||||
buf[1] = roof.pitchDeg;
|
||||
buf[2] = roof.pitchUpperDeg ?? NaN;
|
||||
@@ -85,10 +91,22 @@ function encodeRoof(roof: Roof): Float64Array {
|
||||
buf[7] = roof.overhangGable ?? NaN;
|
||||
buf[8] = roof.ridgeAxis === "y" ? 1 : 0;
|
||||
buf[9] = pts.length;
|
||||
for (let i = 0; i < pts.length; i++) {
|
||||
buf[10 + 2 * i] = pts[i].x;
|
||||
buf[11 + 2 * i] = pts[i].y;
|
||||
let i = 10;
|
||||
for (const p of pts) {
|
||||
buf[i++] = p.x;
|
||||
buf[i++] = p.y;
|
||||
}
|
||||
buf[i++] = holes.length;
|
||||
for (const h of holes) {
|
||||
buf[i++] = h.length;
|
||||
for (const p of h) {
|
||||
buf[i++] = p.x;
|
||||
buf[i++] = p.y;
|
||||
}
|
||||
}
|
||||
// Neigung je Kante: NaN = Feld fehlt, +∞ = Giebel (null), negativ = Standard.
|
||||
buf[i++] = edges ? edges.length : NaN;
|
||||
if (edges) for (const v of edges) buf[i++] = v === null ? Infinity : v;
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -122,7 +140,13 @@ function decodeGeometry(b: Float64Array): RoofGeometry {
|
||||
const planes = polys().map((pts) => ({ pts }));
|
||||
const planesEnd = i;
|
||||
const gables = polys();
|
||||
const geo: RoofGeometry = { eaves, ridges, hips, breaks, planes, gables, ridgeHeight };
|
||||
const eavesHoles: Vec2[][] = [];
|
||||
for (let n = b[i++]; n > 0; n--) {
|
||||
const ring: Vec2[] = [];
|
||||
for (let m = b[i++]; m > 0; m--) ring.push(pt());
|
||||
eavesHoles.push(ring);
|
||||
}
|
||||
const geo: RoofGeometry = { eaves, eavesHoles, ridges, hips, breaks, planes, gables, ridgeHeight };
|
||||
planesFlat.set(geo, b.subarray(planesStart, planesEnd));
|
||||
return geo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): Liste, Änderung der Kantenneigung, Hof hinzufügen/entfernen.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Roof, Vec2 } from "../model/types";
|
||||
import { addRoofHole, removeRoofHole, roofEdgeList, roofHoleWorks, setRoofEdge } from "./roofEdges";
|
||||
|
||||
const rect = (x: number, y: number, w: number, h: number): Vec2[] => [
|
||||
{ x, y },
|
||||
{ x: x + w, y },
|
||||
{ x: x + w, y: y + h },
|
||||
{ x, y: y + h },
|
||||
];
|
||||
|
||||
const roof = (extra: Partial<Roof> = {}): Roof => ({
|
||||
id: "R",
|
||||
type: "roof",
|
||||
floorId: "eg",
|
||||
categoryCode: "31",
|
||||
outline: rect(0, 0, 12, 8),
|
||||
shape: "walm",
|
||||
pitchDeg: 35,
|
||||
overhang: 0,
|
||||
ridgeAxis: "x",
|
||||
thickness: 0.2,
|
||||
...extra,
|
||||
});
|
||||
|
||||
const court = rect(4, 2, 4, 4);
|
||||
|
||||
describe("roofEdgeList", () => {
|
||||
it("Umrisskanten, dann Hofkanten; Standard ohne Feld", () => {
|
||||
const list = roofEdgeList(roof({ holes: [court] }));
|
||||
expect(list).toHaveLength(8);
|
||||
expect(list.map((e) => e.ring)).toEqual([0, 0, 0, 0, 1, 1, 1, 1]);
|
||||
expect(list[0]).toMatchObject({ index: 0, spec: { kind: "default" }, length: 12 });
|
||||
expect(list[5].index).toBe(5);
|
||||
});
|
||||
|
||||
it("liest Giebel, Neigung und negativ = Standard; Sattel: Giebelregel zeigt sich als Vorgabe", () => {
|
||||
const list = roofEdgeList(roof({ edgePitchDeg: [20, null, -1] }));
|
||||
expect(list[0].spec).toEqual({ kind: "pitch", deg: 20 });
|
||||
expect(list[1].spec).toEqual({ kind: "gable" });
|
||||
expect(list[2].spec).toEqual({ kind: "default" });
|
||||
expect(list[3].spec).toEqual({ kind: "default" });
|
||||
const sattel = roofEdgeList(roof({ shape: "sattel" }));
|
||||
expect(sattel.map((e) => e.defaultGable)).toEqual([false, true, false, true]);
|
||||
expect(roofEdgeList(roof()).every((e) => !e.defaultGable)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("setRoofEdge", () => {
|
||||
it("setzt Neigung/Giebel, füllt mit Standard auf, entfernt das Feld wenn alles Standard", () => {
|
||||
const a = setRoofEdge(roof(), 2, { kind: "pitch", deg: 25 });
|
||||
expect(a.edgePitchDeg).toEqual([-1, -1, 25]);
|
||||
const b = setRoofEdge(roof({ ...a }), 0, { kind: "gable" });
|
||||
expect(b.edgePitchDeg).toEqual([null, -1, 25]);
|
||||
const c = setRoofEdge(roof({ ...b }), 0, { kind: "default" });
|
||||
const d = setRoofEdge(roof({ ...c }), 2, { kind: "default" });
|
||||
expect(d.edgePitchDeg).toBeUndefined();
|
||||
});
|
||||
|
||||
it("begrenzt die Neigung auf 0..89 Grad", () => {
|
||||
expect(setRoofEdge(roof(), 0, { kind: "pitch", deg: 120 }).edgePitchDeg).toEqual([89]);
|
||||
expect(setRoofEdge(roof(), 0, { kind: "pitch", deg: -5 }).edgePitchDeg).toEqual([0]);
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
const r = roof({ holes: [court, h2], edgePitchDeg: [-1, -1, -1, -1, 10, -1, -1, -1, 50, -1, -1, -1] });
|
||||
const p = removeRoofHole(r, 0);
|
||||
expect(p.holes).toEqual([h2]);
|
||||
expect(p.edgePitchDeg).toEqual([-1, -1, -1, -1, 50]);
|
||||
const q = removeRoofHole(roof({ ...p }), 0);
|
||||
expect(q.holes).toBeUndefined();
|
||||
expect(q.edgePitchDeg).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Hof entfernen ohne Kantenfeld lässt es weg", () => {
|
||||
const p = removeRoofHole(roof({ holes: [court] }), 0);
|
||||
expect(p).toEqual({ holes: undefined, edgePitchDeg: undefined });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,116 @@
|
||||
// Kanten und Höfe eines Dachs ([26]): die Kantenliste fürs Objekt-Info (Neigung je Kante, Giebel),
|
||||
// Ä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`).
|
||||
//
|
||||
// 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 };
|
||||
|
||||
/** Eine Kante der Kantenliste (Umriss oder Hof). */
|
||||
export interface RoofEdge {
|
||||
/** Index in `edgePitchDeg`. */
|
||||
index: number;
|
||||
/** 0 = Umriss, 1.. = Hof (1-basiert). */
|
||||
ring: number;
|
||||
/** Index der Kante im eigenen Ring. */
|
||||
edge: number;
|
||||
a: Vec2;
|
||||
b: Vec2;
|
||||
/** Länge der Kante (Meter). */
|
||||
length: number;
|
||||
spec: EdgeSpec;
|
||||
/** Standard ist hier ein Giebel (Satteldach/Mansard-Satteldach, Kante quer zum First). */
|
||||
defaultGable: boolean;
|
||||
}
|
||||
|
||||
const MAX_PITCH = 89;
|
||||
|
||||
/** Die Vorgabe aus einem Eintrag von `edgePitchDeg`. */
|
||||
function specOf(v: number | null | undefined): EdgeSpec {
|
||||
if (v === null) return { kind: "gable" };
|
||||
if (v === undefined || !Number.isFinite(v) || v < 0) return { kind: "default" };
|
||||
return { kind: "pitch", deg: v };
|
||||
}
|
||||
|
||||
/** Giebelt der Standard dieser Dachform die Kante a→b (quer zur Firstrichtung)? */
|
||||
function defaultGableEdge(roof: Roof, a: Vec2, b: Vec2): boolean {
|
||||
const gabled = roof.shape === "sattel" || (roof.shape === "mansarde" && (roof.mansardType ?? "giebel") === "giebel");
|
||||
if (!gabled) return false;
|
||||
const dx = Math.abs(b.x - a.x);
|
||||
const dy = Math.abs(b.y - a.y);
|
||||
return roof.ridgeAxis === "y" ? dy < dx : dx < dy;
|
||||
}
|
||||
|
||||
/** Alle Kanten des Dachs (Umriss, dann Höfe) mit ihrer Vorgabe. */
|
||||
export function roofEdgeList(roof: Roof): RoofEdge[] {
|
||||
const rings: Vec2[][] = [roof.outline, ...(roof.holes ?? [])];
|
||||
const out: RoofEdge[] = [];
|
||||
let index = 0;
|
||||
rings.forEach((ring, r) => {
|
||||
ring.forEach((a, edge) => {
|
||||
const b = ring[(edge + 1) % ring.length];
|
||||
out.push({
|
||||
index,
|
||||
ring: r,
|
||||
edge,
|
||||
a,
|
||||
b,
|
||||
length: Math.hypot(b.x - a.x, b.y - a.y),
|
||||
spec: specOf(roof.edgePitchDeg?.[index]),
|
||||
defaultGable: defaultGableEdge(roof, a, b),
|
||||
});
|
||||
index++;
|
||||
});
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `edgePitchDeg` ohne Standard-Einträge am Ende; alles Standard ⇒ `undefined` (Feld entfällt). */
|
||||
function normalized(values: (number | null)[]): (number | null)[] | undefined {
|
||||
const v = values.slice();
|
||||
while (v.length > 0 && v[v.length - 1] !== null && (v[v.length - 1] as number) < 0) v.pop();
|
||||
return v.length === 0 ? undefined : v;
|
||||
}
|
||||
|
||||
/** Teilobjekt für `updateRoof`: Kante `index` auf `spec` setzen. */
|
||||
export function setRoofEdge(roof: Roof, index: number, spec: EdgeSpec): Pick<Roof, "edgePitchDeg"> {
|
||||
const total = roofEdgeList(roof).length;
|
||||
const values: (number | null)[] = Array.from({ length: total }, (_, i) => {
|
||||
const v = roof.edgePitchDeg?.[i];
|
||||
return v === undefined ? -1 : v;
|
||||
});
|
||||
if (index < 0 || index >= total) return { edgePitchDeg: roof.edgePitchDeg };
|
||||
values[index] = spec.kind === "gable" ? null : spec.kind === "pitch" ? Math.max(0, Math.min(MAX_PITCH, spec.deg)) : -1;
|
||||
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 ?? [];
|
||||
if (k < 0 || k >= holes.length) return { holes: roof.holes, edgePitchDeg: roof.edgePitchDeg };
|
||||
let from = roof.outline.length;
|
||||
for (let i = 0; i < k; i++) from += holes[i].length;
|
||||
const to = from + holes[k].length;
|
||||
const rest = holes.filter((_, i) => i !== k);
|
||||
const edges = roof.edgePitchDeg ? [...roof.edgePitchDeg.slice(0, from), ...roof.edgePitchDeg.slice(to)] : undefined;
|
||||
return { holes: rest.length > 0 ? rest : undefined, edgePitchDeg: edges ? normalized(edges) : undefined };
|
||||
}
|
||||
Reference in new issue
Block a user