- hlr_fill.rs (neu): sichtbare Teilpolygone je Fläche (Umriss minus näher liegende Teile der anderen Flächen, Halbebene der Tiefendifferenz, i_overlay), Raster-Vorauswahl, ganz gedeckte Flächen ohne Boolean; Strecken auf Polygone beschneiden. - hlr.rs: Durchdringungslinien zugewandter Flächen verschiedener Körper (Face.solid), nur im Innern beider Flächen; danach gleiche Verdeckung wie Kanten. - Ansicht: Füllungen = sichtbare Teile (keine Füllung mehr über verdeckten Kanten, Gauben/Kamin hinter der Dachmitte), Ansichtsschraffur auf die sichtbaren Teile ihrer Fläche (Dachraster lief über die Gauben), Schatten nur auf sichtbaren Wandteilen; Körper je Bauteil für die Durchdringungslinien. - Tests: kamin_hinter_dachmitte_fuellung_wie_kanten, koerper_durch_wand_zeigt_durchdringungslinie, hlr/hlr_fill-Einheitstests; Goldens (weniger Polygone: verdeckte Flächen entfallen). - TODO, ARCHITEKTUR, core/src/README nachgeführt.
601 lines
23 KiB
TypeScript
601 lines
23 KiB
TypeScript
/**
|
||
* Tests für den Ansichts-Generator (toElevation.ts → Kern `plan/elevation.rs`): Painter-Reihenfolge
|
||
* (nähere Fassade NACH der ferneren), Schlagschatten (nur mit shadows=true), Sichtbarkeit,
|
||
* Durchsicht-Clipping, Öffnungen und Dächer — auf Minimalprojekten. Projektion, Culling und
|
||
* Schatten-Geometrie prüft der Kern selbst (`plan_elevation.rs`).
|
||
*/
|
||
|
||
import { describe, it, expect } from "vitest";
|
||
import type { Project, Wall } from "../model/types";
|
||
import type { CategoryDisplayResolver } from "./generatePlan";
|
||
import { generateElevationPlan } from "./toElevation";
|
||
|
||
describe("toElevation — Painter-Reihenfolge", () => {
|
||
it("im Plan: nähere Wand-Fläche hat einen höheren Primitiv-Index", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
// [G4] Die fernere Wand ragt rechts 2 m heraus; nur dieser Teil ist sichtbar (exakte Sichtbarkeit).
|
||
project.walls = project.walls.map((w) => (w.id === "FAR" ? { ...w, end: { x: 6, y: w.end.y } } : w));
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
expect(plan).not.toBeNull();
|
||
const idxNear = plan.primitives.findIndex(
|
||
(p) => p.kind === "polygon" && p.wallId === "NEAR",
|
||
);
|
||
const idxFar = plan.primitives.findIndex(
|
||
(p) => p.kind === "polygon" && p.wallId === "FAR",
|
||
);
|
||
expect(idxNear).toBeGreaterThanOrEqual(0);
|
||
expect(idxFar).toBeGreaterThanOrEqual(0);
|
||
expect(idxNear).toBeGreaterThan(idxFar); // fern zuerst, nah zuletzt
|
||
const far = plan.primitives.filter((p) => p.kind === "polygon" && p.wallId === "FAR");
|
||
const xs = far.flatMap((p) => (p.kind === "polygon" ? p.pts.map((q) => q.x) : []));
|
||
expect(Math.max(...xs) - Math.min(...xs)).toBeLessThan(2.3); // ohne den verdeckten Teil (6 m)
|
||
});
|
||
});
|
||
|
||
describe("toElevation — Schlagschatten", () => {
|
||
it("im Plan: shadows=true erzeugt zusätzliche Schatten-Primitive, false exakt keine", () => {
|
||
const project = elevationProject({ overhang: true });
|
||
const level = project.drawingLevels[1];
|
||
const withOff = generateElevationPlan(project, level, { shadows: false })!;
|
||
const withOn = generateElevationPlan(project, level, { shadows: true })!;
|
||
// Schatten sind randlose (stroke "none") Polygone im festen Schattengrau.
|
||
const shadowCount = (plan: typeof withOn) =>
|
||
plan.primitives.filter(
|
||
(p) => p.kind === "polygon" && p.stroke === "none" && p.fill === "#8f959e",
|
||
).length;
|
||
expect(shadowCount(withOff)).toBe(0);
|
||
expect(shadowCount(withOn)).toBeGreaterThan(0);
|
||
});
|
||
});
|
||
|
||
describe("toElevation — Fallback", () => {
|
||
it("ohne linePoints liefert generateElevationPlan null", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const bare = { ...project.drawingLevels[1], linePoints: undefined };
|
||
expect(generateElevationPlan(project, bare)).toBeNull();
|
||
});
|
||
});
|
||
|
||
describe("toElevation — Ebenen-Panel-Sichtbarkeit (Nutzer-Report: 'Kategorien sollten auch in der Ansicht wirken')", () => {
|
||
it("eine kategorie-ausgeblendete Wand verschwindet vollständig aus der Ansicht", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const level = project.drawingLevels[1];
|
||
const hideAll: CategoryDisplayResolver = () => ({ render: false, greyed: false, locked: false });
|
||
const plan = generateElevationPlan(project, level, {
|
||
visibleCodes: new Set(["20"]),
|
||
categoryDisplay: hideAll,
|
||
})!;
|
||
const wallPolys = plan.primitives.filter((p) => p.kind === "polygon" && p.wallId != null);
|
||
expect(wallPolys.length).toBe(0);
|
||
});
|
||
|
||
it("bleibt sichtbar, wenn die Kategorie erlaubt ist", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const level = project.drawingLevels[1];
|
||
const showAll: CategoryDisplayResolver = () => ({ render: true, greyed: false, locked: false });
|
||
const plan = generateElevationPlan(project, level, {
|
||
visibleCodes: new Set(["20"]),
|
||
categoryDisplay: showAll,
|
||
})!;
|
||
const wallPolys = plan.primitives.filter((p) => p.kind === "polygon" && p.wallId != null);
|
||
expect(wallPolys.length).toBeGreaterThan(0);
|
||
});
|
||
|
||
it("eine ausgeblendete NÄHERE Wand verdeckt die fernere nicht mehr (fällt auch als Occluder weg)", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const level = project.drawingLevels[1];
|
||
// NEAR (categoryCode "20") ausblenden — FAR bleibt sichtbar UND wird nicht
|
||
// mehr von NEAR verdeckt (anders als eine normale Verdeckung).
|
||
const hideCat: CategoryDisplayResolver = () => ({ render: false, greyed: false, locked: false });
|
||
const plan = generateElevationPlan(project, level, {
|
||
visibleCodes: new Set([]),
|
||
categoryDisplay: hideCat,
|
||
})!;
|
||
const near = plan.primitives.find((p) => p.kind === "polygon" && p.wallId === "NEAR");
|
||
const far = plan.primitives.find((p) => p.kind === "polygon" && p.wallId === "FAR");
|
||
expect(near).toBeUndefined();
|
||
expect(far).toBeUndefined(); // beide tragen categoryCode "20", beide ausgeblendet
|
||
});
|
||
|
||
it("ohne visibleCodes/categoryDisplay (Export-/Print-Pfad) bleibt alles sichtbar wie bisher", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const level = project.drawingLevels[1];
|
||
const plan = generateElevationPlan(project, level)!;
|
||
const wallPolys = plan.primitives.filter((p) => p.kind === "polygon" && p.wallId != null);
|
||
expect(wallPolys.length).toBeGreaterThan(0);
|
||
});
|
||
|
||
it("markiert eine sichtbare, aber gedimmte Kategorie als greyed (nicht ausgeblendet)", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const level = project.drawingLevels[1];
|
||
const greyCat: CategoryDisplayResolver = () => ({ render: true, greyed: true, locked: false });
|
||
const plan = generateElevationPlan(project, level, {
|
||
visibleCodes: new Set(["20"]),
|
||
categoryDisplay: greyCat,
|
||
})!;
|
||
const wallPolys = plan.primitives.filter(
|
||
(p): p is Extract<typeof p, { kind: "polygon" }> => p.kind === "polygon" && p.wallId != null,
|
||
);
|
||
expect(wallPolys.length).toBeGreaterThan(0);
|
||
for (const p of wallPolys) expect(p.greyed).toBe(true);
|
||
});
|
||
});
|
||
|
||
// ── Minimalprojekt-Factory ──────────────────────────────────────────────────
|
||
// Zwei parallele Wände (nah/fern) + optional eine auskragende Dach-Decke.
|
||
function elevationProject(opts: { overhang: boolean }): Project {
|
||
const w = (id: string, y: number): Wall => ({
|
||
id,
|
||
type: "wall",
|
||
floorId: "eg",
|
||
categoryCode: "20",
|
||
start: { x: 0, y },
|
||
end: { x: 4, y },
|
||
wallTypeId: "aw",
|
||
height: 3,
|
||
});
|
||
const project: Project = {
|
||
id: "t",
|
||
name: "T",
|
||
lineStyles: [{ id: "thin", name: "d", weight: 0.13, color: "#111", dash: null }],
|
||
hatches: [{ id: "none", name: "Ohne", pattern: "none", scale: 1, angle: 0, color: "#111" }],
|
||
components: [{ id: "a", name: "A", color: "#d8d2c7", hatchId: "none", joinPriority: 10 }],
|
||
wallTypes: [{ id: "aw", name: "AW", layers: [{ componentId: "a", thickness: 0.2 }] }],
|
||
ceilingTypes: [{ id: "dc", name: "Dach", layers: [{ componentId: "a", thickness: 0.2 }] }],
|
||
drawingLevels: [
|
||
{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false, floorHeight: 3, cutHeight: 1, baseElevation: 0 },
|
||
{
|
||
id: "ans",
|
||
name: "Ansicht Süd",
|
||
kind: "elevation",
|
||
visible: true,
|
||
locked: false,
|
||
linePoints: [{ x: -1, y: -2 }, { x: 5, y: -2 }],
|
||
directionSign: 1,
|
||
},
|
||
],
|
||
layers: [{ code: "20", name: "Wände", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
|
||
walls: [w("NEAR", 0), w("FAR", 3)],
|
||
openings: [],
|
||
ceilings: opts.overhang
|
||
? [
|
||
{
|
||
id: "R",
|
||
type: "ceiling",
|
||
floorId: "eg",
|
||
categoryCode: "20",
|
||
wallTypeId: "aw",
|
||
ceilingTypeId: "dc",
|
||
// Umriss ragt nach Süden (y < 0) über die Süd-Wand (y=0) hinaus.
|
||
outline: [
|
||
{ x: 0, y: -0.6 },
|
||
{ x: 4, y: -0.6 },
|
||
{ x: 4, y: 0.2 },
|
||
{ x: 0, y: 0.2 },
|
||
],
|
||
},
|
||
]
|
||
: [],
|
||
stairs: [],
|
||
rooms: [],
|
||
drawings2d: [],
|
||
context: [],
|
||
};
|
||
return project;
|
||
}
|
||
|
||
describe("toElevation — Hidden-Line-Clipping (keine Durchsicht)", () => {
|
||
// Zwei deckungsgleiche Wände (NEAR vor FAR): die hintere Silhouette liegt
|
||
// vollständig hinter der vorderen und darf KEINE Umrisslinie beisteuern —
|
||
// sonst „scheint" die Hinterwand durch (Nutzer-Report). Erwartet: genau die
|
||
// 4 Kanten der vorderen Wand.
|
||
it("deckungsgleiche Hinterwand trägt keine Umrisslinie bei", () => {
|
||
const project = elevationProject({ overhang: false });
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
const outlineLines = plan.primitives.filter(
|
||
(p) => p.kind === "line" && (p as { cls?: string }).cls === "elevation-outline",
|
||
);
|
||
// Nur die 4 Kanten der NEAR-Fassade (FAR ist vollständig geclippt).
|
||
expect(outlineLines.length).toBe(4);
|
||
});
|
||
|
||
it("höhere Hinterwand: nur der ÜBERSTEHENDE Teil bleibt sichtbar", () => {
|
||
const base = elevationProject({ overhang: false });
|
||
// FAR-Wand höher machen (4 statt 3 m) → ihr oberer Rand ragt über NEAR.
|
||
const project: Project = {
|
||
...base,
|
||
walls: base.walls.map((w) => (w.id === "FAR" ? { ...w, height: 4 } : w)),
|
||
};
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
const outline = plan.primitives.filter(
|
||
(p) => p.kind === "line" && (p as { cls?: string }).cls === "elevation-outline",
|
||
) as Array<{ a: { x: number; y: number }; b: { x: number; y: number } }>;
|
||
// Eine horizontale Kante bei v≈4 (FAR-Oberkante, sichtbar über NEAR) …
|
||
const hasFarTop = outline.some(
|
||
(l) => Math.abs(l.a.y - 4) < 1e-4 && Math.abs(l.b.y - 4) < 1e-4,
|
||
);
|
||
expect(hasFarTop).toBe(true);
|
||
// … aber KEINE horizontale Kante bei v≈0 aus FAR im von NEAR verdeckten
|
||
// Bereich: die einzige v≈0-Kante ist NEARs Unterkante (die FAR-Unterkante
|
||
// liegt hinter NEAR und ist geclippt). Es gibt also nur EINE v≈0-Linie.
|
||
const bottomLines = outline.filter(
|
||
(l) => Math.abs(l.a.y) < 1e-4 && Math.abs(l.b.y) < 1e-4,
|
||
);
|
||
expect(bottomLines.length).toBe(1);
|
||
});
|
||
});
|
||
|
||
describe("toElevation — Öffnungen: Verdeckung + Reveal-Schatten", () => {
|
||
// Projekt mit einem Fenster auf NEAR und einem deckungsgleich dahinter auf FAR.
|
||
function openingProject(): Project {
|
||
const base = elevationProject({ overhang: false });
|
||
const wt = {
|
||
id: "wt",
|
||
name: "Fenster",
|
||
kind: "drehkipp" as const,
|
||
wingCount: 1,
|
||
glazing: "zweifach" as const,
|
||
frameWidth: 0.06,
|
||
defaultSillHeight: 0.9,
|
||
defaultWidth: 1,
|
||
defaultHeight: 1.2,
|
||
};
|
||
const mkOpening = (id: string, hostWallId: string) => ({
|
||
id,
|
||
type: "opening" as const,
|
||
hostWallId,
|
||
categoryCode: "21",
|
||
kind: "window" as const,
|
||
typeId: "wt",
|
||
position: 1.5,
|
||
width: 1,
|
||
height: 1.2,
|
||
sillHeight: 0.9,
|
||
});
|
||
return {
|
||
...base,
|
||
windowTypes: [wt],
|
||
openings: [mkOpening("op-near", "NEAR"), mkOpening("op-far", "FAR")],
|
||
} as unknown as Project;
|
||
}
|
||
|
||
it("Fenster auf der verdeckten Hinterwand wird NICHT emittiert (keine Durchsicht)", () => {
|
||
const project = openingProject();
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
// Öffnungs-Symbollinien (DIN) — die des FAR-Fensters dürften durch NEAR
|
||
// scheinen, wenn nicht gecullt. Nur das NEAR-Fenster liefert Symbole.
|
||
const symbols = plan.primitives.filter(
|
||
(p) => p.kind === "line" && (p as { cls?: string }).cls === "elevation-opening-symbol",
|
||
);
|
||
const nearOnly = generateElevationPlan(
|
||
{ ...project, openings: (project.openings ?? []).filter((o) => o.id === "op-near") },
|
||
project.drawingLevels[1],
|
||
)!;
|
||
const nearSymbols = nearOnly.primitives.filter(
|
||
(p) => p.kind === "line" && (p as { cls?: string }).cls === "elevation-opening-symbol",
|
||
);
|
||
// Mit beiden Fenstern gleich viele Symbole wie mit NUR dem vorderen → das
|
||
// hintere trägt nichts bei (vollständig verdeckt).
|
||
expect(symbols.length).toBe(nearSymbols.length);
|
||
expect(symbols.length).toBeGreaterThan(0);
|
||
});
|
||
|
||
it("Öffnungssymbolik je Art: Schiebe=Pfeil (3 Linien), Fest=keine, Drehkipp=4", () => {
|
||
const base = elevationProject({ overhang: false });
|
||
const mkProject = (kind: "schiebe" | "fest" | "drehkipp"): Project =>
|
||
({
|
||
...base,
|
||
windowTypes: [
|
||
{
|
||
id: "wt",
|
||
name: "F",
|
||
kind,
|
||
wingCount: 1,
|
||
glazing: "zweifach",
|
||
frameWidth: 0.06,
|
||
defaultSillHeight: 0.9,
|
||
defaultWidth: 1,
|
||
defaultHeight: 1.2,
|
||
},
|
||
],
|
||
openings: [
|
||
{
|
||
id: "op",
|
||
type: "opening",
|
||
hostWallId: "NEAR",
|
||
categoryCode: "21",
|
||
kind: "window",
|
||
typeId: "wt",
|
||
position: 1.5,
|
||
width: 1,
|
||
height: 1.2,
|
||
sillHeight: 0.9,
|
||
},
|
||
],
|
||
}) as unknown as Project;
|
||
const symCount = (kind: "schiebe" | "fest" | "drehkipp"): number => {
|
||
const p = mkProject(kind);
|
||
const plan = generateElevationPlan(p, p.drawingLevels[1])!;
|
||
return plan.primitives.filter(
|
||
(pr) => pr.kind === "line" && (pr as { cls?: string }).cls === "elevation-opening-symbol",
|
||
).length;
|
||
};
|
||
expect(symCount("schiebe")).toBe(3); // Pfeil: Schaft + 2 Spitzen
|
||
expect(symCount("fest")).toBe(0); // Festverglasung ohne Symbol
|
||
expect(symCount("drehkipp")).toBe(4); // Dreh (2) + Kipp (2)
|
||
});
|
||
|
||
it("Kämpfer-Zeilen (mullionRows): teilen das Glasfeld horizontal (Glas + Trennlinien)", () => {
|
||
const base = elevationProject({ overhang: false });
|
||
const mk = (mullionRows: number): Project =>
|
||
({
|
||
...base,
|
||
windowTypes: [
|
||
{
|
||
id: "wt",
|
||
name: "F",
|
||
kind: "fest",
|
||
wingCount: 1,
|
||
glazing: "einfach",
|
||
frameWidth: 0.06,
|
||
mullionRows,
|
||
defaultSillHeight: 0.9,
|
||
defaultWidth: 1,
|
||
defaultHeight: 1.2,
|
||
},
|
||
],
|
||
openings: [
|
||
{
|
||
id: "op",
|
||
type: "opening",
|
||
hostWallId: "NEAR",
|
||
categoryCode: "21",
|
||
kind: "window",
|
||
typeId: "wt",
|
||
position: 1.5,
|
||
width: 1,
|
||
height: 1.2,
|
||
sillHeight: 0.9,
|
||
},
|
||
],
|
||
}) as unknown as Project;
|
||
const glassCount = (rows: number): number => {
|
||
const p = mk(rows);
|
||
const plan = generateElevationPlan(p, p.drawingLevels[1])!;
|
||
// Glasflächen = weiss/blau gefüllte Polygone mit Kontur, keine Öffnung/Rahmen.
|
||
return plan.primitives.filter(
|
||
(pr) => pr.kind === "polygon" && pr.fill === "#d3d8dd",
|
||
).length;
|
||
};
|
||
expect(glassCount(1)).toBe(1); // fest, 1 Feld
|
||
expect(glassCount(3)).toBe(3); // in 3 Zeilen geteilt
|
||
});
|
||
|
||
it("Sprossen-Spalten (mullionCols): teilen das Glasfeld vertikal (Glas + Trennlinien)", () => {
|
||
const base = elevationProject({ overhang: false });
|
||
const mk = (mullionCols: number): Project =>
|
||
({
|
||
...base,
|
||
windowTypes: [
|
||
{
|
||
id: "wt",
|
||
name: "F",
|
||
kind: "fest",
|
||
wingCount: 1,
|
||
glazing: "einfach",
|
||
frameWidth: 0.06,
|
||
mullionCols,
|
||
defaultSillHeight: 0.9,
|
||
defaultWidth: 1,
|
||
defaultHeight: 1.2,
|
||
},
|
||
],
|
||
openings: [
|
||
{
|
||
id: "op",
|
||
type: "opening",
|
||
hostWallId: "NEAR",
|
||
categoryCode: "21",
|
||
kind: "window",
|
||
typeId: "wt",
|
||
position: 1.5,
|
||
width: 1,
|
||
height: 1.2,
|
||
sillHeight: 0.9,
|
||
},
|
||
],
|
||
}) as unknown as Project;
|
||
const glassCount = (cols: number): number => {
|
||
const p = mk(cols);
|
||
const plan = generateElevationPlan(p, p.drawingLevels[1])!;
|
||
// Glasflächen = weiss/blau gefüllte Polygone mit Kontur, keine Öffnung/Rahmen.
|
||
return plan.primitives.filter(
|
||
(pr) => pr.kind === "polygon" && pr.fill === "#d3d8dd",
|
||
).length;
|
||
};
|
||
expect(glassCount(1)).toBe(1); // fest, 1 Feld
|
||
expect(glassCount(3)).toBe(3); // in 3 Spalten geteilt
|
||
});
|
||
|
||
it("Reveal-Schatten: shadows=true erzeugt Öffnungs-Schattenbänder, false keine", () => {
|
||
const project = openingProject();
|
||
const level = project.drawingLevels[1];
|
||
const off = generateElevationPlan(project, level, { shadows: false })!;
|
||
const on = generateElevationPlan(project, level, { shadows: true })!;
|
||
const revealShadows = (plan: typeof on) =>
|
||
plan.primitives.filter(
|
||
(p) => p.kind === "polygon" && p.stroke === "none" && p.fill === "#a7adb5",
|
||
).length;
|
||
expect(revealShadows(off)).toBe(0);
|
||
// Ein sichtbares Fenster → zwei Reveal-Bänder (Kopf + linke Laibung).
|
||
expect(revealShadows(on)).toBe(2);
|
||
});
|
||
});
|
||
|
||
describe("Dächer in der Ansicht (roofWorldFacesAll)", () => {
|
||
it("Dachflächen erscheinen als roofId-Polygone bis zur Firsthöhe", () => {
|
||
// Sattel 4×3 über dem Fixture-Haus, First entlang X, Traufe 3 m — die
|
||
// Süd-Schräge zeigt zum Betrachter (Ansicht Süd des Fixtures), die
|
||
// Nord-Schräge ist rückseiten-gecullt.
|
||
const base = elevationProject({ overhang: false });
|
||
const p = {
|
||
...base,
|
||
roofs: [
|
||
{
|
||
id: "R1",
|
||
type: "roof",
|
||
floorId: "eg",
|
||
categoryCode: "35",
|
||
outline: [
|
||
{ x: 0, y: 0 },
|
||
{ x: 4, y: 0 },
|
||
{ x: 4, y: 3 },
|
||
{ x: 0, y: 3 },
|
||
],
|
||
shape: "sattel",
|
||
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);
|
||
expect(plan).not.toBeNull();
|
||
const roofPolys = plan!.primitives.filter(
|
||
(pr) => pr.kind === "polygon" && (pr as { roofId?: string }).roofId === "R1",
|
||
);
|
||
expect(roofPolys.length).toBeGreaterThanOrEqual(1);
|
||
// Die sichtbare Dachfläche reicht bis zur Firsthöhe 3 + 1.5·tan30.
|
||
const ridge = 3 + 1.5 * Math.tan((30 * Math.PI) / 180);
|
||
const maxV = Math.max(
|
||
...roofPolys.flatMap((pr) => (pr as { pts: { y: number }[] }).pts.map((q) => q.y)),
|
||
);
|
||
expect(maxV).toBeCloseTo(ridge, 5);
|
||
});
|
||
});
|
||
|
||
describe("Dächer auf L-Grundriss in der Ansicht", () => {
|
||
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 },
|
||
];
|
||
for (const shape of ["sattel", "pult", "mansarde", "walm"] as const) {
|
||
it(`${shape}: Dachpolygone mit endlichen Koordinaten`, () => {
|
||
const base = elevationProject({ overhang: false });
|
||
const p = {
|
||
...base,
|
||
roofs: [
|
||
{
|
||
id: "R1", type: "roof", floorId: "eg", categoryCode: "35", outline: L, shape,
|
||
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 roofPolys = plan!.primitives.filter(
|
||
(pr) => pr.kind === "polygon" && (pr as { roofId?: string }).roofId === "R1",
|
||
);
|
||
expect(roofPolys.length).toBeGreaterThanOrEqual(1);
|
||
for (const pr of roofPolys) {
|
||
for (const q of (pr as { pts: { x: number; y: number }[] }).pts) {
|
||
expect(Number.isFinite(q.x) && Number.isFinite(q.y)).toBe(true);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
describe("toElevation — Tür-Teilverglasung (glazingRatio)", () => {
|
||
const GLASS_FILL_COLOR = "#d3d8dd";
|
||
const DOOR_LEAF_FILL_COLOR = "#ececec";
|
||
|
||
function doorProject(dt: {
|
||
leafStyle: "glatt" | "kassette" | "glas";
|
||
glazingRatio?: number;
|
||
}): Project {
|
||
const base = elevationProject({ overhang: false });
|
||
const doorType = {
|
||
id: "dt",
|
||
name: "Tür",
|
||
kind: "dreh" as const,
|
||
leafCount: 1 as const,
|
||
leafStyle: dt.leafStyle,
|
||
glazingRatio: dt.glazingRatio,
|
||
frameThickness: 0.05,
|
||
};
|
||
const opening = {
|
||
id: "op",
|
||
type: "opening" as const,
|
||
hostWallId: "NEAR",
|
||
categoryCode: "21",
|
||
kind: "door" as const,
|
||
typeId: "dt",
|
||
position: 1.5,
|
||
width: 1,
|
||
height: 2.1,
|
||
sillHeight: 0,
|
||
};
|
||
return {
|
||
...base,
|
||
doorTypes: [doorType],
|
||
openings: [opening],
|
||
} as unknown as Project;
|
||
}
|
||
|
||
function fillsOf(project: Project): string[] {
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
return plan.primitives
|
||
.filter((p) => p.kind === "polygon")
|
||
.map((p) => (p as { fill: string }).fill);
|
||
}
|
||
|
||
it("glattes Blatt (kein Glas): nur die Blattfarbe, keine Glasfläche", () => {
|
||
const fills = fillsOf(doorProject({ leafStyle: "glatt" }));
|
||
expect(fills).toContain(DOOR_LEAF_FILL_COLOR);
|
||
expect(fills).not.toContain(GLASS_FILL_COLOR);
|
||
});
|
||
|
||
it("Glasblatt, glazingRatio=1 (voll verglast): nur Glasfarbe, keine Blattfläche", () => {
|
||
const fills = fillsOf(doorProject({ leafStyle: "glas", glazingRatio: 1 }));
|
||
expect(fills).toContain(GLASS_FILL_COLOR);
|
||
expect(fills).not.toContain(DOOR_LEAF_FILL_COLOR);
|
||
});
|
||
|
||
it("Glasblatt, glazingRatio=0.5 (teilverglast): BEIDE Farben + Trennlinie", () => {
|
||
const project = doorProject({ leafStyle: "glas", glazingRatio: 0.5 });
|
||
const fills = fillsOf(project);
|
||
expect(fills).toContain(GLASS_FILL_COLOR);
|
||
expect(fills).toContain(DOOR_LEAF_FILL_COLOR);
|
||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||
const divisionLines = plan.primitives.filter(
|
||
(p) => p.kind === "line" && (p as { cls?: string }).cls === "elevation-division",
|
||
);
|
||
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);
|
||
});
|
||
});
|