From 553c430e729d14b108296e46a9194a2bdbc4010e Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 01:12:05 +0200 Subject: [PATCH] Ansicht/Schnitt: keine Naehte zwischen deckungsgleichen Dach-Teilflaechen (konvexe Zerlegung L-foermiger Flaechen) --- src/plan/toElevation.test.ts | 22 ++++++++++++++++++++++ src/plan/toElevation.ts | 32 ++++++++++++++++++++++++++++++++ src/plan/toSection.roof.test.ts | 15 +++++++++++++++ src/plan/toSection.ts | 27 +++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) diff --git a/src/plan/toElevation.test.ts b/src/plan/toElevation.test.ts index e8668e70..84c3995f 100644 --- a/src/plan/toElevation.test.ts +++ b/src/plan/toElevation.test.ts @@ -716,3 +716,25 @@ describe("toElevation — Tür-Teilverglasung (glazingRatio)", () => { expect(divisionLines.length).toBeGreaterThan(0); }); }); + +describe("Dach-Ansicht: keine Nähte zwischen deckungsgleichen Teilflächen", () => { + it("L-Walmdach: die Süd-Schräge (3 konvexe Teile, eine Ebene) zeigt keine Diagonale", () => { + const L = [ + { x: 0, y: 0 }, { x: 11, y: 0 }, { x: 11, y: 4 }, { x: 8, y: 4 }, { x: 8, y: 6 }, { x: 0, y: 6 }, + ]; + const base = elevationProject({ overhang: false }); + const p = { + ...base, + roofs: [ + { id: "R1", type: "roof", floorId: "eg", categoryCode: "35", outline: L, shape: "walm", pitchDeg: 30, overhang: 0, ridgeAxis: "x", baseElevation: 3, thickness: 0.2 }, + ], + } as unknown as Project; + const level = p.drawingLevels.find((z) => z.kind === "elevation")!; + const plan = generateElevationPlan(p, level)!; + const lines = plan.primitives.filter((pr) => pr.kind === "line" && (pr as { cls?: string }).cls === "elevation-outline") as unknown as Array<{ a: { x: number; y: number }; b: { x: number; y: number } }>; + const tan = Math.tan((30 * Math.PI) / 180); + // Naht: von der Südost-Traufecke (11, z=3) zum Knick (6, z=3+2·tan) = 5 m breit, 2·tan hoch. + const seams = lines.filter((l) => Math.abs(Math.abs(l.b.x - l.a.x) - 5) < 0.02 && Math.abs(Math.abs(l.b.y - l.a.y) - 2 * tan) < 0.02); + expect(seams.length).toBe(0); + }); +}); diff --git a/src/plan/toElevation.ts b/src/plan/toElevation.ts index 43a38420..7119a84a 100644 --- a/src/plan/toElevation.ts +++ b/src/plan/toElevation.ts @@ -463,6 +463,8 @@ export interface ProjectedFace { ceilingId?: string; roofId?: string; fill?: RRgb; + /** Welt-Normale (Einheit) — für die Erkennung deckungsgleicher Nachbarflächen. */ + normal?: V3; } /** @@ -497,6 +499,7 @@ export function projectFace(frame: ElevationFrame, face: WorldFace): ProjectedFa ceilingId: face.ceilingId, roofId: face.roofId, fill: face.fill, + normal: face.normal, }; } @@ -1355,6 +1358,32 @@ export function generateElevationPlan( // der Teilboxen (Pfeiler/Sturz/Geschossfugen) heben sich auf, übrig bleibt die // Silhouette samt Öffnungslöchern (VW-Linienzeichnungs-Look). Dach/schräge // Flächen tragen ihre eigene, ebenfalls geclippte Kanten-Kontur (unten). + const edgeKey = (a: [number, number], b: [number, number]): string => { + const r = (v: number) => Math.round(v * 1e4); + const ka = `${r(a[0])},${r(a[1])}`; + const kb = `${r(b[0])},${r(b[1])}`; + return ka < kb ? `${ka}|${kb}` : `${kb}|${ka}`; + }; + const roofEdgeFaces = new Map(); + for (const f of faces) { + if (f.role !== "roof" || !f.roofId || !f.normal) continue; + for (let i = 0; i < f.pts.length; i++) { + const k = edgeKey(f.pts[i], f.pts[(i + 1) % f.pts.length]); + const list = roofEdgeFaces.get(k); + if (list) list.push(f); + else roofEdgeFaces.set(k, [f]); + } + } + const isCoplanarSeam = (f: ProjectedFace, a: [number, number], b: [number, number]): boolean => { + if (f.role !== "roof" || !f.roofId || !f.normal) return false; + return (roofEdgeFaces.get(edgeKey(a, b)) ?? []).some( + (o) => + o !== f && + o.roofId === f.roofId && + o.normal !== undefined && + f.normal![0] * o.normal[0] + f.normal![1] * o.normal[1] + f.normal![2] * o.normal[2] > 1 - 1e-9, + ); + }; const frontalGroups = new Map(); for (const f of faces) { const pts: Vec2[] = f.pts.map(([u, v]) => { @@ -1373,6 +1402,9 @@ export function generateElevationPlan( for (let i = 0; i < f.pts.length; i++) { const a = f.pts[i]; const b = f.pts[(i + 1) % f.pts.length]; + // Naht zwischen zwei deckungsgleichen Teilflächen DESSELBEN Dachs (konvexe + // Zerlegung einer L-/T-förmigen Dachfläche): keine Kante — es ist EINE Fläche. + if (isCoplanarSeam(f, a, b)) continue; pushClippedLine(a, b, f.depthMin - EPS * 5, (sa, sb) => ({ kind: "line", a: { x: sa[0], y: sa[1] }, diff --git a/src/plan/toSection.roof.test.ts b/src/plan/toSection.roof.test.ts index 9d110cc9..955db10c 100644 --- a/src/plan/toSection.roof.test.ts +++ b/src/plan/toSection.roof.test.ts @@ -144,3 +144,18 @@ describe("appendRoofSections", () => { expect(out.cutPolygons.every((cp) => cp.hatch?.pattern === "diagonal")).toBe(true); }); }); + +describe("appendRoofSections — Nähte deckungsgleicher Teilflächen", () => { + it("L-Walmdach, Schnitt längs durch die Süd-Schräge: deckungsgleiche Teilflächen werden ein Band", () => { + const L: Roof["outline"] = [ + { x: 0, y: 0 }, { x: 11, y: 0 }, { x: 11, y: 4 }, { x: 8, y: 4 }, { x: 8, y: 6 }, { x: 0, y: 6 }, + ]; + // Schnitt entlang x bei y=1: Blick +y (Norden), u = x. Süd-Schräge besteht aus zwei Teilflächen EINER Ebene. + const plane: SectionPlaneSpec = { point: [0, 0, 1], normal: [0, 0, 1] }; + const out = emptyOutput(); + appendRoofSections(out, project(roof({ outline: L, shape: "walm" })), plane); + // Walm-Ost, Süd-Schräge (zwei Teilflächen einer Ebene → EIN Band), Walm-West = 3 Bänder. + const roofPolys = out.cutPolygons.filter((c) => c.component.kind === "roof"); + expect(roofPolys.length).toBe(3); + }); +}); diff --git a/src/plan/toSection.ts b/src/plan/toSection.ts index 755a9c13..3707a75b 100644 --- a/src/plan/toSection.ts +++ b/src/plan/toSection.ts @@ -1003,6 +1003,7 @@ export function appendRoofSections( const totalT = layers.reduce((s, l) => s + Math.max(0, l.thickness), 0); if (totalT <= 1e-9) return; + const segs: Array<{ key: string; tLo: number; tHi: number; zTop0: number; zTop1: number; cosTheta: number }> = []; for (const pl of geo.planes) { const pts = pl.pts; if (pts.length < 3) continue; @@ -1064,6 +1065,32 @@ export function appendRoofSections( const zTop0 = zAt(p0.x, p0.y); const zTop1 = zAt(p1.x, p1.y); + const r6 = (v: number) => Math.round(v * 1e5); + segs.push({ + key: `${r6(A / C)}|${r6(B / C)}|${r6(zAt(base.x, base.y))}`, + tLo, + tHi, + zTop0, + zTop1, + cosTheta, + }); + } + + // Deckungsgleiche, aneinanderstossende Teilflächen (konvexe Zerlegung einer L-/T-förmigen + // Dachfläche) zu EINEM Band vereinen — sonst steht an der Naht eine senkrechte Linie. + segs.sort((p, q) => (p.key < q.key ? -1 : p.key > q.key ? 1 : p.tLo - q.tLo)); + const merged: typeof segs = []; + for (const sg of segs) { + const last = merged[merged.length - 1]; + if (last && last.key === sg.key && Math.abs(sg.tLo - last.tHi) < 1e-6) { + last.tHi = sg.tHi; + last.zTop1 = sg.zTop1; + } else { + merged.push({ ...sg }); + } + } + + for (const { tLo, tHi, zTop0, zTop1, cosTheta } of merged) { // Schicht-Bänder von aussen (oben) nach innen, vertikale Dicke je Schicht. let prefixV = 0; for (const layer of layers) {