[105][106] Merge: Fenster/Türen tief einstellbar (Rahmen je Seite, Flügel, Profile, Zargenarten, Schichteinzug je Schicht/Seite, Vorschau) – IDs 103/104→105/106

Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-10-30 01:06:15 +00:00
commit 2eab3b73af
26 files changed
+3099 -85

No files matched your search

+2
View File
@@ -49,6 +49,8 @@ pub mod plan_stairs;
pub mod plan_walls;
pub mod opening_geom;
pub mod opening_shape;
pub mod opening_detail;
pub mod opening_preview;
pub mod plan_openings;
pub mod delaunay;
pub mod document;
+270
View File
@@ -714,6 +714,21 @@ pub enum DoorTypeFrameKind {
Zarge,
#[serde(rename = "blockrahmen")]
Blockrahmen,
/// Blendrahmen ([105]): Rahmen VOR der Wandfläche (Aufschlagseite), überdeckt die Leibungskante.
#[serde(rename = "blendrahmen")]
Blendrahmen,
/// Umfassungszarge ([105]): Stahlzarge umfasst die ganze Wanddicke, Spiegel beidseitig.
#[serde(rename = "umfassungszarge")]
Umfassungszarge,
/// Eckzarge ([105]): Winkel-Stahlzarge nur auf der Aufschlagseite (Spiegel + Falz).
#[serde(rename = "eckzarge")]
Eckzarge,
/// Blockzarge ([105]): Holz-Blockzarge über die ganze Leibungstiefe, Falz auf der Aufschlagseite.
#[serde(rename = "blockzarge")]
Blockzarge,
/// Futter und Bekleidung ([105]): Futterbrett in der Leibung, Bekleidung auf einer/beiden Wandflächen.
#[serde(rename = "futter")]
Futter,
#[serde(other)]
#[ts(skip)]
Unknown,
@@ -857,6 +872,20 @@ pub struct DoorType {
#[serde(rename = "lintelHeight", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub lintel_height: Option<f64>,
/// Rahmen-Detail ([105]): Blendrahmen je Seite, Flügelrahmen, Pfosten/Kämpfer, Zusatzprofile,
/// Anschlag je Seite. Fehlt ⇒ wie bisher (`frameWidth`, `rebateDepth`).
#[serde(rename = "frameDetail", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub frame_detail: Option<FrameDetail>,
/// Schichteinzug ([106]): wie die Wandschichten an Leibung, Sturz und Brüstung anschliessen.
/// Fehlt ⇒ alle Schichten bündig (bzw. `innerLayerRecess`, veraltet).
#[serde(rename = "layerReveals", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub layer_reveals: Option<Vec<LayerReveal>>,
/// Masse der Türzarge/des Türrahmens ([105]): Falz, Spiegel, Futter, Bekleidung.
#[serde(rename = "doorFrame", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub door_frame: Option<DoorFrameDetail>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
@@ -1161,6 +1190,7 @@ pub struct WindowType {
/// Öffnung zurück, statt bündig mit den übrigen Schichten abzuschliessen —
/// anders als {@link insetFromFace} (der Rahmen-Position), ändert dies die
/// WAND-GEOMETRIE selbst an der Laibung. Default false (bündig, Alt-Verhalten).
/// Veraltet ([106]): gilt nur ohne {@link layerReveals} (= innerste Schicht „zurück um Schichtdicke").
#[serde(rename = "innerLayerRecess", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub inner_layer_recess: Option<bool>,
@@ -1207,6 +1237,230 @@ pub struct WindowType {
#[serde(rename = "lintelHeight", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub lintel_height: Option<f64>,
/// Rahmen-Detail ([105]): Blendrahmen je Seite, Flügelrahmen, Pfosten/Kämpfer, Zusatzprofile,
/// Anschlag je Seite. Fehlt ⇒ wie bisher (`frameWidth`, `rebateDepth`).
#[serde(rename = "frameDetail", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub frame_detail: Option<FrameDetail>,
/// Schichteinzug ([106]): wie die Wandschichten an Leibung, Sturz und Brüstung anschliessen.
/// Fehlt ⇒ alle Schichten bündig (bzw. `innerLayerRecess`, veraltet).
#[serde(rename = "layerReveals", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub layer_reveals: Option<Vec<LayerReveal>>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
}
// ── [105] Rahmen-/Anschlag-Details, [106] Schichteinzug ─────────────────────
/// Werte je Seite einer Öffnung (Meter). `left` = Leibung beim Wandanfang (kleineres Achsmass),
/// `right` = beim Wandende, `top` = Sturz, `bottom` = Brüstung/Schwelle. Fehlt ⇒ Rückfallwert.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
#[serde(default)]
pub struct OpeningSides {
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub left: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub right: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub top: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub bottom: Option<f64>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
}
/// Rahmen-Detail eines Fenster-/Türtyps ([105]); an der Öffnung feldweise übersteuerbar
/// (`Opening.frameDetail`). Alle Masse in Metern, fehlend ⇒ Typ-Wert bzw. bisheriges Verhalten.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
#[serde(default)]
pub struct FrameDetail {
/// Blendrahmen: Ansichtsbreite je Seite (fehlt ⇒ `frameWidth`).
#[serde(rename = "frameSides", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub frame_sides: Option<OpeningSides>,
/// Blendrahmen-Tiefe quer zur Wand (übersteuert `frameDepth`).
#[serde(rename = "frameDepth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub frame_depth: Option<f64>,
/// Lage: Abstand der Rahmen-Vorderkante von der Fläche `insetFace` (übersteuert `insetFromFace`).
#[serde(rename = "insetFromFace", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub inset_from_face: Option<f64>,
/// Bezugsfläche der Lage (übersteuert `insetFace`).
#[serde(rename = "insetFace", default, skip_serializing_if = "Option::is_none")]
#[ts(optional, inline)]
pub inset_face: Option<WindowTypeInsetFace>,
/// Flügelrahmen: Ansichtsbreite (fehlt ⇒ wie Blendrahmen).
#[serde(rename = "sashWidth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub sash_width: Option<f64>,
/// Flügelrahmen: Tiefe quer zur Wand (fehlt ⇒ Blendrahmen-Tiefe).
#[serde(rename = "sashDepth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub sash_depth: Option<f64>,
/// Flügel-Überschlag: so weit überdeckt der Flügel den Blendrahmen (fehlt ⇒ 0).
#[serde(rename = "sashOverlap", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub sash_overlap: Option<f64>,
/// Pfosten (senkrechte Teilung): Breite (fehlt ⇒ `postWidth` der Flügeltabelle).
#[serde(rename = "mullionWidth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub mullion_width: Option<f64>,
/// Pfosten-Tiefe (fehlt ⇒ Blendrahmen-Tiefe).
#[serde(rename = "mullionDepth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub mullion_depth: Option<f64>,
/// Kämpfer (waagrechte Teilung, Riegel): Breite (fehlt ⇒ wie Blendrahmen).
#[serde(rename = "transomWidth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub transom_width: Option<f64>,
/// Kämpfer-Tiefe (fehlt ⇒ Blendrahmen-Tiefe).
#[serde(rename = "transomDepth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub transom_depth: Option<f64>,
/// Verbreiterungsprofile je Seite (Ansichtsbreite, aussen am Blendrahmen angesetzt).
#[serde(rename = "extensionProfiles", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub extension_profiles: Option<OpeningSides>,
/// Fensterbank-Anschlussprofil unten (Höhe, unter dem Blendrahmen).
#[serde(rename = "sillProfile", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub sill_profile: Option<f64>,
/// Storen-/Rollladen-Anschlussprofil oben (Höhe, über dem Blendrahmen).
#[serde(rename = "shadingProfile", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub shading_profile: Option<f64>,
/// Anschlag je Seite (Meter; übersteuert `rebateDepth`, 0 = kein Anschlag auf dieser Seite).
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub rebates: Option<OpeningSides>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
}
/// Bekleidung einer Tür ([105]): auf der Aufschlagseite, der Gegenseite, beidseitig oder keine.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)]
pub enum CasingSides {
#[default]
#[serde(rename = "beide")]
Beide,
#[serde(rename = "aufschlag")]
Aufschlag,
#[serde(rename = "gegen")]
Gegen,
#[serde(rename = "keine")]
Keine,
#[serde(other)]
#[ts(skip)]
Unknown,
}
/// Masse einer Türzarge/eines Türrahmens ([105]); Bedeutung je `frameKind`. Fehlt ⇒ Vorgabe.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
#[serde(default)]
pub struct DoorFrameDetail {
/// Falzbreite (parallel zur Wandfläche: Überdeckung Blatt/Rahmen), Vorgabe 0.015.
#[serde(rename = "falzWidth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub falz_width: Option<f64>,
/// Falztiefe (quer zur Wand, ≈ Blattdicke), Vorgabe 0.04.
#[serde(rename = "falzDepth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub falz_depth: Option<f64>,
/// Spiegelbreite der Stahlzarge auf der Wandfläche, Vorgabe 0.05.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub spiegel: Option<f64>,
/// Blechdicke der Stahlzarge, Vorgabe 0.002.
#[serde(rename = "sheetThickness", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub sheet_thickness: Option<f64>,
/// Futterstärke (Brett in der Leibung), Vorgabe 0.025.
#[serde(rename = "liningThickness", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub lining_thickness: Option<f64>,
/// Bekleidungsbreite, Vorgabe 0.07.
#[serde(rename = "casingWidth", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub casing_width: Option<f64>,
/// Bekleidungsdicke, Vorgabe 0.012.
#[serde(rename = "casingThickness", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub casing_thickness: Option<f64>,
/// Bekleidung auf welcher Seite (Vorgabe beide).
#[serde(rename = "casingSides", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub casing_sides: Option<CasingSides>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
}
/// Wie eine Wandschicht an der Öffnung anschliesst ([106]).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, TS)]
pub enum RevealMode {
/// Schicht endet bündig an der Rohbauöffnung (bisher).
#[default]
#[serde(rename = "buendig")]
Buendig,
/// Schicht springt um `amount` zurück (fehlt ⇒ um ihre eigene Dicke).
#[serde(rename = "zurueck")]
Zurueck,
/// Schicht läuft in die Leibung bis an den Rahmen (Dicke dort `amount`, fehlt ⇒ Schichtdicke, höchstens 4 cm).
#[serde(rename = "leibung")]
Leibung,
/// Schicht überdeckt den Rahmen um `amount` (fehlt ⇒ 3 cm), nur vor dem Rahmen.
#[serde(rename = "ueberdaemmt")]
Ueberdaemmt,
#[serde(other)]
#[ts(skip)]
Unknown,
}
/// Abweichende Regel für eine Seite ([106]).
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
#[serde(default)]
pub struct RevealSide {
pub mode: RevealMode,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub amount: Option<f64>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
}
/// Schichteinzug einer Wandschicht an der Öffnung ([106]): Regel für alle Seiten, je Seite
/// übersteuerbar. `layer` zählt ab aussen (0 = äusserste Schicht); negativ ab innen (−1 = innerste),
/// damit dieselbe Regel für verschiedene Wandtypen gilt.
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize, TS)]
#[serde(default)]
pub struct LayerReveal {
pub layer: f64,
pub mode: RevealMode,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub amount: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub left: Option<RevealSide>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub right: Option<RevealSide>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub top: Option<RevealSide>,
#[serde(default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub bottom: Option<RevealSide>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
@@ -2485,6 +2739,22 @@ pub struct Opening {
#[serde(rename = "hostAngle", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub host_angle: Option<f64>,
/// Übersteuert das Rahmen-Detail des Typs feldweise für diese Öffnung ([105]).
#[serde(rename = "frameDetail", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub frame_detail: Option<FrameDetail>,
/// Ersetzt den Schichteinzug des Typs für diese Öffnung ([106]).
#[serde(rename = "layerReveals", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub layer_reveals: Option<Vec<LayerReveal>>,
/// Übersteuert die Rahmenart des Türtyps ([105]).
#[serde(rename = "doorFrameKind", default, skip_serializing_if = "Option::is_none")]
#[ts(optional, inline)]
pub door_frame_kind: Option<DoorTypeFrameKind>,
/// Übersteuert die Zargen-/Rahmenmasse des Türtyps feldweise ([105]).
#[serde(rename = "doorFrame", default, skip_serializing_if = "Option::is_none")]
#[ts(optional)]
pub door_frame: Option<DoorFrameDetail>,
#[serde(flatten)]
#[ts(skip)]
pub extra: Extra,
+76 -2
View File
@@ -419,6 +419,33 @@ fn wall_openings(p: &Project, w: &Wall, openings: &[&Opening], with_recess: bool
out
}
/// Schichteinzug der Öffnungen einer Wand für die Schichtbänder ([106]); Intervall und Höhe wie
/// [`wall_openings`], damit `wall_bands` sie zuordnet.
fn wall_reveals(p: &Project, w: &Wall, openings: &[&Opening], n_bands: usize) -> Vec<wall_bands::RevealIn> {
let (zb, zt) = p.wall_vertical_extent(w);
let mut out = Vec::new();
for &o in openings {
let Some(r) = crate::opening_detail::opening_reveal(p, w, o) else { continue };
if r.thick.len() != n_bands {
continue;
}
let o_bottom = zb + o.sill_height.max(0.0);
let o_top = zt.min(o_bottom + o.height);
let mut shifts = vec![[0.0; 4]; n_bands];
let mut pieces = Vec::new();
for (k, side) in r.sides.iter().enumerate() {
for a in side {
shifts[a.layer][k] = a.shift;
for pc in &a.pieces {
pieces.push((a.layer, k, *pc));
}
}
}
out.push(wall_bands::RevealIn { from: r.from, to: r.to, z_bottom: o_bottom, z_top: o_top, shifts, pieces });
}
out
}
/// Verschneidung je Geschoss (`computeJoinsByFloor`); Fehler = unbekannter Wandtyp/Bauteil.
fn compute_joins_by_floor(p: &Project) -> Result<HashMap<String, WallCuts>, String> {
let mut groups: Vec<(String, Vec<&Wall>)> = Vec::new();
@@ -543,6 +570,7 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result<Vec<RWall>, String> {
bands: bands.iter().map(|b| BandIn { thickness: b.thickness, priority: b.priority }).collect(),
openings: wall_openings(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), true),
cuts: if layered { joins.as_ref().and_then(|j| j.get(&wall.id)).cloned().unwrap_or_default() } else { WallCuts::default() },
reveals: if layered && stacked { wall_reveals(p, wall, by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()), bands.len()) } else { Vec::new() },
};
let (dx, dy) = (wall.end.x - wall.start.x, wall.end.y - wall.start.y);
for piece in wall_bands::wall_bands(&win, ctx) {
@@ -550,7 +578,7 @@ pub fn emit_walls(p: &Project, layered: bool) -> Result<Vec<RWall>, String> {
out.push(RWall {
start: [piece.start.x, piece.start.y],
end: [piece.end.x, piece.end.y],
thickness: b.thickness,
thickness: piece.thickness.unwrap_or(b.thickness),
height: piece.z_top - piece.z_bottom,
base_elevation: piece.z_bottom,
top_drop: piece.top_drop,
@@ -733,7 +761,11 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
let mut shaped: Vec<RMesh> = Vec::new();
let mut w = FlatWriter::new();
w.num(detail).num(p.walls.len() as f64);
for wall in &p.walls {
// [105] Anhang: Rahmen-Detail je (Wand, Öffnung); Türzargen als eigene Quader.
let mut details: Vec<f64> = Vec::new();
let mut n_details = 0.0;
let mut zargen: Vec<RMesh> = Vec::new();
for (wi, wall) in p.walls.iter().enumerate() {
w.nums(&[wall.start.x, wall.start.y, wall.end.x, wall.end.y]);
let slot = w.slot();
let mut count = 0.0;
@@ -752,10 +784,25 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
}
w.nums(&[from, to, o_bottom, o_top, flag(op.kind != ElementKind::Window), t]);
write_opening(&mut w, p, op);
let dframe = crate::opening_detail::door_frame_of(p, op);
if let Some(f) = crate::opening_detail::frame_of(p, op).filter(|f| f.detailed || dframe.is_some()) {
let s4 = |s: crate::opening_detail::Sides| [s.left, s.right, s.top, s.bottom];
details.extend([wi as f64, count]);
details.extend(s4(f.sides));
details.extend(s4(f.ext));
details.extend(s4(f.rebate));
details.extend([f.sash_width, f.sash_depth, f.sash_overlap, f.mullion_width, f.transom_width, f.sill_profile, f.shading_profile, flag(dframe.is_some())]);
n_details += 1.0;
}
if let (Some(df), true) = (dframe.as_ref(), detail > 0.0) {
door_frame_boxes(&mut zargen, wall, &wr, op, df, (from, to, o_bottom, o_top));
}
count += 1.0;
}
w.set(slot, count);
}
w.num(n_details);
w.nums(&details);
let buf = crate::openings3d::opening_meshes_flat(&w.done());
let n = buf.first().copied().unwrap_or(0.0).max(0.0) as usize;
let mut out = Vec::new();
@@ -775,6 +822,7 @@ pub fn emit_opening_meshes(p: &Project, detail: f64) -> Vec<RMesh> {
});
i += 25;
}
out.extend(zargen);
out.extend(shaped);
// Dach-/Deckenfenster ([103]).
for op in p.openings.as_deref().unwrap_or(&[]) {
@@ -859,6 +907,32 @@ pub(crate) fn shaped_wall_opening_meshes(p: &Project, wall: &Wall, wr: &WallRef,
out
}
/// Türzarge als Quader ([105]): Profil (Grundriss = Schnitt) an beiden Leibungen über die Höhe und
/// am Sturz über die Breite; Ecken ohne Überlappung (Leibungsstück endet unter dem Sturzstück).
fn door_frame_boxes(out: &mut Vec<RMesh>, wall: &Wall, wr: &WallRef, op: &Opening, df: &crate::opening_detail::DoorFrame, (from, to, zb, zt): (f64, f64, f64, f64)) {
use crate::opening_detail as od;
let (u, n) = wr.frame();
let face = wr.ref_off - wr.total / 2.0;
let innen = od::aufschlag_innen(op);
let off_of = |d: f64| face + if innen { wr.total - d } else { d };
let s = [wall.start.x, wall.start.y];
let (u, n) = ([u.x, u.y], [n.x, n.y]);
for (part, poly) in od::door_frame_profile(df, wr.total, innen) {
let rgb = if part == od::FramePart::Frame && df.steel { PART_RGB[4] } else { PART_RGB[1] };
for [x0, x1, d0, d1] in od::ortho_rects(&poly) {
let (o0, o1) = (off_of(d0).min(off_of(d1)), off_of(d0).max(off_of(d1)));
let boxes = [
od::axis_box(s, u, n, from + x0, from + x1, zb, zt - x1, o0, o1),
od::axis_box(s, u, n, to - x1, to - x0, zb, zt - x1, o0, o1),
od::axis_box(s, u, n, from + x0, to - x0, zt - x1, zt - x0, o0, o1),
];
for b in boxes.into_iter().flatten() {
out.push(RMesh { positions: b.to_vec(), indices: OPENING_BOX_TRIS.to_vec(), kind: "extrusion", color: rgb, vertex_colors: None, material_index: None });
}
}
}
}
// ── Treppen ─────────────────────────────────────────────────────────────────
fn stair_rgb() -> Rgb {
+835
View File
@@ -0,0 +1,835 @@
//! Fenster/Türen: Rahmen-Detail, Anschlag je Seite, Türzargen-Arten ([105]) und Schichteinzug
//! ([106]) — aus Typ und Öffnungs-Übersteuerung aufgelöst, dazu die gemeinsame Geometrie für
//! Grundriss (`plan/walls.rs`, `plan_walls.rs`), Schnitt (`plan/section.rs`) und 3D (`model3d.rs`,
//! `wall_bands.rs`).
//!
//! Koordinaten quer zur Wand: Abstand ab der Aussenfläche (0 = aussen, `total` = innen) — die
//! Wandschichten liegen in Typ-Reihenfolge von aussen nach innen (wie `plan_walls.rs`, Versatz
//! `ref_off − total/2 + …` entlang der linken Normalen). In der Öffnung: `x` = Abstand von der
//! Rohbaukante in die Öffnung hinein (> 0 = in der lichten Öffnung, < 0 = in der Wand).
use crate::model::*;
pub const DEFAULT_FRAME_WIDTH: f64 = 0.06;
pub const DEFAULT_FRAME_DEPTH: f64 = 0.07;
/// Vorgabe für „in die Leibung laufend": höchstens so dick in der Leibung (Leibungsdämmung, Putz).
pub const DEFAULT_REVEAL_LINING: f64 = 0.04;
/// Vorgabe für „Rahmen überdämmt".
pub const DEFAULT_OVERLAP: f64 = 0.03;
const EPS: f64 = 1e-6;
/// Seite einer Öffnung: links = Leibung beim Wandanfang, rechts = beim Wandende.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Side {
Left,
Right,
Top,
Bottom,
}
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct Sides {
pub left: f64,
pub right: f64,
pub top: f64,
pub bottom: f64,
}
impl Sides {
pub fn all(v: f64) -> Sides {
Sides { left: v, right: v, top: v, bottom: v }
}
pub fn get(&self, s: Side) -> f64 {
match s {
Side::Left => self.left,
Side::Right => self.right,
Side::Top => self.top,
Side::Bottom => self.bottom,
}
}
fn with(o: Option<&OpeningSides>, d: Sides) -> Sides {
let Some(o) = o else { return d };
let f = |v: Option<f64>, d: f64| v.filter(|x| x.is_finite()).map_or(d, |x| x.max(0.0));
Sides { left: f(o.left, d.left), right: f(o.right, d.right), top: f(o.top, d.top), bottom: f(o.bottom, d.bottom) }
}
pub fn uniform(&self) -> bool {
self.left == self.right && self.left == self.top && self.left == self.bottom
}
}
/// Bezugsfläche der Rahmenlage.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Face {
Aussen,
Innen,
Mitte,
}
/// Aufgelöstes Rahmen-Detail einer Öffnung (Typ + Übersteuerung).
#[derive(Clone, Debug, PartialEq)]
pub struct Frame {
/// Blendrahmen-Ansichtsbreite je Seite.
pub sides: Sides,
/// Rahmentiefe (NaN = Vorgabe).
pub depth: f64,
pub inset: f64,
pub face: Face,
/// Flügelrahmen-Breite (NaN = wie Blendrahmen), -Tiefe (NaN), Überschlag.
pub sash_width: f64,
pub sash_depth: f64,
pub sash_overlap: f64,
/// Pfosten/Kämpfer: Breite und Tiefe (NaN = Vorgabe).
pub mullion_width: f64,
pub mullion_depth: f64,
pub transom_width: f64,
pub transom_depth: f64,
/// Verbreiterungsprofile je Seite, Fensterbank- und Storen-Anschlussprofil (0 = keins).
pub ext: Sides,
pub sill_profile: f64,
pub shading_profile: f64,
/// Anschlag je Seite (0 = keiner).
pub rebate: Sides,
/// Ein Detail-Feld ([105]) ist gesetzt (sonst gilt der bisherige Pfad unverändert).
pub detailed: bool,
}
fn fin(v: Option<f64>) -> Option<f64> {
v.filter(|x| x.is_finite())
}
/// Rahmen-Detail des Typs, feldweise von der Öffnung übersteuert.
pub fn merged_frame_detail(ty: Option<&FrameDetail>, ov: Option<&FrameDetail>) -> Option<FrameDetail> {
let (t, o) = match (ty, ov) {
(None, None) => return None,
(Some(t), None) => return Some(t.clone()),
(None, Some(o)) => return Some(o.clone()),
(Some(t), Some(o)) => (t, o),
};
let sides = |a: &Option<OpeningSides>, b: &Option<OpeningSides>| -> Option<OpeningSides> {
match (a, b) {
(Some(a), Some(b)) => Some(OpeningSides { left: b.left.or(a.left), right: b.right.or(a.right), top: b.top.or(a.top), bottom: b.bottom.or(a.bottom), extra: Default::default() }),
(a, b) => b.clone().or_else(|| a.clone()),
}
};
Some(FrameDetail {
frame_sides: sides(&t.frame_sides, &o.frame_sides),
frame_depth: o.frame_depth.or(t.frame_depth),
inset_from_face: o.inset_from_face.or(t.inset_from_face),
inset_face: o.inset_face.or(t.inset_face),
sash_width: o.sash_width.or(t.sash_width),
sash_depth: o.sash_depth.or(t.sash_depth),
sash_overlap: o.sash_overlap.or(t.sash_overlap),
mullion_width: o.mullion_width.or(t.mullion_width),
mullion_depth: o.mullion_depth.or(t.mullion_depth),
transom_width: o.transom_width.or(t.transom_width),
transom_depth: o.transom_depth.or(t.transom_depth),
extension_profiles: sides(&t.extension_profiles, &o.extension_profiles),
sill_profile: o.sill_profile.or(t.sill_profile),
shading_profile: o.shading_profile.or(t.shading_profile),
rebates: sides(&t.rebates, &o.rebates),
extra: Default::default(),
})
}
/// Rahmen einer typisierten Öffnung; `None` ohne Typ.
pub fn frame_of(p: &Project, o: &Opening) -> Option<Frame> {
let (width, depth, inset, face, rebate, detail) = if o.kind == ElementKind::Door {
let t = p.door_type(o)?;
let face = match t.inset_face {
Some(DoorTypeInsetFace::Innen) => Face::Innen,
Some(DoorTypeInsetFace::Mitte) => Face::Mitte,
_ => Face::Aussen,
};
(t.frame_width, t.frame_depth, t.inset_from_face, face, t.rebate_depth, t.frame_detail.as_ref())
} else {
let t = p.window_type(o)?;
let face = match t.inset_face {
Some(WindowTypeInsetFace::Innen) => Face::Innen,
Some(WindowTypeInsetFace::Mitte) => Face::Mitte,
_ => Face::Aussen,
};
(t.frame_width, t.frame_depth, t.inset_from_face, face, t.rebate_depth, t.frame_detail.as_ref())
};
let d = merged_frame_detail(detail, o.frame_detail.as_ref());
let d = d.as_ref();
let width = fin(width).unwrap_or(DEFAULT_FRAME_WIDTH).max(0.0);
let face = match d.and_then(|d| d.inset_face) {
Some(WindowTypeInsetFace::Innen) => Face::Innen,
Some(WindowTypeInsetFace::Mitte) => Face::Mitte,
Some(WindowTypeInsetFace::Aussen) => Face::Aussen,
_ => face,
};
let nan = f64::NAN;
let num = |f: fn(&FrameDetail) -> Option<f64>| d.and_then(f).filter(|x| x.is_finite()).map_or(nan, |x| x.max(0.0));
Some(Frame {
sides: Sides::with(d.and_then(|d| d.frame_sides.as_ref()), Sides::all(width)),
depth: fin(d.and_then(|d| d.frame_depth)).or(fin(depth)).unwrap_or(nan),
inset: fin(d.and_then(|d| d.inset_from_face)).or(fin(inset)).unwrap_or(0.0).max(0.0),
face,
sash_width: num(|d| d.sash_width),
sash_depth: num(|d| d.sash_depth),
sash_overlap: num(|d| d.sash_overlap),
mullion_width: num(|d| d.mullion_width),
mullion_depth: num(|d| d.mullion_depth),
transom_width: num(|d| d.transom_width),
transom_depth: num(|d| d.transom_depth),
ext: Sides::with(d.and_then(|d| d.extension_profiles.as_ref()), Sides::all(0.0)),
sill_profile: fin(d.and_then(|d| d.sill_profile)).unwrap_or(0.0).max(0.0),
shading_profile: fin(d.and_then(|d| d.shading_profile)).unwrap_or(0.0).max(0.0),
rebate: Sides::with(d.and_then(|d| d.rebates.as_ref()), Sides::all(fin(rebate).unwrap_or(0.0).max(0.0))),
detailed: d.is_some(),
})
}
impl Frame {
/// Rahmenlage quer zur Wand `(lo, hi)` ab der Aussenfläche (wie `opening_geom::window_symbol`).
pub fn range(&self, total: f64) -> (f64, f64) {
let depth = total.min(if self.depth > 1e-9 { self.depth } else { DEFAULT_FRAME_DEPTH }).max(0.0);
let c = |v: f64| v.max(0.0).min(total);
match self.face {
Face::Mitte => (c((total - depth) / 2.0), c((total + depth) / 2.0)),
Face::Aussen => (c(self.inset), c(self.inset + depth)),
Face::Innen => (c(total - self.inset - depth), c(total - self.inset)),
}
}
/// Anschlag-Zone (zwischen gewählter Fläche und Rahmen) — nur mit Leibung (Einzug > 0 oder mittig).
pub fn rebate_zone(&self, total: f64) -> Option<(f64, f64)> {
let (lo, hi) = self.range(total);
match self.face {
Face::Innen if self.inset > 1e-4 => Some((hi, total)),
Face::Aussen if self.inset > 1e-4 => Some((0.0, lo)),
Face::Mitte => Some((0.0, lo)),
_ => None,
}
}
}
// ── Schichteinzug ([106]) ───────────────────────────────────────────────────
/// Schichteinzug-Regeln einer Öffnung: Öffnung > Typ > veraltetes `innerLayerRecess`.
pub fn reveal_rules(p: &Project, o: &Opening) -> Vec<LayerReveal> {
if let Some(r) = o.layer_reveals.as_ref() {
return r.clone();
}
if o.kind == ElementKind::Door {
return p.door_type(o).and_then(|t| t.layer_reveals.clone()).unwrap_or_default();
}
let Some(t) = p.window_type(o) else { return Vec::new() };
if let Some(r) = t.layer_reveals.as_ref() {
return r.clone();
}
if t.inner_layer_recess == Some(true) {
return vec![LayerReveal { layer: -1.0, mode: RevealMode::Zurueck, ..Default::default() }];
}
Vec::new()
}
/// Anschluss EINER Schicht an EINER Seite: Rücksprung (`shift` ≥ 0, die Schicht endet um so viel
/// hinter der Rohbaukante) und Zusatzstücke `[x0, x1, o0, o1]` in der Öffnung (x ab Rohbaukante,
/// o quer ab Aussenfläche) im Material der Schicht.
#[derive(Clone, Debug, PartialEq)]
pub struct LayerAdjust {
pub layer: usize,
pub shift: f64,
pub pieces: Vec<[f64; 4]>,
}
fn side_rule(r: &LayerReveal, side: Side) -> (RevealMode, Option<f64>) {
let s = match side {
Side::Left => r.left.as_ref(),
Side::Right => r.right.as_ref(),
Side::Top => r.top.as_ref(),
Side::Bottom => r.bottom.as_ref(),
};
match s {
Some(s) => (s.mode, fin(s.amount)),
None => (r.mode, fin(r.amount)),
}
}
/// Index einer Regel-Schicht (ab aussen; negativ ab innen), `None` ausserhalb.
pub fn layer_index(layer: f64, n: usize) -> Option<usize> {
if !layer.is_finite() {
return None;
}
let k = layer.round() as i64;
let i = if k < 0 { n as i64 + k } else { k };
(i >= 0 && (i as usize) < n).then_some(i as usize)
}
/// Schichtanschlüsse an einer Seite für die Schichtdicken `thick` (aussen → innen) und die
/// Rahmenlage `frame` (ab Aussenfläche). Nur Schichten mit Wirkung erscheinen.
pub fn reveal_adjust(thick: &[f64], rules: &[LayerReveal], side: Side, frame: (f64, f64)) -> Vec<LayerAdjust> {
let n = thick.len();
if n == 0 || rules.is_empty() || thick.iter().any(|t| !t.is_finite()) {
return Vec::new();
}
let mut mode: Vec<Option<(RevealMode, Option<f64>)>> = vec![None; n];
for r in rules {
if let Some(i) = layer_index(r.layer, n) {
mode[i] = Some(side_rule(r, side));
}
}
let mut bounds = Vec::with_capacity(n);
let mut acc = 0.0;
for &t in thick {
bounds.push((acc, acc + t.max(0.0)));
acc += t.max(0.0);
}
let (flo, fhi) = (frame.0.min(frame.1), frame.0.max(frame.1));
let mut out: Vec<LayerAdjust> = Vec::new();
let push = |out: &mut Vec<LayerAdjust>, layer: usize, shift: f64, piece: Option<[f64; 4]>| {
let e = match out.iter().position(|a| a.layer == layer) {
Some(k) => &mut out[k],
None => {
out.push(LayerAdjust { layer, shift: 0.0, pieces: Vec::new() });
out.last_mut().expect("eben eingefügt")
}
};
e.shift = e.shift.max(shift);
if let Some(pc) = piece {
if pc[1] - pc[0] > EPS && pc[3] - pc[2] > EPS {
e.pieces.push(pc);
}
}
};
// Zurück, überdämmt.
for i in 0..n {
let Some((m, amount)) = mode[i] else { continue };
let (l0, l1) = bounds[i];
match m {
RevealMode::Zurueck => push(&mut out, i, amount.unwrap_or(l1 - l0).max(0.0), None),
RevealMode::Ueberdaemmt => {
let a = amount.unwrap_or(DEFAULT_OVERLAP).max(0.0);
// Nur der Teil der Schicht vor bzw. hinter dem Rahmen.
for (s0, s1) in [(l0, l1.min(flo)), (l0.max(fhi), l1)] {
if s1 - s0 > EPS {
push(&mut out, i, 0.0, Some([0.0, a, s0, s1]));
}
}
}
_ => {}
}
}
// In die Leibung: je Seite des Rahmens vom Rahmen weg gestapelt (die rahmennächste Schicht
// liegt auf dem Rohbau, die äussere legt sich darüber).
for outer in [true, false] {
let mut order: Vec<usize> = (0..n).filter(|&i| if outer { bounds[i].1 <= flo + EPS } else { bounds[i].0 >= fhi - EPS }).collect();
if outer {
order.reverse();
}
let mut acc = 0.0f64;
for i in order {
let Some((m, amount)) = mode[i] else { continue };
let (l0, l1) = bounds[i];
match m {
RevealMode::Leibung => {
let a = amount.unwrap_or((l1 - l0).min(DEFAULT_REVEAL_LINING)).max(0.0);
push(&mut out, i, 0.0, Some([0.0, acc + a, l0, l1]));
let strip = if outer { [acc, acc + a, l1, flo] } else { [acc, acc + a, fhi, l0] };
push(&mut out, i, 0.0, Some(strip));
acc += a;
}
RevealMode::Ueberdaemmt => acc = acc.max(amount.unwrap_or(DEFAULT_OVERLAP).max(0.0)),
_ => {}
}
}
}
out.retain(|a| a.shift > EPS || !a.pieces.is_empty());
out.sort_by_key(|a| a.layer);
out
}
/// Rahmen ohne Typ (Schichteinzug nur über die Öffnung): Vorgabe aussen bündig.
fn default_frame() -> Frame {
Frame {
sides: Sides::all(DEFAULT_FRAME_WIDTH),
depth: f64::NAN,
inset: 0.0,
face: Face::Aussen,
sash_width: f64::NAN,
sash_depth: f64::NAN,
sash_overlap: f64::NAN,
mullion_width: f64::NAN,
mullion_depth: f64::NAN,
transom_width: f64::NAN,
transom_depth: f64::NAN,
ext: Sides::default(),
sill_profile: 0.0,
shading_profile: 0.0,
rebate: Sides::default(),
detailed: false,
}
}
/// Schichteinzug einer Öffnung in ihrer Wand: Achs-Intervall, Schichtdicken (aussen → innen)
/// und die Anschlüsse je Seite (links, rechts, oben, unten).
#[derive(Clone, Debug, PartialEq)]
pub struct OpeningReveal {
pub from: f64,
pub to: f64,
pub thick: Vec<f64>,
pub sides: [Vec<LayerAdjust>; 4],
}
pub const SIDES: [Side; 4] = [Side::Left, Side::Right, Side::Top, Side::Bottom];
/// `None`: keine Regeln, kein Wandtyp oder Öffnung ausserhalb der Wand.
pub fn opening_reveal(p: &Project, w: &Wall, o: &Opening) -> Option<OpeningReveal> {
let rules = reveal_rules(p, o);
if rules.is_empty() {
return None;
}
let wt = p.wall_type(w)?;
let thick: Vec<f64> = wt.layers.iter().map(|l| l.thickness).collect();
let total: f64 = thick.iter().sum();
if !(total > 1e-6) {
return None;
}
let frame = frame_of(p, o).unwrap_or_else(default_frame);
let range = frame.range(total);
let wr = crate::opening_geom::WallRef {
start: crate::opening_geom::v(w.start.x, w.start.y),
end: crate::opening_geom::v(w.end.x, w.end.y),
total,
ref_off: crate::joins::reference_offset(crate::model3d::wall_reference(w), total),
};
let (from, to) = crate::opening_geom::opening_interval(&wr, o.position, o.width)?;
let sides = SIDES.map(|s| reveal_adjust(&thick, &rules, s, range));
if sides.iter().all(|v| v.is_empty()) {
return None;
}
Some(OpeningReveal { from, to, thick, sides })
}
/// Grundriss-Block für `plan_walls::wall_poche` (Leibungen links/rechts aller Öffnungen der Wand):
/// `[n, (jamb, dir, schicht, rücksprung, nStücke, (x0, x1, o0, o1)×)×n]`.
pub fn plan_reveal_block(p: &Project, w: &Wall, openings: &[&Opening]) -> Vec<f64> {
let mut b = vec![0.0];
let mut n = 0.0;
for o in openings {
let Some(r) = opening_reveal(p, w, o) else { continue };
for (k, (jamb, dir)) in [(r.from, 1.0), (r.to, -1.0)].into_iter().enumerate() {
for a in &r.sides[k] {
b.extend([jamb, dir, a.layer as f64, a.shift, a.pieces.len() as f64]);
for pc in &a.pieces {
b.extend(pc);
}
n += 1.0;
}
}
}
b[0] = n;
b
}
/// Vorgaben für den Schichteinzug (Dialog): Name und Regeln.
pub fn reveal_presets() -> Vec<(&'static str, Vec<LayerReveal>)> {
let r = |layer: f64, mode: RevealMode, amount: Option<f64>| LayerReveal { layer, mode, amount, ..Default::default() };
vec![
("buendig", vec![]),
("ueberdaemmt3_putzLeibung", vec![r(0.0, RevealMode::Ueberdaemmt, Some(0.03)), r(-1.0, RevealMode::Leibung, None)]),
("leibungsdaemmung_putzLeibung", vec![r(0.0, RevealMode::Leibung, Some(0.03)), r(-1.0, RevealMode::Leibung, None)]),
("innenZurueck", vec![r(-1.0, RevealMode::Zurueck, None)]),
("putzLeibungBeidseitig", vec![r(0.0, RevealMode::Leibung, None), r(-1.0, RevealMode::Leibung, None)]),
]
}
// ── Türzargen und -rahmen ([105]) ───────────────────────────────────────────
/// Bauteil eines Zargen-/Rahmenprofils.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FramePart {
/// Rahmen/Zarge (Holz oder Stahl).
Frame,
/// Futterbrett in der Leibung.
Lining,
/// Bekleidung auf der Wandfläche.
Casing,
}
/// Aufgelöste Türzarge einer Öffnung (nur Arten mit eigener Zeichnung).
#[derive(Clone, Debug, PartialEq)]
pub struct DoorFrame {
pub kind: DoorTypeFrameKind,
pub frame: Frame,
pub falz_width: f64,
pub falz_depth: f64,
pub spiegel: f64,
pub sheet: f64,
pub lining: f64,
pub casing_width: f64,
pub casing_thickness: f64,
pub casing_sides: CasingSides,
/// Stahl (Umfassungs-/Eckzarge) — in der Zeichnung gefüllt.
pub steel: bool,
}
/// Zarge der Tür, wenn ihre Art eine eigene Zeichnung hat (Zarge alt bleibt beim bisherigen Pfad).
pub fn door_frame_of(p: &Project, o: &Opening) -> Option<DoorFrame> {
if o.kind != ElementKind::Door {
return None;
}
let t = p.door_type(o)?;
if t.kind == DoorTypeKind::Wandoeffnung || o.door_type == Some(OpeningDoorType::Wandoeffnung) {
return None;
}
let kind = o.door_frame_kind.or(t.frame_kind).unwrap_or_default();
// Zarge und Blockrahmen behalten das bisherige Rahmenband ([94]).
if matches!(kind, DoorTypeFrameKind::Zarge | DoorTypeFrameKind::Blockrahmen | DoorTypeFrameKind::Unknown) {
return None;
}
let (a, b) = (t.door_frame.as_ref(), o.door_frame.as_ref());
let g = |f: fn(&DoorFrameDetail) -> Option<f64>, d: f64| fin(b.and_then(f)).or(fin(a.and_then(f))).unwrap_or(d).max(0.0);
Some(DoorFrame {
kind,
frame: frame_of(p, o)?,
falz_width: g(|d| d.falz_width, 0.015),
falz_depth: g(|d| d.falz_depth, 0.04),
spiegel: g(|d| d.spiegel, 0.05),
sheet: g(|d| d.sheet_thickness, 0.002).max(0.0005),
lining: g(|d| d.lining_thickness, 0.025),
casing_width: g(|d| d.casing_width, 0.07),
casing_thickness: g(|d| d.casing_thickness, 0.012),
casing_sides: b.and_then(|d| d.casing_sides).or(a.and_then(|d| d.casing_sides)).unwrap_or_default(),
steel: matches!(kind, DoorTypeFrameKind::Umfassungszarge | DoorTypeFrameKind::Eckzarge),
})
}
/// Liegt die Aufschlagseite (wohin das Blatt aufgeht) auf der Innenfläche (hohe Versätze)?
/// Gleiche Regel wie der Schnitt einer Schiebetür (`plan/section.rs`).
pub fn aufschlag_innen(o: &Opening) -> bool {
let swing = if matches!(o.swing, None | Some(SwingSide::Left)) { 1.0 } else { -1.0 };
let dir = if matches!(o.opening_dir, None | Some(OpeningOpeningDir::In)) { 1.0 } else { -1.0 };
swing * dir > 0.0
}
/// Einbaufuge zwischen Mauerwerk und Stahlzarge.
const ZARGE_GAP: f64 = 0.01;
/// Orthogonaler Linienzug, nach rechts (in Laufrichtung) um `t` verdickt, als geschlossenes Polygon.
fn thick_path(path: &[[f64; 2]], t: f64) -> Vec<[f64; 2]> {
let n = path.len();
if n < 2 {
return Vec::new();
}
let right = |a: [f64; 2], b: [f64; 2]| {
let (dx, dy) = (b[0] - a[0], b[1] - a[1]);
let l = (dx * dx + dy * dy).sqrt().max(1e-12);
[dy / l * t, -dx / l * t]
};
let mut off = Vec::with_capacity(n);
for i in 0..n {
let ni = if i == 0 { right(path[0], path[1]) } else { right(path[i - 1], path[i]) };
let nj = if i + 1 < n { right(path[i], path[i + 1]) } else { ni };
// Orthogonale Ecke: Summe der beiden Versätze (bei gerader Fortsetzung nur einer).
let same = (ni[0] - nj[0]).abs() < 1e-12 && (ni[1] - nj[1]).abs() < 1e-12;
let d = if same { ni } else { [ni[0] + nj[0], ni[1] + nj[1]] };
off.push([path[i][0] + d[0], path[i][1] + d[1]]);
}
let mut poly = path.to_vec();
poly.extend(off.into_iter().rev());
poly
}
/// Profil der Zarge an der linken Leibung: Polygone in `(x, d)`; `x` in die Öffnung ab Rohbaukante,
/// `d` ab der Aufschlagfläche in die Wand (0 … `total`, < 0 = vor der Fläche). Die rechte Leibung
/// spiegelt `x`, der Sturz nimmt `x` nach unten.
pub fn door_frame_profile(f: &DoorFrame, total: f64, aufschlag_innen: bool) -> Vec<(FramePart, Vec<[f64; 2]>)> {
let t = total.max(0.0);
let (fzw, fzd) = (f.falz_width, f.falz_depth.min(t));
let fw = f.frame.sides.left.max(fzw + 0.01);
let rect = |x0: f64, x1: f64, d0: f64, d1: f64| vec![[x0, d0], [x1, d0], [x1, d1], [x0, d1]];
let mut out = Vec::new();
match f.kind {
DoorTypeFrameKind::Umfassungszarge => {
let c = ZARGE_GAP;
let path = [[-f.spiegel, 0.0], [c, 0.0], [c, fzd], [c + fzw, fzd], [c + fzw, t], [-f.spiegel, t]];
out.push((FramePart::Frame, thick_path(&path, f.sheet)));
}
DoorTypeFrameKind::Eckzarge => {
let c = ZARGE_GAP;
let path = [[-f.spiegel, 0.0], [c, 0.0], [c, fzd], [c + fzw, fzd], [c + fzw, (fzd + 0.03).min(t)]];
out.push((FramePart::Frame, thick_path(&path, f.sheet)));
}
DoorTypeFrameKind::Blockzarge => {
out.push((FramePart::Frame, vec![[0.0, 0.0], [fw - fzw, 0.0], [fw - fzw, fzd], [fw, fzd], [fw, t], [0.0, t]]));
}
DoorTypeFrameKind::Blockrahmen => {
// Lage aus insetFace/insetFromFace (ab Aussenfläche) in Aufschlag-Koordinaten.
let (lo, hi) = f.frame.range(t);
let (d0, d1) = if aufschlag_innen { (t - hi, t - lo) } else { (lo, hi) };
let fzd = fzd.min(d1 - d0);
out.push((FramePart::Frame, vec![[0.0, d0], [fw - fzw, d0], [fw - fzw, d0 + fzd], [fw, d0 + fzd], [fw, d1], [0.0, d1]]));
}
DoorTypeFrameKind::Blendrahmen => {
let fd = if f.frame.depth > 1e-9 { f.frame.depth } else { DEFAULT_FRAME_DEPTH };
let ov = fzw;
out.push((FramePart::Frame, vec![[ov - fw, 0.0], [ov, 0.0], [ov, -fd + fzd.min(fd)], [ov - fzw, -fd + fzd.min(fd)], [ov - fzw, -fd], [ov - fw, -fd]]));
}
DoorTypeFrameKind::Futter => {
let lt = f.lining;
out.push((FramePart::Lining, rect(0.0, lt, 0.0, t)));
let (cw, ct) = (f.casing_width, f.casing_thickness);
if matches!(f.casing_sides, CasingSides::Beide | CasingSides::Aufschlag) {
out.push((FramePart::Casing, rect(lt + fzw - cw, lt + fzw, -ct, 0.0)));
}
if matches!(f.casing_sides, CasingSides::Beide | CasingSides::Gegen) {
out.push((FramePart::Casing, rect(lt + 0.005 - cw, lt + 0.005, t, t + ct)));
}
}
_ => {}
}
out.retain(|(_, p)| p.len() >= 3);
out
}
/// Lage des Türblatts quer zur Wand `(d0, d1)` ab der Aufschlagfläche: im Falz der Zarge.
pub fn leaf_band(f: &DoorFrame, total: f64, aufschlag_innen: bool) -> (f64, f64) {
let leaf = f.falz_depth.clamp(0.02, 0.08);
match f.kind {
DoorTypeFrameKind::Blockrahmen => {
let (lo, hi) = f.frame.range(total);
let d0 = if aufschlag_innen { total - hi } else { lo };
(d0, d0 + leaf)
}
DoorTypeFrameKind::Blendrahmen => {
let fd = if f.frame.depth > 1e-9 { f.frame.depth } else { DEFAULT_FRAME_DEPTH };
(-fd, -fd + leaf)
}
_ => (0.0, leaf),
}
}
/// Lichte Kante der Zarge (grösstes `x` des Profils in der Öffnung).
pub fn profile_clear_x(profile: &[(FramePart, Vec<[f64; 2]>)]) -> f64 {
profile.iter().flat_map(|(_, p)| p.iter().map(|q| q[0])).fold(0.0, f64::max)
}
/// Zerlegt ein orthogonales Polygon in Rechtecke `[x0, x1, d0, d1]` (für 3D-Quader).
pub fn ortho_rects(poly: &[[f64; 2]]) -> Vec<[f64; 4]> {
let mut xs: Vec<f64> = poly.iter().map(|p| p[0]).collect();
let mut ds: Vec<f64> = poly.iter().map(|p| p[1]).collect();
let srt = |v: &mut Vec<f64>| {
v.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
v.dedup_by(|a, b| (*a - *b).abs() < 1e-9);
};
srt(&mut xs);
srt(&mut ds);
let inside = |x: f64, y: f64| {
let mut c = false;
let n = poly.len();
for i in 0..n {
let (a, b) = (poly[i], poly[(i + 1) % n]);
if (a[1] > y) != (b[1] > y) && x < a[0] + (y - a[1]) / (b[1] - a[1]) * (b[0] - a[0]) {
c = !c;
}
}
c
};
let mut out: Vec<[f64; 4]> = Vec::new();
for i in 0..xs.len().saturating_sub(1) {
let xm = (xs[i] + xs[i + 1]) / 2.0;
let mut run: Option<f64> = None;
for j in 0..ds.len().saturating_sub(1) {
let inn = inside(xm, (ds[j] + ds[j + 1]) / 2.0);
match (inn, run) {
(true, None) => run = Some(ds[j]),
(false, Some(d0)) => {
out.push([xs[i], xs[i + 1], d0, ds[j]]);
run = None;
}
_ => {}
}
}
if let Some(d0) = run {
out.push([xs[i], xs[i + 1], d0, *ds.last().expect("nicht leer")]);
}
}
out
}
/// Achsen-Quader (Ecken-Bits wie `OPENING_BOX_TRIS`: bit0 Achse, bit1 Höhe, bit2 quer) in Weltkoordinaten:
/// Wandstart `s`, Achsrichtung `u`, linke Normale `n`; Achsmass `a0..a1`, Höhe `z0..z1`, Versatz `o0..o1`.
#[allow(clippy::too_many_arguments)]
pub fn axis_box(s: [f64; 2], u: [f64; 2], n: [f64; 2], a0: f64, a1: f64, z0: f64, z1: f64, o0: f64, o1: f64) -> Option<[f64; 24]> {
if !(a1 - a0 > EPS && z1 - z0 > EPS && (o1 - o0).abs() > EPS) || ![a0, a1, z0, z1, o0, o1].iter().all(|v| v.is_finite()) {
return None;
}
let mut p = [0.0; 24];
for i in 0..8 {
let a = if i & 1 != 0 { a1 } else { a0 };
let z = if i & 2 != 0 { z1 } else { z0 };
let o = if i & 4 != 0 { o1 } else { o0 };
p[i * 3] = s[0] + u[0] * a + n[0] * o;
p[i * 3 + 1] = s[1] + u[1] * a + n[1] * o;
p[i * 3 + 2] = z;
}
Some(p)
}
#[cfg(test)]
mod tests {
use super::*;
fn rule(layer: f64, mode: RevealMode, amount: Option<f64>) -> LayerReveal {
LayerReveal { layer, mode, amount, ..Default::default() }
}
/// Aussendämmung 0.16, Backstein 0.15, Innenputz 0.01; Rahmen 0.16..0.23 (auf dem Backstein).
const WALL: [f64; 3] = [0.16, 0.15, 0.01];
const FRAME: (f64, f64) = (0.16, 0.23);
#[test]
fn buendig_ohne_wirkung() {
assert!(reveal_adjust(&WALL, &[rule(0.0, RevealMode::Buendig, None)], Side::Left, FRAME).is_empty());
assert!(reveal_adjust(&WALL, &[], Side::Left, FRAME).is_empty());
}
#[test]
fn zurueck_um_schichtdicke_und_mass() {
let a = reveal_adjust(&WALL, &[rule(-1.0, RevealMode::Zurueck, None)], Side::Top, FRAME);
assert_eq!(a.len(), 1);
assert_eq!(a[0].layer, 2);
assert!((a[0].shift - 0.01).abs() < 1e-12);
let a = reveal_adjust(&WALL, &[rule(0.0, RevealMode::Zurueck, Some(0.05))], Side::Left, FRAME);
assert_eq!((a[0].layer, a[0].shift), (0, 0.05));
}
#[test]
fn ueberdaemmt_nur_vor_dem_rahmen() {
let a = reveal_adjust(&WALL, &[rule(0.0, RevealMode::Ueberdaemmt, Some(0.03))], Side::Left, FRAME);
assert_eq!(a[0].pieces, vec![[0.0, 0.03, 0.0, 0.16]]);
// Rahmen mitten in der Dämmung: nur der Teil davor.
let a = reveal_adjust(&WALL, &[rule(0.0, RevealMode::Ueberdaemmt, None)], Side::Left, (0.1, 0.17));
assert_eq!(a[0].pieces, vec![[0.0, 0.03, 0.0, 0.1]]);
}
#[test]
fn innenputz_in_die_leibung_bis_rahmen() {
let a = reveal_adjust(&WALL, &[rule(-1.0, RevealMode::Leibung, None)], Side::Right, FRAME);
assert_eq!(a.len(), 1);
// Ecke im Putz-Band und Streifen über die Backstein-Leibung bis an den Rahmen.
assert_eq!(a[0].pieces.len(), 2);
let s = a[0].pieces[1];
assert!((s[1] - 0.01).abs() < 1e-12 && (s[2] - 0.23).abs() < 1e-12 && (s[3] - 0.31).abs() < 1e-12);
}
#[test]
fn leibung_stapelt_vom_rahmen_weg() {
// Rahmen innen auf dem Backstein: Dämmung (3 cm) und Aussenputz laufen in die Leibung.
let wall = [0.02, 0.16, 0.15];
let rules = [rule(0.0, RevealMode::Leibung, Some(0.01)), rule(1.0, RevealMode::Leibung, Some(0.03))];
let a = reveal_adjust(&wall, &rules, Side::Left, (0.18, 0.25));
let putz = a.iter().find(|x| x.layer == 0).unwrap();
// Putz liegt über der Dämmung: x 0.03 … 0.04.
assert!(putz.pieces.iter().any(|p| (p[0] - 0.03).abs() < 1e-12 && (p[1] - 0.04).abs() < 1e-12));
}
#[test]
fn veraltetes_inner_layer_recess_wird_regel() {
let mut p = Project::default();
p.window_types = Some(vec![WindowType { id: "w".into(), inner_layer_recess: Some(true), ..Default::default() }]);
let o = Opening { kind: ElementKind::Window, type_id: Some("w".into()), ..Default::default() };
let r = reveal_rules(&p, &o);
assert_eq!(r.len(), 1);
assert_eq!((r[0].layer, r[0].mode), (-1.0, RevealMode::Zurueck));
// Öffnung übersteuert.
let o2 = Opening { layer_reveals: Some(vec![]), ..o };
assert!(reveal_rules(&p, &o2).is_empty());
}
#[test]
fn rahmen_je_seite_und_uebersteuerung() {
let mut p = Project::default();
let fd = FrameDetail { frame_sides: Some(OpeningSides { bottom: Some(0.09), ..Default::default() }), rebates: Some(OpeningSides { left: Some(0.0), ..Default::default() }), ..Default::default() };
p.window_types = Some(vec![WindowType { id: "w".into(), frame_width: Some(0.07), rebate_depth: Some(0.05), frame_detail: Some(fd), ..Default::default() }]);
let o = Opening { kind: ElementKind::Window, type_id: Some("w".into()), frame_detail: Some(FrameDetail { frame_sides: Some(OpeningSides { top: Some(0.12), ..Default::default() }), ..Default::default() }), ..Default::default() };
let f = frame_of(&p, &o).unwrap();
assert_eq!(f.sides, Sides { left: 0.07, right: 0.07, top: 0.12, bottom: 0.09 });
assert_eq!(f.rebate, Sides { left: 0.0, right: 0.05, top: 0.05, bottom: 0.05 });
assert!(f.detailed);
assert_eq!(f.sill_profile, 0.0);
}
#[test]
fn zargen_profile() {
let mut p = Project::default();
let mk = |k| DoorType { id: "d".into(), frame_kind: Some(k), frame_width: Some(0.06), ..Default::default() };
let o = Opening { kind: ElementKind::Door, type_id: Some("d".into()), ..Default::default() };
for k in [DoorTypeFrameKind::Umfassungszarge, DoorTypeFrameKind::Eckzarge, DoorTypeFrameKind::Blockzarge, DoorTypeFrameKind::Blendrahmen, DoorTypeFrameKind::Futter] {
p.door_types = Some(vec![mk(k)]);
let f = door_frame_of(&p, &o).unwrap();
let prof = door_frame_profile(&f, 0.3, false);
assert!(!prof.is_empty(), "{k:?}");
for (_, poly) in &prof {
let r = ortho_rects(poly);
assert!(!r.is_empty(), "{k:?}");
}
}
p.door_types = Some(vec![mk(DoorTypeFrameKind::Zarge)]);
assert!(door_frame_of(&p, &o).is_none());
// Umfassungszarge: Spiegel beidseitig über die Wandflächen hinaus.
p.door_types = Some(vec![mk(DoorTypeFrameKind::Umfassungszarge)]);
let f = door_frame_of(&p, &o).unwrap();
let prof = door_frame_profile(&f, 0.3, false);
let ds: Vec<f64> = prof[0].1.iter().map(|q| q[1]).collect();
assert!(ds.iter().any(|&d| d < 0.0) && ds.iter().any(|&d| d > 0.3));
// Futter: Bekleidung beidseitig.
p.door_types = Some(vec![mk(DoorTypeFrameKind::Futter)]);
let prof = door_frame_profile(&door_frame_of(&p, &o).unwrap(), 0.3, false);
assert_eq!(prof.iter().filter(|(k, _)| *k == FramePart::Casing).count(), 2);
}
/// Projekt: Aussenwand (Putz, Dämmung, Backstein, Putz) mit einer Öffnung des Typs `t`.
fn wand_mit(win: Option<WindowType>, door: Option<DoorType>) -> Project {
let mut p = Project::default();
for (id, _) in [("a", 0), ("b", 1), ("c", 2), ("d", 3)] {
p.components.push(Component { id: id.into(), ..Default::default() });
}
let l = |c: &str, t: f64| Layer { component_id: c.into(), thickness: t, ..Default::default() };
p.wall_types.push(WallType { id: "aw".into(), layers: vec![l("a", 0.02), l("b", 0.16), l("c", 0.15), l("d", 0.015)], ..Default::default() });
p.drawing_levels.push(DrawingLevel { id: "eg".into(), kind: DrawingLevelKind::Floor, floor_height: Some(2.6), ..Default::default() });
p.walls.push(Wall { id: "w".into(), floor_id: "eg".into(), wall_type_id: "aw".into(), start: Vec2 { x: 0.0, y: 0.0 }, end: Vec2 { x: 5.0, y: 0.0 }, height: 2.6, ..Default::default() });
let kind = if door.is_some() { ElementKind::Door } else { ElementKind::Window };
p.window_types = win.map(|t| vec![t]);
p.door_types = door.map(|t| vec![t]);
p.openings = Some(vec![Opening { id: "o".into(), host_wall_id: "w".into(), kind, type_id: Some("t".into()), position: 1.0, width: 1.2, height: 1.4, sill_height: if kind == ElementKind::Window { 0.9 } else { 0.0 }, ..Default::default() }]);
p
}
#[test]
fn schichteinzug_im_3d_und_grundriss_block() {
let reveals = vec![LayerReveal { layer: 1.0, mode: RevealMode::Ueberdaemmt, amount: Some(0.03), ..Default::default() }, LayerReveal { layer: -1.0, mode: RevealMode::Leibung, ..Default::default() }];
let p = wand_mit(Some(WindowType { id: "t".into(), inset_from_face: Some(0.18), frame_depth: Some(0.08), layer_reveals: Some(reveals), ..Default::default() }), None);
let walls = crate::model3d::emit_walls(&p, true).unwrap();
// Zusatzstücke (eigene Dicke): Dämmung 0.16 über dem Rahmen, Putz-Streifen in der Leibung.
assert!(walls.iter().any(|w| (w.thickness - 0.16).abs() < 1e-9 && w.holes.is_none() && (w.end[0] - w.start[0] - 1.2).abs() < 1e-9));
assert!(walls.iter().any(|w| (w.thickness - 0.07).abs() < 1e-9));
let b = plan_reveal_block(&p, &p.walls[0], &[&p.openings.as_ref().unwrap()[0]]);
assert!(b[0] >= 2.0);
// Ohne Regeln: kein Block, keine Stücke.
let p0 = wand_mit(Some(WindowType { id: "t".into(), ..Default::default() }), None);
assert_eq!(plan_reveal_block(&p0, &p0.walls[0], &[&p0.openings.as_ref().unwrap()[0]]), vec![0.0]);
}
#[test]
fn zarge_und_rahmen_detail_im_3d() {
let p = wand_mit(None, Some(DoorType { id: "t".into(), frame_kind: Some(DoorTypeFrameKind::Futter), frame_width: Some(0.06), ..Default::default() }));
let p0 = wand_mit(None, Some(DoorType { id: "t".into(), frame_width: Some(0.06), ..Default::default() }));
let pos = |p: &Project| crate::model3d::emit_opening_meshes(p, 1.0).into_iter().map(|m| m.positions).collect::<Vec<_>>();
assert_ne!(pos(&p), pos(&p0));
// Fensterrahmen je Seite: unten breiter ⇒ andere Quader als gleichmässig.
let fd = FrameDetail { frame_sides: Some(OpeningSides { bottom: Some(0.12), ..Default::default() }), sill_profile: Some(0.03), ..Default::default() };
let a = crate::model3d::emit_opening_meshes(&wand_mit(Some(WindowType { id: "t".into(), frame_width: Some(0.06), frame_detail: Some(fd), ..Default::default() }), None), 1.0);
let b = crate::model3d::emit_opening_meshes(&wand_mit(Some(WindowType { id: "t".into(), frame_width: Some(0.06), ..Default::default() }), None), 1.0);
assert_ne!(a.iter().map(|m| m.positions.clone()).collect::<Vec<_>>(), b.iter().map(|m| m.positions.clone()).collect::<Vec<_>>());
}
#[test]
fn rechtecke_eines_l_profils() {
let r = ortho_rects(&[[0.0, 0.0], [2.0, 0.0], [2.0, 1.0], [1.0, 1.0], [1.0, 3.0], [0.0, 3.0]]);
let area: f64 = r.iter().map(|q| (q[1] - q[0]) * (q[3] - q[2])).sum();
assert!((area - 4.0).abs() < 1e-12);
}
}
+4 -1
View File
@@ -147,6 +147,8 @@ pub struct WindowSpec {
pub inset_inner: bool,
/// Rahmen mittig in der Wand (`insetFace: "mitte"`); hat Vorrang vor `inset_inner`/Einzug.
pub inset_mid: bool,
/// Rahmenbreite an der Leibung beim Wandende ([105]); NaN = wie `frame_width`.
pub frame_width_end: f64,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
@@ -262,7 +264,8 @@ pub fn window_symbol(
vec![add(a, scale(n, frame_outer_n)), add(b, scale(n, frame_outer_n)), add(b, scale(n, frame_inner_n)), add(a, scale(n, frame_inner_n))]
};
sym.jamb_marks.push(frame_block(fw / 2.0, fw / 2.0));
sym.jamb_marks.push(frame_block(axis_width - fw / 2.0, fw / 2.0));
let fwe = if spec.frame_width_end.is_nan() { fw } else { max(0.01, spec.frame_width_end) };
sym.jamb_marks.push(frame_block(axis_width - fwe / 2.0, fwe / 2.0));
for i in 0..segs.len().saturating_sub(1) {
let u_pos = segs[i].2;
if fein {
+100
View File
@@ -0,0 +1,100 @@
//! Vorschau-Projekt einer Öffnung für den Fenster-/Tür-Dialog ([105]/[106]): die Wirtswand (gleicher
//! Wandtyp, gerade, Achse entlang x) mit NUR dieser Öffnung in der Mitte, ein Geschoss mit Schnitthöhe
//! durch die Öffnung, ein Schnitt quer durch die Öffnungsmitte und eine Ansicht von aussen. Die TS-Seite
//! rechnet daraus Grundriss, Schnitt und Ansicht wie für jedes Projekt (`src/plan/openingPreview.ts`).
use crate::model::*;
/// Rand links/rechts neben der Öffnung (Meter).
const MARGIN: f64 = 0.7;
pub const FLOOR_ID: &str = "preview-floor";
pub const SECTION_ID: &str = "preview-section";
pub const ELEVATION_ID: &str = "preview-elevation";
/// `None`: Öffnung oder Wirtswand fehlt.
pub fn opening_preview(p: &Project, opening_id: &str) -> Option<Project> {
let o = p.openings.as_deref()?.iter().find(|o| o.id == opening_id)?;
let host = p.walls.iter().find(|w| w.id == o.host_wall_id)?;
let floor = p.drawing_levels.iter().find(|l| l.id == host.floor_id);
let width = if o.width.is_finite() && o.width > 0.05 { o.width } else { 1.0 };
let len = width + 2.0 * MARGIN;
let total = p.wall_thickness(host, 0.2);
let mut lvl = floor.cloned().unwrap_or_default();
lvl.id = FLOOR_ID.into();
lvl.name = "EG".into();
lvl.kind = DrawingLevelKind::Floor;
lvl.visible = true;
lvl.base_elevation = Some(0.0);
lvl.layout_id = None;
// Schnitthöhe durch die Öffnung (Fenster mit hoher Brüstung erscheinen sonst nur in Aufsicht).
let sill = if o.kind == ElementKind::Window { o.sill_height.max(0.0) } else { 0.0 };
lvl.cut_height = Some(sill + o.height.max(0.1).min(3.0) / 2.0);
let mut wall = host.clone();
wall.id = "preview-wall".into();
wall.floor_id = FLOOR_ID.into();
wall.start = Vec2 { x: 0.0, y: 0.0 };
wall.end = Vec2 { x: len, y: 0.0 };
let mut op = o.clone();
op.host_wall_id = wall.id.clone();
op.position = MARGIN;
op.width = width;
let mid = MARGIN + width / 2.0;
let reach = total.max(0.2) + 0.6;
let mut section = DrawingLevel { id: SECTION_ID.into(), name: "Schnitt".into(), kind: DrawingLevelKind::Section, visible: true, ..Default::default() };
section.line_points = Some([Vec2 { x: mid, y: -reach }, Vec2 { x: mid, y: reach }]);
section.direction_sign = Some(1.0);
section.level_marks = Some(false);
let mut elevation = DrawingLevel { id: ELEVATION_ID.into(), name: "Ansicht".into(), kind: DrawingLevelKind::Elevation, visible: true, ..Default::default() };
// Aussenfläche liegt rechts der Achse (−y): Ansicht von dort.
elevation.line_points = Some([Vec2 { x: 0.0, y: -reach }, Vec2 { x: len, y: -reach }]);
elevation.direction_sign = Some(1.0);
elevation.level_marks = Some(false);
Some(Project {
format_version: p.format_version,
id: "opening-preview".into(),
name: "Vorschau".into(),
line_styles: p.line_styles.clone(),
text_styles: p.text_styles.clone(),
hatches: p.hatches.clone(),
components: p.components.clone(),
wall_types: p.wall_types.iter().filter(|t| t.id == host.wall_type_id).cloned().collect(),
door_types: p.door_types.clone(),
window_types: p.window_types.clone(),
pens: p.pens.clone(),
pen_sets: p.pen_sets.clone(),
active_pen_set_id: p.active_pen_set_id.clone(),
layers: p.layers.clone(),
drawing_levels: vec![lvl, section, elevation],
walls: vec![wall],
openings: Some(vec![op]),
scale_line_weights: p.scale_line_weights,
..Default::default()
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn vorschau_hat_wand_oeffnung_schnitt_und_ansicht() {
let mut p = Project::default();
p.drawing_levels.push(DrawingLevel { id: "eg".into(), kind: DrawingLevelKind::Floor, ..Default::default() });
p.walls.push(Wall { id: "w".into(), floor_id: "eg".into(), start: Vec2 { x: 3.0, y: 4.0 }, end: Vec2 { x: 3.0, y: 12.0 }, ..Default::default() });
p.openings = Some(vec![Opening { id: "o".into(), host_wall_id: "w".into(), kind: ElementKind::Window, position: 5.0, width: 1.2, height: 1.4, sill_height: 0.9, ..Default::default() }]);
let q = opening_preview(&p, "o").unwrap();
assert_eq!(q.walls.len(), 1);
assert!((q.walls[0].end.x - 2.6).abs() < 1e-12);
let o = &q.openings.as_ref().unwrap()[0];
assert_eq!((o.position, o.width), (MARGIN, 1.2));
assert_eq!(q.drawing_levels.len(), 3);
assert!((q.drawing_levels[0].cut_height.unwrap() - 1.6).abs() < 1e-12);
assert!(opening_preview(&p, "fehlt").is_none());
}
}
+159 -35
View File
@@ -188,6 +188,60 @@ pub struct TypeIn {
pub frame_width: f64,
pub transom_height: f64,
pub kind: KindIn,
/// Rahmen-Detail ([105]), aus dem Anhang der Kodierung; `None` = bisher.
pub detail: Option<Box<FrameDetailIn>>,
}
/// Rahmen-Detail einer Öffnung ([105]); Seiten in der Reihenfolge links, rechts, oben, unten,
/// NaN = Vorgabe.
#[derive(Clone, Debug, PartialEq)]
pub struct FrameDetailIn {
pub sides: [f64; 4],
pub ext: [f64; 4],
pub rebate: [f64; 4],
pub sash_width: f64,
pub sash_depth: f64,
pub sash_overlap: f64,
pub mullion_width: f64,
pub transom_width: f64,
pub sill_profile: f64,
pub shading_profile: f64,
/// Türzarge mit eigener Zeichnung: Blendrahmen-Ring und Zargen-Umgriff entfallen.
pub skip_frame: bool,
}
/// Anzahl Zahlen eines Anhang-Eintrags nach (Wand, Öffnung).
pub const DETAIL_LEN: usize = 20;
impl FrameDetailIn {
fn read(r: &mut Reader) -> Option<FrameDetailIn> {
let mut v = [0.0; DETAIL_LEN];
for x in v.iter_mut() {
*x = r.num()?;
}
Some(FrameDetailIn {
sides: [v[0], v[1], v[2], v[3]],
ext: [v[4], v[5], v[6], v[7]],
rebate: [v[8], v[9], v[10], v[11]],
sash_width: v[12],
sash_depth: v[13],
sash_overlap: v[14],
mullion_width: v[15],
transom_width: v[16],
sill_profile: v[17],
shading_profile: v[18],
skip_frame: v[19] != 0.0,
})
}
}
/// Wert oder Vorgabe (NaN/negativ ⇒ Vorgabe).
fn dv(v: f64, d: f64) -> f64 {
if v.is_finite() && v >= 0.0 {
v
} else {
d
}
}
/// Eine Öffnung: Achs-Intervall (ab Wandstart), absolute Höhen, Tür/Fenster, Wanddicke und Typ.
@@ -356,37 +410,43 @@ impl Emitter<'_> {
/// Rahmen-Ring über `[from,to] × [z_b,z_t]` mit Profilbreite `w` ohne überlappende Profile
/// (`frameRingQuads`): `join` bestimmt, welche Glieder an den Ecken durchlaufen.
pub fn frame_ring_quads(from: f64, to: f64, z_b: f64, z_t: f64, w: f64, join: CornerJoin, bottom: bool) -> Vec<Quad> {
frame_ring_quads_sides(from, to, z_b, z_t, [w, w, w, w], join, bottom)
}
/// Wie [`frame_ring_quads`], Profilbreite je Seite `[links, rechts, oben, unten]` ([105]).
pub fn frame_ring_quads_sides(from: f64, to: f64, z_b: f64, z_t: f64, w: [f64; 4], join: CornerJoin, bottom: bool) -> Vec<Quad> {
let [wl, wr, wt, wb] = w;
let bx = |u0: f64, u1: f64, h0: f64, h1: f64| -> Quad { [[u0, h0], [u1, h0], [u0, h1], [u1, h1]] };
let mut out = Vec::with_capacity(4);
if to - from <= 2.0 * w + EPS || z_t - z_b <= (if bottom { 2.0 } else { 1.0 }) * w + EPS {
if to - from <= wl + wr + EPS || z_t - z_b <= (if bottom { wb + wt } else { wt }) + EPS {
// Zu klein für einen Ring: ein Vollprofil.
out.push(bx(from, to, z_b, z_t));
return out;
}
let bz = if bottom { z_b + w } else { z_b };
let bz = if bottom { z_b + wb } else { z_b };
match join {
CornerJoin::Horizontal => {
out.push(bx(from, to, z_t - w, z_t));
out.push(bx(from, to, z_t - wt, z_t));
if bottom {
out.push(bx(from, to, z_b, z_b + w));
out.push(bx(from, to, z_b, z_b + wb));
}
out.push(bx(from, from + w, bz, z_t - w));
out.push(bx(to - w, to, bz, z_t - w));
out.push(bx(from, from + wl, bz, z_t - wt));
out.push(bx(to - wr, to, bz, z_t - wt));
}
CornerJoin::Mitre => {
out.push([[from + w, z_t - w], [to - w, z_t - w], [from, z_t], [to, z_t]]);
out.push([[from + wl, z_t - wt], [to - wr, z_t - wt], [from, z_t], [to, z_t]]);
if bottom {
out.push([[from, z_b], [to, z_b], [from + w, z_b + w], [to - w, z_b + w]]);
out.push([[from, z_b], [to, z_b], [from + wl, z_b + wb], [to - wr, z_b + wb]]);
}
out.push([[from, z_b], [from + w, bz], [from, z_t], [from + w, z_t - w]]);
out.push([[to - w, bz], [to, z_b], [to - w, z_t - w], [to, z_t]]);
out.push([[from, z_b], [from + wl, bz], [from, z_t], [from + wl, z_t - wt]]);
out.push([[to - wr, bz], [to, z_b], [to - wr, z_t - wt], [to, z_t]]);
}
CornerJoin::Vertical => {
out.push(bx(from, from + w, z_b, z_t));
out.push(bx(to - w, to, z_b, z_t));
out.push(bx(from + w, to - w, z_t - w, z_t));
out.push(bx(from, from + wl, z_b, z_t));
out.push(bx(to - wr, to, z_b, z_t));
out.push(bx(from + wl, to - wr, z_t - wt, z_t));
if bottom {
out.push(bx(from + w, to - w, z_b, z_b + w));
out.push(bx(from + wl, to - wr, z_b, z_b + wb));
}
}
}
@@ -530,6 +590,10 @@ fn resolve_frame(o: &OpeningIn) -> Option<FrameParams<'_>> {
/// Maueranschlag: Wandnasen links, rechts und oben in der Zone zwischen der Anschlag-Fläche und
/// der Rahmen-Vorderkante (aussen bzw. bei `insetFace: "innen"` innen; mittig: aussen).
fn rebate_boxes(em: &mut Emitter, o: &OpeningIn, ty: &TypeIn, p: &FrameParams) {
if let Some(d) = ty.detail.as_deref() {
rebate_boxes_sides(em, o, ty, p, d);
return;
}
let rd = jmin(or(ty.rebate_depth, 0.0), (o.to - o.from) / 2.0 - 0.01);
if !(rd > EPS) {
return;
@@ -544,6 +608,27 @@ fn rebate_boxes(em: &mut Emitter, o: &OpeningIn, ty: &TypeIn, p: &FrameParams) {
em.axis_box(o.from + rd, o.to - rd, o.z_top - rd, o.z_top, n0, n1, Part::Rebate);
}
/// Anschlag je Seite ([105]): links, rechts, oben und (Fenster) unten.
fn rebate_boxes_sides(em: &mut Emitter, o: &OpeningIn, ty: &TypeIn, p: &FrameParams, d: &FrameDetailIn) {
if !(ty.inset_mid || or(ty.inset_from_face, 0.0) > 1e-4) {
return;
}
let half = p.half_thickness;
let (n0, n1) = if ty.inset_inner && !ty.inset_mid { (-half, p.n_min) } else { (p.n_max, half) };
if n1 - n0 <= EPS {
return;
}
let lim = |v: f64, m: f64| jmax(0.0, jmin(dv(v, 0.0), m));
let wmax = (o.to - o.from) / 2.0 - 0.01;
let hmax = (o.z_top - o.z_bottom) / 3.0;
let (rl, rr, rt) = (lim(d.rebate[0], wmax), lim(d.rebate[1], wmax), lim(d.rebate[2], hmax));
let rb = if o.door { 0.0 } else { lim(d.rebate[3], hmax) };
em.axis_box(o.from, o.from + rl, o.z_bottom, o.z_top, n0, n1, Part::Rebate);
em.axis_box(o.to - rr, o.to, o.z_bottom, o.z_top, n0, n1, Part::Rebate);
em.axis_box(o.from + rl, o.to - rr, o.z_top - rt, o.z_top, n0, n1, Part::Rebate);
em.axis_box(o.from + rl, o.to - rr, o.z_bottom, o.z_bottom + rb, n0, n1, Part::Rebate);
}
/// Flügeleinteilung auf `[from, to]`: feste Breiten exakt, der Rest gleichmässig.
fn sash_spans(sashes: &[SashIn], from: f64, to: f64) -> Vec<(SashIn, f64, f64)> {
let width = jmax(0.0, to - from);
@@ -586,25 +671,40 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
let detail_bodies = fine || medium;
let fw = p.frame_width;
let (from0, to0, zb0, zt0) = (o.from, o.to, o.z_bottom, o.z_top);
for q in frame_ring_quads(from0, to0, zb0, zt0, fw, p.corner_join, p.has_sill) {
em.plane_quad(&q, p.n_min, p.n_max, Part::Frame);
// [105] Rahmen je Seite, Verbreiterungs-/Anschlussprofile, Flügel, Pfosten, Kämpfer.
let dd = o.ty.as_ref().and_then(|t| t.detail.as_deref());
let [fl, fr, ft, fb] = dd.map_or([fw; 4], |d| d.sides.map(|v| dv(v, fw)));
let (rf0, rt0, rb0, rtop0) = dd.map_or((from0, to0, zb0, zt0), |d| (from0 + dv(d.ext[0], 0.0), to0 - dv(d.ext[1], 0.0), zb0 + dv(d.sill_profile, 0.0), zt0 - dv(d.shading_profile, 0.0)));
let mw = dd.map_or(fw, |d| dv(d.mullion_width, fw));
let tw = dd.map_or(fw, |d| dv(d.transom_width, fw));
if dd.is_some() {
// Profile in der Rahmenlage: Verbreiterung links/rechts (volle Höhe), Bank- und Storenanschluss.
em.axis_box(from0, rf0, zb0, zt0, p.n_min, p.n_max, Part::Frame);
em.axis_box(rt0, to0, zb0, zt0, p.n_min, p.n_max, Part::Frame);
em.axis_box(rf0, rt0, zb0, rb0, p.n_min, p.n_max, Part::Frame);
em.axis_box(rf0, rt0, rtop0, zt0, p.n_min, p.n_max, Part::Frame);
}
if !dd.is_some_and(|d| d.skip_frame) {
for q in frame_ring_quads_sides(rf0, rt0, rb0, rtop0, [fl, fr, ft, fb], p.corner_join, p.has_sill) {
em.plane_quad(&q, p.n_min, p.n_max, Part::Frame);
}
}
// Schwellenprofil über die ganze Wanddicke.
if detail_bodies && p.draw_threshold_profile {
let strip_h = 0.02;
em.axis_box(from0 + fw, to0 - fw, zb0, zb0 + strip_h, -p.half_thickness, p.half_thickness, Part::Sill);
}
let sash_from = from0 + fw;
let sash_to = to0 - fw;
let sash_bottom = zb0 + if p.has_sill { fw } else { 0.0 };
let mut sash_top = zt0 - fw;
let sash_from = rf0 + fl;
let sash_to = rt0 - fr;
let sash_bottom = rb0 + if p.has_sill { fb } else { 0.0 };
let mut sash_top = rtop0 - ft;
// Oberlicht-Band (über dem Riegel) für dessen Einteilung.
let mut transom_band: Option<(f64, f64)> = None;
if p.transom_height > EPS {
let split_z = clamp_range(zt0 - p.transom_height, sash_bottom, sash_top);
em.axis_box(sash_from, sash_to, split_z - fw / 2.0, split_z + fw / 2.0, p.n_min, p.n_max, Part::Frame);
transom_band = Some((split_z + fw / 2.0, sash_top));
sash_top = split_z - fw / 2.0;
em.axis_box(sash_from, sash_to, split_z - tw / 2.0, split_z + tw / 2.0, p.n_min, p.n_max, Part::Frame);
transom_band = Some((split_z + tw / 2.0, sash_top));
sash_top = split_z - tw / 2.0;
}
// Pfosten im Oberlicht (mittel/fein).
if let (true, Some((tb, tt))) = (sashes_on, transom_band) {
@@ -635,7 +735,7 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
add_posts(p.mullion_cols, &mut posts);
posts.sort_by(|x, y| x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal));
for &center in &posts {
em.axis_box(center - fw / 2.0, center + fw / 2.0, sash_bottom, sash_top, p.n_min, p.n_max, Part::Frame);
em.axis_box(center - mw / 2.0, center + mw / 2.0, sash_bottom, sash_top, p.n_min, p.n_max, Part::Frame);
}
if p.mullion_rows > 1.0 && sash_top - sash_bottom > EPS {
let cell = (sash_top - sash_bottom) / p.mullion_rows;
@@ -662,9 +762,10 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
for (band_sashes, band_bottom, band_top) in bands {
if sashes_on && !band_sashes.is_empty() && sash_to - sash_from > EPS && band_top - band_bottom > EPS {
let segs = sash_spans(band_sashes, sash_from, sash_to);
let sfw = fw * 0.7;
let sfw = dd.map_or(fw * 0.7, |d| dv(d.sash_width, fw * 0.7));
let sash_front_n = p.n_max - 0.005;
let sash_back_n = jmax(p.n_min, p.n_max - 0.055);
let sash_back_n = jmax(p.n_min, p.n_max - dd.map_or(0.055, |d| dv(d.sash_depth, 0.055)));
let sov = dd.map_or(0.0, |d| dv(d.sash_overlap, 0.0));
let glass_front_n = p.n_max - 0.02;
let sym_back_n = glass_front_n;
let sym_front_n = glass_front_n + 0.003;
@@ -680,7 +781,7 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
if ct - cf <= EPS || tz - bz <= EPS {
continue;
}
for q in frame_ring_quads(cf, ct, bz, tz, sfw, p.corner_join, true) {
for q in frame_ring_quads(cf - sov, ct + sov, bz - sov, tz + sov, sfw + sov, p.corner_join, true) {
em.plane_quad(&q, sash_back_n, sash_front_n, Part::Frame);
}
if !fine {
@@ -736,7 +837,7 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
em.axis_box(from0 - ov, to0 + ov, bank_bottom, bank_top, inner_n - proj, inner_n + under, Part::Sill);
}
// Tür-Zarge mit Umgriff vor beiden Wandflächen.
if detail_bodies && p.zarge_cladding {
if detail_bodies && p.zarge_cladding && !dd.is_some_and(|d| d.skip_frame) {
let (proud, ext, cas_w) = (0.013, 0.02, fw);
for sign in [1.0, -1.0] {
let face_n = sign * p.half_thickness;
@@ -753,10 +854,13 @@ fn frame_meshes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams, detail: Detail
/// Aussenfläche, Mehrfachverglasung mit Luftraum nach innen (`glassPanesForOpening`).
fn glass_panes(em: &mut Emitter, o: &OpeningIn, p: &FrameParams) {
let fw = p.frame_width;
let sash_from = o.from + fw;
let sash_to = o.to - fw;
let sash_bottom = o.z_bottom + if p.has_sill { fw } else { 0.0 };
let sash_top_full = o.z_top - fw;
let dd = o.ty.as_ref().and_then(|t| t.detail.as_deref());
let [fl, fr, ft, fb] = dd.map_or([fw; 4], |d| d.sides.map(|v| dv(v, fw)));
let (e_l, e_r, e_b, e_t) = dd.map_or((0.0, 0.0, 0.0, 0.0), |d| (dv(d.ext[0], 0.0), dv(d.ext[1], 0.0), dv(d.sill_profile, 0.0), dv(d.shading_profile, 0.0)));
let sash_from = o.from + e_l + fl;
let sash_to = o.to - e_r - fr;
let sash_bottom = o.z_bottom + e_b + if p.has_sill { fb } else { 0.0 };
let sash_top_full = o.z_top - e_t - ft;
let glass_thick = GLASS_HALF_THICK * 2.0;
let panes = jmax(1.0, jmin(3.0, js_round(p.glazing_panes)));
let push = |em: &mut Emitter, z_bottom: f64, z_top: f64| {
@@ -1068,7 +1172,7 @@ fn decode_type(r: &mut Reader, door: bool) -> Option<TypeIn> {
shading_rails,
})
};
Some(TypeIn { frame_depth, inset_from_face, inset_inner, inset_mid, rebate_depth, corner_join, frame_width, transom_height, kind })
Some(TypeIn { frame_depth, inset_from_face, inset_inner, inset_mid, rebate_depth, corner_join, frame_width, transom_height, kind, detail: None })
}
/// Flügelliste `[n, Flügel × n]`.
@@ -1102,23 +1206,41 @@ fn decode(buf: &[f64]) -> Option<(Vec<WallIn>, Detail)> {
};
let n = r.count()?;
let mut walls = Vec::with_capacity(n.min(1 << 16));
for _ in 0..n {
// (Wand, Öffnung) im Puffer → Lage in `walls` (für den Anhang [105]).
let mut slots: Vec<((usize, usize), (usize, usize))> = Vec::new();
for wi in 0..n {
let start = [r.num()?, r.num()?];
let end = [r.num()?, r.num()?];
let n_ops = r.count()?;
let mut openings = Vec::with_capacity(n_ops.min(1024));
for _ in 0..n_ops {
for oi in 0..n_ops {
let (from, to, z_bottom, z_top) = (r.num()?, r.num()?, r.num()?, r.num()?);
let door = flag(&mut r)?;
let wall_thickness = r.num()?;
let ty = if flag(&mut r)? { Some(decode_type(&mut r, door)?) } else { None };
// Unsinn (NaN/∞ in Lage oder Wanddicke): Öffnung auslassen.
if [from, to, z_bottom, z_top, wall_thickness].iter().all(|v| v.is_finite()) {
slots.push(((wi, oi), (walls.len(), openings.len())));
openings.push(OpeningIn { from, to, z_bottom, z_top, door, wall_thickness, ty });
}
}
if [start[0], start[1], end[0], end[1]].iter().all(|v| v.is_finite()) {
walls.push(WallIn { start, end, openings });
} else {
slots.retain(|s| s.0 .0 != wi);
}
}
// Anhang ([105], optional): `[n, (Wand, Öffnung, Detail × DETAIL_LEN) × n]`.
if let Some(nd) = r.count() {
for _ in 0..nd {
let (wi, oi) = (r.num()?, r.num()?);
let d = FrameDetailIn::read(&mut r)?;
let key = (wi as usize, oi as usize);
if let Some(&(_, (a, b))) = slots.iter().find(|s| s.0 == key) {
if let Some(ty) = walls.get_mut(a).and_then(|w| w.openings.get_mut(b)).and_then(|o| o.ty.as_mut()) {
ty.detail = Some(Box::new(d));
}
}
}
}
Some((walls, detail))
@@ -1169,6 +1291,7 @@ mod tests {
shading_sturz: false,
shading_rails: false,
}),
detail: None,
}
}
@@ -1194,6 +1317,7 @@ mod tests {
slide_side: 1.0,
hinge_end: false,
}),
detail: None,
}
}
+171 -19
View File
@@ -545,7 +545,7 @@ fn wall_layers_reversed_in_u(w: &Wall, u: (f64, f64)) -> bool {
}
/// `splitWallLayers`: stehende Teil-Rechtecke je Schicht quer zur Dicke (u).
fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_world: (f64, f64)) -> Result<Vec<Cut>, String> {
fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_world: (f64, f64), plane: &Plane) -> Result<Vec<Cut>, String> {
let total = sum_thickness(layers);
let [u_min, u_max, v_min, v_max] = bbox(&cp.pts);
let u_span = u_max - u_min;
@@ -553,28 +553,93 @@ fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_wo
return Ok(vec![cp.clone()]);
}
let scale = u_span / total;
let ordered: Vec<&Layer> = if wall_layers_reversed_in_u(owner, u_world) { layers.iter().rev().collect() } else { layers.iter().collect() };
let reversed = wall_layers_reversed_in_u(owner, u_world);
let ordered: Vec<&Layer> = if reversed { layers.iter().rev().collect() } else { layers.iter().collect() };
let category = p.layer_category(&owner.category_code);
let mut out = Vec::with_capacity(layers.len());
// [106] Schichteinzug am Sturz (Stück liegt über der Öffnung) bzw. an der Brüstung (darunter).
let (top, bottom) = section_reveal(p, owner, plane, v_min, v_max);
let n = layers.len();
let mut acc = 0.0;
for layer in ordered {
for (k, layer) in ordered.into_iter().enumerate() {
let li = if reversed { n - 1 - k } else { k };
let comp = p.component_or_fallback(&layer.component_id);
let (fill, hatch) = layer_style(p, comp, owner.hatch_id.as_deref(), owner.hatch_source, owner.foreground.as_deref(), owner.foreground_source, owner.background.as_deref(), owner.background_source, category, SECTION_WALL_AXIS_ANGLE_DEG)?;
let u_left = u_min + acc * scale;
acc += layer.thickness;
let u_right = u_min + acc * scale;
let mut c = Cut::new(cp.kind, cp.index, vec![[u_left, v_max], [u_right, v_max], [u_right, v_min], [u_left, v_min]]);
c.fill = Some(fill);
c.hatch = Some(hatch);
c.join_priority = Some(comp.join_priority);
c.component_id = Some(comp.id.clone());
c.source_id = cp.source_id.clone();
c.category = cp.category.clone();
out.push(c);
let mk = |pts: Vec<[f64; 2]>| {
let mut c = Cut::new(cp.kind, cp.index, pts);
c.fill = Some(fill.clone());
c.hatch = Some(hatch.clone());
c.join_priority = Some(comp.join_priority);
c.component_id = Some(comp.id.clone());
c.source_id = cp.source_id.clone();
c.category = cp.category.clone();
c
};
let shift = |s: &Option<(f64, Vec<crate::opening_detail::LayerAdjust>)>| s.as_ref().and_then(|(_, v)| v.iter().find(|a| a.layer == li)).map_or(0.0, |a| a.shift);
let (vb, vt) = (v_min + shift(&top), v_max - shift(&bottom));
if vt - vb > 1e-6 {
out.push(mk(vec![[u_left, vt], [u_right, vt], [u_right, vb], [u_left, vb]]));
}
// Zusatzstücke dieser Schicht in der Öffnung.
let u_of = |o: f64| if reversed { u_max - o * scale } else { u_min + o * scale };
for (side, below) in [(&top, true), (&bottom, false)] {
let Some((z, adj)) = side else { continue };
for a in adj.iter().filter(|a| a.layer == li) {
for pc in &a.pieces {
let (z0, z1) = if below { (z - pc[1], z - pc[0]) } else { (z + pc[0], z + pc[1]) };
let (ua, ub) = (min(u_of(pc[2]), u_of(pc[3])), max(u_of(pc[2]), u_of(pc[3])));
out.push(mk(vec![[ua, z1], [ub, z1], [ub, z0], [ua, z0]]));
}
}
}
}
Ok(out)
}
/// Schichteinzug der Öffnung, deren Sturz (unten an `v_min`) bzw. Brüstung (oben an `v_max`) dieses
/// Wandstück ist und die die Schnittebene quert: `(Öffnungs-OK bzw. -UK, Anschlüsse)`.
#[allow(clippy::type_complexity)]
fn section_reveal(p: &Project, wall: &Wall, plane: &Plane, v_min: f64, v_max: f64) -> (Option<(f64, Vec<crate::opening_detail::LayerAdjust>)>, Option<(f64, Vec<crate::opening_detail::LayerAdjust>)>) {
let (mut top, mut bottom) = (None, None);
let u_raw = plane.u_model();
let l = hypot2(u_raw.0, u_raw.1);
if !(l > 1e-12) {
return (None, None);
}
let u = (u_raw.0 / l, u_raw.1 / l);
let (a, n) = axis_frame(wall);
let un = u.0 * n.0 + u.1 * n.1;
if un.abs() < MIN_CROSS {
return (None, None);
}
let p0 = plane.base();
let rel = (p0.0 - wall.start.x, p0.1 - wall.start.y);
let n0 = rel.0 * n.0 + rel.1 * n.1;
let a0 = rel.0 * a.0 + rel.1 * a.1;
let ua = u.0 * a.0 + u.1 * a.1;
let along = a0 + ((0.0 - n0) / un) * ua;
let (zb, zt) = p.wall_vertical_extent(wall);
for o in p.openings_of_wall(&wall.id) {
let Some(r) = crate::opening_detail::opening_reveal(p, wall, o) else { continue };
if along < r.from + 1e-4 || along > r.to - 1e-4 {
continue;
}
let o_bottom = zb + o.sill_height.max(0.0);
let o_top = zt.min(o_bottom + o.height);
let [_, _, t, b] = r.sides;
if (v_min - o_top).abs() < 1e-3 {
top = Some((o_top, t));
}
if (v_max - o_bottom).abs() < 1e-3 {
bottom = Some((o_bottom, b));
}
}
(top, bottom)
}
/// `attachCutStyles`: Stil, Herkunft, Schicht-Bänder, Terminierung, Dominanz.
fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[Option<&Wall>], slabs: &[SlabOwner]) -> Result<Vec<Cut>, String> {
if cuts.is_empty() {
@@ -598,7 +663,7 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[Option
if let Some(o) = owner {
let wt = p.wall_type_or_fallback(o);
if wt.layers.len() > 1 {
bands.extend(split_wall_layers(&cp, p, &wt.layers, o, u_world)?);
bands.extend(split_wall_layers(&cp, p, &wt.layers, o, u_world, plane)?);
continue;
}
}
@@ -1480,6 +1545,19 @@ fn window_cut(p: &Project, wall: &Wall, o: &Opening, c: &CrossSection) -> Result
inset_from_face: t.inset_from_face.unwrap_or(f64::NAN),
inset_inner: t.inset_face == Some(WindowTypeInsetFace::Innen),
inset_mid: t.inset_face == Some(WindowTypeInsetFace::Mitte),
frame_width_end: f64::NAN,
});
// [105] Rahmen-Detail: Lage/Tiefe übersteuert, Breite oben/unten, Anschlussprofile.
let det = crate::opening_detail::frame_of(p, o).filter(|f| f.detailed);
let spec = spec.map(|s| match &det {
Some(f) => crate::opening_geom::WindowSpec {
frame_depth: f.depth,
inset_from_face: f.inset,
inset_inner: f.face == crate::opening_detail::Face::Innen,
inset_mid: f.face == crate::opening_detail::Face::Mitte,
..s
},
None => s,
});
let finite = [wall.start.x, wall.start.y, wall.end.x, wall.end.y, total, ref_off, o.position, o.width].iter().all(|x| x.is_finite());
let sym = if finite {
@@ -1514,12 +1592,22 @@ fn window_cut(p: &Project, wall: &Wall, o: &Opening, c: &CrossSection) -> Result
let u1 = c.u_at(f_max);
let h = c.z_top - c.z_bottom;
let fwv = min(fw, h / 3.0);
let (sp, sh) = det.as_ref().map_or((0.0, 0.0), |f| (min(f.sill_profile, h / 4.0), min(f.shading_profile, h / 4.0)));
let (fwb, fwt) = det.as_ref().map_or((fwv, fwv), |f| (min(max(0.02, f.sides.bottom), h / 3.0), min(max(0.02, f.sides.top), h / 3.0)));
let (zb0, zt0) = (c.z_bottom + sp, c.z_top - sh);
let mut out = vec![opening_poly(rect(c.u_at(c.face_min), c.u_at(c.face_max), c.z_bottom, c.z_top), false, &o.id)];
out.push(opening_poly(rect(u0, u1, c.z_bottom, c.z_bottom + fwv), true, &o.id));
out.push(opening_poly(rect(u0, u1, c.z_top - fwv, c.z_top), true, &o.id));
out.push(opening_poly(rect(u0, u1, zb0, zb0 + fwb), true, &o.id));
out.push(opening_poly(rect(u0, u1, zt0 - fwt, zt0), true, &o.id));
// Fensterbank- und Storen-Anschlussprofil.
if sp > 1e-4 {
out.push(opening_poly(rect(u0, u1, c.z_bottom, zb0), true, &o.id));
}
if sh > 1e-4 {
out.push(opening_poly(rect(u0, u1, zt0, c.z_top), true, &o.id));
}
for s in glass {
let u = c.u_at(s);
let mut l = line(v2(u, c.z_bottom + fwv), v2(u, c.z_top - fwv), "section-window-glass", GLASS_MM, OPENING_INK);
let mut l = line(v2(u, zb0 + fwb), v2(u, zt0 - fwt), "section-window-glass", GLASS_MM, OPENING_INK);
if let Primitive::Line { opening_id, .. } = &mut l {
*opening_id = Some(o.id.clone());
}
@@ -1589,6 +1677,11 @@ fn door_cut(p: &Project, o: &Opening, c: &CrossSection) -> Vec<Primitive> {
lintel_cut(&mut out, o, c, p.door_type(o).and_then(|t| t.lintel_height), 0.0);
}
let kind = p.door_type(o).map(|t| t.kind);
// [105] Zargen-Arten: Sturz-Profil der Zarge und Blatt im Falz.
if let Some(df) = crate::opening_detail::door_frame_of(p, o).filter(|_| matches!(kind, Some(DoorTypeKind::Dreh | DoorTypeKind::Pendel | DoorTypeKind::Unknown))) {
door_frame_cut(&mut out, o, c, &df);
return out;
}
if o.door_type == Some(OpeningDoorType::Wandoeffnung) || kind == Some(DoorTypeKind::Wandoeffnung) {
return out;
}
@@ -1621,6 +1714,64 @@ fn door_cut(p: &Project, o: &Opening, c: &CrossSection) -> Vec<Primitive> {
out
}
/// Türzarge im Schnitt ([105]): Profil am Sturz (gleiches Profil wie im Grundriss, `x` nach unten)
/// und Türblatt im Falz der Aufschlagseite.
fn door_frame_cut(out: &mut Vec<Primitive>, o: &Opening, c: &CrossSection, df: &crate::opening_detail::DoorFrame) {
use crate::opening_detail as od;
let total = c.face_max - c.face_min;
let innen = od::aufschlag_innen(o);
let s_of = |d: f64| c.face_min + if innen { total - d } else { d };
let profile = od::door_frame_profile(df, total, innen);
let clear = od::profile_clear_x(&profile);
for (_, poly) in &profile {
let pts: Vec<Vec2> = poly.iter().map(|q| v2(c.u_at(s_of(q[1])), c.z_top - q[0])).collect();
let mut pr = if df.steel { polygon(pts, OPENING_INK, OPENING_INK, FRAME_MM, no_hatch_base()) } else { polygon(pts, "#ffffff", OPENING_INK, FRAME_MM, no_hatch_base()) };
if let Primitive::Polygon { opening_id, .. } = &mut pr {
*opening_id = Some(o.id.clone());
}
out.push(pr);
}
let (d0, d1) = od::leaf_band(df, total, innen);
let top = c.z_top - max(clear - df.falz_width, 0.0);
out.push(opening_poly(rect(c.u_at(s_of(d0)), c.u_at(s_of(d1)), c.z_bottom + 0.01, top), true, &o.id));
}
/// Anschlag im Schnitt ([105]/[94]): Wandnase oben (Sturz) und unten (Brüstung) über die Zone
/// zwischen gewählter Fläche und Rahmen, je Wandschicht in deren Schnitt-Darstellung.
fn rebate_cut(p: &Project, wall: &Wall, o: &Opening, c: &CrossSection) -> Result<Vec<Primitive>, String> {
let mut out = Vec::new();
let Some(f) = crate::opening_detail::frame_of(p, o) else { return Ok(out) };
let wt = p.wall_type_or_fallback(wall);
let total = sum_thickness(&wt.layers);
let Some((z0, z1)) = f.rebate_zone(total) else { return Ok(out) };
let h = c.z_top - c.z_bottom;
let category = p.layer_category(&wall.category_code);
for (rd, top) in [(f.rebate.top, true), (if o.kind == ElementKind::Door { 0.0 } else { f.rebate.bottom }, false)] {
let rd = min(rd, h / 3.0);
if !(rd > 1e-4) {
continue;
}
let (v0, v1) = if top { (c.z_top - rd, c.z_top) } else { (c.z_bottom, c.z_bottom + rd) };
let mut l0 = 0.0;
for layer in &wt.layers {
let l1 = l0 + layer.thickness;
let (a, b) = (z0.max(l0), z1.min(l1));
l0 = l1;
if b - a <= 1e-6 {
continue;
}
let comp = p.component_or_fallback(&layer.component_id);
let (fill, hatch) = layer_style(p, comp, wall.hatch_id.as_deref(), wall.hatch_source, wall.foreground.as_deref(), wall.foreground_source, wall.background.as_deref(), wall.background_source, category, SECTION_WALL_AXIS_ANGLE_DEG)?;
let mut pr = polygon(rect(c.u_at(c.face_min + a), c.u_at(c.face_min + b), v0, v1), &fill, OPENING_INK, FRAME_MM, hatch);
if let Primitive::Polygon { opening_id, .. } = &mut pr {
*opening_id = Some(o.id.clone());
}
out.push(pr);
}
}
Ok(out)
}
/// `sectionOpeningPrimitives`.
pub fn section_opening_primitives(p: &Project, level: &LevelSpec, vis: &Visibility) -> Result<Vec<Primitive>, String> {
let Some(plane) = level.plane() else { return Ok(Vec::new()) };
@@ -1656,7 +1807,8 @@ pub fn section_opening_primitives(p: &Project, level: &LevelSpec, vis: &Visibili
continue;
}
let Some(c) = cross_section(p, wall, o, p0, u)? else { continue };
let prims = if o.kind == ElementKind::Window { window_cut(p, wall, o, &c)? } else { door_cut(p, o, &c) };
let mut prims = if o.kind == ElementKind::Window { window_cut(p, wall, o, &c)? } else { door_cut(p, o, &c) };
prims.extend(rebate_cut(p, wall, o, &c)?);
let greyed = vis.greyed(&o.category_code);
for pr in prims {
out.push(if greyed { pr.with_greyed(true) } else { pr });
@@ -2198,8 +2350,8 @@ mod ts_faelle {
let w2 = p.walls.iter().find(|w| w.id == "W2").unwrap().clone();
let w4 = p.walls.iter().find(|w| w.id == "W4").unwrap().clone();
let u = (1.0, 0.0);
let b2 = split_wall_layers(&cp, &p, &layers, &w2, u).unwrap();
let b4 = split_wall_layers(&cp, &p, &layers, &w4, u).unwrap();
let b2 = split_wall_layers(&cp, &p, &layers, &w2, u, &Plane { point: [0.0; 3], normal: [1.0, 0.0, 0.0] }).unwrap();
let b4 = split_wall_layers(&cp, &p, &layers, &w4, u, &Plane { point: [0.0; 3], normal: [1.0, 0.0, 0.0] }).unwrap();
// W4 (Aussenseite −x): layers[0] an uMin; W2 gespiegelt: layers[0] an uMax.
assert_eq!(b4[0].component_id.as_deref(), Some(layers[0].component_id.as_str()));
assert!(close(bbox(&b4[0].pts)[0], 0.0));
@@ -2207,7 +2359,7 @@ mod ts_faelle {
// Override der Wand gilt für jede Schicht
p.walls[1].background = Some("#123456".into());
let w = p.walls[1].clone();
let bands = split_wall_layers(&cp, &p, &layers, &w, u).unwrap();
let bands = split_wall_layers(&cp, &p, &layers, &w, u, &Plane { point: [0.0; 3], normal: [1.0, 0.0, 0.0] }).unwrap();
assert!(bands.iter().all(|b| b.fill.as_deref() == Some("#123456")));
}
}
+140 -16
View File
@@ -97,7 +97,7 @@ fn line_buf(out: &mut Vec<f64>, l: Option<&joins::Line>) {
/// Eingabe von `plan_walls::wall_poche` (wie `encodeWallPoche` in TS).
#[allow(clippy::too_many_arguments)]
fn encode_wall_poche(w: &Wall, layers: &[f64], total: f64, ref_off: f64, gaps: &[(f64, f64)], cuts: &WallCuts, grob: bool, view_only: bool) -> Vec<f64> {
fn encode_wall_poche(w: &Wall, layers: &[f64], total: f64, ref_off: f64, gaps: &[(f64, f64)], cuts: &WallCuts, grob: bool, view_only: bool, reveals: &[f64]) -> Vec<f64> {
let mut b = vec![w.start.x, w.start.y, w.end.x, w.end.y, total, ref_off, if grob { 1.0 } else { 0.0 }, if view_only { 1.0 } else { 0.0 }];
b.push(layers.len() as f64);
b.extend_from_slice(layers);
@@ -124,6 +124,10 @@ fn encode_wall_poche(w: &Wall, layers: &[f64], total: f64, ref_off: f64, gaps: &
for g in gaps {
b.extend([g.0, g.1]);
}
// [106] Schichteinzug an den Leibungen.
if reveals.first().is_some_and(|n| *n > 0.0) {
b.extend_from_slice(reveals);
}
b
}
@@ -163,7 +167,7 @@ fn v2(x: f64, y: f64) -> Vec2 {
/// Wand-Poché (`addWallPoche`).
#[allow(clippy::too_many_arguments)]
fn wall_poche(c: &Ctx, out: &mut Vec<Primitive>, e: &EffWall, gaps: &[(f64, f64)], cuts: &WallCuts, greyed: bool, wall_lw: f64, category: Option<&LayerCategory>, view_only: bool) -> Result<(), String> {
fn wall_poche(c: &Ctx, out: &mut Vec<Primitive>, e: &EffWall, gaps: &[(f64, f64)], cuts: &WallCuts, greyed: bool, wall_lw: f64, category: Option<&LayerCategory>, view_only: bool, reveals: &[f64]) -> Result<(), String> {
let p = c.p;
let w = e.w;
let detail = c.a.detail;
@@ -175,7 +179,7 @@ fn wall_poche(c: &Ctx, out: &mut Vec<Primitive>, e: &EffWall, gaps: &[(f64, f64)
let outline_mm = wall_lw * detail.outline_factor();
let layer_mm = LAYER_LINE_MM * detail.layer_factor();
let thick: Vec<f64> = wt.layers.iter().map(|l| l.thickness).collect();
let f = crate::plan_walls::wall_poche(&encode_wall_poche(w, &thick, total, ref_off, gaps, cuts, detail == Detail::Grob, view_only));
let f = crate::plan_walls::wall_poche(&encode_wall_poche(w, &thick, total, ref_off, gaps, cuts, detail == Detail::Grob, view_only, reveals));
if f.is_empty() {
return Ok(());
}
@@ -305,7 +309,13 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
Detail::Mittel => 1.0,
Detail::Fein => 2.0,
};
let mut b: Vec<f64> = vec![w.start.x, w.start.y, w.end.x, w.end.y, total, ref_off, o.position, o.width, b01(door), detail_code];
// [105] Rahmen-Detail und Türzarge (eigene Zeichnung in `opening_detail_plan`).
let det = crate::opening_detail::frame_of(p, o).filter(|f| f.detailed);
let dframe = crate::opening_detail::door_frame_of(p, o);
// Verbreiterungsprofile: das Fenster-Element sitzt um sie eingerückt in der Rohbauöffnung.
let (ext_l, ext_r) = det.as_ref().filter(|_| !door).map_or((0.0, 0.0), |f| (f.ext.left, f.ext.right));
let (o_pos, o_wid) = if ext_l + ext_r > 1e-6 && o.width - ext_l - ext_r > 0.05 { (o.position + ext_l, o.width - ext_l - ext_r) } else { (o.position, o.width) };
let mut b: Vec<f64> = vec![w.start.x, w.start.y, w.end.x, w.end.y, total, ref_off, o_pos, o_wid, b01(door), detail_code];
// Tür
b.push(b01(o.swing.is_some_and(|s| s != SwingSide::Left)));
b.push(b01(o.opening_dir.is_some_and(|s| s != OpeningOpeningDir::In)));
@@ -320,8 +330,8 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
OpeningLintelLines::Beide => 3.0,
OpeningLintelLines::Unknown => f64::NAN,
});
// Rahmenband (Tür mit Typ)
match dt {
// Rahmenband (Tür mit Typ; Zargen-Arten [105] zeichnet `opening_detail_plan`)
match dt.filter(|_| dframe.is_none()) {
Some(t) => b.extend([
1.0,
t.frame_width.unwrap_or(0.06),
@@ -337,14 +347,29 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
}
// Fenster
b.push(b01(wt.is_some()));
b.push(wt.map_or(0.0, |t| t.frame_width.unwrap_or(0.06)));
b.push(wt.and_then(|t| t.frame_depth).unwrap_or(f64::NAN));
b.push(wt.and_then(|t| t.inset_from_face).unwrap_or(f64::NAN));
b.push(match wt.and_then(|t| t.inset_face) {
Some(WindowTypeInsetFace::Innen) => 1.0,
Some(WindowTypeInsetFace::Mitte) => 2.0,
_ => 0.0,
});
match det.as_ref().filter(|_| wt.is_some()) {
// [105]: Rahmen je Seite (links hier, rechts im Anhang), Tiefe/Lage übersteuert.
Some(f) => b.extend([
f.sides.left,
f.depth,
f.inset,
match f.face {
crate::opening_detail::Face::Innen => 1.0,
crate::opening_detail::Face::Mitte => 2.0,
crate::opening_detail::Face::Aussen => 0.0,
},
]),
None => {
b.push(wt.map_or(0.0, |t| t.frame_width.unwrap_or(0.06)));
b.push(wt.and_then(|t| t.frame_depth).unwrap_or(f64::NAN));
b.push(wt.and_then(|t| t.inset_from_face).unwrap_or(f64::NAN));
b.push(match wt.and_then(|t| t.inset_face) {
Some(WindowTypeInsetFace::Innen) => 1.0,
Some(WindowTypeInsetFace::Mitte) => 2.0,
_ => 0.0,
});
}
}
b.push(o.wing_count.unwrap_or(f64::NAN));
b.push(if detail == Detail::Fein { 2.0 } else { 1.0 });
let sill = wt.and_then(|t| t.sill_line.as_ref());
@@ -366,7 +391,13 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
b.push(o.sash_line.as_ref().and_then(|l| l.weight).unwrap_or(SYMBOL_HAIRLINE_MM));
b.push(o.sill_line_style.as_ref().and_then(|l| l.weight).unwrap_or(SYMBOL_HAIRLINE_MM));
// Details ([94]): Anschlag, Fensterbank, Storenkasten.
b.push(if door { dt.and_then(|t| t.rebate_depth) } else { wt.and_then(|t| t.rebate_depth) }.unwrap_or(0.0));
// Anschlag: je Seite verschieden ⇒ zeichnet `opening_detail_plan`.
let rebate_sides = det.as_ref().map(|f| f.rebate).filter(|r| (r.left - r.right).abs() > 1e-9 || dframe.is_some());
b.push(match (&det, rebate_sides) {
(_, Some(_)) => 0.0,
(Some(f), None) => f.rebate.left,
(None, None) => if door { dt.and_then(|t| t.rebate_depth) } else { wt.and_then(|t| t.rebate_depth) }.unwrap_or(0.0),
});
b.push(match wt.and_then(|t| t.sill_board) {
Some(WindowTypeSillBoard::Keine) => 1.0,
Some(WindowTypeSillBoard::Innen) => 2.0,
@@ -397,6 +428,10 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
b01(s.opening.is_some_and(|k| k != OpeningKind::Fest)),
]);
}
// [105] Anhang: Rahmenbreite rechts (Fenster).
if let Some(f) = det.as_ref().filter(|f| wt.is_some() && (f.sides.right - f.sides.left).abs() > 1e-9) {
b.push(f.sides.right);
}
let f = crate::plan_openings::plan_opening(&b);
if f.is_empty() {
return Ok(());
@@ -462,6 +497,94 @@ fn opening_symbol(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, colo
i += 9;
}
}
let ctx = DetailCtx { stroke: frame_color, weight: frame_weight, greyed, detail, wall_line };
opening_detail_plan(c, out, w, o, &ctx, rebate_sides, (ext_l, ext_r), dframe.as_ref())
}
/// Stil der Detail-Zeichnung einer Öffnung.
struct DetailCtx<'a> {
stroke: &'a str,
weight: f64,
greyed: bool,
detail: Detail,
wall_line: (&'a str, f64),
}
/// Grundriss-Detail einer Öffnung ([105]): Anschlag je Seite (Wandnase in der Schicht-Schraffur),
/// Verbreiterungsprofile neben dem Fensterrahmen und die Türzarge nach Art (Profil je Leibung,
/// Stahl im feinen Detail gefüllt).
#[allow(clippy::too_many_arguments)]
fn opening_detail_plan(c: &Ctx, out: &mut Vec<Primitive>, w: &Wall, o: &Opening, s: &DetailCtx, rebate: Option<crate::opening_detail::Sides>, ext: (f64, f64), dframe: Option<&crate::opening_detail::DoorFrame>) -> Result<(), String> {
use crate::opening_detail as od;
let p = c.p;
if rebate.is_none() && ext.0 + ext.1 <= 1e-6 && dframe.is_none() {
return Ok(());
}
let wtype = wall_type(p, w)?;
let total = thickness(&wtype.layers);
let ref_off = joins::reference_offset(crate::model3d::wall_reference(w), total);
let wr = crate::opening_geom::WallRef { start: crate::opening_geom::v(w.start.x, w.start.y), end: crate::opening_geom::v(w.end.x, w.end.y), total, ref_off };
let Some((js, je)) = crate::opening_geom::opening_jambs(&wr, o.position, o.width) else { return Ok(()) };
let (u, n) = wr.frame();
let face = ref_off - total / 2.0;
let width = ((je.x - js.x).powi(2) + (je.y - js.y).powi(2)).sqrt();
// Punkt: Leibung (0 links, 1 rechts), x in die Öffnung, o quer ab Aussenfläche.
let pt = |side: usize, x: f64, off: f64| {
let (base, dir) = if side == 0 { (js, 1.0) } else { (je, -1.0) };
v2(base.x + u.x * x * dir + n.x * (face + off), base.y + u.y * x * dir + n.y * (face + off))
};
let id = Some(o.id.as_str());
let frame = od::frame_of(p, o);
// Anschlag je Seite.
if let (Some(r), Some(f)) = (rebate, frame.as_ref()) {
if let Some((z0, z1)) = f.rebate_zone(total) {
let category = c.cat(&w.category_code);
let angle = atan2(w.end.y - w.start.y, w.end.x - w.start.x) * 180.0 / std::f64::consts::PI;
for (side, rd) in [(0usize, r.left), (1, r.right)] {
let rd = rd.min(width / 2.0 - 0.01);
if !(rd > 1e-4) {
continue;
}
let mut l0 = 0.0;
for (li, layer) in wtype.layers.iter().enumerate() {
let l1 = l0 + layer.thickness;
let (a, b) = (z0.max(l0), z1.min(l1));
l0 = l1;
if b - a <= 1e-6 {
continue;
}
let (hatch, fill) = layer_style(p, w, wtype, li, category, angle)?;
out.push(wall_polygon(vec![pt(side, 0.0, a), pt(side, rd, a), pt(side, rd, b), pt(side, 0.0, b)], &fill, s.wall_line.0, s.wall_line.1, hatch, s.greyed, None, Some(&w.id), id));
}
}
}
}
// Verbreiterungsprofile (Fenster) in der Rahmenlage.
if let Some(f) = frame.as_ref().filter(|_| ext.0 + ext.1 > 1e-6 && s.detail != Detail::Grob) {
let (lo, hi) = f.range(total);
for (side, e) in [(0usize, ext.0), (1, ext.1)] {
if e > 1e-6 {
let pts = vec![pt(side, 0.0, lo), pt(side, e, lo), pt(side, e, hi), pt(side, 0.0, hi)];
out.push(wall_polygon(pts, "none", s.stroke, s.weight, no_hatch(), s.greyed, None, None, id));
}
}
}
// Türzarge.
if let Some(df) = dframe {
let innen = od::aufschlag_innen(o);
let off_of = |d: f64| if innen { total - d } else { d };
let fein = s.detail == Detail::Fein;
for (part, poly) in od::door_frame_profile(df, total, innen) {
if s.detail == Detail::Grob && part == od::FramePart::Casing {
continue;
}
let fill = if fein && df.steel { s.stroke } else { "none" };
for side in [0usize, 1] {
let pts: Vec<Vec2> = poly.iter().map(|q| pt(side, q[0], off_of(q[1]))).collect();
out.push(wall_polygon(pts, fill, s.stroke, s.weight, no_hatch(), s.greyed, None, None, id));
}
}
}
Ok(())
}
@@ -507,7 +630,8 @@ pub fn plan_walls(c: &Ctx, reference_lines: bool, out: &mut Vec<Primitive>, boun
let cut = cut_by_id.get(w.id.as_str()).copied().unwrap_or(&empty);
let (zb, zt) = p.wall_vertical_extent(w);
let view_only = zt < cut_z || zb > cut_z;
wall_poche(c, out, e, &gaps, cut, greyed, lw, category, view_only)?;
let reveals = crate::opening_detail::plan_reveal_block(p, w, &openings);
wall_poche(c, out, e, &gaps, cut, greyed, lw, category, view_only, &reveals)?;
if reference_lines {
out.push(mk_line(w.start, w.end, "wall-axis", 0.13, Some(Some(vec![0.18, 0.06, 0.04, 0.06])), None, greyed, None));
}
+3
View File
@@ -130,6 +130,8 @@ fn plan_opening_inner(buf: &[f64]) -> Option<Vec<f64>> {
operable: r.num()? != 0.0,
});
}
// [105] Anhang (optional): Rahmenbreite rechts.
let frame_width_end = r.num().unwrap_or(f64::NAN);
if ![sx, sy, ex, ey, total, ref_off, position, width].iter().all(|x| x.is_finite()) {
return None;
}
@@ -220,6 +222,7 @@ fn plan_opening_inner(buf: &[f64]) -> Option<Vec<f64>> {
inset_from_face: win_inset,
inset_inner: win_inset_side == 1.0,
inset_mid: win_inset_side == 2.0,
frame_width_end,
})
} else {
None
+255
View File
@@ -312,6 +312,21 @@ fn wall_poche_inner(buf: &[f64]) -> Option<Vec<f64>> {
for _ in 0..n_gap {
gaps.push((r.num()?, r.num()?));
}
// [106] Schichteinzug (optional): je Leibung und Schicht Rücksprung und Zusatzstücke.
let mut adj: Vec<Adj> = Vec::new();
if let Some(n_adj) = r.count() {
for _ in 0..n_adj {
let (jamb, dir, layer, shift) = (r.num()?, r.num()?, r.count()?, r.num()?);
let n_p = r.count()?;
let mut pieces = Vec::with_capacity(n_p);
for _ in 0..n_p {
pieces.push([r.num()?, r.num()?, r.num()?, r.num()?]);
}
if jamb.is_finite() && shift.is_finite() && layer < n_layers && pieces.iter().flatten().all(|v| v.is_finite()) {
adj.push(Adj { jamb, dir, layer, shift: max(0.0, shift), pieces });
}
}
}
if !(sx.is_finite() && sy.is_finite() && ex.is_finite() && ey.is_finite() && total.is_finite() && ref_off.is_finite()) {
return None;
}
@@ -353,6 +368,12 @@ fn wall_poche_inner(buf: &[f64]) -> Option<Vec<f64>> {
.filter(|c| min(c.from, c.to) < e - CUTOUT_EPS && max(c.from, c.to) > s + CUTOUT_EPS)
.copied()
.collect();
let seg_adj: Vec<&Adj> = adj.iter().filter(|a| (a.dir > 0.0 && (a.jamb - e).abs() < 1e-6) || (a.dir < 0.0 && (a.jamb - s).abs() < 1e-6)).collect();
if !seg_adj.is_empty() {
let seg = Seg { s, e, p1, p2, wstart, wend, axis_len, sc, ec };
adjusted_segment(&mut o, &seg, &thick, ref_off - total / 2.0, &layer_cuts, &seg_cutouts, &seg_adj, &band_join_edges);
continue;
}
let axis_pt = |d: f64| if d == s { p1 } else if d == e { p2 } else { along(wstart, wend, d) };
let mut off = ref_off - total / 2.0;
for li in 0..n_layers {
@@ -462,6 +483,196 @@ fn wall_poche_inner(buf: &[f64]) -> Option<Vec<f64>> {
Some(out)
}
// ── Schichteinzug an Leibungen ([106]) ──────────────────────────────────────
/// Anschluss einer Schicht an einer Leibung: `jamb` Achsmass der Rohbaukante, `dir` > 0 ⇒ die
/// Öffnung liegt bei grösserem Achsmass (Segment endet hier), < 0 ⇒ Segment beginnt hier;
/// `pieces` = `[x0, x1, o0, o1]` (x ab Rohbaukante in die Öffnung, o quer ab Aussenfläche).
struct Adj {
jamb: f64,
dir: f64,
layer: usize,
shift: f64,
pieces: Vec<[f64; 4]>,
}
struct Seg {
s: f64,
e: f64,
p1: V,
p2: V,
wstart: V,
wend: V,
axis_len: f64,
sc: Option<Line>,
ec: Option<Line>,
}
/// Segment mit Schichteinzug: Schichtbänder je Schicht verkürzt bzw. um Zusatzstücke ergänzt;
/// Umriss und Fugen aus dem Raster der Teilflächen (Kante zwischen Fläche und Leere = Umriss,
/// zwischen zwei Schichten = Fuge, an Aussparungen nichts), Wandenden mit ihrem Gehrungsschnitt.
#[allow(clippy::too_many_arguments)]
fn adjusted_segment(o: &mut Out, g: &Seg, thick: &[f64], off0: f64, layer_cuts: &Option<LayerCuts>, cutouts: &[Cutout], adj: &[&Adj], band_join_edges: &[f64]) {
let (s, e) = (g.s, g.e);
let axis_pt = |d: f64| if d == s { g.p1 } else if d == e { g.p2 } else { along(g.wstart, g.wend, d) };
let n_layers = thick.len();
let mut offs = vec![off0];
for t in thick {
let last = *offs.last().expect("nicht leer");
offs.push(last + t);
}
let (off_lo, off_hi) = (off0, offs[n_layers]);
let mut rects: Vec<(f64, f64, f64, f64, usize)> = Vec::new();
for li in 0..n_layers {
let (mut a, mut b) = (s, e);
for ad in adj.iter().filter(|ad| ad.layer == li) {
if ad.dir > 0.0 {
b = min(b, e - ad.shift);
} else {
a = max(a, s + ad.shift);
}
}
let (lo, hi) = (offs[li], offs[li + 1]);
let holes: Vec<(f64, f64)> = cutouts.iter().filter(|c| lo < max(c.off_a, c.off_b) - CUTOUT_EPS && hi > min(c.off_a, c.off_b) + CUTOUT_EPS).map(|c| (c.from, c.to)).collect();
let start_cut = if s <= 1e-6 { layer_cuts.as_ref().map_or(g.sc, |lc| lc.start[li]) } else { None };
let end_cut = if e >= g.axis_len - 1e-6 { layer_cuts.as_ref().map_or(g.ec, |lc| lc.end[li]) } else { None };
if b - a > CUTOUT_EPS {
for (pa, pb) in subtract_intervals(a, b, &holes) {
let bsc = if pa <= s + CUTOUT_EPS { start_cut } else { None };
let bec = if pb >= e - CUTOUT_EPS { end_cut } else { None };
o.polygon(ART_BAND, li, band_join_edges, &clipped_band(axis_pt(pa), axis_pt(pb), lo, hi, bsc, bec));
rects.push((pa, pb, lo, hi, li));
}
}
// Seitenfugen an Wandenden (wie im Normalfall).
let side_start = if s <= 1e-6 { layer_cuts.as_ref().and_then(|lc| lc.start_side[li]) } else { None };
let side_end = if e >= g.axis_len - 1e-6 { layer_cuts.as_ref().and_then(|lc| lc.end_side[li]) } else { None };
let u_seg = normalize(sub(g.p2, g.p1));
let n_seg = left_normal(u_seg);
let side_point = |base: V, layer_off: f64, cut: Line| {
let pt = add(base, scale(n_seg, layer_off));
line_intersect(pt, u_seg, cut.point, cut.dir).unwrap_or(pt)
};
if let Some(c) = side_start {
o.line(LINE_JOINT_L, li, side_point(g.p1, lo, c), side_point(g.p1, hi, c));
}
if let Some(c) = side_end {
o.line(LINE_JOINT_L, li, side_point(g.p2, lo, c), side_point(g.p2, hi, c));
}
}
for ad in adj {
for pc in &ad.pieces {
let (x0, x1) = if ad.dir > 0.0 { (ad.jamb + pc[0], ad.jamb + pc[1]) } else { (ad.jamb - pc[1], ad.jamb - pc[0]) };
let (y0, y1) = (off0 + pc[2], off0 + pc[3]);
if x1 - x0 <= CUTOUT_EPS || y1 - y0 <= CUTOUT_EPS {
continue;
}
o.polygon(ART_BAND, ad.layer, &[], &clipped_band(axis_pt(x0), axis_pt(x1), y0, y1, None, None));
rects.push((x0, x1, y0, y1, ad.layer));
}
}
// Raster der Teilflächen.
let mut xs: Vec<f64> = vec![s, e];
let mut ys: Vec<f64> = offs.clone();
for r in &rects {
xs.extend([r.0, r.1]);
ys.extend([r.2, r.3]);
}
let sort = |v: &mut Vec<f64>| {
v.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
v.dedup_by(|a, b| (*a - *b).abs() < 1e-9);
};
sort(&mut xs);
sort(&mut ys);
let (nx, ny) = (xs.len().saturating_sub(1), ys.len().saturating_sub(1));
const EMPTY: i64 = -1;
const CUT: i64 = -2;
let mut cell = vec![EMPTY; nx * ny];
for i in 0..nx {
let xm = (xs[i] + xs[i + 1]) / 2.0;
for j in 0..ny {
let ym = (ys[j] + ys[j + 1]) / 2.0;
cell[i * ny + j] = match rects.iter().find(|r| xm > r.0 && xm < r.1 && ym > r.2 && ym < r.3) {
Some(r) => r.4 as i64,
None if ym > off_lo && ym < off_hi && cutouts.iter().any(|c| xm > min(c.from, c.to) && xm < max(c.from, c.to)) => CUT,
None => EMPTY,
};
}
}
let at = |i: i64, j: i64| -> i64 {
if i < 0 || j < 0 || i as usize >= nx || j as usize >= ny {
EMPTY
} else {
cell[i as usize * ny + j as usize]
}
};
// 0 keine Kante · 1 Umriss · 2+k Fuge der Schicht k.
let kind = |a: i64, b: i64| -> i64 {
if a == b || a == CUT || b == CUT {
0
} else if a == EMPTY || b == EMPTY {
1
} else {
2 + a.min(b)
}
};
let emit = |o: &mut Out, k: i64, a: V, b: V| {
if k == 1 {
o.line(LINE_OUTLINE, 0, a, b);
} else if k >= 2 {
o.line(LINE_JOINT, (k - 2) as usize, a, b);
}
};
// Längskanten (entlang der Achse) bei y = ys[j].
for j in 0..=ny {
let y = ys[j];
let mut i = 0;
while i < nx {
let k = kind(at(i as i64, j as i64 - 1), at(i as i64, j as i64));
let mut i1 = i + 1;
while i1 < nx && kind(at(i1 as i64, j as i64 - 1), at(i1 as i64, j as i64)) == k {
i1 += 1;
}
if k != 0 {
let (x0, x1) = (xs[i], xs[i1]);
let sc = if x0 <= s + CUTOUT_EPS { g.sc } else { None };
let ec = if x1 >= e - CUTOUT_EPS { g.ec } else { None };
let q = clipped_band(axis_pt(x0), axis_pt(x1), y, y, sc, ec);
emit(o, k, q[0], q[1]);
}
i = i1;
}
}
// Querkanten bei x = xs[i] (an Wandenden mit Gehrung: deren Schnittlinie).
for i in 0..=nx {
let x = xs[i];
let mut j = 0;
while j < ny {
let k = kind(at(i as i64 - 1, j as i64), at(i as i64, j as i64));
let mut j1 = j + 1;
while j1 < ny && kind(at(i as i64 - 1, j1 as i64), at(i as i64, j1 as i64)) == k {
j1 += 1;
}
if k != 0 {
let (y0, y1) = (ys[j], ys[j1]);
if (x - s).abs() < CUTOUT_EPS && g.sc.is_some() {
let q = clipped_band(g.p1, g.p2, y0, y1, g.sc, None);
emit(o, k, q[0], q[3]);
} else if (x - e).abs() < CUTOUT_EPS && g.ec.is_some() {
let q = clipped_band(g.p1, g.p2, y0, y1, None, g.ec);
emit(o, k, q[1], q[2]);
} else {
let base = axis_pt(x);
let n = left_normal(normalize(sub(g.wend, g.wstart)));
emit(o, k, add(base, scale(n, y0)), add(base, scale(n, y1)));
}
}
j = j1;
}
}
// Keine Umriss-Fläche: nicht jede Ausgabe lässt einzelne Kanten weg (SVG); die Linien oben ersetzen sie.
}
#[cfg(test)]
mod tests {
use super::*;
@@ -513,6 +724,50 @@ mod tests {
assert_eq!(count(&wall_poche(&wall(4.0, true, &[(1.0, 2.0)])), 1.0), 2);
}
/// Polygone (art, schicht, Ecken) der Ausgabe.
fn polys(out: &[f64]) -> Vec<(f64, usize, Vec<(f64, f64)>)> {
let (mut i, mut v) = (1, Vec::new());
for _ in 0..out[0] as usize {
if out[i] == 1.0 {
let q = i + 4 + out[i + 3] as usize;
v.push((out[i + 1], out[i + 2] as usize, (0..4).map(|k| (out[q + 2 * k], out[q + 2 * k + 1])).collect()));
i = q + 8;
} else {
i += 7;
}
}
v
}
#[test]
fn schichteinzug_kuerzt_band_und_setzt_stueck() {
let mut b = wall(4.0, false, &[(1.0, 2.0)]);
// Innere Schicht (1) an der Leibung bei 1.0 um 5 cm zurück; äussere (0) bei 2.0 3 cm über den Rahmen.
b.extend([2.0, 1.0, 1.0, 1.0, 0.05, 0.0, 2.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.03, 0.0, 0.1]);
let o = wall_poche(&b);
let p = polys(&o);
let band1: Vec<_> = p.iter().filter(|x| x.0 == ART_BAND && x.1 == 1).collect();
assert!(band1.iter().any(|x| x.2.iter().any(|q| (q.0 - 0.95).abs() < 1e-9)));
// Zusatzstück der äusseren Schicht in der Öffnung (x 1.97 … 2.0).
assert!(p.iter().any(|x| x.0 == ART_BAND && x.1 == 0 && x.2.iter().any(|q| (q.0 - 1.97).abs() < 1e-9)));
// Umriss als Linien, Stufe am Rücksprung (Querlinie bei x = 0.95).
let mut i = 1;
let mut step = false;
for _ in 0..o[0] as usize {
if o[i] == 1.0 {
i += 4 + o[i + 3] as usize + 8;
} else {
if o[i + 1] == LINE_OUTLINE && (o[i + 3] - 0.95).abs() < 1e-9 && (o[i + 5] - 0.95).abs() < 1e-9 {
step = true;
}
i += 7;
}
}
assert!(step);
// Ohne Block wie bisher.
assert_eq!(count(&wall_poche(&wall(4.0, false, &[(1.0, 2.0)])), 1.0), 6);
}
#[test]
fn unsinn_ohne_panic() {
assert!(wall_poche(&[1.0, 2.0]).is_empty());
+1
View File
@@ -38,6 +38,7 @@ pub fn run(p: &Project, name: &str, args: &[f64], text: &str) -> Result<String,
("roofCutLayers", _) => json(&model3d::emit_roof_cut_layers(p)?),
("scheduleRows", _) => json(&export_schedule::schedule_rows(p)),
("openingSchedule", _) => json(&crate::opening_schedule::opening_schedule(p)),
("openingPreview", _) => json(&crate::opening_preview::opening_preview(p, text)),
("scheduleCsv", 1) => Ok(export_schedule::export_schedule_csv(p, text, args[0] != 0.0)),
("pickGeometry", _) => json(&model3d::pick_geometry(p)?),
("modelJson", _) => crate::model::to_value_typed_only(p).map(|v| v.to_string()).map_err(|e| e.to_string()),
+87 -1
View File
@@ -35,6 +35,26 @@ pub struct OpeningIn {
pub recess_inner_layer: bool,
}
/// Schichteinzug einer Öffnung ([106], nur gestapelte Schichten): erkannt am gleichen Intervall/
/// Höhe wie ihr [`OpeningIn`]; je Band Rücksprung links/rechts/oben/unten und Zusatzstücke
/// `(band, seite 0 L | 1 R | 2 oben | 3 unten, [x0, x1, o0, o1])` mit x ab Rohbaukante in die
/// Öffnung, o quer ab der Aussenfläche (Band 0 = aussen).
#[derive(Clone, Debug, PartialEq, Default)]
pub struct RevealIn {
pub from: f64,
pub to: f64,
pub z_bottom: f64,
pub z_top: f64,
pub shifts: Vec<[f64; 4]>,
pub pieces: Vec<(usize, usize, [f64; 4])>,
}
impl RevealIn {
fn of(&self, h: &OpeningIn) -> bool {
self.from == h.from && self.to == h.to && self.z_bottom == h.z_bottom && self.z_top == h.z_top
}
}
/// Eine Decke desselben Geschosses: z-Ausdehnung, Umriss, Schichten (Dicke, Rang; `None` =
/// Bauteil unbekannt). `layers = None`: Deckentyp unbekannt.
#[derive(Clone, Debug, PartialEq)]
@@ -80,6 +100,8 @@ pub struct WallIn {
pub bands: Vec<BandIn>,
pub openings: Vec<OpeningIn>,
pub cuts: WallCuts,
/// Schichteinzug ([106]); leer = alle Schichten bündig.
pub reveals: Vec<RevealIn>,
}
/// Decken und Dächer eines Geschosses — einmal je Geschoss gelesen, für alle seine Wände; die
@@ -122,6 +144,8 @@ pub struct Piece {
pub z_top: f64,
pub top_drop: Option<[f64; 2]>,
pub holes: Vec<[f64; 4]>,
/// Eigene Dicke (Schichteinzug-Stück, [106]); `None` = Banddicke.
pub thickness: Option<f64>,
}
#[derive(Clone, Copy, Debug)]
@@ -366,6 +390,7 @@ impl Emitter<'_> {
z_top: zt,
top_drop: (drop[0] > EPS || drop[1] > EPS).then_some(drop),
holes,
thickness: None,
});
}
}
@@ -607,20 +632,56 @@ pub fn wall_bands(w: &WallIn, ctx: &FloorContext) -> Vec<Piece> {
}
}
}
reveal_pieces(&mut em, &offsets);
em.out
}
/// Zusatzstücke des Schichteinzugs ([106]) als eigene Körper der Schicht: Leibungen über die
/// Öffnungshöhe (ohne die Ecken der Sturz-/Brüstungsstücke derselben Schicht), Sturz/Brüstung
/// über die ganze Öffnungsbreite.
fn reveal_pieces(em: &mut Emitter, offsets: &[f64]) {
let w = em.w;
if !w.stacked || w.bands.is_empty() {
return;
}
let face = offsets[0] - w.bands[0].thickness / 2.0;
for r in &w.reveals {
let reach = |band: usize, side: usize| r.pieces.iter().filter(|p| p.0 == band && p.1 == side).fold(0.0f64, |m, p| m.max(p.2[1]));
for &(band, side, [x0, x1, o0, o1]) in &r.pieces {
if band >= w.bands.len() || !(x1 - x0 > EPS) || !(o1 - o0 > EPS) {
continue;
}
let off = face + (o0 + o1) / 2.0;
let (a, b, zb, zt) = match side {
0 => (r.from + x0, r.from + x1, r.z_bottom + reach(band, 3), r.z_top - reach(band, 2)),
1 => (r.to - x1, r.to - x0, r.z_bottom + reach(band, 3), r.z_top - reach(band, 2)),
2 => (r.from, r.to, r.z_top - x1, r.z_top - x0),
_ => (r.from, r.to, r.z_bottom + x0, r.z_bottom + x1),
};
let before = em.out.len();
em.push(band, a, b, zb, zt, off, vec![], [0.0, 0.0]);
if let Some(pc) = em.out.get_mut(before) {
pc.thickness = Some(o1 - o0);
}
}
}
}
/// Ein Körper eines Bands im layered-Pfad: Öffnungs-Löcher auf den Körper-Start umrechnen (an der
/// innersten Schicht mit Laibungs-Rücksprung geweitet); schräge Oberkante mit Löchern geht in
/// render3d nicht → gestuft annähern.
#[allow(clippy::too_many_arguments)]
fn emit_band_piece(em: &mut Emitter, li: usize, off: f64, cutouts: &[OpeningIn], innermost: bool, recess: f64, a: f64, bb: f64, zb: f64, zt_start: f64, zt_end: f64) {
let zt = zt_start.max(zt_end);
let reveals = &em.w.reveals;
let holes: Vec<[f64; 4]> = cutouts
.iter()
.filter(|h| h.z_top > zb + EPS && h.z_bottom < zt - EPS)
.map(|h| {
if innermost && h.recess_inner_layer {
if let Some(s) = reveals.iter().find(|r| r.of(h)).and_then(|r| r.shifts.get(li)) {
// [106]: Schicht springt je Seite zurück.
[h.from - a - s[0], h.to - a + s[1], h.z_bottom - s[3], h.z_top + s[2]]
} else if innermost && h.recess_inner_layer {
[h.from - a - recess, h.to - a + recess, h.z_bottom - recess, h.z_top + recess]
} else {
[h.from - a, h.to - a, h.z_bottom, h.z_top]
@@ -659,6 +720,7 @@ mod tests {
bands,
openings: vec![],
cuts: WallCuts::default(),
reveals: vec![],
}
}
fn band(t: f64, p: f64) -> BandIn {
@@ -734,6 +796,30 @@ mod tests {
assert!(s.iter().all(|q| q.holes.is_empty() && q.top_drop.is_none()));
}
#[test]
fn schichteinzug_weitet_loch_und_setzt_stuecke() {
let mut w = base((0.0, 0.0), (4.0, 0.0), vec![band(0.16, 1.0), band(0.15, 2.0), band(0.01, 1.0)]);
let o = OpeningIn { from: 1.0, to: 2.0, z_bottom: 0.9, z_top: 2.1, recess_inner_layer: false };
w.openings.push(o);
w.reveals.push(RevealIn {
from: 1.0,
to: 2.0,
z_bottom: 0.9,
z_top: 2.1,
shifts: vec![[0.0; 4], [0.0; 4], [0.02, 0.02, 0.0, 0.0]],
pieces: vec![(0, 2, [0.0, 0.03, 0.0, 0.16])],
});
let ps = bands_of(&w);
let inner = ps.iter().find(|p| p.band == 2 && p.thickness.is_none()).unwrap();
assert!(close(inner.holes[0][0], 0.98) && close(inner.holes[0][1], 2.02));
let outer = ps.iter().find(|p| p.band == 0 && p.thickness.is_none()).unwrap();
assert!(close(outer.holes[0][0], 1.0));
let st = ps.iter().find(|p| p.thickness.is_some()).unwrap();
assert!(close(st.thickness.unwrap(), 0.16) && close(st.z_bottom, 2.07) && close(st.z_top, 2.1));
// Stück liegt in der Aussendämmung (Mitte −0.16 + 0.08 bei Gesamtdicke 0.32 zentriert).
assert!(close(st.start.y, -0.08));
}
#[test]
fn decke_hoeherer_prioritaet_schneidet_nur_schwache_baender() {
let mut w = base((0.0, 0.0), (4.0, 0.0), vec![band(0.15, 50.0), band(0.02, 10.0)]);