Schnitt/Ansicht: keine losen Fremd-Ueberlagerungen, keine Griffe in Grundriss-Koordinaten, Fang an Schnittkanten, Ansichtskanten hinter Bauteilen vor der Ebene, geschnittene Fenster/Tueren
- Fremd-Art-Ueberlagerung nur noch im gleichen Koordinatenraum (Geschoss <-> freie Zeichnung); Grundriss optional ausgerichtet unter Schnitt/Ansicht (DrawingLevel.planUnderlayId) - Im Schnitt/in der Ansicht nur Griffe/Transformationen fuer 2D-Elemente der Ebene (Bauteile leben im Grundriss-Raum) - Fangkanten der abgeleiteten Geometrie fuer computeSnap (sheetSnapGeometry) - Im Schnitt gezeichnete 2D-Elemente werden angezeigt - Kein Flackern/Zoom-Verlust: altes Ergebnis bleibt bis zum neuen, reine 2D-Aenderungen rechnen nicht neu - section.rs: Bauteile komplett vor der Schnittebene verdecken nichts mehr - Geschnittene Fenster (Rahmenprofil + Glas) und Tueren (Zarge + Blatt), Bodenlinie, Schnitt-Einstellungen ohne Auswahl
This commit is contained in:
1 parent
6fbc8d4ff8
commit
f44ba9ed85
20 files changed
+1049
-57
No files matched your search
@@ -825,6 +825,8 @@ const SECTION_HIDDEN_INK = "#8a929c";
|
||||
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). */
|
||||
@@ -957,6 +959,19 @@ export function generateSectionPlan(
|
||||
});
|
||||
}
|
||||
|
||||
// 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 } };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { DrawingLevel } from "../model/types";
|
||||
import type { Primitive } from "./generatePlan";
|
||||
import {
|
||||
PLAN_UNDERLAY_GAP_M,
|
||||
crossKindOverlayAllowed,
|
||||
mapPlanPoint,
|
||||
planToSectionMap,
|
||||
planUnderlayPrimitives,
|
||||
} from "./planUnderlay";
|
||||
import { sectionPlaneFromLevel, sectionUAxisModel } from "./toSection";
|
||||
|
||||
const level = (p0: { x: number; y: number }, p1: { x: number; y: number }, sign: 1 | -1 = 1): DrawingLevel => ({
|
||||
id: "s",
|
||||
name: "S",
|
||||
kind: "section",
|
||||
visible: true,
|
||||
locked: false,
|
||||
linePoints: [p0, p1],
|
||||
directionSign: sign,
|
||||
});
|
||||
|
||||
const line = (a: { x: number; y: number }, b: { x: number; y: number }): Primitive => ({
|
||||
kind: "line",
|
||||
a,
|
||||
b,
|
||||
cls: "t",
|
||||
weightMm: 0.25,
|
||||
});
|
||||
|
||||
describe("planToSectionMap", () => {
|
||||
it("u stimmt mit der Schnitt-u-Achse überein (Punkt liegt senkrecht unter seiner Projektion)", () => {
|
||||
for (const [lv, p] of [
|
||||
[level({ x: -1, y: 2 }, { x: 12, y: 2 }), { x: 4, y: 7 }],
|
||||
[level({ x: 3, y: 0 }, { x: 3, y: 9 }, -1), { x: 6, y: 2 }],
|
||||
[level({ x: 0, y: 0 }, { x: 5, y: 5 }), { x: 1, y: 3 }],
|
||||
] as const) {
|
||||
const m = planToSectionMap(lv)!;
|
||||
const plane = sectionPlaneFromLevel(lv)!;
|
||||
const uAx = sectionUAxisModel(plane);
|
||||
const len = Math.hypot(uAx.x, uAx.y);
|
||||
const uExpected = ((p.x - plane.point[0]) * uAx.x + (p.y - plane.point[2]) * uAx.y) / len;
|
||||
expect(mapPlanPoint(m, p).x).toBeCloseTo(uExpected, 9);
|
||||
}
|
||||
});
|
||||
|
||||
it("Blickrichtung zeigt im Blatt nach oben, keine Spiegelung", () => {
|
||||
// Linie entlang +x, Blick nach +y (Norden): reine Verschiebung.
|
||||
const m = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }))!;
|
||||
expect(m.theta).toBeCloseTo(0, 12);
|
||||
const q = mapPlanPoint(m, { x: 0, y: 5 });
|
||||
expect(q.x).toBeCloseTo(1, 12);
|
||||
expect(q.y).toBeCloseTo(3, 12); // 3 m hinter der Linie → 3 m nach oben
|
||||
// Umgekehrte Blickrichtung: 180°-Drehung (Determinante +1).
|
||||
const r = planToSectionMap(level({ x: -1, y: 2 }, { x: 12, y: 2 }, -1))!;
|
||||
expect(Math.abs(r.theta)).toBeCloseTo(Math.PI, 12);
|
||||
expect(mapPlanPoint(r, { x: 0, y: 0 }).y).toBeCloseTo(2, 12);
|
||||
});
|
||||
|
||||
it("ohne Linie keine Abbildung", () => {
|
||||
expect(planToSectionMap({ ...level({ x: 0, y: 0 }, { x: 1, y: 0 }), linePoints: undefined })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("planUnderlayPrimitives", () => {
|
||||
it("legt den Grundriss mit Abstand unter den Schnitt, gedimmt, plus Schnittlinie", () => {
|
||||
const lv = level({ x: -1, y: 2 }, { x: 12, y: 2 });
|
||||
const out = planUnderlayPrimitives(lv, [line({ x: 0, y: 0 }, { x: 11, y: 6 })], -0.3);
|
||||
const mapped = out[0] as Extract<Primitive, { kind: "line" }>;
|
||||
expect(mapped.greyed).toBe(true);
|
||||
// Oberste Grundriss-Kante (y = 6 → w = 4) liegt GAP unter der Schnitt-Unterkante.
|
||||
const top = Math.max(mapped.a.y, mapped.b.y);
|
||||
expect(top).toBeCloseTo(-0.3 - PLAN_UNDERLAY_GAP_M, 9);
|
||||
// u bleibt erhalten (x − (−1)).
|
||||
expect(Math.min(mapped.a.x, mapped.b.x)).toBeCloseTo(1, 9);
|
||||
const cut = out[out.length - 1] as Extract<Primitive, { kind: "line" }>;
|
||||
expect(cut.cls).toBe("section-underlay-line");
|
||||
expect(cut.b.x - cut.a.x).toBeCloseTo(13, 9);
|
||||
// Schnittlinie liegt 4 m unter der obersten Grundriss-Kante (w = 0).
|
||||
expect(cut.a.y).toBeCloseTo(top - 4, 9);
|
||||
});
|
||||
});
|
||||
|
||||
describe("crossKindOverlayAllowed", () => {
|
||||
it("nur Ebenen im selben Koordinatenraum überlagern sich", () => {
|
||||
expect(crossKindOverlayAllowed("floor", "drawing")).toBe(true);
|
||||
expect(crossKindOverlayAllowed("floor", "section")).toBe(false);
|
||||
expect(crossKindOverlayAllowed("floor", "elevation")).toBe(false);
|
||||
expect(crossKindOverlayAllowed("section", "floor")).toBe(false);
|
||||
expect(crossKindOverlayAllowed("elevation", "section")).toBe(false);
|
||||
expect(crossKindOverlayAllowed("section", "drawing")).toBe(false);
|
||||
// Freie Zeichnung bleibt Kalkierpapier für alles.
|
||||
expect(crossKindOverlayAllowed("drawing", "section")).toBe(true);
|
||||
expect(crossKindOverlayAllowed("drawing", "floor")).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,184 @@
|
||||
// Grundriss-Unterlage in Schnitt/Ansicht: ein Geschoss-Grundriss wird
|
||||
// AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt — wie die klassische
|
||||
// Konstruktion "Ansicht über dem Grundriss". Die Schnittlinie wird dazu
|
||||
// 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
|
||||
// senkrecht unter seiner Projektion im Schnitt.
|
||||
//
|
||||
// Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) —
|
||||
// Kreise bleiben Kreise, Bögen behalten ihren Drehsinn.
|
||||
|
||||
import type { DrawingLevel, DrawingLevelKind, Vec2 } from "../model/types";
|
||||
import type { Primitive } from "./generatePlan";
|
||||
|
||||
/** Abstand (Meter) zwischen tiefster Schnitt-/Ansichtskante und Grundriss-Oberkante. */
|
||||
export const PLAN_UNDERLAY_GAP_M = 1.5;
|
||||
|
||||
/** Abbildung Grundriss (Modell x/y) → Schnitt-Blatt (u, Höhe). */
|
||||
export interface PlanToSectionMap {
|
||||
/** Ursprung = Startpunkt der Schnittlinie. */
|
||||
p0: Vec2;
|
||||
/** Horizontale Schnitt-u-Achse im Grundriss (Blickrichtungs-RECHTS). */
|
||||
u: Vec2;
|
||||
/** Blickrichtung im Grundriss (Einheit). */
|
||||
n: Vec2;
|
||||
/** Drehwinkel (Radiant, CCW) der Abbildung. */
|
||||
theta: number;
|
||||
/** Vertikaler Versatz im Blatt. */
|
||||
dy: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut die Abbildung aus der Schnitt-/Ansichtslinie einer Ebene (`null` ohne
|
||||
* Linie). `dy` bleibt 0 — der Aufrufer schiebt den Grundriss danach unter den
|
||||
* Schnitt (s. {@link planUnderlayPrimitives}).
|
||||
*/
|
||||
export function planToSectionMap(level: DrawingLevel): PlanToSectionMap | null {
|
||||
const line = level.linePoints;
|
||||
if (!line) return null;
|
||||
const [p0, p1] = line;
|
||||
const len = Math.hypot(p1.x - p0.x, p1.y - p0.y);
|
||||
if (len < 1e-9) return null;
|
||||
const dx = (p1.x - p0.x) / len;
|
||||
const dy = (p1.y - p0.y) / len;
|
||||
const sign = level.directionSign ?? 1;
|
||||
// Wie `sectionPlaneFromLevel`: Links-Normale der Linie, per directionSign gedreht.
|
||||
const n: Vec2 = { x: -dy * sign, y: dx * sign };
|
||||
// Wie `sectionUAxisModel`: u = (n.y, −n.x) — Blickrichtungs-RECHTS.
|
||||
const u: Vec2 = { x: n.y, y: -n.x };
|
||||
// Bild der x-Achse (1,0) ist (u.x, n.x) → cosθ = u.x, sinθ = n.x.
|
||||
return { p0, u, n, theta: Math.atan2(n.x, u.x), dy: 0 };
|
||||
}
|
||||
|
||||
/** Bildet einen Grundriss-Punkt ins Schnitt-Blatt ab. */
|
||||
export function mapPlanPoint(m: PlanToSectionMap, p: Vec2): Vec2 {
|
||||
const rx = p.x - m.p0.x;
|
||||
const ry = p.y - m.p0.y;
|
||||
return { x: rx * m.u.x + ry * m.u.y, y: rx * m.n.x + ry * m.n.y + m.dy };
|
||||
}
|
||||
|
||||
/**
|
||||
* Bildet ein Plan-Primitiv ab. Achsparallele Rasterbilder lassen sich nicht
|
||||
* drehen und entfallen (`null`) — ausser die Abbildung ist eine reine
|
||||
* Verschiebung.
|
||||
*/
|
||||
export function mapPlanPrimitive(m: PlanToSectionMap, pr: Primitive): Primitive | null {
|
||||
const P = (p: Vec2) => mapPlanPoint(m, p);
|
||||
switch (pr.kind) {
|
||||
case "polygon": {
|
||||
const hatch = pr.hatch.origin || m.theta !== 0
|
||||
? {
|
||||
...pr.hatch,
|
||||
// SVG-Musterwinkel dreht im Uhrzeigersinn (Bildschirm) = −Winkel im Modell.
|
||||
angle: pr.hatch.angle - (m.theta * 180) / Math.PI,
|
||||
origin: pr.hatch.origin ? P(pr.hatch.origin) : undefined,
|
||||
}
|
||||
: pr.hatch;
|
||||
return { ...pr, pts: pr.pts.map(P), hatch };
|
||||
}
|
||||
case "line":
|
||||
// `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit.
|
||||
return { ...pr, a: P(pr.a), b: P(pr.b) };
|
||||
case "arc":
|
||||
return { ...pr, center: P(pr.center), from: P(pr.from), to: P(pr.to) };
|
||||
case "text":
|
||||
return { ...pr, at: P(pr.at) };
|
||||
case "drawingText":
|
||||
return { ...pr, at: P(pr.at), angle: pr.angle + m.theta };
|
||||
case "drawingTextPath":
|
||||
return { ...pr, pathPts: pr.pathPts.map(P) };
|
||||
case "drawingCircle":
|
||||
return { ...pr, center: P(pr.center) };
|
||||
case "drawingArc":
|
||||
return { ...pr, center: P(pr.center), a0: pr.a0 + m.theta, a1: pr.a1 + m.theta };
|
||||
case "drawingImage": {
|
||||
if (Math.abs(m.theta) > 1e-9) return null;
|
||||
const a = P(pr.min);
|
||||
const b = P(pr.max);
|
||||
return {
|
||||
...pr,
|
||||
min: { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) },
|
||||
max: { x: Math.max(a.x, b.x), y: Math.max(a.y, b.y) },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Alle Stützpunkte eines Primitivs (für die Höhenlage der Unterlage). */
|
||||
function primitivePoints(pr: Primitive): Vec2[] {
|
||||
switch (pr.kind) {
|
||||
case "polygon": return pr.pts;
|
||||
case "line": return [pr.a, pr.b];
|
||||
case "arc": return [pr.from, pr.to, pr.center];
|
||||
case "text":
|
||||
case "drawingText": return [pr.at];
|
||||
case "drawingTextPath": return pr.pathPts;
|
||||
case "drawingCircle":
|
||||
case "drawingArc":
|
||||
return [{ x: pr.center.x, y: pr.center.y + pr.r }];
|
||||
case "drawingImage": return [pr.min, pr.max];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt die Grundriss-Primitive `planPrims` ausgerichtet unter einen Schnitt/
|
||||
* eine Ansicht, deren tiefste Kante bei `sectionMinY` liegt. Die Unterlage ist
|
||||
* gedimmt (Referenz) und trägt zusätzlich die Schnittlinie selbst (strichpunk-
|
||||
* tiert), damit sichtbar ist, wo geschnitten bzw. von wo geblickt wird.
|
||||
*/
|
||||
export function planUnderlayPrimitives(
|
||||
level: DrawingLevel,
|
||||
planPrims: Primitive[],
|
||||
sectionMinY: number,
|
||||
): Primitive[] {
|
||||
const base = planToSectionMap(level);
|
||||
if (!base) return [];
|
||||
const mapped: Primitive[] = [];
|
||||
let maxY = -Infinity;
|
||||
for (const pr of planPrims) {
|
||||
const q = mapPlanPrimitive(base, pr);
|
||||
if (!q) continue;
|
||||
for (const p of primitivePoints(q)) if (p.y > maxY) maxY = p.y;
|
||||
mapped.push(q);
|
||||
}
|
||||
// Schnittlinie (w = 0) liegt immer mit in der Unterlage.
|
||||
if (0 > maxY) maxY = 0;
|
||||
const shift = sectionMinY - PLAN_UNDERLAY_GAP_M - maxY;
|
||||
const out: Primitive[] = [];
|
||||
for (const q of mapped) {
|
||||
const moved = mapPlanPrimitive({ p0: { x: 0, y: 0 }, u: { x: 1, y: 0 }, n: { x: 0, y: 1 }, theta: 0, dy: shift }, q);
|
||||
if (moved) out.push({ ...moved, greyed: true } as Primitive);
|
||||
}
|
||||
const [l0, l1] = level.linePoints!;
|
||||
const len = Math.hypot(l1.x - l0.x, l1.y - l0.y);
|
||||
out.push({
|
||||
kind: "line",
|
||||
a: { x: 0, y: shift },
|
||||
b: { x: len, y: shift },
|
||||
cls: "section-underlay-line",
|
||||
weightMm: 0.25,
|
||||
dash: [3, 0.8, 0.4, 0.8],
|
||||
color: "#8a3b2c",
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Welche Fremd-Art-Ebene darf als Unterlage in welcher aktiven Ebene erscheinen?
|
||||
* Massgebend ist der Koordinatenraum: Geschoss und freie Zeichnung teilen X/Y,
|
||||
* Schnitte/Ansichten messen dagegen Länge×Höhe entlang IHRER Linie. Ein Schnitt
|
||||
* im Grundriss (oder ein Grundriss/eine andere Ansicht im Schnitt) lag darum
|
||||
* nur zufällig irgendwo und überdeckte den eigentlichen Plan (Nutzer-Report
|
||||
* 2026-10-20: Fenster der Ansicht im EG-Grundriss, Raumstempel im Schnitt).
|
||||
* • freie Zeichnung: alles (Kalkierpapier zum Abzeichnen, Nutzer-Wunsch).
|
||||
* • Geschoss: nur freie Zeichnungen (gleicher X/Y-Raum).
|
||||
* • Schnitt/Ansicht: nichts — ein Grundriss kommt dort ausgerichtet über
|
||||
* `DrawingLevel.planUnderlayId` dazu (s. plan/planUnderlay.ts).
|
||||
*/
|
||||
export function crossKindOverlayAllowed(active: DrawingLevelKind, other: DrawingLevelKind): boolean {
|
||||
if (active === "drawing") return true;
|
||||
if (active === "floor") return other === "drawing";
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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";
|
||||
|
||||
const section = (x: number): DrawingLevel => ({
|
||||
id: "sx",
|
||||
name: "Sx",
|
||||
kind: "section",
|
||||
visible: true,
|
||||
locked: false,
|
||||
// Senkrecht durch W1 (y = 0) bei x, Blick nach Westen.
|
||||
linePoints: [{ x, y: -1 }, { x, y: 5 }],
|
||||
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");
|
||||
expect(own.length).toBeGreaterThanOrEqual(4);
|
||||
const glass = own.filter((p): p is Extract<Primitive, { kind: "line" }> => p.kind === "line");
|
||||
expect(glass.length).toBeGreaterThan(0);
|
||||
// Glas läuft zwischen Brüstung (0.9 m über Wand-UK) und Sturz (2.1 m) — mit Rahmen dazwischen.
|
||||
const vs = glass.flatMap((g) => [g.a.y, g.b.y]);
|
||||
expect(Math.min(...vs)).toBeGreaterThan(0.9);
|
||||
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("Ansichten bekommen keine Schnitt-Öffnungen", () => {
|
||||
expect(sectionOpeningPrimitives(sampleProject, { ...section(3.5), kind: "elevation" })).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,210 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { DrawingLevel, Project } from "../model/types";
|
||||
import { sameSectionInputs, sameSectionLine } from "./toSection";
|
||||
|
||||
const project = { walls: [], drawings2d: [], ceilings: [] } as unknown as Project;
|
||||
|
||||
describe("sameSectionInputs", () => {
|
||||
it("2D-Zeichnungen (z. B. Linien im Schnitt) lösen keine Neuberechnung aus", () => {
|
||||
expect(sameSectionInputs(project, { ...project, drawings2d: [] })).toBe(true);
|
||||
});
|
||||
it("Bauteil-Änderungen schon", () => {
|
||||
expect(sameSectionInputs(project, { ...project, walls: [] })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sameSectionLine", () => {
|
||||
const lv: DrawingLevel = {
|
||||
id: "s",
|
||||
name: "S",
|
||||
kind: "section",
|
||||
visible: true,
|
||||
locked: false,
|
||||
linePoints: [{ x: 0, y: 0 }, { x: 5, y: 0 }],
|
||||
};
|
||||
it("Name/Unterlage egal, Linie/Richtung/Tiefe nicht", () => {
|
||||
expect(sameSectionLine(lv, { ...lv, name: "X", planUnderlayId: "eg", hiddenLines: true })).toBe(true);
|
||||
expect(sameSectionLine(lv, { ...lv, linePoints: [{ x: 0, y: 0 }, { x: 5, y: 1 }] })).toBe(false);
|
||||
expect(sameSectionLine(lv, { ...lv, directionSign: -1 })).toBe(false);
|
||||
expect(sameSectionLine(lv, { ...lv, depth: 3 })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1213,3 +1213,47 @@ export async function computeSection(
|
||||
if (level.depth !== undefined) filterByDepth(output, project, plane, level.depth);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Projekt-Felder, die den abgeleiteten Schnitt/die Ansicht NICHT beeinflussen.
|
||||
* Vor allem `drawings2d`: jede Linie, die man IM Schnitt zeichnet, landet dort —
|
||||
* ohne diesen Ausschluss rechnete jede solche Änderung den ganzen Schnitt neu.
|
||||
*/
|
||||
const SECTION_IRRELEVANT_KEYS = new Set<string>(["drawings2d", "layouts", "viewSnapshots", "masterLayouts"]);
|
||||
|
||||
/**
|
||||
* Ob zwei Projektstände denselben Schnitt/dieselbe Ansicht ergeben — Vergleich
|
||||
* je Feld per Referenz (das Projekt wird immutabel aktualisiert, unveränderte
|
||||
* Teile behalten ihre Identität), ohne {@link SECTION_IRRELEVANT_KEYS}. Bei
|
||||
* Unsicherheit `false` (dann wird eben neu gerechnet).
|
||||
*/
|
||||
export function sameSectionInputs(a: Project, b: Project): boolean {
|
||||
if (a === b) return true;
|
||||
const ra = a as unknown as Record<string, unknown>;
|
||||
const rb = b as unknown as Record<string, unknown>;
|
||||
const keys = new Set([...Object.keys(ra), ...Object.keys(rb)]);
|
||||
for (const k of keys) {
|
||||
if (SECTION_IRRELEVANT_KEYS.has(k)) continue;
|
||||
if (ra[k] !== rb[k]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Ob zwei Stände einer Schnitt-/Ansichtsebene dieselbe Projektion ergeben. */
|
||||
export function sameSectionLine(a: DrawingLevel, b: DrawingLevel): boolean {
|
||||
if (a === b) return true;
|
||||
const la = a.linePoints;
|
||||
const lb = b.linePoints;
|
||||
const sameLine =
|
||||
la === lb ||
|
||||
(!!la && !!lb &&
|
||||
la[0].x === lb[0].x && la[0].y === lb[0].y && la[1].x === lb[1].x && la[1].y === lb[1].y);
|
||||
return (
|
||||
sameLine &&
|
||||
a.id === b.id &&
|
||||
a.kind === b.kind &&
|
||||
(a.directionSign ?? 1) === (b.directionSign ?? 1) &&
|
||||
a.depth === b.depth &&
|
||||
!!a.shadows === !!b.shadows
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user