[K3c] Merge: Schnitt und Ansicht im Kern (section.rs, elevation.rs), Schnitt 8×8 33 s → 0.19 s
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
52 files changed
+3795
-4552
No files matched your search
+6
-2
@@ -7,7 +7,7 @@
|
||||
// dossier-cli <projekt.obp> migrate [--out neu.obp]
|
||||
// dossier-cli <projekt.obp> plan [--level EG] [--scale 100] [--format svg|json] [--out eg.svg]
|
||||
// json = render2d-Szene (planToRenderScene)
|
||||
// dossier-cli <projekt.obp> section <Name> [--out schnitt.svg] (braucht render3d-WASM)
|
||||
// dossier-cli <projekt.obp> section <Name> [--out schnitt.svg] (--format json: render2d-Szene)
|
||||
// dossier-cli <projekt.obp> elevation <Name> [--out ansicht.svg]
|
||||
// dossier-cli <projekt.obp> ifc [--ebkph] [--ebenen] (IFC mit eBKP-H-Hauptgruppen bzw. Modell-Ebenen als Klassifikation)
|
||||
// --schema 4|2x3: IFC4 (Standard) oder IFC2x3 (Coordination View 2.0)
|
||||
@@ -595,6 +595,10 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
plan = generateElevationPlan(project, lvl);
|
||||
if (!plan) fail("keine gültige Ansichtslinie");
|
||||
}
|
||||
if (args.flags.get("format") === "json") {
|
||||
out(args, JSON.stringify(planToRenderScene(plan, scale)), `${lvl.name}.scene.json`);
|
||||
return 0;
|
||||
}
|
||||
out(args, planToSvgString(plan, { scaleDenominator: scale }), `${lvl.name}.svg`);
|
||||
return 0;
|
||||
}
|
||||
@@ -792,7 +796,7 @@ async function execute(project: Project, file: string, command: string, rest: st
|
||||
await time("planToSvgString", () => planToSvgString(plan, { scaleDenominator: scale }));
|
||||
}
|
||||
await time("projectToModel3d", () => projectToModel3d(project));
|
||||
if (sec) await time("computeSection", () => computeSection(project, sec), Math.max(3, runs / 2));
|
||||
if (sec) await time("Schnitt (Kern)", async () => generateSectionPlan((await computeSection(project, sec))!, false, { visibleCodes: allCodes }), Math.max(3, runs / 2));
|
||||
if (elev) await time("generateElevationPlan", () => generateElevationPlan(project, elev), Math.max(3, runs / 2));
|
||||
if (project.walls.length) {
|
||||
const w0 = project.walls[0];
|
||||
|
||||
@@ -54,6 +54,8 @@ export type QueryName =
|
||||
| "drawingLines"
|
||||
| "drawingPrims"
|
||||
| "levelMarkers"
|
||||
| "sectionPlan"
|
||||
| "elevationPlan"
|
||||
| "modelJson";
|
||||
|
||||
/** Ab so vielen Ops öffnet `sync` das Dokument neu, statt sie einzeln anzuwenden. */
|
||||
@@ -142,9 +144,9 @@ export class ProjectDocument {
|
||||
* Abfrage mit binärer Antwort (`queries.rs::run_bin`, z. B. `planDomains` als Plan-Puffer v2,
|
||||
* s. `plan/planBuf.ts`). Fehler kommen als Fehlerpuffer (`decodePlanBuf` wirft die Meldung).
|
||||
*/
|
||||
queryBin(name: QueryName, args: number[] = [], text = ""): Uint8Array {
|
||||
queryBin(name: QueryName, args: number[] | Float64Array = [], text = ""): Uint8Array {
|
||||
if (!this.handle) throw new Error(`Kern-Abfrage „${name}": Dokument nicht offen`);
|
||||
return core().doc_query_bin(this.handle, name, Float64Array.from(args), text);
|
||||
return core().doc_query_bin(this.handle, name, args instanceof Float64Array ? args : Float64Array.from(args), text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-5
@@ -172,7 +172,6 @@ export {
|
||||
type PlanImage,
|
||||
type UnderlayGroup,
|
||||
generatePlan,
|
||||
generateSectionPlan,
|
||||
generateVisibleLevelsPlan,
|
||||
materializeGreyed,
|
||||
materializeUnderlay,
|
||||
@@ -290,10 +289,7 @@ export {
|
||||
} from "../plan/planView/underlayAccess";
|
||||
|
||||
export {
|
||||
sectionOpeningPrimitives,
|
||||
} from "../plan/sectionOpenings";
|
||||
|
||||
export {
|
||||
type ElevationOptions,
|
||||
generateElevationPlan,
|
||||
} from "../plan/toElevation";
|
||||
|
||||
@@ -305,6 +301,7 @@ export {
|
||||
export {
|
||||
type SectionOutput,
|
||||
computeSection,
|
||||
generateSectionPlan,
|
||||
sameSectionInputs,
|
||||
sameSectionLine,
|
||||
sectionPlaneFromLevel,
|
||||
|
||||
+1
-137
@@ -1,7 +1,6 @@
|
||||
// Geometrie-Helfer für Öffnungen (Fenster/Türen) — reine Funktionen, die eine
|
||||
// `Opening` relativ zu ihrer Wirts-Wand in konkrete Welt-Geometrie auflösen:
|
||||
// • die Öffnungs-Lücke entlang der Wandachse (from/to in Metern),
|
||||
// • die Fenster-Rahmen-/Glaslinien quer über die Lücke (`windowSymbol`, Fassade über den Rust-Kern),
|
||||
// • die vertikale Lage (UK/OK der Öffnung, absolut in Metern).
|
||||
//
|
||||
// Da JEDE Größe aus der aktuellen Wandachse (`wall.start`/`wall.end`) abgeleitet
|
||||
@@ -10,8 +9,7 @@
|
||||
//
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Opening, Project, SashDef, Vec2, Wall } from "../model/types";
|
||||
import { core } from "../engine/coreWasm";
|
||||
import type { Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getWallType, wallTypeThickness } from "../model/types";
|
||||
import { add, along, leftNormal, normalize, scale, sub } from "../model/geometry";
|
||||
import { wallReferenceOffset, wallVerticalExtent } from "../model/wall";
|
||||
@@ -101,137 +99,3 @@ export function openingCenter(wall: Wall, o: Opening): Vec2 | null {
|
||||
if (!iv) return null;
|
||||
return along(wall.start, wall.end, (iv.from + iv.to) / 2);
|
||||
}
|
||||
|
||||
// ── Fenster-Symbol (Plan) ────────────────────────────────────────────────────
|
||||
|
||||
/** Aufgelöste Fenster-Linien im Grundriss (Weltkoordinaten). */
|
||||
export interface WindowSymbol {
|
||||
/** Rahmen-Rechteck (volle Dicke) als Ecken. */
|
||||
frame: Vec2[];
|
||||
/** Glaslinien-Segmente quer über die Lücke (1–3 parallele Linien). */
|
||||
glassLines: [Vec2, Vec2][];
|
||||
/**
|
||||
* Flügel-/Pfosten-Trennlinien, jeweils von einer Laibungsseite zur anderen
|
||||
* (parallel zu den Laibungslinien, quer zur Öffnungsrichtung). Ist `sashes`
|
||||
* (dritter Parameter von {@link windowSymbol}) gesetzt, ergeben sich die
|
||||
* Positionen aus den Flügel-/Pfostenbreiten (siehe `sashSegments`); sonst
|
||||
* (Alt-Fall) `wingCount − 1` gleichmäßig verteilte Querlinien. Entspricht den
|
||||
* Mittelpfosten in `_make_oeffnung_pieces` des Rhino-Plugins (`oeff_fluegel`).
|
||||
*/
|
||||
mullionLines: [Vec2, Vec2][];
|
||||
/**
|
||||
* Flügelrahmen (Flügelkontur) je ÖFFENBAREM Flügel (Dreh/Kipp/Drehkipp/
|
||||
* Schiebe): ein Rechteck INNERHALB des Blendrahmens (Schachtelung
|
||||
* Blendrahmen → Flügelrahmen → Glas), das den öffenbaren Flügel vom festen
|
||||
* Feld unterscheidet. Feste Flügel (`opening:"fest"`) bekommen KEINEN
|
||||
* Flügelrahmen — dort sitzt das Glas direkt im Blendrahmen. Nur befüllt im
|
||||
* neuen (spec-)Pfad; leer im Alt-Fall (kein `spec`).
|
||||
*/
|
||||
sashFrames: Vec2[][];
|
||||
/**
|
||||
* (Alt-Feld, für Rückwärtskompatibilität der Schnittstelle beibehalten) — im
|
||||
* neuen Pfad leer; die Öffenbarkeit wird jetzt über {@link sashFrames}
|
||||
* ausgedrückt statt über eine Diagonale quer über die Box.
|
||||
*/
|
||||
sashOpeningLines: [Vec2, Vec2][];
|
||||
/**
|
||||
* Stulp-/Flügelstoss-Marken (SIA-„kleines Quadrat mittig", Figur 37/38): je
|
||||
* Flügel-Trennung ein kleines Rechteck-Polygon auf der Glasebene, das den
|
||||
* Anschlag der zwei zusammenstossenden Flügelprofile darstellt. Bei „mittel"
|
||||
* ein Quadrat je Stoss, bei „fein" zwei (die beiden Stulpprofile). „grob":
|
||||
* leer. Zählt zur "Fenster"-Linien-Kategorie (Flügel/Sprossen), NICHT zum
|
||||
* Blendrahmen — separat von {@link jambMarks} steuerbar. Der Aufrufer
|
||||
* zeichnet sie als dünne Umriss-Rechtecke.
|
||||
*/
|
||||
meetingMarks: Vec2[][];
|
||||
/**
|
||||
* Blendrahmen-Querschnittsblöcke an den beiden Laibungs-Enden (ein Block je
|
||||
* Seite, unabhängig von Flügelanzahl/Detailgrad) — Teil des Blendrahmens,
|
||||
* zählt zur "Rahmen"-Linien-Kategorie (im Unterschied zu {@link meetingMarks},
|
||||
* die an inneren Flügelstössen sitzen und zur "Fenster"-Kategorie zählen).
|
||||
*/
|
||||
jambMarks: Vec2[][];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render-Parameter des Fensters für die reiche 2D-Symbolik (aus dem
|
||||
* referenzierten {@link WindowType}): Flügeltabelle, Profilbreite, Rahmentiefe
|
||||
* und Schichteinzug. Fehlt der Spec (kein Typ auflösbar), zeichnet
|
||||
* {@link windowSymbol} das schlichte Alt-Symbol (`o.wingCount`, volle Wanddicke).
|
||||
*/
|
||||
export interface WindowRenderSpec {
|
||||
sashes: SashDef[];
|
||||
/** Sichtbare Profilbreite (Meter) von Blend-/Flügelrahmen in der Öffnungsebene. */
|
||||
frameWidth: number;
|
||||
/** Rahmentiefe quer zur Wand (Meter); fehlt ⇒ {@link DEFAULT_FRAME_DEPTH}. */
|
||||
frameDepth?: number;
|
||||
/** Schichteinzug: Abstand der Rahmen-Vorderkante von {@link insetFace} (Meter). */
|
||||
insetFromFace?: number;
|
||||
/** Bezugsfläche des Schichteinzugs; Default "aussen". */
|
||||
insetFace?: "aussen" | "innen";
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst die Fenster-Symbolik auf: ein Rahmen-Rechteck über die Lücke (volle
|
||||
* Wanddicke) plus 1–3 Glaslinien (dünne parallele Linien in der Wandmitte,
|
||||
* `glassCount` steuert die Anzahl) plus optionale Flügel-/Pfosten-Trennlinien
|
||||
* und Öffnungsandeutungen je Flügel.
|
||||
*
|
||||
* `sashes` (optional) ist die aufgelöste Flügeltabelle (siehe
|
||||
* `sashesOfWindowType`) EINES referenzierten Fenstertyps. Fehlt sie (kein Typ
|
||||
* referenziert/auflösbar), bleibt die Mittelpfosten-Berechnung beim
|
||||
* BISHERIGEN Verhalten — `o.wingCount` gleichmäßig verteilt, KEINE
|
||||
* Öffnungsandeutungen — exakt wie vor dieser Erweiterung (Rückwärtskompatibilität).
|
||||
*
|
||||
* Die Berechnung läuft im Rust-Kern (`src-tauri/core/src/opening_geom.rs`, [K3a]); diese Funktion
|
||||
* ist die Fassade mit unveränderter Signatur.
|
||||
*/
|
||||
export function windowSymbol(
|
||||
project: Project,
|
||||
wall: Wall,
|
||||
o: Opening,
|
||||
glassCount: number,
|
||||
spec?: WindowRenderSpec,
|
||||
detail: "grob" | "mittel" | "fein" = "fein",
|
||||
): WindowSymbol | null {
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const b: number[] = [
|
||||
wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, wallReferenceOffset(wall, total),
|
||||
o.position, o.width, glassCount, o.wingCount ?? Number.NaN,
|
||||
detail === "grob" ? 0 : detail === "mittel" ? 1 : 2,
|
||||
spec ? 1 : 0,
|
||||
spec?.frameWidth ?? 0, spec?.frameDepth ?? Number.NaN, spec?.insetFromFace ?? Number.NaN,
|
||||
spec?.insetFace === "innen" ? 1 : 0,
|
||||
spec?.sashes.length ?? 0,
|
||||
];
|
||||
for (const s of spec?.sashes ?? []) {
|
||||
b.push(s.kind === "pfosten" ? 1 : 0, s.autoWidth === false ? 0 : 1, s.width ?? Number.NaN, s.postWidth ?? Number.NaN,
|
||||
s.opening && s.opening !== "fest" ? 1 : 0);
|
||||
}
|
||||
const f = core().window_symbol_flat(Float64Array.from(b));
|
||||
if (f.length === 0) return null;
|
||||
let i = 1;
|
||||
const pt = (): Vec2 => ({ x: f[i++], y: f[i++] });
|
||||
const frame = [pt(), pt(), pt(), pt()];
|
||||
const segs = (): [Vec2, Vec2][] => {
|
||||
const n = f[i++];
|
||||
const out: [Vec2, Vec2][] = [];
|
||||
for (let k = 0; k < n; k++) out.push([pt(), pt()]);
|
||||
return out;
|
||||
};
|
||||
const rings = (): Vec2[][] => {
|
||||
const n = f[i++];
|
||||
const out: Vec2[][] = [];
|
||||
for (let k = 0; k < n; k++) {
|
||||
const m = f[i++];
|
||||
out.push(Array.from({ length: m }, pt));
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const glassLines = segs();
|
||||
const mullionLines = segs();
|
||||
const sashFrames = rings();
|
||||
const meetingMarks = rings();
|
||||
const jambMarks = rings();
|
||||
return { frame, glassLines, mullionLines, sashFrames, sashOpeningLines: [], meetingMarks, jambMarks };
|
||||
}
|
||||
+2
-293
@@ -5,9 +5,8 @@
|
||||
// 3D-Meshes, sondern direkt aus den Parametern (Wandachsen, Schichtaufbau,
|
||||
// Öffnungen) — exakt, schnell, sauber.
|
||||
//
|
||||
// Diese Datei ist nur noch der ORCHESTRATOR: `generatePlan()`/
|
||||
// `generateSectionPlan()` sowie die `resolve*SectionStyle`-Helfer (für den
|
||||
// Schnitt-Pfad, `toSection.ts`). Die Bauteil-Domänen (Decken, Dächer, Räume,
|
||||
// Diese Datei ist nur noch der ORCHESTRATOR `generatePlan()` (Schnitt und Ansicht:
|
||||
// `toSection.ts`/`toElevation.ts`, im Kern). Die Bauteil-Domänen (Decken, Dächer, Räume,
|
||||
// Wände mit Öffnungen, Treppen, Stützen, Extrusionen, Kontext, Schnittführung)
|
||||
// rechnet der Rust-Kern auf dem Projekt-Dokument (`src-tauri/core/src/plan/`,
|
||||
// Abfrage `planDomains`, [K3d]) und liefert fertige `Primitive` — auch die freie
|
||||
@@ -17,24 +16,14 @@
|
||||
// leben in `generatePlan/shared.ts`.
|
||||
|
||||
import type {
|
||||
Ceiling,
|
||||
Component,
|
||||
ContextImage,
|
||||
ContextObject,
|
||||
Drawing2D,
|
||||
Project,
|
||||
Vec2,
|
||||
Wall,
|
||||
} from "../model/types";
|
||||
import {
|
||||
getCeilingType,
|
||||
getComponent,
|
||||
getLayerCategory,
|
||||
getWallType,
|
||||
} from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { decodePlanBuf, type DecodedPlanBuf } from "./planBuf";
|
||||
import type { SectionOutput } from "./toSection";
|
||||
import {
|
||||
HATCH_INK,
|
||||
HATCH_PAPER,
|
||||
@@ -63,91 +52,6 @@ import { layersStyleSig } from "./generatePlan/layerSig";
|
||||
export { HATCH_INK, HATCH_PAPER, resolveBackground, resolveForeground, resolveHatch, resolveHatchId };
|
||||
export type { CategoryDisplayResolver, DetailLevel, HatchRender, Primitive };
|
||||
|
||||
/**
|
||||
* Füllfarbe + Schraffur eines aufgelösten Bauteils, fertig für eine Cut-Poché.
|
||||
*/
|
||||
export interface SectionCutStyle {
|
||||
fill: string;
|
||||
hatch: HatchRender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst das tragende Bauteil (höchste `joinPriority`) einer Wand auf und liefert
|
||||
* dessen Poché-Füllung + echte Schraffur für die Schnitt-Poché (mittel/fein).
|
||||
* Die grobe Grundriss-Poché (1:100) folgt dieser Bauteil-Regel NICHT mehr —
|
||||
* sie ist immer vollschwarz, unabhängig vom Bauteil-Pattern (SIA 400 Fig. 36,
|
||||
* s. `addWallPoche`). `null`, wenn Wandtyp oder Bauteil nicht auflösbar sind
|
||||
* (z. B. verwaistes `wallTypeId`); der Aufrufer fällt dann auf die generische
|
||||
* Schnitt-Schraffur zurück.
|
||||
*/
|
||||
export function resolveWallSectionStyle(project: Project, wall: Wall): SectionCutStyle | null {
|
||||
try {
|
||||
const wt = getWallType(project, wall);
|
||||
let best: Component | null = null;
|
||||
for (const layer of wt.layers) {
|
||||
const comp = getComponent(project, layer.componentId);
|
||||
if (!best || comp.joinPriority > best.joinPriority) best = comp;
|
||||
}
|
||||
if (!best) return null;
|
||||
const category = getLayerCategory(project, wall.categoryCode);
|
||||
const wallAngleDeg =
|
||||
(Math.atan2(wall.end.y - wall.start.y, wall.end.x - wall.start.x) * 180) / Math.PI;
|
||||
const hatchId = resolveHatchId(wall.hatchId, wall.hatchSource, category, best.hatchId) ?? best.hatchId;
|
||||
const hatch = resolveHatch(
|
||||
project,
|
||||
hatchId,
|
||||
wallAngleDeg,
|
||||
resolveForeground(best, wall.foreground, category, wall.foregroundSource),
|
||||
);
|
||||
// Poché-Hintergrund neutral (Papier) statt Bauteil-Albedo; Vollmuster → Tinte
|
||||
// (unabhängig von `hatch.color`, das jetzt den aufgelösten Vordergrund tragen
|
||||
// kann, s. {@link resolveHatch}).
|
||||
const solid = hatch.pattern === "solid";
|
||||
return {
|
||||
fill: solid ? HATCH_INK : HATCH_PAPER,
|
||||
hatch,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Löst das erste Bauteil des Deckentyps einer Decke auf — dieselbe Regel wie
|
||||
* `addCeilingPoche` für die normale Deckenpoché — und liefert dessen
|
||||
* Füllfarbe + echte Schraffur für die Schnitt-Poché. `null`, wenn Deckentyp
|
||||
* oder Bauteil nicht auflösbar sind bzw. der Deckentyp keine Schicht trägt.
|
||||
*/
|
||||
export function resolveCeilingSectionStyle(
|
||||
project: Project,
|
||||
ceiling: Ceiling,
|
||||
): SectionCutStyle | null {
|
||||
try {
|
||||
const wt = getCeilingType(project, ceiling);
|
||||
if (wt.layers.length === 0) return null;
|
||||
const comp = getComponent(project, wt.layers[0].componentId);
|
||||
const category = getLayerCategory(project, ceiling.categoryCode);
|
||||
const hatchId =
|
||||
resolveHatchId(ceiling.hatchId, ceiling.hatchSource, category, comp.hatchId) ?? comp.hatchId;
|
||||
const hatch = resolveHatch(
|
||||
project,
|
||||
hatchId,
|
||||
undefined,
|
||||
resolveForeground(comp, ceiling.foreground, category, ceiling.foregroundSource),
|
||||
);
|
||||
// Poché-Hintergrund neutral (Papier) statt Bauteil-Albedo; Vollmuster → Tinte
|
||||
// — dieselbe Neutralisierung wie {@link resolveWallSectionStyle}, damit die
|
||||
// geschnittene Decke nicht als andersfarbige Fläche gegenüber der Wand auffällt.
|
||||
const solid = hatch.pattern === "solid";
|
||||
return {
|
||||
fill: solid ? HATCH_INK : HATCH_PAPER,
|
||||
hatch,
|
||||
};
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Ein georeferenziertes Hintergrund-Rasterbild (Luftbild) im Grundriss —
|
||||
* Modell-Meter-Rechteck [min..max], das die interaktive Ansicht UNTER der
|
||||
* Geometrie zeichnet (Kontext-Schicht, `ContextImage`). NICHT Teil der
|
||||
@@ -597,201 +501,6 @@ export function generateVisibleLevelsPlan(
|
||||
);
|
||||
}
|
||||
|
||||
// ── Schnitt/Ansicht (abgeleitete Projektion aus render3d::section) ──────────────
|
||||
// Die Rohdaten (Cut-Polygone + sichtbare/verdeckte projizierte Kanten) liefert
|
||||
// der WASM-Extraktor (plan/toSection.ts → section.rs). Hier werden sie 1:1 in
|
||||
// die BESTEHENDEN Plan-Primitive übersetzt — kein neues Primitiv nötig:
|
||||
// • Cut-Polygon → `polygon` (kräftige Poché-Umrisslinie + Schnitt-Schraffur),
|
||||
// • sichtbare Kante → `line` (durchgezogen),
|
||||
// • verdeckte Kante → `line` (gestrichelt).
|
||||
// Damit rendern PlanView (SVG) UND toRenderScene (Engine/WASM-2D) den Schnitt
|
||||
// ohne jede Sonderbehandlung, mit voller Papier-mm-/Parität-Infrastruktur.
|
||||
|
||||
/** Tinte der Schnitt-Poché-Umrisslinie + Schraffur (dunkles Grau). */
|
||||
const SECTION_INK = "#1f242c";
|
||||
/** Tinte der sichtbaren Ansichtskanten. */
|
||||
const SECTION_VISIBLE_INK = "#2b3039";
|
||||
/** Tinte der verdeckten (gestrichelten) Ansichtskanten (etwas heller). */
|
||||
const SECTION_HIDDEN_INK = "#8a929c";
|
||||
/** Strichstärke der Cut-Poché-Umrisslinie (mm Papier, kräftig wie eine Wand). */
|
||||
const SECTION_CUT_OUTLINE_MM = 0.35;
|
||||
/** Strichstärke sichtbarer Ansichtskanten (mm Papier). */
|
||||
const SECTION_VISIBLE_MM = 0.18;
|
||||
/** Strichstärke der Bodenlinie unter dem Schnitt (mm Papier, wie in der Ansicht). */
|
||||
const SECTION_GROUND_MM = 0.5;
|
||||
/** Strichstärke verdeckter Ansichtskanten (mm Papier, dünner). */
|
||||
const SECTION_HIDDEN_MM = 0.13;
|
||||
/** Strichmuster verdeckter Kanten (mm Papier). */
|
||||
const SECTION_HIDDEN_DASH: number[] = [0.12, 0.08];
|
||||
|
||||
/**
|
||||
* Schnitt-Schraffur der Cut-Flächen (diagonale Poché wie ein Wandschnitt) —
|
||||
* Fallback, wenn `toSection.ts` das Quell-Bauteil einer Cut-Fläche NICHT
|
||||
* auflösen konnte (siehe `attachCutStyles`). Vordergrund fest `HATCH_INK`,
|
||||
* damit auch der Fallback monochrom bleibt statt der rohen 3D-Albedo-Farbe.
|
||||
*/
|
||||
const SECTION_HATCH: HatchRender = {
|
||||
pattern: "diagonal",
|
||||
scale: 1,
|
||||
angle: 45,
|
||||
color: HATCH_INK,
|
||||
lineWeight: 0.13,
|
||||
dash: null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Baut aus einem {@link SectionOutput} (render3d::section, (u, v)-Meter) den
|
||||
* Plan eines Schnitts/einer Ansicht. `u` wird zur Plan-X, `v` (absolute Höhe)
|
||||
* zur Plan-Y — die PlanView zeigt Y nach oben, also erscheint der Schnitt
|
||||
* aufrecht. Rein darstellend; kennt das Projekt NICHT direkt — `visibleCodes`/
|
||||
* `categoryDisplay` (optional) filtern/dimmen jedes Cut-Band trotzdem über
|
||||
* `cp.categoryCode` (von `toSection.ts::attachCutStyles` aufgelöst), damit das
|
||||
* Ebenen-Panel auch im Schnitt/in der Ansicht wirkt, wie im Grundriss. Ein
|
||||
* Band ohne `categoryCode` (unauflösbares Bauteil) bleibt immer sichtbar.
|
||||
*/
|
||||
export function generateSectionPlan(
|
||||
output: SectionOutput,
|
||||
mono = false,
|
||||
opts: {
|
||||
hiddenLines?: boolean;
|
||||
visibleCodes?: Set<string>;
|
||||
categoryDisplay?: CategoryDisplayResolver;
|
||||
} = {},
|
||||
): Plan {
|
||||
const primitives: Primitive[] = [];
|
||||
let minX = Infinity,
|
||||
minY = Infinity,
|
||||
maxX = -Infinity,
|
||||
maxY = -Infinity;
|
||||
const acc = (x: number, y: number) => {
|
||||
if (x < minX) minX = x;
|
||||
if (y < minY) minY = y;
|
||||
if (x > maxX) maxX = x;
|
||||
if (y > maxY) maxY = y;
|
||||
};
|
||||
const catDisplay = opts.categoryDisplay ?? SHOW_ALL;
|
||||
|
||||
// Cut-Polygone: gefüllte Poché-Fläche + Schnitt-Schraffur + kräftige
|
||||
// Umrisslinie — wie eine geschnittene Wand im Grundriss. `toSection.ts`
|
||||
// (computeSection) löst je Cut-Polygon bereits das Quell-Bauteil auf und
|
||||
// hängt dessen echte Füllfarbe/Schraffur an (`cp.fill`/`cp.hatch`); fehlt
|
||||
// diese Auflösung (Fallback, z. B. verwaistes Bauteil), greift die generische
|
||||
// Schnitt-Schraffur (`SECTION_HATCH`, HATCH_PAPER-Hintergrund) — NICHT die rohe
|
||||
// Albedo-Farbe aus dem 3D-Modell (Nutzer-Vorgabe 2026-07-04: einheitlich
|
||||
// monochrom, auch im Fallback-Fall).
|
||||
for (const cp of output.cutPolygons) {
|
||||
if (cp.pts.length < 3) continue;
|
||||
// Ebenen-Panel-Sichtbarkeit: nur wenn das Quell-Bauteil aufgelöst werden
|
||||
// konnte (categoryCode gesetzt) — sonst (Fallback) immer zeichnen.
|
||||
if (cp.categoryCode !== undefined) {
|
||||
if (opts.visibleCodes && !opts.visibleCodes.has(cp.categoryCode)) continue;
|
||||
if (!catDisplay(cp.categoryCode).render) continue;
|
||||
}
|
||||
const pts: Vec2[] = cp.pts.map(([u, v]) => {
|
||||
acc(u, v);
|
||||
return { x: u, y: v };
|
||||
});
|
||||
const fill = cp.fill ?? HATCH_PAPER;
|
||||
const hatch = cp.hatch ?? SECTION_HATCH;
|
||||
// Mono: neutrale Poché — Papier statt Bauteilfarbe, Schraffur-Musterlinien →
|
||||
// Tinte. Eine dunkle SIA-Vollpoché ("solid") BLEIBT jedoch dunkel
|
||||
// (Tinte bleibt Tinte, Papier bleibt Papier).
|
||||
const solid = hatch.pattern === "solid";
|
||||
const monoFill = solid ? HATCH_INK : HATCH_PAPER;
|
||||
const monoHatch =
|
||||
solid ? hatch : hatch.pattern !== "none" ? { ...hatch, color: SECTION_INK } : hatch;
|
||||
// Auswahl im Schnitt: das QUELL-Element (via cp.sourceId + component.kind) als
|
||||
// wallId/ceilingId/roofId ans Polygon hängen — so wählt ein Klick auf das
|
||||
// geschnittene Bauteil im Schnitt exakt jene Wand/Decke/Dach im Modell, und
|
||||
// die bestehende PlanView-Pick-/Highlight-Logik greift ohne Sonderfall.
|
||||
const kind = cp.component.kind;
|
||||
const sourceId = cp.sourceId;
|
||||
primitives.push({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
fill: mono ? monoFill : fill,
|
||||
stroke: SECTION_INK,
|
||||
strokeWidthMm: SECTION_CUT_OUTLINE_MM,
|
||||
hatch: mono ? monoHatch : hatch,
|
||||
wallId: kind === "wall" ? sourceId : undefined,
|
||||
ceilingId: kind === "slab" && !cp.stairId ? sourceId : undefined,
|
||||
roofId: kind === "roof" ? sourceId : undefined,
|
||||
stairId: cp.stairId,
|
||||
extrudedSolidId: kind === "body" ? sourceId : undefined,
|
||||
noStrokeEdges: cp.noStrokeEdges,
|
||||
greyed: cp.categoryCode !== undefined && catDisplay(cp.categoryCode).greyed,
|
||||
});
|
||||
}
|
||||
|
||||
// Geländelinie(n): kräftige Linie, über Kategorie filterbar.
|
||||
for (const pr of output.profiles ?? []) {
|
||||
if (pr.categoryCode !== undefined) {
|
||||
if (opts.visibleCodes && !opts.visibleCodes.has(pr.categoryCode)) continue;
|
||||
if (!catDisplay(pr.categoryCode).render) continue;
|
||||
}
|
||||
for (let i = 0; i + 1 < pr.pts.length; i++) {
|
||||
const [a, b] = [pr.pts[i], pr.pts[i + 1]];
|
||||
acc(a[0], a[1]);
|
||||
acc(b[0], b[1]);
|
||||
primitives.push({
|
||||
kind: "line",
|
||||
a: { x: a[0], y: a[1] },
|
||||
b: { x: b[0], y: b[1] },
|
||||
cls: "section-terrain",
|
||||
weightMm: SECTION_GROUND_MM,
|
||||
color: SECTION_INK,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Verdeckte Kanten zuerst (liegen unter den sichtbaren), gestrichelt —
|
||||
// Standard AUS (VW-üblich): sie legen sich sonst als blasses Liniengewirr
|
||||
// über Poché und Ansichtskanten. Zuschaltbar je Schnitt-/Ansichts-Ebene.
|
||||
for (const e of opts.hiddenLines ? output.hiddenEdges : []) {
|
||||
acc(e.a[0], e.a[1]);
|
||||
acc(e.b[0], e.b[1]);
|
||||
primitives.push({
|
||||
kind: "line",
|
||||
a: { x: e.a[0], y: e.a[1] },
|
||||
b: { x: e.b[0], y: e.b[1] },
|
||||
cls: "section-hidden",
|
||||
weightMm: SECTION_HIDDEN_MM,
|
||||
dash: SECTION_HIDDEN_DASH,
|
||||
color: SECTION_HIDDEN_INK,
|
||||
});
|
||||
}
|
||||
|
||||
// Sichtbare Ansichtskanten, durchgezogen.
|
||||
for (const e of output.visibleEdges) {
|
||||
acc(e.a[0], e.a[1]);
|
||||
acc(e.b[0], e.b[1]);
|
||||
primitives.push({
|
||||
kind: "line",
|
||||
a: { x: e.a[0], y: e.a[1] },
|
||||
b: { x: e.b[0], y: e.b[1] },
|
||||
cls: "section-visible",
|
||||
weightMm: SECTION_VISIBLE_MM,
|
||||
color: SECTION_VISIBLE_INK,
|
||||
});
|
||||
}
|
||||
|
||||
// Bodenlinie wie in der Ansicht (toElevation.ts): kräftige Linie über die
|
||||
// volle Breite an der untersten Kante — ohne sie "schwebte" der Schnitt.
|
||||
if (isFinite(minX) && maxX > minX) {
|
||||
primitives.push({
|
||||
kind: "line",
|
||||
a: { x: minX, y: minY },
|
||||
b: { x: maxX, y: minY },
|
||||
cls: "section-ground",
|
||||
weightMm: SECTION_GROUND_MM,
|
||||
color: SECTION_INK,
|
||||
});
|
||||
}
|
||||
|
||||
if (!isFinite(minX)) return { primitives, bounds: { minX: 0, minY: 0, maxX: 1, maxY: 1 } };
|
||||
return { primitives, bounds: { minX, minY, maxX, maxY } };
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-Pass für den Schwarz-Weiss-Modus: ersetzt alle Farb-Informationen der
|
||||
* Plan-Primitive durch einheitliche Tinte/Weiss. Wirkt in-place.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Gemeinsame Grundlage des Grundriss-Generators: das `Primitive`-Vokabular
|
||||
// (das EINZIGE Austauschformat zwischen `generatePlan()`/`generateSectionPlan()`
|
||||
// (das EINZIGE Austauschformat zwischen `generatePlan()`, Schnitt/Ansicht
|
||||
// und den Domänen — unter `generatePlan/` in TS, die meisten im Rust-Kern mit
|
||||
// derselben JSON-Form, `src-tauri/core/src/plan/prim.rs`), die By-Layer/By-Object-
|
||||
// Attribut-Auflösung (`resolve*`) sowie die Papier-mm-/Tinten-Konstanten, die
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
// Ebenen-Panel-Sichtbarkeit im Schnitt/in der Ansicht: generateSectionPlan
|
||||
// filtert/dimmt jedes Cut-Band über `cp.categoryCode` (visibleCodes/
|
||||
// categoryDisplay) — genau wie jedes andere Bauteil im Grundriss. Vorher
|
||||
// wirkte das Ebenen-Panel im Schnitt/in der Ansicht gar nicht (Nutzer-Report).
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { generateSectionPlan } from "./generatePlan";
|
||||
import type { CategoryDisplayResolver } from "./generatePlan";
|
||||
import type { SectionCutPolygon, SectionOutput } from "./toSection";
|
||||
|
||||
function cut(kind: "wall" | "slab" | "roof", categoryCode: string | undefined): SectionCutPolygon {
|
||||
return {
|
||||
component: { kind, index: 0 },
|
||||
color: [0.5, 0.5, 0.5],
|
||||
pts: [
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 2],
|
||||
[0, 2],
|
||||
],
|
||||
sourceId: "X1",
|
||||
categoryCode,
|
||||
};
|
||||
}
|
||||
|
||||
const SHOW_ALL: CategoryDisplayResolver = () => ({ render: true, greyed: false, locked: false });
|
||||
|
||||
describe("generateSectionPlan — Kategorie-Sichtbarkeit (Ebenen-Panel)", () => {
|
||||
it("lässt ein Band mit kategorie-verstecktem categoryCode weg (visibleCodes ohne den Code)", () => {
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", "20")],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const polys = generateSectionPlan(output, false, {
|
||||
visibleCodes: new Set(["30"]), // "20" fehlt
|
||||
categoryDisplay: SHOW_ALL,
|
||||
}).primitives.filter((p) => p.kind === "polygon");
|
||||
expect(polys.length).toBe(0);
|
||||
});
|
||||
|
||||
it("lässt ein Band weg, wenn categoryDisplay(code).render=false liefert", () => {
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", "20")],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const hideCat: CategoryDisplayResolver = () => ({ render: false, greyed: false, locked: false });
|
||||
const polys = generateSectionPlan(output, false, {
|
||||
visibleCodes: new Set(["20"]),
|
||||
categoryDisplay: hideCat,
|
||||
}).primitives.filter((p) => p.kind === "polygon");
|
||||
expect(polys.length).toBe(0);
|
||||
});
|
||||
|
||||
it("dimmt (greyed) ein sichtbares Band, wenn categoryDisplay greyed=true liefert", () => {
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", "20")],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const greyCat: CategoryDisplayResolver = () => ({ render: true, greyed: true, locked: false });
|
||||
const polys = generateSectionPlan(output, false, {
|
||||
visibleCodes: new Set(["20"]),
|
||||
categoryDisplay: greyCat,
|
||||
}).primitives.filter(
|
||||
(p): p is Extract<typeof p, { kind: "polygon" }> => p.kind === "polygon",
|
||||
);
|
||||
expect(polys[0]?.greyed).toBe(true);
|
||||
});
|
||||
|
||||
it("zeichnet ein Band OHNE categoryCode immer (unauflösbares Bauteil, Fallback)", () => {
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", undefined)],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const hideAll: CategoryDisplayResolver = () => ({ render: false, greyed: false, locked: false });
|
||||
const polys = generateSectionPlan(output, false, {
|
||||
visibleCodes: new Set([]),
|
||||
categoryDisplay: hideAll,
|
||||
}).primitives.filter((p) => p.kind === "polygon");
|
||||
expect(polys.length).toBe(1);
|
||||
});
|
||||
|
||||
it("ohne opts (Export-/Print-Pfad) bleibt jedes Band sichtbar wie bisher", () => {
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", "20")],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const polys = generateSectionPlan(output).primitives.filter((p) => p.kind === "polygon");
|
||||
expect(polys.length).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -1,58 +0,0 @@
|
||||
// Auswahl im Schnitt-View: generateSectionPlan hängt jedem Cut-Polygon die
|
||||
// Quell-Element-Id (cp.sourceId) je nach component.kind als wallId/ceilingId/
|
||||
// roofId ans Plan-Polygon — damit ein Klick im Schnitt das Bauteil im Modell
|
||||
// wählt (die bestehende PlanView-Pick-Logik greift dann ohne Sonderfall).
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { generateSectionPlan } from "./generatePlan";
|
||||
import type { SectionCutPolygon, SectionOutput } from "./toSection";
|
||||
|
||||
function cut(kind: "wall" | "slab" | "roof", sourceId: string): SectionCutPolygon {
|
||||
return {
|
||||
component: { kind, index: 0 },
|
||||
color: [0.5, 0.5, 0.5],
|
||||
pts: [
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 2],
|
||||
[0, 2],
|
||||
],
|
||||
sourceId,
|
||||
};
|
||||
}
|
||||
|
||||
const output: SectionOutput = {
|
||||
cutPolygons: [cut("wall", "W1"), cut("slab", "C1"), cut("roof", "R1")],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
|
||||
describe("generateSectionPlan — Auswahl-Ids am Cut-Polygon", () => {
|
||||
it("schreibt sourceId je component.kind als wallId/ceilingId/roofId", () => {
|
||||
const polys = generateSectionPlan(output).primitives.filter(
|
||||
(p): p is Extract<typeof p, { kind: "polygon" }> => p.kind === "polygon",
|
||||
);
|
||||
const wall = polys.find((p) => p.wallId === "W1");
|
||||
const ceiling = polys.find((p) => p.ceilingId === "C1");
|
||||
const roof = polys.find((p) => p.roofId === "R1");
|
||||
expect(wall).toBeTruthy();
|
||||
expect(ceiling).toBeTruthy();
|
||||
expect(roof).toBeTruthy();
|
||||
// Kanäle schließen sich je Polygon aus (eine Wand trägt keine ceilingId).
|
||||
expect(wall?.ceilingId).toBeUndefined();
|
||||
expect(wall?.roofId).toBeUndefined();
|
||||
expect(ceiling?.wallId).toBeUndefined();
|
||||
});
|
||||
|
||||
it("lässt die Ids weg, wenn cp.sourceId fehlt (unauflösbares Bauteil)", () => {
|
||||
const noId: SectionOutput = {
|
||||
cutPolygons: [{ ...cut("wall", "W1"), sourceId: undefined }],
|
||||
visibleEdges: [],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
const poly = generateSectionPlan(noId).primitives.find(
|
||||
(p): p is Extract<typeof p, { kind: "polygon" }> => p.kind === "polygon",
|
||||
);
|
||||
expect(poly?.wallId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cutMeshWithPlane, ringsToPolygons, type Pt2 } from "./meshSection";
|
||||
|
||||
const ringArea = (r: Pt2[]): number => {
|
||||
let a = 0;
|
||||
for (let i = 0; i < r.length; i++) {
|
||||
const p = r[i];
|
||||
const q = r[(i + 1) % r.length];
|
||||
a += p[0] * q[1] - q[0] * p[1];
|
||||
}
|
||||
return a / 2;
|
||||
};
|
||||
|
||||
/** Quader als geschlossenes Netz (12 Dreiecke, aussen orientiert). `inward` kehrt um (Hohlraum). */
|
||||
function box(x0: number, y0: number, z0: number, x1: number, y1: number, z1: number, inward = false) {
|
||||
const p = [x0, y0, z0, x1, y0, z0, x1, y1, z0, x0, y1, z0, x0, y0, z1, x1, y0, z1, x1, y1, z1, x0, y1, z1];
|
||||
const f = [0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 0, 4, 3, 4, 7];
|
||||
return { p, f: inward ? f.map((_, i) => f[i - (i % 3) + [0, 2, 1][i % 3]]) : f };
|
||||
}
|
||||
const merge = (a: ReturnType<typeof box>, b: ReturnType<typeof box>) => ({ p: [...a.p, ...b.p], f: [...a.f, ...b.f.map((i) => i + a.p.length / 3)] });
|
||||
|
||||
describe("cutMeshWithPlane", () => {
|
||||
it("senkrechter Schnitt durch einen Quader: ein Ring, Fläche = Breite × Höhe", () => {
|
||||
const b = box(0, 0, 0, 4, 2, 3);
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "vertical", point: { x: 0, y: 1 }, dir: { x: 1, y: 0 } });
|
||||
expect(r.rings).toHaveLength(1);
|
||||
expect(r.lines).toHaveLength(0);
|
||||
expect(Math.abs(ringArea(r.rings[0]))).toBeCloseTo(4 * 3, 9);
|
||||
});
|
||||
|
||||
it("waagrechter Schnitt: Grundriss-Ring (x,y)", () => {
|
||||
const b = box(1, 1, 0, 4, 3, 5);
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "horizontal", z: 2.5 });
|
||||
expect(r.rings).toHaveLength(1);
|
||||
expect(Math.abs(ringArea(r.rings[0]))).toBeCloseTo(3 * 2, 9);
|
||||
});
|
||||
|
||||
it("Ebene exakt auf Ecken/Kanten (Raster!) schliesst trotzdem sauber", () => {
|
||||
const b = box(0, 0, 0, 4, 2, 3);
|
||||
for (const y of [0, 2]) {
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "vertical", point: { x: 0, y }, dir: { x: 1, y: 0 } });
|
||||
expect(r.lines).toHaveLength(0);
|
||||
}
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "horizontal", z: 3 });
|
||||
expect(r.lines).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("Ebene schneidet nicht: leer", () => {
|
||||
const b = box(0, 0, 0, 1, 1, 1);
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "horizontal", z: 10 });
|
||||
expect(r.rings).toEqual([]);
|
||||
expect(r.lines).toEqual([]);
|
||||
});
|
||||
|
||||
it("Hohlkörper: Aussenring + Loch", () => {
|
||||
const m = merge(box(0, 0, 0, 10, 10, 10), box(3, 3, 3, 7, 7, 7, true));
|
||||
const r = cutMeshWithPlane(m.p, m.f, { kind: "horizontal", z: 5 });
|
||||
expect(r.rings).toHaveLength(2);
|
||||
const polys = ringsToPolygons(r.rings);
|
||||
expect(polys).toHaveLength(1);
|
||||
expect(polys[0]).toHaveLength(2);
|
||||
const area = Math.abs(ringArea(polys[0][0])) - Math.abs(ringArea(polys[0][1]));
|
||||
expect(area).toBeCloseTo(100 - 16, 9);
|
||||
});
|
||||
|
||||
it("zwei getrennte Körper: zwei Polygone ohne Löcher", () => {
|
||||
const m = merge(box(0, 0, 0, 2, 2, 2), box(5, 0, 0, 7, 2, 2));
|
||||
const polys = ringsToPolygons(cutMeshWithPlane(m.p, m.f, { kind: "horizontal", z: 1 }).rings);
|
||||
expect(polys).toHaveLength(2);
|
||||
expect(polys.every((p) => p.length === 1)).toBe(true);
|
||||
});
|
||||
|
||||
it("offenes Netz (Gelände): Linienzug statt Ring, Höhe als v", () => {
|
||||
// Zwei Dreiecke, die eine geneigte Fläche z = x bilden (x 0..4, y 0..4).
|
||||
const p = [0, 0, 0, 4, 0, 4, 4, 4, 4, 0, 4, 0];
|
||||
const f = [0, 1, 2, 0, 2, 3];
|
||||
const r = cutMeshWithPlane(p, f, { kind: "vertical", point: { x: 0, y: 2 }, dir: { x: 1, y: 0 } });
|
||||
expect(r.rings).toEqual([]);
|
||||
expect(r.lines).toHaveLength(1);
|
||||
const line = r.lines[0];
|
||||
const first = line[0];
|
||||
const last = line[line.length - 1];
|
||||
expect(Math.min(first[0], last[0])).toBeCloseTo(0, 9);
|
||||
expect(Math.max(first[0], last[0])).toBeCloseTo(4, 9);
|
||||
// v = z = u auf dieser Fläche
|
||||
for (const [u, v] of line) expect(v).toBeCloseTo(u, 9);
|
||||
});
|
||||
|
||||
it("schräge Schnittrichtung", () => {
|
||||
const b = box(0, 0, 0, 2, 2, 2);
|
||||
const s = Math.SQRT1_2;
|
||||
const r = cutMeshWithPlane(b.p, b.f, { kind: "vertical", point: { x: 0, y: 0 }, dir: { x: s, y: s } });
|
||||
expect(r.rings).toHaveLength(1);
|
||||
// Diagonale des Quaders: Länge 2√2, Höhe 2
|
||||
expect(Math.abs(ringArea(r.rings[0]))).toBeCloseTo(2 * Math.SQRT2 * 2, 6);
|
||||
});
|
||||
});
|
||||
@@ -1,96 +0,0 @@
|
||||
// Ebenenschnitt beliebiger Dreiecksnetze (docs/boolean-geometrie-plan.md, Baustein 1 / [G1]).
|
||||
//
|
||||
// Schneidet ein Netz (Modell-Koordinaten x, y, z = Höhe — wie `ImportedMesh`/`TerrainMesh`/truck-
|
||||
// Meshes) mit einer SENKRECHTEN Ebene (Schnitt) oder einer WAAGRECHTEN Ebene (Grundriss auf
|
||||
// Schnitthöhe) und liefert Linienzüge bzw. Ringe in den Ebenen-Koordinaten:
|
||||
// • senkrecht: (u, v) wie die Schnitt-Pipeline (u entlang der Ebene, v = Höhe),
|
||||
// • waagrecht: (x, y).
|
||||
// Geschlossene Netze (Körper) ergeben geschlossene Ringe → Polygone mit Löchern; offene Netze
|
||||
// (Gelände) ergeben offene Linienzüge (Geländelinie im Schnitt).
|
||||
//
|
||||
// Die Rechnung liegt im Rust-Kern (`src-tauri/core/src/mesh_section.rs`, [K3c]); hier nur die
|
||||
// Fassade mit unveränderter Signatur.
|
||||
|
||||
import { core } from "../engine/coreWasm";
|
||||
|
||||
export type Pt2 = [number, number];
|
||||
|
||||
export interface CutResult {
|
||||
/** Geschlossene Ringe (Körper). */
|
||||
rings: Pt2[][];
|
||||
/** Offene Linienzüge (offene Netze, z. B. Gelände). */
|
||||
lines: Pt2[][];
|
||||
}
|
||||
|
||||
/** Ebene durch `point` (Modell x,y) in Richtung `dir` (Einheitsvektor): senkrechter Schnitt. */
|
||||
export interface VerticalPlane {
|
||||
kind: "vertical";
|
||||
point: { x: number; y: number };
|
||||
dir: { x: number; y: number };
|
||||
}
|
||||
/** Waagrechte Ebene auf Höhe `z`. */
|
||||
export interface HorizontalPlane {
|
||||
kind: "horizontal";
|
||||
z: number;
|
||||
}
|
||||
export type CutPlane = VerticalPlane | HorizontalPlane;
|
||||
|
||||
/** Liest `[n, (k, u, v …) × n]` ab `i` (Index wandert mit). */
|
||||
function readRings(f: Float64Array, at: { i: number }): Pt2[][] {
|
||||
const out: Pt2[][] = [];
|
||||
for (let k = 0, n = f[at.i++]; k < n; k++) {
|
||||
const count = f[at.i++];
|
||||
const ring = new Array<Pt2>(count);
|
||||
for (let j = 0; j < count; j++, at.i += 2) ring[j] = [f[at.i], f[at.i + 1]];
|
||||
out.push(ring);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schneidet das Netz mit `plane`. `positions` flach [x,y,z,…], `indices` je 3 ein Dreieck.
|
||||
* Entartete Segmente (Länge ~0) werden verworfen.
|
||||
*/
|
||||
export function cutMeshWithPlane(positions: ArrayLike<number>, indices: ArrayLike<number>, plane: CutPlane): CutResult {
|
||||
const pl =
|
||||
plane.kind === "vertical"
|
||||
? [0, plane.point.x, plane.point.y, plane.dir.x, plane.dir.y]
|
||||
: [1, plane.z];
|
||||
const f = core().mesh_section_cut_flat(Float64Array.from(positions), Float64Array.from(indices), Float64Array.from(pl));
|
||||
if (f.length === 0) return { rings: [], lines: [] };
|
||||
const at = { i: 0 };
|
||||
const rings = readRings(f, at);
|
||||
const lines = readRings(f, at);
|
||||
return { rings, lines };
|
||||
}
|
||||
|
||||
/** Ring mit Löchern (Aussenring zuerst, dann Löcher). */
|
||||
export type RingSet = Pt2[][];
|
||||
|
||||
/**
|
||||
* Ordnet geschlossene Ringe zu Aussenring + Löchern (Schachtelungstiefe gerade = aussen, ungerade =
|
||||
* Loch). Unabhängig vom Umlaufsinn. Aussenringe zuerst-gross; Löcher folgen ihrem Aussenring.
|
||||
*/
|
||||
export function ringsToPolygons(rings: Pt2[][]): RingSet[] {
|
||||
const b: number[] = [rings.length];
|
||||
for (const r of rings) {
|
||||
b.push(r.length);
|
||||
for (const p of r) b.push(p[0], p[1]);
|
||||
}
|
||||
const f = core().mesh_section_polygons_flat(Float64Array.from(b));
|
||||
if (f.length === 0) return [];
|
||||
const at = { i: 1 };
|
||||
const out: RingSet[] = [];
|
||||
for (let k = 0; k < f[0]; k++) {
|
||||
const nr = f[at.i++];
|
||||
const set: RingSet = [];
|
||||
for (let r = 0; r < nr; r++) {
|
||||
const count = f[at.i++];
|
||||
const ring = new Array<Pt2>(count);
|
||||
for (let j = 0; j < count; j++, at.i += 2) ring[j] = [f[at.i], f[at.i + 1]];
|
||||
set.push(ring);
|
||||
}
|
||||
out.push(set);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// waagrecht gedreht, die Blickrichtung zeigt im Blatt nach OBEN (Betrachter
|
||||
// steht unten, die gesehene Fassade liegt an der Unterkante des Grundrisses),
|
||||
// und die u-Achse stimmt exakt mit der des Schnitts/der Ansicht überein
|
||||
// (`sectionUAxisModel` / `elevationFrame`): ein Punkt im Grundriss liegt also
|
||||
// (`sectionUAxisModel`, im Kern `Plane::u_model` bzw. der Ansichts-Rahmen): ein Punkt im Grundriss liegt also
|
||||
// senkrecht unter seiner Projektion im Schnitt.
|
||||
//
|
||||
// Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) —
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
// Gelände und freie Körper im Schnitt ([G1]): echter Lauf über computeSection (render3d- und
|
||||
// truck-WASM aus src/engine/pkg*).
|
||||
// Gelände und freie Körper im Schnitt ([G1]): echter Lauf über computeSection/generateSectionPlan
|
||||
// (Kern, truck-WASM aus src/engine/pkgTruck).
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { setWasmBytesProvider } from "../engine/wasmSource";
|
||||
import { computeSection } from "./toSection";
|
||||
import { generateSectionPlan } from "./generatePlan";
|
||||
import { computeSection, generateSectionPlan } from "./toSection";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { ExtrudedSolid, Project, TerrainMesh } from "../model/types";
|
||||
|
||||
@@ -34,15 +33,16 @@ function terrain(): TerrainMesh {
|
||||
describe("Schnitt: Gelände und freie Körper", () => {
|
||||
it("Geländelinie als Linienzug im Schnitt, auf den Gebäudebereich begrenzt", async () => {
|
||||
const p: Project = { ...sampleProject, context: [...(sampleProject.context ?? []), terrain()] };
|
||||
const out = (await computeSection(p, section))!;
|
||||
expect(out.profiles?.length).toBeGreaterThan(0);
|
||||
const pts = out.profiles!.flatMap((x) => x.pts);
|
||||
const plan = generateSectionPlan((await computeSection(p, section))!);
|
||||
const terrainLines = plan.primitives.filter((q) => q.kind === "line" && q.cls === "section-terrain");
|
||||
expect(terrainLines.length).toBeGreaterThan(0);
|
||||
const us = terrainLines.flatMap((q) => (q.kind === "line" ? [q.a.x, q.b.x] : []));
|
||||
// Begrenzung: nicht über das ganze 40-m-Gelände, sondern Inhalt ± Rand
|
||||
const us = out.cutPolygons.flatMap((c) => c.pts.map((q) => q[0]));
|
||||
expect(Math.min(...pts.map((q) => q[0]))).toBeGreaterThanOrEqual(Math.min(...us) - 6.01);
|
||||
expect(Math.max(...pts.map((q) => q[0]))).toBeLessThanOrEqual(Math.max(...us) + 6.01);
|
||||
const plan = generateSectionPlan(out);
|
||||
expect(plan.primitives.some((q) => q.kind === "line" && q.cls === "section-terrain")).toBe(true);
|
||||
const cut = plan.primitives.flatMap((q) =>
|
||||
q.kind === "polygon" ? q.pts.map((r) => r.x) : q.kind === "line" && q.cls === "section-visible" ? [q.a.x, q.b.x] : [],
|
||||
);
|
||||
expect(Math.min(...us)).toBeGreaterThanOrEqual(Math.min(...cut) - 6.01);
|
||||
expect(Math.max(...us)).toBeLessThanOrEqual(Math.max(...cut) + 6.01);
|
||||
}, 30_000);
|
||||
|
||||
it("Kugel (B-Rep) wird als Schnittfläche gefüllt, wenn die Ebene sie trifft", async () => {
|
||||
@@ -55,11 +55,7 @@ describe("Schnitt: Gelände und freie Körper", () => {
|
||||
brep: { spec: { kind: "sphere", center: [px, pz, 1], r: 1 }, origin: { x: px - 1, y: pz - 1 } },
|
||||
};
|
||||
const p: Project = { ...sampleProject, extrudedSolids: [...(sampleProject.extrudedSolids ?? []), sphere] };
|
||||
const out = (await computeSection(p, section))!;
|
||||
const body = out.cutPolygons.filter((c) => c.component.kind === "body");
|
||||
expect(body.length).toBeGreaterThan(0);
|
||||
expect(body[0].sourceId).toBe("ball");
|
||||
const plan = generateSectionPlan(out);
|
||||
expect(plan.primitives.some((q) => q.kind === "polygon" && q.extrudedSolidId === "ball")).toBe(true);
|
||||
const plan = generateSectionPlan((await computeSection(p, section))!);
|
||||
expect(plan.primitives.some((q) => q.kind === "polygon" && q.extrudedSolidId === "ball" && q.fill === "#d9dde2")).toBe(true);
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -1,134 +0,0 @@
|
||||
// Zusätze zum Schnitt, die nicht Wand/Decke/Dach sind (Baustein [G1], meshSection.ts):
|
||||
// • Geländelinie: das Gelände-Netz (`TerrainMesh`) geschnitten → Linienzug im Schnitt,
|
||||
// auf den Bereich des Gebäudes (± Rand) begrenzt.
|
||||
// • Körper: freie Körper (`ExtrudedSolid`, B-Rep) geschnitten → gefüllte Schnittflächen.
|
||||
|
||||
import type { ExtrudedSolid, Project } from "../model/types";
|
||||
import { getFloor } from "../model/types";
|
||||
import { buildSolidMesh } from "../engine/truckSolid";
|
||||
import { extrudedSolidSpec } from "./extrudedSolidSpec";
|
||||
import { isVoidSolid } from "./voids";
|
||||
import { cutMeshWithPlane, ringsToPolygons } from "./meshSection";
|
||||
import type { Pt2 } from "./meshSection";
|
||||
import { keyhole } from "./voids";
|
||||
import type { SectionCutPolygon, SectionOutput, SectionPlaneSpec } from "./toSection";
|
||||
|
||||
type UDir = { x: number; y: number };
|
||||
|
||||
/** Seitenrand (m) der Geländelinie um den Inhalt des Schnitts. */
|
||||
const TERRAIN_MARGIN = 6;
|
||||
/** Neutrale Füllung geschnittener freier Körper (kein Bauteil/Material zugeordnet). */
|
||||
const BODY_FILL = "#d9dde2";
|
||||
const BODY_RGB: [number, number, number] = [0.85, 0.87, 0.89];
|
||||
|
||||
function planeOf(plane: SectionPlaneSpec, dir: UDir) {
|
||||
return { kind: "vertical" as const, point: { x: plane.point[0], y: plane.point[2] }, dir };
|
||||
}
|
||||
|
||||
/** Wertebereich in u über alle Cut-Polygone und Kanten (für die Geländebegrenzung). */
|
||||
function uRange(output: SectionOutput): [number, number] | null {
|
||||
let lo = Infinity;
|
||||
let hi = -Infinity;
|
||||
for (const cp of output.cutPolygons) for (const p of cp.pts) (lo = Math.min(lo, p[0])), (hi = Math.max(hi, p[0]));
|
||||
for (const e of [...output.visibleEdges, ...output.hiddenEdges]) {
|
||||
lo = Math.min(lo, e.a[0], e.b[0]);
|
||||
hi = Math.max(hi, e.a[0], e.b[0]);
|
||||
}
|
||||
return Number.isFinite(lo) ? [lo, hi] : null;
|
||||
}
|
||||
|
||||
/** Schneidet einen Linienzug auf [lo, hi] in u (Segmentweise, interpoliert die Ränder). */
|
||||
function clipLineToU(pts: Pt2[], lo: number, hi: number): Pt2[][] {
|
||||
const out: Pt2[][] = [];
|
||||
let cur: Pt2[] = [];
|
||||
const flush = () => {
|
||||
if (cur.length >= 2) out.push(cur);
|
||||
cur = [];
|
||||
};
|
||||
for (let i = 0; i + 1 < pts.length; i++) {
|
||||
const a = pts[i];
|
||||
const b = pts[i + 1];
|
||||
const [u0, u1] = [a[0], b[0]];
|
||||
if ((u0 < lo && u1 < lo) || (u0 > hi && u1 > hi)) {
|
||||
flush();
|
||||
continue;
|
||||
}
|
||||
const at = (u: number): Pt2 => {
|
||||
const t = u1 === u0 ? 0 : (u - u0) / (u1 - u0);
|
||||
return [u, a[1] + (b[1] - a[1]) * t];
|
||||
};
|
||||
const pa: Pt2 = u0 < lo ? at(lo) : u0 > hi ? at(hi) : a;
|
||||
const pb: Pt2 = u1 < lo ? at(lo) : u1 > hi ? at(hi) : b;
|
||||
if (cur.length === 0) cur.push(pa);
|
||||
cur.push(pb);
|
||||
if (u1 < lo || u1 > hi) flush();
|
||||
}
|
||||
flush();
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Hängt die Geländelinien aller Gelände-Netze an `output.profiles`. */
|
||||
export function appendTerrainProfiles(output: SectionOutput, project: Project, plane: SectionPlaneSpec, uDir: UDir): void {
|
||||
const terrains = (project.context ?? []).filter((c) => c.type === "terrainMesh");
|
||||
if (terrains.length === 0) return;
|
||||
const range = uRange(output);
|
||||
const cut = planeOf(plane, uDir);
|
||||
for (const t of terrains) {
|
||||
if (t.type !== "terrainMesh" || t.positions.length < 9) continue;
|
||||
const { lines } = cutMeshWithPlane(t.positions, t.indices, cut);
|
||||
for (const line of lines) {
|
||||
const parts = range ? clipLineToU(line, range[0] - TERRAIN_MARGIN, range[1] + TERRAIN_MARGIN) : [line];
|
||||
for (const pts of parts) {
|
||||
(output.profiles ??= []).push({ kind: "terrain", id: t.id, categoryCode: t.categoryCode, pts });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Welche Körper im Schnitt erscheinen (freie Körper, keine Abzugskörper). */
|
||||
export function sectionSolids(project: Project): Array<{ index: number; solid: ExtrudedSolid }> {
|
||||
const out: Array<{ index: number; solid: ExtrudedSolid }> = [];
|
||||
(project.extrudedSolids ?? []).forEach((solid, index) => {
|
||||
if (solid.operation === "subtract" || isVoidSolid(solid)) return;
|
||||
out.push({ index, solid });
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Hängt die geschnittenen freien Körper als Cut-Polygone an (truck-Mesh, asynchron). */
|
||||
export async function appendBodySections(output: SectionOutput, project: Project, plane: SectionPlaneSpec, uDir: UDir): Promise<void> {
|
||||
const cut = planeOf(plane, uDir);
|
||||
for (const { index, solid } of sectionSolids(project)) {
|
||||
let baseZ = 0;
|
||||
try {
|
||||
baseZ = solid.levelId ? (getFloor(project, solid.levelId).baseElevation ?? 0) : 0;
|
||||
} catch {
|
||||
baseZ = 0;
|
||||
}
|
||||
const spec = extrudedSolidSpec(solid, baseZ);
|
||||
if (!spec) continue;
|
||||
let mesh: { positions: number[]; indices: number[] };
|
||||
try {
|
||||
mesh = await buildSolidMesh(spec, 0.01);
|
||||
} catch {
|
||||
continue; // Körper nicht baubar → im Schnitt weglassen, wie im 3D
|
||||
}
|
||||
const { rings } = cutMeshWithPlane(mesh.positions, mesh.indices, cut);
|
||||
for (const poly of ringsToPolygons(rings)) {
|
||||
const { pts } = poly.length > 1 ? keyhole(poly as [number, number][][]) : { pts: poly[0] };
|
||||
const cp: SectionCutPolygon = {
|
||||
component: { kind: "body", index },
|
||||
color: BODY_RGB,
|
||||
pts: pts as Array<[number, number]>,
|
||||
fill: BODY_FILL,
|
||||
noStrokeEdges: poly.length > 1 ? holeBridgeEdges(pts.length, poly) : undefined,
|
||||
};
|
||||
output.cutPolygons.push(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Kanten-Indizes der Schlüsselloch-Stege eines Rings mit Löchern. */
|
||||
function holeBridgeEdges(n: number, poly: Pt2[][]): number[] {
|
||||
return keyhole(poly as [number, number][][]).bridges.filter((i) => i < n);
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// Geschnittene Fenster/Türen im Schnitt (Kern, `core/src/plan/section.rs`), über `generateSectionPlan`
|
||||
// mit `openings: true` wie in der Schnitt-Ansicht.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { DrawingLevel } from "../model/types";
|
||||
import type { Primitive } from "./generatePlan";
|
||||
import { sectionOpeningPrimitives } from "./sectionOpenings";
|
||||
import { computeSection, generateSectionPlan } from "./toSection";
|
||||
|
||||
const section = (x: number): DrawingLevel => ({
|
||||
id: "sx",
|
||||
@@ -15,10 +17,14 @@ const section = (x: number): DrawingLevel => ({
|
||||
directionSign: 1,
|
||||
});
|
||||
|
||||
describe("sectionOpeningPrimitives", () => {
|
||||
it("geschnittenes Fenster: Rahmenprofile an Brüstung/Sturz + Glaslinie, wählbar", () => {
|
||||
const prims = sectionOpeningPrimitives(sampleProject, section(3.5));
|
||||
const own = prims.filter((p) => "openingId" in p && p.openingId === "O1");
|
||||
async function openingPrims(level: DrawingLevel, openings = true): Promise<Primitive[]> {
|
||||
const out = (await computeSection(sampleProject, level))!;
|
||||
return generateSectionPlan(out, false, { openings }).primitives.filter((p) => "openingId" in p && p.openingId);
|
||||
}
|
||||
|
||||
describe("Schnitt: geschnittene Öffnungen", () => {
|
||||
it("geschnittenes Fenster: Rahmenprofile an Brüstung/Sturz + Glaslinie, wählbar", async () => {
|
||||
const own = (await openingPrims(section(3.5))).filter((p) => "openingId" in p && p.openingId === "O1");
|
||||
expect(own.length).toBeGreaterThanOrEqual(4);
|
||||
const glass = own.filter((p): p is Extract<Primitive, { kind: "line" }> => p.kind === "line");
|
||||
expect(glass.length).toBeGreaterThan(0);
|
||||
@@ -28,11 +34,13 @@ describe("sectionOpeningPrimitives", () => {
|
||||
expect(Math.max(...vs)).toBeLessThan(2.1 + 1e-9);
|
||||
});
|
||||
|
||||
it("Schnitt neben dem Fenster: nichts", () => {
|
||||
expect(sectionOpeningPrimitives(sampleProject, section(1.0)).some((p) => "openingId" in p && p.openingId === "O1")).toBe(false);
|
||||
it("Schnitt neben dem Fenster: nichts", async () => {
|
||||
expect((await openingPrims(section(1.0))).some((p) => "openingId" in p && p.openingId === "O1")).toBe(false);
|
||||
});
|
||||
|
||||
it("Ansichten bekommen keine Schnitt-Öffnungen", () => {
|
||||
expect(sectionOpeningPrimitives(sampleProject, { ...section(3.5), kind: "elevation" })).toEqual([]);
|
||||
it("nur auf Wunsch (Export ohne Öffnungen) und nie in Ansichten", async () => {
|
||||
expect(await openingPrims(section(3.5), false)).toEqual([]);
|
||||
const out = (await computeSection(sampleProject, { ...section(3.5), kind: "elevation" }))!;
|
||||
expect(generateSectionPlan(out, false, { openings: true }).primitives.some((p) => "openingId" in p && p.openingId)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,210 +0,0 @@
|
||||
// Geschnittene Fenster/Türen im Schnitt. Der Schnitt-Extraktor (section.rs)
|
||||
// spart in einer geschnittenen Wand nur die Öffnung aus (Brüstung + Sturz als
|
||||
// Poché, dazwischen nichts) — das Fenster selbst fehlte, die Öffnung wirkte wie
|
||||
// ein Loch. Hier entsteht der vertikale Querschnitt des Öffnungselements:
|
||||
// • Fenster: Blendrahmen-Profil unten (auf der Brüstung) und oben (am Sturz)
|
||||
// über die Rahmentiefe + Glaslinie(n) dazwischen. Rahmentiefe/-lage und
|
||||
// Glas-Lage stammen aus DEMSELBEN `windowSymbol` wie der Grundriss — die
|
||||
// Lage in der Wand stimmt also mit dem Grundriss überein.
|
||||
// • Tür: Zargen-Profil am Sturz + geschlossenes Türblatt.
|
||||
// Alles in Schnitt-Koordinaten (u, Höhe), wie `SectionOutput`.
|
||||
|
||||
import type { DrawingLevel, Opening, Project, Vec2, Wall } from "../model/types";
|
||||
import { getWallType, getWindowType, sashesOfWindowType, wallTypeThickness } from "../model/types";
|
||||
import { dot, sub } from "../model/geometry";
|
||||
import { wallReferenceOffset } from "../model/wall";
|
||||
import { openingInterval, openingVerticalExtent, wallAxisFrame, windowSymbol } from "../geometry/opening";
|
||||
import { NO_HATCH, SHOW_ALL, type CategoryDisplayResolver, type Primitive } from "./generatePlan/shared";
|
||||
import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection";
|
||||
|
||||
const INK = "#1f242c";
|
||||
/** Umriss geschnittener Rahmen-/Blattprofile (mm Papier). */
|
||||
const FRAME_MM = 0.25;
|
||||
/** Glaslinien (mm Papier). */
|
||||
const GLASS_MM = 0.13;
|
||||
/** Default-Rahmentiefe/-profilbreite (m), wie im Grundriss (`opening.ts`). */
|
||||
const DEFAULT_FRAME_DEPTH = 0.07;
|
||||
const DEFAULT_FRAME_WIDTH = 0.06;
|
||||
/** Türblatt-Dicke (m). */
|
||||
const DOOR_LEAF_THICKNESS = 0.04;
|
||||
/** Unter diesem |cos| zwischen Wandnormale und Schnitt-u gilt die Wand als
|
||||
* (fast) parallel zum Schnitt — dort gibt es keinen sinnvollen Querschnitt. */
|
||||
const MIN_CROSS = 0.15;
|
||||
|
||||
const rect = (u0: number, u1: number, v0: number, v1: number): Vec2[] => [
|
||||
{ x: Math.min(u0, u1), y: v0 },
|
||||
{ x: Math.max(u0, u1), y: v0 },
|
||||
{ x: Math.max(u0, u1), y: v1 },
|
||||
{ x: Math.min(u0, u1), y: v1 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Plan-Primitive (u, Höhe) aller Fenster/Türen, deren Wand die Schnittebene der
|
||||
* Ebene `level` IM Bereich der Öffnung kreuzt. Jedes Primitiv trägt die
|
||||
* `openingId` — ein Klick im Schnitt wählt die Öffnung.
|
||||
*/
|
||||
export function sectionOpeningPrimitives(
|
||||
project: Project,
|
||||
level: DrawingLevel,
|
||||
visibleCodes?: Set<string>,
|
||||
categoryDisplay: CategoryDisplayResolver = SHOW_ALL,
|
||||
): Primitive[] {
|
||||
const plane = sectionPlaneFromLevel(level);
|
||||
if (!plane || level.kind !== "section") return [];
|
||||
const uRaw = sectionUAxisModel(plane);
|
||||
const uLen = Math.hypot(uRaw.x, uRaw.y) || 1;
|
||||
const U: Vec2 = { x: uRaw.x / uLen, y: uRaw.y / uLen };
|
||||
const P0: Vec2 = { x: plane.point[0], y: plane.point[2] };
|
||||
const wallsById = new Map(project.walls.map((w) => [w.id, w]));
|
||||
const out: Primitive[] = [];
|
||||
|
||||
for (const o of project.openings ?? []) {
|
||||
if (visibleCodes && !visibleCodes.has(o.categoryCode)) continue;
|
||||
const disp = categoryDisplay(o.categoryCode);
|
||||
if (!disp.render) continue;
|
||||
const wall = wallsById.get(o.hostWallId);
|
||||
if (!wall) continue;
|
||||
if (visibleCodes && !visibleCodes.has(wall.categoryCode)) continue;
|
||||
const cut = crossSection(project, wall, o, P0, U);
|
||||
if (!cut) continue;
|
||||
const prims = o.kind === "window" ? windowCut(project, wall, o, cut) : doorCut(o, cut);
|
||||
for (const p of prims) out.push(disp.greyed ? ({ ...p, greyed: true } as Primitive) : p);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Abbildung "Offset quer zur Wand (n)" → Schnitt-u, falls die Schnittebene die
|
||||
* Wandachse innerhalb der Öffnung kreuzt. */
|
||||
interface CrossSection {
|
||||
/** u eines Punktes mit Wand-Offset `s` (entlang der linken Normalen). */
|
||||
uAt: (s: number) => number;
|
||||
zBottom: number;
|
||||
zTop: number;
|
||||
/** Wand-Offsets der Wandflächen (min/max). */
|
||||
faceMin: number;
|
||||
faceMax: number;
|
||||
}
|
||||
|
||||
function crossSection(project: Project, wall: Wall, o: Opening, P0: Vec2, U: Vec2): CrossSection | null {
|
||||
const iv = openingInterval(wall, o);
|
||||
if (!iv) return null;
|
||||
const { u: a, n } = wallAxisFrame(wall);
|
||||
const un = dot(U, n);
|
||||
if (Math.abs(un) < MIN_CROSS) return null;
|
||||
const rel = sub(P0, wall.start);
|
||||
const n0 = dot(rel, n);
|
||||
const a0 = dot(rel, a);
|
||||
const ua = dot(U, a);
|
||||
// Schnittlinie p(t) = P0 + t·U; Offset quer zur Wand: n0 + t·un.
|
||||
const tAt = (s: number) => (s - n0) / un;
|
||||
// Lage entlang der Achse dort, wo die Schnittlinie die Wandmitte quert.
|
||||
const total = wallTypeThickness(getWallType(project, wall));
|
||||
const refOff = wallReferenceOffset(wall, total);
|
||||
const along = a0 + tAt(refOff) * ua;
|
||||
if (along < iv.from + 1e-4 || along > iv.to - 1e-4) return null;
|
||||
const { zBottom, zTop } = openingVerticalExtent(project, wall, o);
|
||||
if (zTop - zBottom < 1e-3) return null;
|
||||
return {
|
||||
uAt: (s) => tAt(s),
|
||||
zBottom,
|
||||
zTop,
|
||||
faceMin: refOff - total / 2,
|
||||
faceMax: refOff + total / 2,
|
||||
};
|
||||
}
|
||||
|
||||
const profile = (pts: Vec2[], openingId: string): Primitive => ({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
fill: "#ffffff",
|
||||
stroke: INK,
|
||||
strokeWidthMm: FRAME_MM,
|
||||
hatch: NO_HATCH,
|
||||
openingId,
|
||||
});
|
||||
|
||||
const pick = (pts: Vec2[], openingId: string): Primitive => ({
|
||||
kind: "polygon",
|
||||
pts,
|
||||
fill: "none",
|
||||
stroke: "none",
|
||||
strokeWidthMm: 0,
|
||||
hatch: NO_HATCH,
|
||||
openingId,
|
||||
});
|
||||
|
||||
function windowCut(project: Project, wall: Wall, o: Opening, c: CrossSection): Primitive[] {
|
||||
const wt = getWindowType(project, o);
|
||||
const spec = wt
|
||||
? {
|
||||
sashes: sashesOfWindowType(wt),
|
||||
frameWidth: wt.frameWidth ?? DEFAULT_FRAME_WIDTH,
|
||||
frameDepth: wt.frameDepth,
|
||||
insetFromFace: wt.insetFromFace,
|
||||
insetFace: wt.insetFace,
|
||||
}
|
||||
: undefined;
|
||||
const fw = Math.max(0.02, spec?.frameWidth ?? DEFAULT_FRAME_WIDTH);
|
||||
const { n } = wallAxisFrame(wall);
|
||||
const offOf = (p: Vec2) => dot(sub(p, wall.start), n);
|
||||
|
||||
// Rahmenband quer zur Wand aus dem Grundriss-Symbol (gleiche Lage wie dort).
|
||||
let fMin = (c.faceMin + c.faceMax) / 2 - DEFAULT_FRAME_DEPTH / 2;
|
||||
let fMax = fMin + DEFAULT_FRAME_DEPTH;
|
||||
let glass: number[] = [(fMin + fMax) / 2];
|
||||
const sym = windowSymbol(project, wall, o, 1, spec, "mittel");
|
||||
if (sym && spec) {
|
||||
const offs = sym.frame.map(offOf);
|
||||
fMin = Math.min(...offs);
|
||||
fMax = Math.max(...offs);
|
||||
const g = sym.glassLines.map(([p]) => offOf(p));
|
||||
if (g.length > 0) glass = [...new Set(g.map((x) => Math.round(x * 1e6) / 1e6))];
|
||||
}
|
||||
const u0 = c.uAt(fMin);
|
||||
const u1 = c.uAt(fMax);
|
||||
const h = c.zTop - c.zBottom;
|
||||
const fwv = Math.min(fw, h / 3);
|
||||
const out: Primitive[] = [pick(rect(c.uAt(c.faceMin), c.uAt(c.faceMax), c.zBottom, c.zTop), o.id)];
|
||||
out.push(profile(rect(u0, u1, c.zBottom, c.zBottom + fwv), o.id));
|
||||
out.push(profile(rect(u0, u1, c.zTop - fwv, c.zTop), o.id));
|
||||
for (const s of glass) {
|
||||
const u = c.uAt(s);
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: u, y: c.zBottom + fwv },
|
||||
b: { x: u, y: c.zTop - fwv },
|
||||
cls: "section-window-glass",
|
||||
weightMm: GLASS_MM,
|
||||
color: INK,
|
||||
openingId: o.id,
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function doorCut(o: Opening, c: CrossSection): Primitive[] {
|
||||
const out: Primitive[] = [pick(rect(c.uAt(c.faceMin), c.uAt(c.faceMax), c.zBottom, c.zTop), o.id)];
|
||||
if (o.doorType === "wandoeffnung") return out;
|
||||
const mid = (c.faceMin + c.faceMax) / 2;
|
||||
const fw = Math.min(DEFAULT_FRAME_WIDTH, (c.zTop - c.zBottom) / 4);
|
||||
// Zarge am Sturz über die Rahmentiefe.
|
||||
out.push(
|
||||
profile(
|
||||
rect(c.uAt(mid - DEFAULT_FRAME_DEPTH / 2), c.uAt(mid + DEFAULT_FRAME_DEPTH / 2), c.zTop - fw, c.zTop),
|
||||
o.id,
|
||||
),
|
||||
);
|
||||
// Geschlossenes Türblatt (knapp über Boden bis unter die Zarge).
|
||||
out.push(
|
||||
profile(
|
||||
rect(
|
||||
c.uAt(mid - DOOR_LEAF_THICKNESS / 2),
|
||||
c.uAt(mid + DOOR_LEAF_THICKNESS / 2),
|
||||
c.zBottom + 0.01,
|
||||
c.zTop - fw,
|
||||
),
|
||||
o.id,
|
||||
),
|
||||
);
|
||||
return out;
|
||||
}
|
||||
@@ -1,87 +1,16 @@
|
||||
/**
|
||||
* Unit-Tests für den Ansichts-Generator (toElevation.ts): Projektion einer
|
||||
* bekannten Fläche auf (u, v)+Tiefe, Rückseiten-Culling, Painter-Reihenfolge
|
||||
* (nähere Fassade NACH der ferneren) und Schlagschatten (nur mit shadows=true).
|
||||
* Alles rein geometrisch auf synthetischen RWall/RSlab-Fixtures bzw. einem
|
||||
* Minimalprojekt — KEIN WASM.
|
||||
* 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 { RModel3d, RSlab, RWall } from "./toWalls3d";
|
||||
import type { SectionPlaneSpec } from "./toSection";
|
||||
import type { CategoryDisplayResolver } from "./generatePlan";
|
||||
import {
|
||||
buildShadows,
|
||||
collectElevationFaces,
|
||||
elevationFrame,
|
||||
generateElevationPlan,
|
||||
} from "./toElevation";
|
||||
|
||||
// Betrachter im Süden (world z = −2), Blick nach +Z (in die Szene). Damit liegt
|
||||
// eine Wand bei z ≈ 0 HINTER der Ebene (depth > 0) und ihre Süd-Langseite zeigt
|
||||
// zum Betrachter (front-facing).
|
||||
const PLANE_SOUTH: SectionPlaneSpec = { point: [-1, 0, -2], normal: [0, 0, 1] };
|
||||
|
||||
function wall(over: Partial<RWall> = {}): RWall {
|
||||
return {
|
||||
start: [0, 0],
|
||||
end: [4, 0],
|
||||
thickness: 0.2,
|
||||
height: 3,
|
||||
baseElevation: 0,
|
||||
color: [0.8, 0.8, 0.8],
|
||||
layers: [],
|
||||
wallId: "W",
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
describe("toElevation — Projektion + Culling", () => {
|
||||
it("Süd-Langseite einer Wand: erwartetes (u, v)-Rechteck + Tiefe, Rückseite gecullt", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const model: RModel3d = { walls: [wall()], slabs: [], meshes: [], roofLayers: [] };
|
||||
const visible = collectElevationFaces(model, frame);
|
||||
// Genau EINE sichtbare Fläche (die Süd-Langseite); alle anderen sind
|
||||
// Rückseiten oder streifend (Deckel/Boden/Stirnkappen).
|
||||
expect(visible.length).toBe(1);
|
||||
const face = visible[0];
|
||||
expect(face.wallId).toBe("W");
|
||||
const us = face.pts.map((p) => p[0]);
|
||||
const vs = face.pts.map((p) => p[1]);
|
||||
// U (entspiegelt, Blick +z ⇒ rechts = +x) = [1, 0, 0], P.x = −1.
|
||||
expect(Math.min(...us)).toBeCloseTo(1, 6); // x=0 → u=1
|
||||
expect(Math.max(...us)).toBeCloseTo(5, 6); // x=4 → u=5
|
||||
expect(Math.min(...vs)).toBeCloseTo(0, 6);
|
||||
expect(Math.max(...vs)).toBeCloseTo(3, 6);
|
||||
expect(face.depth).toBeCloseTo(1.9, 6); // z ≈ −0.1 − (−2)
|
||||
});
|
||||
|
||||
it("Rückseiten-Culling: eine Wand hinter dem Betrachter erscheint nicht", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const model: RModel3d = { walls: [wall({ start: [0, -5], end: [4, -5] })], slabs: [], meshes: [], roofLayers: [] };
|
||||
expect(collectElevationFaces(model, frame)).toEqual([]);
|
||||
});
|
||||
});
|
||||
import { generateElevationPlan } from "./toElevation";
|
||||
|
||||
describe("toElevation — Painter-Reihenfolge", () => {
|
||||
it("nähere Fassade wird NACH der ferneren emittiert", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const model: RModel3d = {
|
||||
walls: [
|
||||
wall({ wallId: "NEAR", start: [0, 0], end: [4, 0] }), // z ≈ 0 → näher
|
||||
wall({ wallId: "FAR", start: [0, 3], end: [4, 3] }), // z ≈ 3 → ferner
|
||||
],
|
||||
slabs: [],
|
||||
meshes: [],
|
||||
roofLayers: [],
|
||||
};
|
||||
const faces = collectElevationFaces(model, frame);
|
||||
const near = faces.find((f) => f.wallId === "NEAR")!;
|
||||
const far = faces.find((f) => f.wallId === "FAR")!;
|
||||
expect(near.depth).toBeLessThan(far.depth);
|
||||
});
|
||||
|
||||
it("im Plan: nähere Wand-Fläche hat einen höheren Primitiv-Index", () => {
|
||||
const project = elevationProject({ overhang: false });
|
||||
const plan = generateElevationPlan(project, project.drawingLevels[1])!;
|
||||
@@ -99,61 +28,6 @@ describe("toElevation — Painter-Reihenfolge", () => {
|
||||
});
|
||||
|
||||
describe("toElevation — Schlagschatten", () => {
|
||||
it("buildShadows: Überstand vor einer Fassade wirft ein Schatten-Polygon", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
// Wandfläche (Fassade) hinter dem Überstand.
|
||||
const wallFaces = collectElevationFaces(
|
||||
{ walls: [wall()], slabs: [], meshes: [], roofLayers: [] },
|
||||
frame,
|
||||
);
|
||||
// Überstand-Slab, der VOR der Wand (näher, z < −0.1) liegt und sie u-seitig
|
||||
// überdeckt.
|
||||
const slab: RSlab = {
|
||||
outline: [
|
||||
[0, -0.6],
|
||||
[4, -0.6],
|
||||
[4, 0.2],
|
||||
[0, 0.2],
|
||||
],
|
||||
zBottom: 2.8,
|
||||
zTop: 3,
|
||||
color: [0.9, 0.9, 0.9],
|
||||
ceilingId: "R",
|
||||
};
|
||||
const slabFaces = collectElevationFaces(
|
||||
{ walls: [], slabs: [slab], meshes: [], roofLayers: [] },
|
||||
frame,
|
||||
);
|
||||
const shadows = buildShadows(wallFaces, slabFaces);
|
||||
expect(shadows.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("buildShadows: kein Überlapp → keine Schatten", () => {
|
||||
const frame = elevationFrame(PLANE_SOUTH);
|
||||
const wallFaces = collectElevationFaces(
|
||||
{ walls: [wall({ start: [0, 0], end: [4, 0] })], slabs: [], meshes: [], roofLayers: [] },
|
||||
frame,
|
||||
);
|
||||
// Slab weit seitlich versetzt (u außerhalb der Wand).
|
||||
const slab: RSlab = {
|
||||
outline: [
|
||||
[20, -0.6],
|
||||
[24, -0.6],
|
||||
[24, 0.2],
|
||||
[20, 0.2],
|
||||
],
|
||||
zBottom: 2.8,
|
||||
zTop: 3,
|
||||
color: [0.9, 0.9, 0.9],
|
||||
ceilingId: "R",
|
||||
};
|
||||
const slabFaces = collectElevationFaces(
|
||||
{ walls: [], slabs: [slab], meshes: [], roofLayers: [] },
|
||||
frame,
|
||||
);
|
||||
expect(buildShadows(wallFaces, slabFaces).length).toBe(0);
|
||||
});
|
||||
|
||||
it("im Plan: shadows=true erzeugt zusätzliche Schatten-Primitive, false exakt keine", () => {
|
||||
const project = elevationProject({ overhang: true });
|
||||
const level = project.drawingLevels[1];
|
||||
|
||||
+23
-1001
File diff suppressed because it is too large.
Load diff
@@ -1,215 +0,0 @@
|
||||
/**
|
||||
* Unit-Tests für die Schnitt-Boolean-Dominanz (toSection): an Wand-Decken-
|
||||
* Übergängen schneidet die STÄRKERE Schicht (höhere `Component.joinPriority`)
|
||||
* die schwächere per achsparalleler Rechteck-Subtraktion weg. Gleiche Priorität
|
||||
* koexistiert (kein Schnitt).
|
||||
*
|
||||
* Getestet über den Rust-Kern (`plan_section.rs`):
|
||||
* `subtractDominantBands` gegen den Nutzer-Testfall — ELEMENTÜBERGREIFEND:
|
||||
* ein Decken-Beton-Band (100) schneidet ein überlappendes Wand-Putz-Band
|
||||
* (10) weg; Beton bleibt voll; gleiche Priorität koexistiert.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
subtractDominantBands,
|
||||
type Rect,
|
||||
type SectionCutPolygon,
|
||||
} from "./toSection";
|
||||
|
||||
/** Rechteck-Kurzform. */
|
||||
function r(uMin: number, uMax: number, vMin: number, vMax: number): Rect {
|
||||
return { uMin, uMax, vMin, vMax };
|
||||
}
|
||||
|
||||
/** Ein achsparalleles Cut-Band mit joinPriority. */
|
||||
function band(
|
||||
uMin: number,
|
||||
uMax: number,
|
||||
vMin: number,
|
||||
vMax: number,
|
||||
joinPriority: number,
|
||||
tag = "",
|
||||
): SectionCutPolygon {
|
||||
return {
|
||||
component: { kind: "wall", index: 0 },
|
||||
color: [0.5, 0.5, 0.5],
|
||||
pts: [
|
||||
[uMin, vMax],
|
||||
[uMax, vMax],
|
||||
[uMax, vMin],
|
||||
[uMin, vMin],
|
||||
],
|
||||
fill: tag || "#fff",
|
||||
joinPriority,
|
||||
};
|
||||
}
|
||||
|
||||
/** Ein achsparalleles Cut-Band mit joinPriority UND Komponenten-Identität (für die MERGE-Regel). */
|
||||
function cband(
|
||||
uMin: number,
|
||||
uMax: number,
|
||||
vMin: number,
|
||||
vMax: number,
|
||||
joinPriority: number,
|
||||
componentId: string,
|
||||
tag = "",
|
||||
): SectionCutPolygon {
|
||||
return { ...band(uMin, uMax, vMin, vMax, joinPriority, tag), componentId };
|
||||
}
|
||||
|
||||
/** Bounding-Box eines Bands als Rect. */
|
||||
function boxOf(b: SectionCutPolygon): Rect {
|
||||
const us = b.pts.map((p) => p[0]);
|
||||
const vs = b.pts.map((p) => p[1]);
|
||||
return { uMin: Math.min(...us), uMax: Math.max(...us), vMin: Math.min(...vs), vMax: Math.max(...vs) };
|
||||
}
|
||||
|
||||
/** Gesamtfläche einer Band-/Rect-Menge. */
|
||||
function area(items: Array<Rect | SectionCutPolygon>): number {
|
||||
return items.reduce((s, it) => {
|
||||
const b = "pts" in it ? boxOf(it) : it;
|
||||
return s + (b.uMax - b.uMin) * (b.vMax - b.vMin);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
describe("subtractDominantBands: stärkere Schicht schneidet schwächere", () => {
|
||||
it("Nutzer-Testfall ELEMENTÜBERGREIFEND: Decken-Beton(100) schneidet Wand-Putz(10) weg", () => {
|
||||
// Wand-Putz-Band (Element B): schwach, joinPriority 10, u∈[0,2], v∈[0,3].
|
||||
const putz = band(0, 2, 0, 3, 10, "putz");
|
||||
// Decken-Beton-Band (Element A): stark, joinPriority 100, überlappt den
|
||||
// oberen Teil des Putzes: u∈[0,2], v∈[2,4].
|
||||
const beton = band(0, 2, 2, 4, 100, "beton");
|
||||
|
||||
const out = subtractDominantBands([putz, beton]);
|
||||
// Beton bleibt voll erhalten (kein stärkeres Band).
|
||||
const betonOut = out.filter((b) => b.fill === "beton");
|
||||
expect(betonOut).toHaveLength(1);
|
||||
expect(boxOf(betonOut[0])).toEqual(boxOf(beton));
|
||||
|
||||
// Putz ist im Überlappungsbereich v∈[2,3] weggeschnitten → Rest nur v∈[0,2].
|
||||
const putzOut = out.filter((b) => b.fill === "putz");
|
||||
expect(putzOut).toHaveLength(1);
|
||||
expect(boxOf(putzOut[0])).toEqual(r(0, 2, 0, 2));
|
||||
// In der Überlappungsregion existiert KEIN Putz mehr.
|
||||
expect(putzOut[0].pts.every((p) => p[1] <= 2 + 1e-9)).toBe(true);
|
||||
});
|
||||
|
||||
it("gestaffelte Kette Beton100 > Backstein50 > Dämmung20 > Putz10", () => {
|
||||
// Alle vier Bänder überlappen in derselben Region u∈[0,1], gestapelt in v.
|
||||
// Jedes schwächere wird von JEDEM stärkeren geschnitten, wo sie überlappen.
|
||||
const beton = band(0, 1, 3, 4, 100, "beton");
|
||||
const backstein = band(0, 1, 2.5, 3.5, 50, "backstein"); // überlappt Beton in v∈[3,3.5]
|
||||
const daemmung = band(0, 1, 2, 3, 20, "daemmung"); // überlappt Backstein in v∈[2.5,3]
|
||||
const putz = band(0, 1, 0, 3.2, 10, "putz"); // überlappt alle darüber
|
||||
|
||||
const out = subtractDominantBands([beton, backstein, daemmung, putz]);
|
||||
|
||||
// Beton unangetastet.
|
||||
expect(area(out.filter((b) => b.fill === "beton"))).toBeCloseTo(1, 9);
|
||||
// Backstein: [2.5,3.5] minus Beton-Overlap [3,3.5] = [2.5,3] → Fläche 0.5.
|
||||
expect(area(out.filter((b) => b.fill === "backstein"))).toBeCloseTo(0.5, 9);
|
||||
// Dämmung: [2,3] minus Backstein-Overlap [2.5,3] = [2,2.5] → Fläche 0.5.
|
||||
// (Beton [3,4] überlappt Dämmung nicht.)
|
||||
expect(area(out.filter((b) => b.fill === "daemmung"))).toBeCloseTo(0.5, 9);
|
||||
// Putz: [0,3.2] minus Overlap mit ALLEN stärkeren.
|
||||
// Beton[3,4]→[3,3.2], Backstein[2.5,3.5]→[2.5,3.2], Dämmung[2,3]→[2,3] überdecken
|
||||
// zusammen v∈[2,3.2]; Rest = v∈[0,2] → Fläche 2.
|
||||
expect(area(out.filter((b) => b.fill === "putz"))).toBeCloseTo(2, 9);
|
||||
});
|
||||
|
||||
it("gleiche Priorität koexistiert: Betonwand + Betondecke schneiden sich NICHT", () => {
|
||||
const betonWand = band(0, 1, 0, 3, 100, "wand");
|
||||
const betonDecke = band(0, 1, 2, 4, 100, "decke"); // überlappt in v∈[2,3]
|
||||
const out = subtractDominantBands([betonWand, betonDecke]);
|
||||
// Beide voll erhalten (durchgehende Betonfläche).
|
||||
expect(area(out.filter((b) => b.fill === "wand"))).toBeCloseTo(3, 9);
|
||||
expect(area(out.filter((b) => b.fill === "decke"))).toBeCloseTo(2, 9);
|
||||
});
|
||||
|
||||
it("Band ohne joinPriority nimmt an keiner Subtraktion teil", () => {
|
||||
const stark = band(0, 2, 0, 2, 100, "stark");
|
||||
const ohne: SectionCutPolygon = { ...band(0, 2, 0, 2, 0, "ohne"), joinPriority: undefined };
|
||||
const out = subtractDominantBands([stark, ohne]);
|
||||
// Beide unverändert durchgereicht.
|
||||
expect(area(out.filter((b) => b.fill === "stark"))).toBeCloseTo(4, 9);
|
||||
expect(area(out.filter((b) => b.fill === "ohne"))).toBeCloseTo(4, 9);
|
||||
});
|
||||
|
||||
it("vollständig überdecktes schwächeres Band verschwindet", () => {
|
||||
const stark = band(0, 3, 0, 3, 100, "stark");
|
||||
const schwach = band(1, 2, 1, 2, 10, "schwach"); // ganz im starken enthalten
|
||||
const out = subtractDominantBands([stark, schwach]);
|
||||
expect(out.filter((b) => b.fill === "schwach")).toHaveLength(0);
|
||||
expect(area(out.filter((b) => b.fill === "stark"))).toBeCloseTo(9, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("subtractDominantBands: MERGE-Regel (gleiche Komponente + Priorität)", () => {
|
||||
it("(a) zwei berührende Bänder gleicher Komponente+Priorität → EIN Körper, keine Innenkante", () => {
|
||||
// Beton-Wand (vertikal) trifft Beton-Decke (deren Schnittband hier u-deckungs-
|
||||
// gleich): gleiche componentId "beton", gleiche joinPriority, Überlappung v∈[2,3].
|
||||
const betonWand = cband(0, 1, 0, 3, 100, "beton", "wand");
|
||||
const betonDecke = cband(0, 1, 2, 4, 100, "beton", "decke"); // überlappt in v∈[2,3]
|
||||
const out = subtractDominantBands([betonWand, betonDecke]);
|
||||
// Zu EINEM Rechteck u∈[0,1], v∈[0,4] verschmolzen → keine innere Trennlinie.
|
||||
expect(out).toHaveLength(1);
|
||||
expect(boxOf(out[0])).toEqual(r(0, 1, 0, 4));
|
||||
expect(out[0].componentId).toBe("beton");
|
||||
expect(area(out)).toBeCloseTo(4, 9);
|
||||
});
|
||||
|
||||
it("(a2) exakt bündig aneinander (Kantenberührung, kein Überlapp) → verschmilzt", () => {
|
||||
// Zwei Backstein-Kerne, die sich nur an v=3 berühren: die Innenkante muss weg.
|
||||
const unten = cband(0, 1, 0, 3, 100, "backstein", "u");
|
||||
const oben = cband(0, 1, 3, 5, 100, "backstein", "o");
|
||||
const out = subtractDominantBands([unten, oben]);
|
||||
expect(out).toHaveLength(1);
|
||||
expect(boxOf(out[0])).toEqual(r(0, 1, 0, 5));
|
||||
});
|
||||
|
||||
it("(b) gleiche Priorität, VERSCHIEDENE Komponenten → bleiben getrennt (coexist)", () => {
|
||||
// Selbe Geometrie wie (a), aber unterschiedliche componentId → kein Merge.
|
||||
const wand = cband(0, 1, 0, 3, 100, "beton-wand", "wand");
|
||||
const decke = cband(0, 1, 2, 4, 100, "beton-decke", "decke");
|
||||
const out = subtractDominantBands([wand, decke]);
|
||||
expect(out).toHaveLength(2);
|
||||
expect(area(out.filter((b) => b.fill === "wand"))).toBeCloseTo(3, 9);
|
||||
expect(area(out.filter((b) => b.fill === "decke"))).toBeCloseTo(2, 9);
|
||||
});
|
||||
|
||||
it("(c) Bänder ohne componentId verschmelzen nie (Dominanz-Tests bit-identisch)", () => {
|
||||
// Wie der bestehende Koexistenz-Test, ohne componentId → weiterhin 2 Bänder.
|
||||
const a = band(0, 1, 0, 3, 100, "a");
|
||||
const b = band(0, 1, 2, 4, 100, "b");
|
||||
const out = subtractDominantBands([a, b]);
|
||||
expect(out).toHaveLength(2);
|
||||
expect(area(out.filter((x) => x.fill === "a"))).toBeCloseTo(3, 9);
|
||||
expect(area(out.filter((x) => x.fill === "b"))).toBeCloseTo(2, 9);
|
||||
});
|
||||
|
||||
it("Merge respektiert die Dominanz: stärkeres Fremd-Band schneidet erst, dann verschmelzen die Reste", () => {
|
||||
// Zwei gleichartige Putz-Bänder (Prio 10) u-deckungsgleich, dazwischen greift
|
||||
// KEIN stärkeres Band -> sie verschmelzen; ein separates starkes Beton-Band
|
||||
// (Prio 100) schneidet vorher ein Stück aus dem oberen Putz.
|
||||
const putzUnten = cband(0, 1, 0, 2, 10, "putz", "pu");
|
||||
const putzOben = cband(0, 1, 2, 4, 10, "putz", "po");
|
||||
const beton = cband(0, 1, 3, 5, 100, "beton", "beton"); // schneidet Putz-Oben v∈[3,4] weg
|
||||
const out = subtractDominantBands([putzUnten, putzOben, beton]);
|
||||
// Putz: unten[0,2] + oben-Rest[2,3] verschmelzen zu [0,3] → EIN Band, Fläche 3.
|
||||
const putz = out.filter((b) => b.componentId === "putz");
|
||||
expect(putz).toHaveLength(1);
|
||||
expect(boxOf(putz[0])).toEqual(r(0, 1, 0, 3));
|
||||
// Beton unangetastet.
|
||||
expect(area(out.filter((b) => b.componentId === "beton"))).toBeCloseTo(2, 9);
|
||||
});
|
||||
|
||||
it("Teil-/Eck-Überlappung gleicher Komponente verschmilzt NICHT (Union wäre L-förmig)", () => {
|
||||
// Nicht achs-deckungsgleich, nur Eck-Überlapp → Bounding-Box würde leere
|
||||
// Fläche abdecken, darum bleiben beide getrennt.
|
||||
const a = cband(0, 2, 0, 2, 100, "x", "a");
|
||||
const b = cband(1, 3, 1, 3, 100, "x", "b");
|
||||
const out = subtractDominantBands([a, b]);
|
||||
expect(out).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -1,71 +0,0 @@
|
||||
// Schnitt-Tiefe (DrawingLevel.depth): filterByDepth blendet Ansichtskanten aus,
|
||||
// deren Quell-Wand weiter als `depth` hinter der Schnittebene (Blickrichtung)
|
||||
// liegt. Owner-Distanz-Näherung (Wand-Mitte) — reiner TS-Datenpfad, ohne WASM.
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { filterByDepth } from "./toSection";
|
||||
import type { SectionOutput, SectionPlaneSpec } from "./toSection";
|
||||
import type { Project, Wall } from "../model/types";
|
||||
|
||||
// Zwei Wände auf verschiedenen Tiefen: W_near bei y=1, W_far bei y=8.
|
||||
function makeWall(id: string, y: number): Wall {
|
||||
return {
|
||||
id,
|
||||
type: "wall",
|
||||
floorId: "eg",
|
||||
categoryCode: "20",
|
||||
wallTypeId: "wt",
|
||||
start: { x: 0, y },
|
||||
end: { x: 4, y },
|
||||
height: 2.6,
|
||||
} as unknown as Wall;
|
||||
}
|
||||
|
||||
const project = {
|
||||
id: "p",
|
||||
name: "T",
|
||||
walls: [makeWall("W_near", 1), makeWall("W_far", 8)],
|
||||
ceilings: [],
|
||||
roofs: [],
|
||||
openings: [],
|
||||
components: [],
|
||||
wallTypes: [],
|
||||
drawingLevels: [{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }],
|
||||
} as unknown as Project;
|
||||
|
||||
// Schnittebene bei y=0, Blickrichtung +y (in die Szene). wallSegmentOwners
|
||||
// nummeriert die Wände in project.walls-Reihenfolge: index 0 = W_near, 1 = W_far.
|
||||
const plane: SectionPlaneSpec = { point: [0, 0, 0], normal: [0, 0, 1] };
|
||||
|
||||
function edge(index: number) {
|
||||
return { component: { kind: "wall" as const, index }, a: [0, 0] as [number, number], b: [1, 1] as [number, number] };
|
||||
}
|
||||
|
||||
describe("filterByDepth", () => {
|
||||
it("behält nahe Kanten, verwirft Kanten hinter der Tiefengrenze", () => {
|
||||
const out: SectionOutput = {
|
||||
cutPolygons: [],
|
||||
visibleEdges: [edge(0), edge(1)],
|
||||
hiddenEdges: [edge(1)],
|
||||
};
|
||||
filterByDepth(out, project, plane, 4); // Tiefe 4 m: W_near (1) bleibt, W_far (8) fällt weg.
|
||||
expect(out.visibleEdges.map((e) => e.component.index)).toEqual([0]);
|
||||
expect(out.hiddenEdges).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("behält alles, wenn die Tiefe alle Bauteile umfasst", () => {
|
||||
const out: SectionOutput = {
|
||||
cutPolygons: [],
|
||||
visibleEdges: [edge(0), edge(1)],
|
||||
hiddenEdges: [],
|
||||
};
|
||||
filterByDepth(out, project, plane, 20);
|
||||
expect(out.visibleEdges).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("depth <= 0 ist ein No-op", () => {
|
||||
const out: SectionOutput = { cutPolygons: [], visibleEdges: [edge(0), edge(1)], hiddenEdges: [] };
|
||||
filterByDepth(out, project, plane, 0);
|
||||
expect(out.visibleEdges).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
* `splitWallLayers`/`splitSlabLayers` — Attribut-Override (By-Layer/By-Object)
|
||||
* bei MEHRSCHICHTIGEM Wand-/Deckentyp im Schnitt. Vorher wurde `owner.foreground`/
|
||||
* `hatchId`/`hatchSource`/`background`/`backgroundSource` hier komplett ignoriert
|
||||
* (nur der einschichtige Pfad über resolveWallSectionStyle/resolveCeilingSectionStyle
|
||||
* respektierte den Override) — Regressionsschutz für den Nachzieh-Fix
|
||||
* (2D-Vervollständigung, Fund D).
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { getCeilingType, getWallType } from "../model/types";
|
||||
import { splitWallLayers, splitSlabLayers, type SectionCutPolygon } from "./toSection";
|
||||
|
||||
const cp: SectionCutPolygon = {
|
||||
component: { kind: "wall", index: 0 },
|
||||
color: [0.5, 0.5, 0.5],
|
||||
pts: [
|
||||
[0, 0],
|
||||
[1, 0],
|
||||
[1, 2],
|
||||
[0, 2],
|
||||
],
|
||||
};
|
||||
|
||||
describe("splitWallLayers — Attribut-Override greift auf ALLE Schichten", () => {
|
||||
const wall = sampleProject.walls.find((w) => w.id === "W1")!; // wallTypeId "aw", 4 Schichten
|
||||
const wt = getWallType(sampleProject, wall);
|
||||
|
||||
it("Testvoraussetzung: Wandtyp ist tatsächlich mehrschichtig", () => {
|
||||
expect(wt.layers.length).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it("ohne Override: Füllung bleibt SIA-neutral, nicht die Override-Testfarbe", () => {
|
||||
const bands = splitWallLayers(cp, sampleProject, wt, wall, { x: 1, y: 0 });
|
||||
expect(bands.length).toBe(wt.layers.length);
|
||||
for (const b of bands) {
|
||||
expect(typeof b.fill).toBe("string");
|
||||
expect(b.fill).not.toBe("#ff00ff");
|
||||
}
|
||||
});
|
||||
|
||||
it("mit explizitem background-Override: JEDE Schicht bekommt die Override-Farbe", () => {
|
||||
const overridden = { ...wall, background: "#ff00ff" };
|
||||
const bands = splitWallLayers(cp, sampleProject, wt, overridden, { x: 1, y: 0 });
|
||||
expect(bands.length).toBe(wt.layers.length);
|
||||
for (const b of bands) expect(b.fill).toBe("#ff00ff");
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitSlabLayers — Attribut-Override greift auf ALLE Schichten", () => {
|
||||
const ceiling = (sampleProject.ceilings ?? []).find((c) => c.id === "C1")!; // ceilingTypeId "dg-massiv"
|
||||
const wt = getCeilingType(sampleProject, ceiling);
|
||||
|
||||
it("Testvoraussetzung: Deckentyp ist tatsächlich mehrschichtig", () => {
|
||||
expect(wt.layers.length).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it("mit explizitem background-Override: JEDE Schicht bekommt die Override-Farbe", () => {
|
||||
const overridden = { ...ceiling, background: "#00ffff" };
|
||||
const bands = splitSlabLayers(cp, sampleProject, wt, overridden);
|
||||
expect(bands.length).toBe(wt.layers.length);
|
||||
for (const b of bands) expect(b.fill).toBe("#00ffff");
|
||||
});
|
||||
|
||||
it("mit backgroundSource:'layer': category.color wird für ALLE Schichten übernommen", () => {
|
||||
const category = sampleProject.layers.find((l) => l.code === ceiling.categoryCode)!;
|
||||
const overridden = { ...ceiling, backgroundSource: "layer" as const };
|
||||
const bands = splitSlabLayers(cp, sampleProject, wt, overridden);
|
||||
expect(bands.length).toBe(wt.layers.length);
|
||||
for (const b of bands) expect(b.fill).toBe(category.color);
|
||||
});
|
||||
});
|
||||
@@ -1,42 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { SectionCutPolygon } from "./toSection";
|
||||
import { mergeMonolithCuts, unionRectOutlines } from "./toSection";
|
||||
|
||||
const band = (index: number, u0: number, u1: number, v0: number, v1: number): SectionCutPolygon => ({
|
||||
component: { kind: "slab", index },
|
||||
color: [1, 1, 1],
|
||||
pts: [[u0, v0], [u1, v0], [u1, v1], [u0, v1]],
|
||||
});
|
||||
|
||||
describe("unionRectOutlines", () => {
|
||||
it("drei überlappende Tritte → ein Sägezahn-Umriss", () => {
|
||||
const rings = unionRectOutlines([
|
||||
{ uMin: 0, uMax: 0.3, vMin: 0, vMax: 0.2 },
|
||||
{ uMin: 0.3, uMax: 0.6, vMin: 0.05, vMax: 0.4 },
|
||||
{ uMin: 0.6, uMax: 0.9, vMin: 0.25, vMax: 0.6 },
|
||||
]);
|
||||
expect(rings.length).toBe(1);
|
||||
// Fläche = Summe minus nichts (keine Überlappung in der Fläche, nur Kanten).
|
||||
const area = rings[0].reduce((a, p, i, r) => {
|
||||
const q = r[(i + 1) % r.length];
|
||||
return a + (p[0] * q[1] - q[0] * p[1]) / 2;
|
||||
}, 0);
|
||||
expect(area).toBeCloseTo(0.3 * 0.2 + 0.3 * 0.35 + 0.3 * 0.35, 9);
|
||||
});
|
||||
it("getrennte Flächen → getrennte Ringe", () => {
|
||||
expect(unionRectOutlines([
|
||||
{ uMin: 0, uMax: 1, vMin: 0, vMax: 1 },
|
||||
{ uMin: 2, uMax: 3, vMin: 0, vMax: 1 },
|
||||
]).length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mergeMonolithCuts", () => {
|
||||
it("vereint nur Bänder derselben Gruppe", () => {
|
||||
const cuts = [band(0, 0, 1, 2.4, 2.6), band(5, 0, 0.3, 0, 0.2), band(6, 0.3, 0.6, 0.05, 0.4)];
|
||||
const out = mergeMonolithCuts(cuts, (i) => (i >= 5 ? "ST1" : undefined));
|
||||
expect(out.length).toBe(2);
|
||||
expect(out[0]).toBe(cuts[0]);
|
||||
expect(out[1].pts.length).toBe(8); // zwei versetzte Rechtecke → 8 Ecken
|
||||
});
|
||||
});
|
||||
@@ -1,72 +1,20 @@
|
||||
/**
|
||||
* Unit-Tests für die Aussen/Innen-Orientierung der mehrschichtigen Wand-Bänder
|
||||
* im SCHNITT (toSection): die Schicht-Bänder müssen der GRUNDRISS-Konvention
|
||||
* folgen (layers[0] = Aussenseite auf der `−leftNormal`-Weltseite der Achse), so
|
||||
* dass die Dämmung aussen und der Backstein innen liegt und zwei gegenüber-
|
||||
* liegende Wände im Schnitt SPIEGELVERKEHRT erscheinen (nicht identisch).
|
||||
*
|
||||
* Getestet ohne WASM: die Orientierungs-Hilfsfunktionen (`sectionUAxisModel`,
|
||||
* `wallLayersReversedInU`) und `splitWallLayers` mit einem synthetischen
|
||||
* Schnittrechteck gegen den echten „aw"-Wandtyp des Sample-Projekts.
|
||||
* u-Achse der Schnittebene (`sectionUAxisModel`, `sectionPlaneFromLevel`): Blickrichtungs-RECHTS wie
|
||||
* im Kern-Schnitt. Die Aussen/Innen-Lage der Schicht-Bänder prüft der Kern
|
||||
* (`core/src/plan/section.rs`, `schichten_aussen_aussen_und_override_auf_allen_schichten`).
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
sectionPlaneFromLevel,
|
||||
sectionUAxisModel,
|
||||
wallLayersReversedInU,
|
||||
splitWallLayers,
|
||||
type SectionCutPolygon,
|
||||
} from "./toSection";
|
||||
import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { getWallType } from "../model/types";
|
||||
import type { Wall } from "../model/types";
|
||||
|
||||
/** Wand aus dem Sample-Projekt per ID. */
|
||||
function wall(id: string): Wall {
|
||||
const w = sampleProject.walls.find((x) => x.id === id);
|
||||
if (!w) throw new Error(`Wand ${id} fehlt im Sample-Projekt`);
|
||||
return w;
|
||||
}
|
||||
|
||||
/** Achsparalleles Schnittrechteck (u, v): uMin..uMax × 0..2.6 m. */
|
||||
function rect(uMin: number, uMax: number): SectionCutPolygon {
|
||||
return {
|
||||
component: { kind: "wall", index: 0 },
|
||||
color: [0.5, 0.5, 0.5],
|
||||
pts: [
|
||||
[uMin, 2.6],
|
||||
[uMax, 2.6],
|
||||
[uMax, 0],
|
||||
[uMin, 0],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
/** Bänder nach uLeft (linke Kante) aufsteigend, mit ihrer u-Breite. */
|
||||
function bandsByU(polys: SectionCutPolygon[]): Array<{ uLeft: number; width: number }> {
|
||||
return polys
|
||||
.map((p) => {
|
||||
const us = p.pts.map((pt) => pt[0]);
|
||||
// Auf mm runden — glättet die Float-Akkumulation für stabile Vergleiche.
|
||||
const width = Math.round((Math.max(...us) - Math.min(...us)) * 1e6) / 1e6;
|
||||
return { uLeft: Math.min(...us), width };
|
||||
})
|
||||
.sort((a, b) => a.uLeft - b.uLeft);
|
||||
}
|
||||
|
||||
// Schnitt A: horizontale Linie y=2 (x −1…6), quer durch W2 (x=5) und W4 (x=0).
|
||||
const planeA = sectionPlaneFromLevel(
|
||||
sampleProject.drawingLevels.find((l) => l.id === "schnitt-a")!,
|
||||
)!;
|
||||
|
||||
// „aw" = [render-ext(0.02) · insulation(0.16) · brick(0.15) · render-int(0.015)].
|
||||
const aw = getWallType(sampleProject, wall("W2"));
|
||||
const RENDER_EXT_T = 0.02; // Aussenputz — layers[0], die Aussenseite
|
||||
const RENDER_INT_T = 0.015; // Innenputz — letzte Schicht, die Innenseite
|
||||
|
||||
describe("Schnitt-u-Weltachse", () => {
|
||||
it("entspricht der WASM-Konvention u = cross(up, normal) → Grundriss (Nz, −Nx)", () => {
|
||||
it("entspricht der Kern-Konvention u = cross(up, normal) → Grundriss (Nz, −Nx)", () => {
|
||||
// Schnitt A: Ebenennormale world = (0,0,1) → uWorld model = (1, 0) —
|
||||
// Betrachter-RECHTS (Entspiegelung: Blick nach Norden ⇒ Osten rechts).
|
||||
expect(planeA.normal[0]).toBeCloseTo(0, 9);
|
||||
@@ -77,59 +25,3 @@ describe("Schnitt-u-Weltachse", () => {
|
||||
expect(u.y).toBeCloseTo(0, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Wand-Aufbaurichtung vs. Schnitt-u-Achse", () => {
|
||||
const uWorld = sectionUAxisModel(planeA);
|
||||
|
||||
it("W2 (Aussenseite +x) gespiegelt, W4 (Aussenseite −x) nicht — entspiegelte u-Achse", () => {
|
||||
// Beide Wände gehören zum CCW-Umriss; die linke Normale zeigt nach innen.
|
||||
// Gegenüberliegende Wände ⇒ genau eine der beiden wird gespiegelt. (Mit
|
||||
// der Entspiegelung der u-Achse tauschen die Rollen gegenüber früher —
|
||||
// Geometrie UND Bandreihenfolge kippen zusammen, die Aussenseite bleibt
|
||||
// in der Zeichnung physisch aussen.)
|
||||
expect(wallLayersReversedInU(wall("W2"), uWorld)).toBe(true);
|
||||
expect(wallLayersReversedInU(wall("W4"), uWorld)).toBe(false);
|
||||
});
|
||||
|
||||
it("degenerierte Wand (Länge 0) bleibt unverändert (kein Spiegeln)", () => {
|
||||
const dot: Wall = { ...wall("W2"), end: { ...wall("W2").start } };
|
||||
expect(wallLayersReversedInU(dot, uWorld)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("splitWallLayers: Aussenputz auf der Aussenseite, Wände spiegelverkehrt", () => {
|
||||
const uWorld = sectionUAxisModel(planeA);
|
||||
const cp = rect(0, 0.345); // volle Wanddicke, Skala 1:1
|
||||
|
||||
it("W2: gespiegelt — Aussenputz an uMax, Innenputz an uMin", () => {
|
||||
const bands = bandsByU(splitWallLayers(cp, sampleProject, aw, wall("W2"), uWorld));
|
||||
expect(bands).toHaveLength(4);
|
||||
// Entspiegelte u-Achse: W2s Aussenseite (+x) liegt jetzt bei uMax.
|
||||
expect(bands[0].width).toBeCloseTo(RENDER_INT_T, 6);
|
||||
expect(bands[3].width).toBeCloseTo(RENDER_EXT_T, 6);
|
||||
});
|
||||
|
||||
it("W4: Aussenputz (layers[0]) an uMin, Innenputz an uMax", () => {
|
||||
const bands = bandsByU(splitWallLayers(cp, sampleProject, aw, wall("W4"), uWorld));
|
||||
expect(bands).toHaveLength(4);
|
||||
expect(bands[0].width).toBeCloseTo(RENDER_EXT_T, 6);
|
||||
expect(bands[3].width).toBeCloseTo(RENDER_INT_T, 6);
|
||||
});
|
||||
|
||||
it("propagiert sourceId (Quell-Element) auf ALLE Schicht-Bänder", () => {
|
||||
const cpWithId: SectionCutPolygon = { ...cp, sourceId: "W2" };
|
||||
const bands = splitWallLayers(cpWithId, sampleProject, aw, wall("W2"), uWorld);
|
||||
expect(bands.length).toBeGreaterThan(1);
|
||||
expect(bands.every((b) => b.sourceId === "W2")).toBe(true);
|
||||
});
|
||||
|
||||
it("W2 und W4 liegen spiegelverkehrt (nicht identisch)", () => {
|
||||
const b2 = bandsByU(splitWallLayers(cp, sampleProject, aw, wall("W2"), uWorld));
|
||||
const b4 = bandsByU(splitWallLayers(cp, sampleProject, aw, wall("W4"), uWorld));
|
||||
// Reihenfolge der Bandbreiten von uMin→uMax ist exakt umgekehrt.
|
||||
const w2 = b2.map((b) => b.width);
|
||||
const w4 = b4.map((b) => b.width);
|
||||
expect(w2).not.toEqual(w4);
|
||||
expect(w2).toEqual([...w4].reverse());
|
||||
});
|
||||
});
|
||||
@@ -1,169 +0,0 @@
|
||||
// Dach im Vertikalschnitt: appendRoofSections schneidet die Schnittebene
|
||||
// analytisch mit den Dachflächen (der Rust-Extraktor kennt nur Wände/Decken).
|
||||
// Geprüft werden u-Intervalle, Oberkanten-Verlauf (linear je Fläche), die
|
||||
// vertikale Dicke (lotrechte Dicke / cos(Neigung)) und die Schicht-Bänder.
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { appendRoofSections } from "./toSection";
|
||||
import type { SectionOutput, SectionPlaneSpec } from "./toSection";
|
||||
import type { Project, Roof } from "../model/types";
|
||||
|
||||
const RECT: Roof["outline"] = [
|
||||
{ x: -3, y: 0 },
|
||||
{ x: 3, y: 0 },
|
||||
{ x: 3, y: 4 },
|
||||
{ x: -3, y: 4 },
|
||||
];
|
||||
|
||||
function roof(over: Partial<Roof> = {}): Roof {
|
||||
return {
|
||||
id: "R1",
|
||||
type: "roof",
|
||||
floorId: "eg",
|
||||
categoryCode: "35",
|
||||
outline: RECT,
|
||||
shape: "sattel",
|
||||
pitchDeg: 30,
|
||||
overhang: 0,
|
||||
ridgeAxis: "x",
|
||||
baseElevation: 5, // explizit — kein Geschoss-Lookup nötig
|
||||
thickness: 0.3,
|
||||
...over,
|
||||
};
|
||||
}
|
||||
|
||||
function project(r: Roof, extra: Partial<Project> = {}): Project {
|
||||
return {
|
||||
id: "t",
|
||||
name: "T",
|
||||
lineStyles: [],
|
||||
hatches: [],
|
||||
components: [],
|
||||
wallTypes: [],
|
||||
drawingLevels: [],
|
||||
layers: [],
|
||||
walls: [],
|
||||
roofs: [r],
|
||||
...extra,
|
||||
} as unknown as Project;
|
||||
}
|
||||
|
||||
/** Schnittebene: Blick entlang +x (Osten), Spur x=0 — Betrachter-RECHTS =
|
||||
* Süden, u fällt also mit Modell-y (entspiegelte u-Achse). */
|
||||
const PLANE: SectionPlaneSpec = { point: [0, 0, 0], normal: [1, 0, 0] };
|
||||
|
||||
const emptyOutput = (): SectionOutput => ({ cutPolygons: [], visibleEdges: [], hiddenEdges: [] });
|
||||
|
||||
describe("appendRoofSections", () => {
|
||||
it("Flachdach: EIN Rechteck-Band, Oberkante = Traufhöhe, Höhe = Dicke", () => {
|
||||
const out = emptyOutput();
|
||||
appendRoofSections(out, project(roof({ shape: "flach", pitchDeg: 0 })), PLANE);
|
||||
expect(out.cutPolygons.length).toBe(1);
|
||||
const cp = out.cutPolygons[0];
|
||||
expect(cp.component).toEqual({ kind: "roof", index: 0 });
|
||||
// u-Intervall = Tiefe 0..4 → u −4..0 (u = −Modell-y); Oberkante 5,
|
||||
// Unterkante 5 − 0.3 (cosθ = 1).
|
||||
const us = cp.pts.map((p) => p[0]).sort((a, b) => a - b);
|
||||
expect(us[0]).toBeCloseTo(-4, 6);
|
||||
expect(us[3]).toBeCloseTo(0, 6);
|
||||
const vs = cp.pts.map((p) => p[1]).sort((a, b) => a - b);
|
||||
expect(vs[3]).toBeCloseTo(5, 6);
|
||||
expect(vs[0]).toBeCloseTo(5 - 0.3, 6);
|
||||
});
|
||||
|
||||
it("Satteldach quer zum First: zwei Bänder (steigend/fallend) mit Neigungs-Dicke", () => {
|
||||
const out = emptyOutput();
|
||||
appendRoofSections(out, project(roof()), PLANE);
|
||||
expect(out.cutPolygons.length).toBe(2);
|
||||
const tan30 = Math.tan((30 * Math.PI) / 180);
|
||||
const cos30 = Math.cos((30 * Math.PI) / 180);
|
||||
const ridgeZ = 5 + 2 * tan30; // First bei halber Tiefe (y=2 → u=−2)
|
||||
// Alle Oberkanten-Werte je Band: an u=0/−4 Traufe (5), an u=−2 First.
|
||||
const topAt = (cp: (typeof out.cutPolygons)[number], u: number): number =>
|
||||
Math.max(...cp.pts.filter((p) => Math.abs(p[0] - u) < 1e-6).map((p) => p[1]));
|
||||
const bands = out.cutPolygons;
|
||||
const front = bands.find((b) => b.pts.some((p) => Math.abs(p[0]) < 1e-6));
|
||||
const back = bands.find((b) => b.pts.some((p) => Math.abs(p[0] + 4) < 1e-6));
|
||||
expect(front).toBeDefined();
|
||||
expect(back).toBeDefined();
|
||||
expect(topAt(front!, 0)).toBeCloseTo(5, 5);
|
||||
expect(topAt(front!, -2)).toBeCloseTo(ridgeZ, 5);
|
||||
expect(topAt(back!, -4)).toBeCloseTo(5, 5);
|
||||
expect(topAt(back!, -2)).toBeCloseTo(ridgeZ, 5);
|
||||
// Vertikale Banddicke = lotrechte Dicke / cos(Neigung).
|
||||
const vAt = (cp: (typeof out.cutPolygons)[number], u: number): number[] =>
|
||||
cp.pts.filter((p) => Math.abs(p[0] - u) < 1e-6).map((p) => p[1]);
|
||||
const [hi, lo] = vAt(front!, 0).sort((a, b) => b - a);
|
||||
expect(hi - lo).toBeCloseTo(0.3 / cos30, 5);
|
||||
});
|
||||
|
||||
it("Schnittspur ausserhalb des Dachs: keine Bänder", () => {
|
||||
const out = emptyOutput();
|
||||
// Spur x=0 — Dach komplett rechts davon (x 10..16).
|
||||
const far = roof({
|
||||
outline: [
|
||||
{ x: 10, y: 0 },
|
||||
{ x: 16, y: 0 },
|
||||
{ x: 16, y: 4 },
|
||||
{ x: 10, y: 4 },
|
||||
],
|
||||
});
|
||||
appendRoofSections(out, project(far), PLANE);
|
||||
expect(out.cutPolygons.length).toBe(0);
|
||||
});
|
||||
|
||||
it("mehrschichtiges Dach (roofTypeId): je Schicht ein Band pro Fläche, aussen oben", () => {
|
||||
const p = project(roof({ shape: "flach", pitchDeg: 0, roofTypeId: "rt1" }), {
|
||||
hatches: [
|
||||
{ id: "h1", name: "H", pattern: "diagonal", scale: 1, angle: 45, color: "#111111" },
|
||||
],
|
||||
components: [
|
||||
{ id: "tile", name: "Ziegel", color: "#a03a2a", hatchId: "h1", joinPriority: 1 },
|
||||
{ id: "ins", name: "Dämmung", color: "#ffffff", hatchId: "h1", joinPriority: 2 },
|
||||
],
|
||||
roofTypes: [
|
||||
{
|
||||
id: "rt1",
|
||||
name: "Aufbau",
|
||||
layers: [
|
||||
{ componentId: "tile", thickness: 0.05 },
|
||||
{ componentId: "ins", thickness: 0.25 },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const out = emptyOutput();
|
||||
appendRoofSections(out, p, PLANE);
|
||||
expect(out.cutPolygons.length).toBe(2); // 1 Fläche × 2 Schichten
|
||||
const tops = out.cutPolygons.map((cp) => Math.max(...cp.pts.map((q) => q[1])));
|
||||
// Eindeckung oben (OK 5), Dämmung darunter (OK 5 − 0.05).
|
||||
expect(Math.max(...tops)).toBeCloseTo(5, 6);
|
||||
expect(Math.min(...tops)).toBeCloseTo(4.95, 6);
|
||||
// Schicht-Stile sind aufgelöst (Schraffur des Bauteils).
|
||||
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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -1,106 +0,0 @@
|
||||
// Decken-Terminierung im 2D-Schnitt (applyWallTermination) — der Spiegel von
|
||||
// terminateOrSubtractSpans (3D): Wände mit sliceTermination "below" enden an
|
||||
// der Decken-Unterkante, "above" beginnen an der Oberkante; "both"/undefined
|
||||
// bleibt bei der reinen Prioritäts-Subtraktion (unverändert hier).
|
||||
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { applyWallTermination } from "./toSection";
|
||||
import type { SectionCutPolygon } from "./toSection";
|
||||
import type { Wall } from "../model/types";
|
||||
|
||||
const rect = (
|
||||
uMin: number,
|
||||
uMax: number,
|
||||
vMin: number,
|
||||
vMax: number,
|
||||
): Array<[number, number]> => [
|
||||
[uMin, vMax],
|
||||
[uMax, vMax],
|
||||
[uMax, vMin],
|
||||
[uMin, vMin],
|
||||
];
|
||||
|
||||
const wallBand = (joinPriority: number | undefined, pts = rect(0, 0.3, 0, 2.6)): SectionCutPolygon => ({
|
||||
component: { kind: "wall", index: 0 },
|
||||
color: [0.8, 0.8, 0.8],
|
||||
pts,
|
||||
joinPriority,
|
||||
});
|
||||
|
||||
const slabBand = (joinPriority: number, vMin: number, vMax: number, uMin = -2, uMax = 2): SectionCutPolygon => ({
|
||||
component: { kind: "slab", index: 0 },
|
||||
color: [0.9, 0.9, 0.9],
|
||||
pts: rect(uMin, uMax, vMin, vMax),
|
||||
joinPriority,
|
||||
});
|
||||
|
||||
const wall = (sliceTermination?: Wall["sliceTermination"]): Wall =>
|
||||
({
|
||||
id: "W1",
|
||||
start: { x: 0, y: 0 },
|
||||
end: { x: 5, y: 0 },
|
||||
height: 2.6,
|
||||
wallTypeId: "wt",
|
||||
floorId: "eg",
|
||||
categoryCode: "21",
|
||||
sliceTermination,
|
||||
}) as Wall;
|
||||
|
||||
const bbox = (cp: SectionCutPolygon) => {
|
||||
const vs = cp.pts.map((p) => p[1]);
|
||||
return { vMin: Math.min(...vs), vMax: Math.max(...vs) };
|
||||
};
|
||||
|
||||
describe("applyWallTermination — 2D-Schnitt = 3D-Terminierung", () => {
|
||||
it("'below': Wand-Band endet an der Unterkante der dominanten Decke", () => {
|
||||
const bands = [wallBand(50), slabBand(100, 2.2, 2.5)];
|
||||
const out = applyWallTermination(bands, [wall("below")]);
|
||||
const wb = out.find((b) => b.component.kind === "wall")!;
|
||||
expect(bbox(wb).vMax).toBeCloseTo(2.2, 9);
|
||||
expect(bbox(wb).vMin).toBeCloseTo(0, 9);
|
||||
});
|
||||
|
||||
it("'above': Wand-Band beginnt an der Oberkante der dominanten Decke", () => {
|
||||
const bands = [wallBand(50), slabBand(100, 2.2, 2.5)];
|
||||
const out = applyWallTermination(bands, [wall("above")]);
|
||||
const wb = out.find((b) => b.component.kind === "wall")!;
|
||||
expect(bbox(wb).vMin).toBeCloseTo(2.5, 9);
|
||||
expect(bbox(wb).vMax).toBeCloseTo(2.6, 9);
|
||||
});
|
||||
|
||||
it("'both'/undefined: Band bleibt unverändert (Prioritäts-Subtraktion regelt)", () => {
|
||||
const bands = [wallBand(50), slabBand(100, 2.2, 2.5)];
|
||||
for (const term of ["both", undefined] as const) {
|
||||
const out = applyWallTermination(bands, [wall(term)]);
|
||||
const wb = out.find((b) => b.component.kind === "wall")!;
|
||||
expect(wb.pts).toEqual(rect(0, 0.3, 0, 2.6));
|
||||
}
|
||||
});
|
||||
|
||||
it("nur STRIKT dominante Decken terminieren (schwächere/gleiche nicht)", () => {
|
||||
for (const prio of [50, 10]) {
|
||||
const bands = [wallBand(50), slabBand(prio, 2.2, 2.5)];
|
||||
const out = applyWallTermination(bands, [wall("below")]);
|
||||
const wb = out.find((b) => b.component.kind === "wall")!;
|
||||
expect(bbox(wb).vMax).toBeCloseTo(2.6, 9);
|
||||
}
|
||||
});
|
||||
|
||||
it("ohne u-Überlapp keine Terminierung; Band unter der Decken-UK verschwindet nicht", () => {
|
||||
// Decke liegt in u komplett rechts neben der Wand.
|
||||
const far = [wallBand(50), slabBand(100, 2.2, 2.5, 5, 8)];
|
||||
const outFar = applyWallTermination(far, [wall("below")]);
|
||||
expect(bbox(outFar.find((b) => b.component.kind === "wall")!).vMax).toBeCloseTo(2.6, 9);
|
||||
|
||||
// Decke UNTER dem Wandfuss ⇒ 'below'-Clip entfernt das ganze Band.
|
||||
const under = [wallBand(50), slabBand(100, -0.5, -0.2)];
|
||||
const outUnder = applyWallTermination(under, [wall("below")]);
|
||||
expect(outUnder.some((b) => b.component.kind === "wall")).toBe(false);
|
||||
});
|
||||
|
||||
it("Bänder ohne joinPriority (unauflösbares Bauteil) bleiben unangetastet", () => {
|
||||
const bands = [wallBand(undefined), slabBand(100, 2.2, 2.5)];
|
||||
const out = applyWallTermination(bands, [wall("below")]);
|
||||
expect(out.find((b) => b.component.kind === "wall")!.pts).toEqual(rect(0, 0.3, 0, 2.6));
|
||||
});
|
||||
});
|
||||
+134
-1086
File diff suppressed because it is too large.
Load diff
@@ -1392,12 +1392,12 @@ describe("Per-Schicht-Decken-Dominanz Wand/Decke (3D-Entsprechung der Schnitt-Bo
|
||||
// render-int x=4.8350 (INNEN) -> überdeckt -> Decken-z-Schnitt
|
||||
// Die Decke schneidet ein Band also nur dort, wo ihre Outline die Footprint-
|
||||
// Mittellinie DIESES Bandes überdeckt (geometrischer Überlapp wie
|
||||
// toSection.ts::subtractDominantBands) — NICHT mehr per wandweitem BBox-Test.
|
||||
// Schnitt-Dominanz im Kern (plan_section.rs)) — NICHT mehr per wandweitem BBox-Test.
|
||||
// (Frühere Tests erwarteten hier „ALLE Schichten geschnitten"; das kodierte das
|
||||
// falsche BBox-Verhalten und ist die Ursache des 3D-Kranzes. Korrigiert.)
|
||||
it("Decke schneidet nur die von ihrer Outline überdeckten (inneren) Bänder; Dämmung/Aussenputz laufen durch; Beton spaltet den Backstein PER SCHICHT", () => {
|
||||
const w2 = projectToWalls3d(sampleProject).filter((w) => w.wallId === "W2");
|
||||
// PER-SCHICHT-Decken-Dominanz (identisch zu toSection.ts::subtractDominantBands):
|
||||
// PER-SCHICHT-Decken-Dominanz (identisch zu Schnitt-Dominanz im Kern (plan_section.rs)):
|
||||
// jede Deckenschicht (screed 30 / insulation 20 / concrete 100) schneidet nur
|
||||
// Wandbänder mit STRIKT niedrigerer Priorität in IHREM z-Band. Der Backstein (50)
|
||||
// wird also NUR von der Beton-Schicht (100, z-Band [2.3,2.5]) gekappt und läuft
|
||||
@@ -1949,7 +1949,7 @@ describe("Wand-Joins im 3D (L-/T-Stösse, identisch zum 2D-Grundriss/Schnitt)",
|
||||
it("Joins wirken NUR im layered-3D-Pfad, nicht im Schnitt-Pfad (layered=false unverändert)", () => {
|
||||
// Der Schnitt-Pfad (computeSection, layeredWalls:false) darf KEINE Join-Cuts
|
||||
// bekommen: W2 bleibt eine Voll-Box über die ganze Dicke, ungehrt (Achse
|
||||
// 0..4), damit toSection.ts::subtractDominantBands seine eigene Dominanz auf
|
||||
// 0..4), damit Schnitt-Dominanz im Kern (plan_section.rs) seine eigene Dominanz auf
|
||||
// Rohgeometrie anwendet.
|
||||
const w2 = projectToWalls3d(sampleProject, false).filter((w) => w.wallId === "W2");
|
||||
expect(w2.length).toBe(1); // Voll-Box, keine Schicht-Bänder
|
||||
|
||||
@@ -110,12 +110,8 @@ export function roofMeshes(project: Project, onlyRoofId?: string): RMesh[] {
|
||||
/**
|
||||
* Optionen für {@link projectToModel3d}. `layeredWalls` steuert, ob eine
|
||||
* mehrschichtige Wand als eigene Box je Materiallage (Default, 3D-Viewer) oder
|
||||
* als EINE Voll-Box über die ganze Dicke emittiert wird. Der Schnitt-Pfad
|
||||
* (`computeSection`) setzt `false`, damit die Cut-Polygone 1:1 zur Wand liegen
|
||||
* (die Schicht-Zerlegung macht dort `splitWallLayers` TS-seitig) — sonst
|
||||
* verschöben die per-Lage vervielfachten Boxen die `ComponentRef.index`
|
||||
* gegenüber `wallSegmentOwners` und die materialspezifische Schnitt-Schraffur
|
||||
* ginge verloren.
|
||||
* als EINE Voll-Box über die ganze Dicke emittiert wird (so rechnen auch Schnitt
|
||||
* und Ansicht im Kern, `core/src/plan/{section,elevation}.rs`).
|
||||
*/
|
||||
export interface Model3dOptions {
|
||||
layeredWalls?: boolean;
|
||||
|
||||
+1
-17
@@ -3,7 +3,7 @@ import type { Pair } from "../geometry/polygonBool";
|
||||
import { generatePlan } from "./generatePlan";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import type { ExtrudedSolid, Project } from "../model/types";
|
||||
import { keyhole, segmentOutside, subtractRings, subtractVoidsInSection, voidPrisms, voidSectionRects } from "./voids";
|
||||
import { segmentOutside, subtractRings } from "./voids";
|
||||
|
||||
const sq = (x0: number, y0: number, x1: number, y1: number): Pair[] => [[x0, y0], [x1, y0], [x1, y1], [x0, y1]];
|
||||
const area = (r: Pair[]) => Math.abs(r.reduce((s, p, i) => s + p[0] * r[(i + 1) % r.length][1] - r[(i + 1) % r.length][0] * p[1], 0) / 2);
|
||||
@@ -40,10 +40,6 @@ describe("Abzugskoerper — Polygon-Kern", () => {
|
||||
const edges = r[0].noStrokeEdges.map((i) => [r[0].pts[i], r[0].pts[(i + 1) % r[0].pts.length]]);
|
||||
expect(edges.every(([a, b]) => a[0] === 4 && b[0] === 4)).toBe(true);
|
||||
});
|
||||
it("keyhole haengt mehrere Loecher ein", () => {
|
||||
const k = keyhole([sq(0, 0, 10, 2), sq(1, 0.5, 2, 1.5).reverse(), sq(5, 0.5, 6, 1.5).reverse()]);
|
||||
expect(k.bridges).toHaveLength(4);
|
||||
});
|
||||
it("segmentOutside: Linie durch Quadrat in zwei Teile", () => {
|
||||
const parts = segmentOutside({ x: 0, y: 0.5 }, { x: 4, y: 0.5 }, [sq(1, 0, 2, 1)]);
|
||||
expect(parts.map(([a, b]) => [a, b])).toEqual([[0, 0.25], [0.5, 1]]);
|
||||
@@ -77,16 +73,4 @@ describe("Abzugskoerper — Grundriss und Schnitt", () => {
|
||||
const p = withVoid(sampleProject, { points: box, baseOffset: 1.5, height: 0.5 });
|
||||
expect(wallPolys(p).length).toBe(wallPolys(sampleProject).length);
|
||||
});
|
||||
it("Schnitt: Rechtecke aus Grundflaeche x Hoehenbereich, Abzug aus Cut-Polygonen", () => {
|
||||
const p = withVoid(sampleProject, { points: box, baseOffset: 0.5, height: 1 });
|
||||
const [v] = voidPrisms(p);
|
||||
const rects = voidSectionRects(v, { x: 0, y: my }, { x: 1, y: 0 });
|
||||
expect(rects).toHaveLength(1);
|
||||
expect(rects[0][0][0]).toBeCloseTo(mx - 0.3, 9);
|
||||
expect(rects[0][2][1]).toBeCloseTo(v.z1, 9);
|
||||
const cuts = [{ pts: sq(mx - 2, 0, mx + 2, 2.5) as Array<[number, number]> }];
|
||||
const out = subtractVoidsInSection(cuts, p, { x: 0, y: my }, { x: 1, y: 0 });
|
||||
expect(out).toHaveLength(1);
|
||||
expect(area(out[0].pts)).toBeCloseTo(4 * 2.5 - 0.6 * 1, 6);
|
||||
});
|
||||
});
|
||||
+2
-72
@@ -4,7 +4,8 @@
|
||||
//
|
||||
// • Grundriss: Poché-Polygone der getroffenen Bauteile minus Körper-Grundfläche, sofern der
|
||||
// Körper die Schnitthöhe (Wände/Stützen) bzw. die Platte (Decken) durchdringt.
|
||||
// • Schnitt: Cut-Polygone minus Körper-Schnitt (Grundfläche ∩ Schnittspur × Höhenbereich).
|
||||
// • Schnitt: Cut-Polygone minus Körper-Schnitt (Grundfläche ∩ Schnittspur × Höhenbereich), im Kern
|
||||
// (`core/src/plan/section.rs`).
|
||||
// • 3D/STEP: Boolean-Differenz (truck, Mesh-CSG-Fallback), s. `toWalls3d/voids3d.ts`
|
||||
// bzw. `exportStep.ts`.
|
||||
//
|
||||
@@ -74,21 +75,6 @@ function encodeRings(rings: Pair[][]): Float64Array {
|
||||
return Float64Array.from(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Löcher per Steg in den Aussenring einhängen (Schlüsselloch). Liefert die Punkte und die
|
||||
* Indizes der Stegkanten (Kante i = pts[i] → pts[i+1]).
|
||||
*/
|
||||
export function keyhole(poly: Pair[][]): { pts: Pair[]; bridges: number[] } {
|
||||
const f = core().voids_keyhole_flat(encodeRings(poly));
|
||||
const n = f[0];
|
||||
const pts = new Array<Pair>(n);
|
||||
for (let i = 0; i < n; i++) pts[i] = [f[1 + 2 * i], f[2 + 2 * i]];
|
||||
const nb = f[1 + 2 * n];
|
||||
const bridges = new Array<number>(nb);
|
||||
for (let i = 0; i < nb; i++) bridges[i] = f[2 + 2 * n + i];
|
||||
return { pts, bridges };
|
||||
}
|
||||
|
||||
/**
|
||||
* Polygon (Ring `pts`, optional nicht gestrichene Kanten) minus Schneider. Liefert die
|
||||
* Rest-Polygone mit übertragenen `noStrokeEdges` (eine Kante bleibt ungestrichen, wenn sie
|
||||
@@ -202,62 +188,6 @@ export function subtractVoidsInPlan(prims: Primitive[], project: Project, cutZ:
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Schnitt ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Schnitt-Rechtecke (u, v) eines Abzugskörpers mit der senkrechten Ebene durch `base` in
|
||||
* Richtung `uDir` (Einheitsvektor; u = Abstand entlang uDir ab `base`).
|
||||
*/
|
||||
export function voidSectionRects(v: VoidPrism, base: Vec2, uDir: Vec2): Pair[][] {
|
||||
const f = core().voids_section_rects_flat(
|
||||
Float64Array.from([v.pts.length, ...v.pts.flatMap((p) => [p.x, p.y])]),
|
||||
Float64Array.from([base.x, base.y, uDir.x, uDir.y]),
|
||||
);
|
||||
const rects: Pair[][] = [];
|
||||
for (let k = 0; k < (f[0] ?? 0); k++) {
|
||||
const u0 = f[1 + 2 * k];
|
||||
const u1 = f[2 + 2 * k];
|
||||
rects.push([
|
||||
[u0, v.z0],
|
||||
[u1, v.z0],
|
||||
[u1, v.z1],
|
||||
[u0, v.z1],
|
||||
]);
|
||||
}
|
||||
return rects;
|
||||
}
|
||||
|
||||
/** Minimal-Form eines Schnitt-Polygons (s. `SectionCutPolygon` in toSection.ts). */
|
||||
interface CutPolyLike {
|
||||
pts: Array<[number, number]>;
|
||||
noStrokeEdges?: number[];
|
||||
}
|
||||
|
||||
/** Zieht die Abzugskörper von den Cut-Polygonen eines Schnitts ab (neue Liste). */
|
||||
export function subtractVoidsInSection<T extends CutPolyLike>(
|
||||
cuts: T[],
|
||||
project: Project,
|
||||
base: Vec2,
|
||||
uDir: Vec2,
|
||||
): T[] {
|
||||
const voids = voidPrisms(project);
|
||||
if (voids.length === 0) return cuts;
|
||||
const rects = voids.flatMap((v) => voidSectionRects(v, base, uDir));
|
||||
if (rects.length === 0) return cuts;
|
||||
const out: T[] = [];
|
||||
for (const cp of cuts) {
|
||||
const rest = subtractRings(cp.pts as Pair[], rects, cp.noStrokeEdges ?? []);
|
||||
if (rest === null) {
|
||||
out.push(cp);
|
||||
continue;
|
||||
}
|
||||
for (const r of rest) {
|
||||
out.push({ ...cp, pts: r.pts as Array<[number, number]>, noStrokeEdges: r.noStrokeEdges.length ? r.noStrokeEdges : undefined });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── 3D / B-Rep ───────────────────────────────────────────────────────────────
|
||||
|
||||
export type Box2 = { x0: number; y0: number; x1: number; y1: number };
|
||||
|
||||
@@ -23,13 +23,12 @@ import { categoryNameForPick } from "../core";
|
||||
import type { PickKind } from "../core";
|
||||
import { generatePlan, generateSectionPlan, generateVisibleLevelsPlan } from "../core";
|
||||
import { planWithExtra } from "../core";
|
||||
import type { CategoryDisplayResolver, Plan, Primitive } from "../core";
|
||||
import type { CategoryDisplayResolver, Primitive } from "../core";
|
||||
import type { RichTextDoc } from "../text/richText";
|
||||
import { computeSection, sameSectionInputs, sameSectionLine } from "../core";
|
||||
import type { SectionOutput } from "../core";
|
||||
import { generateElevationPlan } from "../core";
|
||||
import { crossKindOverlayAllowed, planUnderlayPrimitives } from "../core";
|
||||
import { sectionOpeningPrimitives } from "../core";
|
||||
import { levelMarkerPrimitives, levelMarksEnabled } from "../core";
|
||||
import { setSheetOwnerOutlines, setSheetSnapSegments, snapSegmentsFromPrimitives } from "../tools/sheetSnapGeometry";
|
||||
import { pushNativeScene, pushNativeWalls } from "./plan/nativeSync";
|
||||
@@ -923,24 +922,12 @@ function LevelPlanView({
|
||||
}
|
||||
|
||||
/**
|
||||
* Geschnittene Fenster/Türen in den Schnitt-Plan einsetzen: nach den Cut-
|
||||
* Polygonen (liegen in deren Aussparung), vor den Ansichtskanten — die Reihen-
|
||||
* folge spielt kaum eine Rolle, da sie sich nicht überdecken.
|
||||
*/
|
||||
function withSectionOpenings(plan: Plan, openings: Primitive[]): Plan {
|
||||
if (openings.length === 0) return plan;
|
||||
return { ...plan, primitives: [...plan.primitives, ...openings] };
|
||||
}
|
||||
|
||||
/**
|
||||
* Schnitt-/Ansichts-Ebene: der render3d-Schnitt-Extraktor (WASM, plan/toSection)
|
||||
* durchschneidet das Modell entlang der Schnittlinie der Ebene und übersetzt das
|
||||
* Ergebnis (Cut-Polygone + sichtbare/verdeckte Kanten) über generateSectionPlan
|
||||
* in Plan-Primitive, die dieselbe PlanView wie ein Grundriss zeichnet.
|
||||
* Schnitt-/Ansichts-Ebene: der Kern rechnet Schnitt bzw. Ansicht entlang der Schnittlinie der
|
||||
* Ebene (`generateSectionPlan`/`generateElevationPlan`, Plan-Puffer v2 mit Pick-Ids, samt den
|
||||
* geschnittenen Fenstern/Türen), die dieselbe PlanView wie ein Grundriss zeichnet.
|
||||
*
|
||||
* Die Berechnung ist asynchron (WASM lazy geladen); bis das Ergebnis da ist,
|
||||
* bzw. wenn die Ebene keine Schnittlinie trägt oder das WASM-Modul den Export
|
||||
* (noch) nicht kennt, wird ein Hinweis eingeblendet.
|
||||
* Der Schnitt ist asynchron (die freien Körper baut truck); bis das Ergebnis da ist bzw. wenn
|
||||
* die Ebene keine Schnittlinie trägt, wird ein Hinweis eingeblendet.
|
||||
*/
|
||||
function SectionPlanView({
|
||||
project,
|
||||
@@ -1052,9 +1039,8 @@ function SectionPlanView({
|
||||
selectedDrawingIds?: string[];
|
||||
gripHandlers: GripHandlers;
|
||||
}) {
|
||||
// Die Ansicht (kind "elevation") läuft NICHT über den WASM-Schnitt, sondern
|
||||
// über den rein TS-seitigen Flächen-Generator (Painter, toElevation.ts) —
|
||||
// synchron, kein Lazy-Load. Nur der echte Schnitt braucht die WASM-Pipeline.
|
||||
// Die Ansicht (kind "elevation") ist synchron (Kern, Painter); nur der Schnitt wartet auf die
|
||||
// truck-Körper.
|
||||
const isElevation = level.kind === "elevation";
|
||||
const [output, setOutput] = useState<SectionOutput | null>(null);
|
||||
const [status, setStatus] = useState<"loading" | "ready" | "empty" | "error">(
|
||||
@@ -1122,14 +1108,12 @@ function SectionPlanView({
|
||||
const sectionPlan = useMemo(
|
||||
() =>
|
||||
!isElevation && output
|
||||
? withSectionOpenings(
|
||||
generateSectionPlan(output, mono, {
|
||||
hiddenLines: level.hiddenLines,
|
||||
visibleCodes,
|
||||
categoryDisplay,
|
||||
}),
|
||||
sectionOpeningPrimitives(inputs.project, inputs.level, visibleCodes, categoryDisplay),
|
||||
)
|
||||
? generateSectionPlan(output, mono, {
|
||||
hiddenLines: level.hiddenLines,
|
||||
visibleCodes,
|
||||
categoryDisplay,
|
||||
openings: true,
|
||||
})
|
||||
: null,
|
||||
[isElevation, output, mono, level.hiddenLines, visibleCodes, categoryDisplay, inputs],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user