This repository has been archived on 2026-11-16. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
DOSSIER-STANDALONE/src/plan/generateVisibleLevelsPlan.test.ts
T

190 lines
7.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* `generateVisibleLevelsPlan` — Überlagerung mehrerer sichtbarer Geschoss-/
* Zeichnungs-Ebenen in EINEM Plan (Nutzer-Wunsch: "mehrere Geschosse
* gleichzeitig einschaltbar", "wie bei den Ebenen" — aktive Ebene farbig,
* andere je Darstellungsmodus gedimmt/gesperrt/versteckt).
*/
import { describe, it, expect } from "vitest";
import { generateVisibleLevelsPlan } from "./generatePlan";
import type { CategoryDisplayResolver } from "./generatePlan";
import type { DrawingLevel, Project, Wall } from "../model/types";
const visible = new Set(["20", "90"]);
const SHOW_ALL: CategoryDisplayResolver = () => ({ render: true, greyed: false, locked: false });
function wallOf(id: string, floorId: string, x: number): Wall {
return {
id,
type: "wall",
floorId,
categoryCode: "20",
start: { x, y: 0 },
end: { x: x + 4, y: 0 },
wallTypeId: "aw",
height: 2.6,
} as unknown as Wall;
}
function baseProject(levels: DrawingLevel[], walls: Wall[]): Project {
return {
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 }] }],
drawingLevels: levels,
layers: [{ code: "20", name: "Wände", color: "#0a0a0a", lw: 0.5, visible: true, locked: false }],
walls,
doors: [],
openings: [],
ceilings: [],
stairs: [],
rooms: [],
drawings2d: [],
context: [],
} as unknown as Project;
}
function floor(id: string, name: string): DrawingLevel {
return {
id,
name,
kind: "floor",
visible: true,
locked: false,
floorHeight: 2.6,
cutHeight: 1.0,
baseElevation: 0,
};
}
describe("generateVisibleLevelsPlan", () => {
it("überlagert eine zweite sichtbare Ebene zusätzlich zur aktiven", () => {
const p = baseProject(
[floor("eg", "EG"), floor("og", "OG")],
[wallOf("w-eg", "eg", 0), wallOf("w-og", "og", 10)],
);
const levelDisplay: CategoryDisplayResolver = (id) => ({
render: true,
greyed: id !== "eg",
locked: false,
});
const plan = generateVisibleLevelsPlan(p, "eg", visible, SHOW_ALL, "mittel", false, false, levelDisplay);
const wallIds = plan.primitives.map((pr) => (pr as { wallId?: string }).wallId).filter(Boolean);
expect(wallIds).toContain("w-eg");
expect(wallIds).toContain("w-og");
});
it("gedimmte (nicht-aktive) Ebene: ihre Primitive tragen greyed=true", () => {
const p = baseProject(
[floor("eg", "EG"), floor("og", "OG")],
[wallOf("w-eg", "eg", 0), wallOf("w-og", "og", 10)],
);
const levelDisplay: CategoryDisplayResolver = (id) => ({
render: true,
greyed: id !== "eg",
locked: false,
});
const plan = generateVisibleLevelsPlan(p, "eg", visible, SHOW_ALL, "mittel", false, false, levelDisplay);
const ogPoche = plan.primitives.find(
(pr) => (pr as { wallId?: string }).wallId === "w-og" && pr.kind === "polygon",
) as { greyed?: boolean } | undefined;
const egPoche = plan.primitives.find(
(pr) => (pr as { wallId?: string }).wallId === "w-eg" && pr.kind === "polygon",
) as { greyed?: boolean } | undefined;
expect(ogPoche?.greyed).toBe(true);
expect(egPoche?.greyed).toBeFalsy();
});
it("Modus 'active' (render=false für andere): zeigt NUR die aktive Ebene", () => {
const p = baseProject(
[floor("eg", "EG"), floor("og", "OG")],
[wallOf("w-eg", "eg", 0), wallOf("w-og", "og", 10)],
);
const levelDisplay: CategoryDisplayResolver = (id) => ({
render: id === "eg",
greyed: false,
locked: false,
});
const plan = generateVisibleLevelsPlan(p, "eg", visible, SHOW_ALL, "mittel", false, false, levelDisplay);
const wallIds = plan.primitives.map((pr) => (pr as { wallId?: string }).wallId).filter(Boolean);
expect(wallIds).toContain("w-eg");
expect(wallIds).not.toContain("w-og");
});
it("dedupliziert projektglobale Zutaten (Schnittlinien) — nur einmal, nicht je Ebene", () => {
const p = baseProject(
[
floor("eg", "EG"),
floor("og", "OG"),
{
id: "s-a",
name: "Schnitt A",
kind: "section",
visible: true,
locked: false,
linePoints: [{ x: 0, y: 2 }, { x: 6, y: 2 }],
directionSign: 1,
},
],
[wallOf("w-eg", "eg", 0), wallOf("w-og", "og", 10)],
);
const plan = generateVisibleLevelsPlan(p, "eg", visible, SHOW_ALL, "mittel", false, false, SHOW_ALL);
const bands = plan.primitives.filter(
(pr) => pr.kind === "polygon" && (pr as { sectionLineId?: string }).sectionLineId === "s-a",
);
expect(bands.length).toBe(1);
});
it("Regression: sehr viele Primitive (grossflächiger Import) lösen keinen Stack-Overflow aus", () => {
// Nutzer-Report 2026-10-08: Import eines Kataster-DXF einer ganzen Stadt
// (~400 MB, hunderttausende Elemente) liess die App mit "Maximum call
// stack size exceeded" abstürzen — Ursache war `primitives.push(...grosses
// Array)`, das V8s Argumentzahl-Grenze für Funktionsaufrufe sprengt (anders
// als Array-LITERAL-Spread `[...a,...b]`, der KEIN Funktionsaufruf ist und
// beliebig gross sein darf). Reproduziert hier mit genug Elementen, um die
// Grenze (~65–130k, engine-abhängig) sicher zu überschreiten.
const N = 200_000;
const drawings2d: Project["drawings2d"] = [];
for (let i = 0; i < N; i++) {
drawings2d.push({
id: `d${i}`,
type: "drawing2d",
levelId: "eg",
categoryCode: "2d-line",
geom: { shape: "line", a: { x: 0, y: i * 0.001 }, b: { x: 1, y: i * 0.001 } },
} as unknown as Project["drawings2d"][number]);
}
const p = { ...baseProject([floor("eg", "EG")], []), drawings2d };
const visibleWide = new Set(["20", "90", "2d-line"]);
expect(() =>
generateVisibleLevelsPlan(p, "eg", visibleWide, SHOW_ALL, "mittel", false, false, SHOW_ALL),
).not.toThrow();
});
it("Schnitt/Ansicht-Ebenen bleiben Einzel-Pane (kein Stapeln über kind-Grenze)", () => {
const p = baseProject(
[
floor("eg", "EG"),
{
id: "s-a",
name: "Schnitt A",
kind: "section",
visible: true,
locked: false,
linePoints: [{ x: 0, y: 2 }, { x: 6, y: 2 }],
directionSign: 1,
},
],
[wallOf("w-eg", "eg", 0)],
);
// Aktive Ebene ist der Schnitt selbst — Geschoss "eg" darf NICHT als
// Referenz-Wand-Poché mit hineingemischt werden (andere Projektionsachse).
const plan = generateVisibleLevelsPlan(p, "s-a", visible, SHOW_ALL, "mittel", false, false, SHOW_ALL);
const wallIds = plan.primitives.map((pr) => (pr as { wallId?: string }).wallId).filter(Boolean);
expect(wallIds).not.toContain("w-eg");
});
});