From f1b30d07b1211dc9c576fefb72cc47beda2d2bd5 Mon Sep 17 00:00:00 2001 From: karim Date: Fri, 23 Oct 2026 01:15:55 +0200 Subject: [PATCH] Schnitt: ueberlappende/anstossende Dachbaender mit gleicher Oberkante zu einem Band vereint --- src/plan/toSection.roof.test.ts | 9 +++++++++ src/plan/toSection.ts | 27 ++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/plan/toSection.roof.test.ts b/src/plan/toSection.roof.test.ts index 955db10c..767188a1 100644 --- a/src/plan/toSection.roof.test.ts +++ b/src/plan/toSection.roof.test.ts @@ -158,4 +158,13 @@ describe("appendRoofSections — Nähte deckungsgleicher Teilflächen", () => { const roofPolys = out.cutPolygons.filter((c) => c.component.kind === "roof"); expect(roofPolys.length).toBe(3); }); + it("Schnitt genau auf der Höhenlinie (y=2): überlappende gleich hohe Bänder 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 }, + ]; + const plane: SectionPlaneSpec = { point: [0, 0, 2], normal: [0, 0, 1] }; + const out = emptyOutput(); + appendRoofSections(out, project(roof({ outline: L, shape: "walm" })), plane); + expect(out.cutPolygons.filter((c) => c.component.kind === "roof").length).toBe(3); + }); }); diff --git a/src/plan/toSection.ts b/src/plan/toSection.ts index 3707a75b..22b8a4df 100644 --- a/src/plan/toSection.ts +++ b/src/plan/toSection.ts @@ -1003,7 +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 }> = []; + const segs: Array<{ 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; @@ -1065,9 +1065,7 @@ 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, @@ -1076,15 +1074,26 @@ export function appendRoofSections( }); } - // 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)); + // Aneinanderstossende/überlappende Bänder, deren Oberkante in einer Geraden weiterläuft und die gleiche + // Dicke haben (z. B. Teilflächen EINER Ebene aus der konvexen Zerlegung, oder zwei + // Flächen, die genau an der Schnittspur anstossen), zu EINEM Band vereinen — sonst + // steht an der Naht eine senkrechte Linie. + segs.sort((p, q) => 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; + const slope = (x: typeof sg) => (x.zTop1 - x.zTop0) / Math.max(x.tHi - x.tLo, 1e-12); + const lineZ = (x: typeof sg, t: number) => x.zTop0 + slope(x) * (t - x.tLo); + if ( + last && + sg.tLo <= last.tHi + 1e-6 && // anstossend ODER überlappend + Math.abs(lineZ(last, sg.tLo) - sg.zTop0) < 1e-6 && + Math.abs(slope(sg) - slope(last)) < 1e-6 && + Math.abs(sg.cosTheta - last.cosTheta) < 1e-6 + ) { + const hi = Math.max(last.tHi, sg.tHi); + last.zTop1 = lineZ(last, hi); + last.tHi = hi; } else { merged.push({ ...sg }); }