[K3c][K3d][K4] Merge: Schnitt-Besitzer aus dem Schnitt-Modell (Deckenschichten richtig), Strichmuster im Shader (big16 9 s → 0.1 s), Unterlage im Kern, WASM-Allokator-Absturz
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
23 files changed
+1237
-504
No files matched your search
@@ -1298,7 +1298,7 @@ pub struct DrawingLevel {
|
||||
pub hidden_lines: Option<bool>,
|
||||
/// Grundriss-Unterlage (nur Schnitt/Ansicht): ID eines Geschosses, dessen
|
||||
/// Grundriss AUSGERICHTET unter dem Schnitt/der Ansicht gezeigt wird (Schnitt-
|
||||
/// linie waagrecht, Blickrichtung nach oben, s. `plan/planUnderlay.ts`).
|
||||
/// linie waagrecht, Blickrichtung nach oben, s. Kern `plan/underlay.rs`).
|
||||
/// Fehlt ⇒ keine Unterlage.
|
||||
#[serde(rename = "planUnderlayId", default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
|
||||
@@ -41,6 +41,21 @@ pub struct RSlab {
|
||||
pub cut: Option<RCutMeta>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub monolith: Option<String>,
|
||||
/// Herkunft der Platte (nur im Kern, nicht serialisiert): der Schnitt ordnet seine Bänder darüber
|
||||
/// der Decke bzw. Deckenschicht oder der Treppe zu, statt die Platten abzuzählen.
|
||||
#[serde(skip)]
|
||||
pub source: SlabSource,
|
||||
}
|
||||
|
||||
/// Herkunft einer `RSlab`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum SlabSource {
|
||||
#[default]
|
||||
None,
|
||||
/// Index in `Project::ceilings`; `layer` = Schicht des Deckentyps (`None` = ungeschichtet).
|
||||
Ceiling { index: usize, layer: Option<usize> },
|
||||
/// Index in `Project::stairs`.
|
||||
Stair { index: usize },
|
||||
}
|
||||
|
||||
/// Ein rohes Dreiecks-Mesh (`RMesh`).
|
||||
@@ -80,11 +95,11 @@ fn ceiling_layers<'a>(p: &'a Project, c: &Ceiling) -> Option<&'a [Layer]> {
|
||||
|
||||
/// Deckenplatten (`emitSlabs`): eine Platte je Materiallage, oben→unten gestapelt.
|
||||
pub fn emit_slabs(p: &Project) -> Vec<RSlab> {
|
||||
let mut ceilings: Vec<&Ceiling> = Vec::new();
|
||||
let mut ceilings: Vec<(usize, &Ceiling)> = Vec::new();
|
||||
let mut layers_of: Vec<Option<&[Layer]>> = Vec::new();
|
||||
let mut w = FlatWriter::new();
|
||||
let count = w.slot();
|
||||
for c in p.ceilings.as_deref().unwrap_or(&[]) {
|
||||
for (ci, c) in p.ceilings.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
if c.outline.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
@@ -100,7 +115,7 @@ pub fn emit_slabs(p: &Project) -> Vec<RSlab> {
|
||||
for l in layers.unwrap_or(&[]) {
|
||||
w.num(l.thickness);
|
||||
}
|
||||
ceilings.push(c);
|
||||
ceilings.push((ci, c));
|
||||
layers_of.push(layers);
|
||||
}
|
||||
if ceilings.is_empty() {
|
||||
@@ -109,12 +124,12 @@ pub fn emit_slabs(p: &Project) -> Vec<RSlab> {
|
||||
w.set(count, ceilings.len() as f64);
|
||||
let mut out = Vec::new();
|
||||
for d in crate::ceilings3d::ceilings(&w.done()) {
|
||||
let c = ceilings[d.ceiling];
|
||||
let (ci, c) = ceilings[d.ceiling];
|
||||
let layers = layers_of[d.ceiling];
|
||||
let outline: Vec<RVec2> = d.ring.clone();
|
||||
for (layer_idx, z_bottom, z_top) in d.slabs {
|
||||
let Some(layers) = layers.filter(|_| layer_idx >= 0) else {
|
||||
out.push(RSlab { outline: outline.clone(), z_bottom, z_top, color: SLAB_RGB, ceiling_id: c.id.clone(), hatch: None, cut: None, monolith: None });
|
||||
out.push(RSlab { outline: outline.clone(), z_bottom, z_top, color: SLAB_RGB, ceiling_id: c.id.clone(), hatch: None, cut: None, monolith: None, source: SlabSource::Ceiling { index: ci, layer: None } });
|
||||
continue;
|
||||
};
|
||||
let l = &layers[layer_idx as usize];
|
||||
@@ -142,6 +157,7 @@ pub fn emit_slabs(p: &Project) -> Vec<RSlab> {
|
||||
hatch: resolve_component_hatch(p, &l.component_id, None),
|
||||
cut,
|
||||
monolith: None,
|
||||
source: SlabSource::Ceiling { index: ci, layer: Some(layer_idx as usize) },
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -729,22 +745,22 @@ fn rail_rgb() -> Rgb {
|
||||
}
|
||||
|
||||
/// Flache Eingabe der Treppen für `stairs3d` (23 Zahlen je Treppe); `wanted` wählt vor.
|
||||
fn stair_input<'a>(p: &'a Project, wanted: impl Fn(&Stair, Option<&StairType>) -> bool) -> Option<(Vec<&'a Stair>, Vec<f64>)> {
|
||||
let mut stairs: Vec<&Stair> = Vec::new();
|
||||
fn stair_input<'a>(p: &'a Project, wanted: impl Fn(&Stair, Option<&StairType>) -> bool) -> Option<(Vec<(usize, &'a Stair)>, Vec<f64>)> {
|
||||
let mut stairs: Vec<(usize, &Stair)> = Vec::new();
|
||||
let mut types: Vec<Option<&StairType>> = Vec::new();
|
||||
for s in p.stairs.as_deref().unwrap_or(&[]) {
|
||||
for (si, s) in p.stairs.as_deref().unwrap_or(&[]).iter().enumerate() {
|
||||
let st = p.stair_type(s);
|
||||
if !wanted(s, st) {
|
||||
continue;
|
||||
}
|
||||
stairs.push(s);
|
||||
stairs.push((si, s));
|
||||
types.push(st);
|
||||
}
|
||||
if stairs.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut buf = vec![stairs.len() as f64];
|
||||
for (s, st) in stairs.iter().zip(&types) {
|
||||
for (&(_, s), st) in stairs.iter().zip(&types) {
|
||||
let (z_bottom, z_top) = p.stair_vertical_extent(s);
|
||||
buf.extend(s.encode());
|
||||
buf.push(z_bottom);
|
||||
@@ -773,7 +789,7 @@ pub fn emit_stairs(p: &Project, for_section: bool) -> Vec<RSlab> {
|
||||
crate::stairs3d::slabs(&buf, for_section)
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
let stair = stairs[s.src];
|
||||
let (si, stair) = stairs[s.src];
|
||||
RSlab {
|
||||
outline: s.pts,
|
||||
z_bottom: s.z_bottom,
|
||||
@@ -783,6 +799,7 @@ pub fn emit_stairs(p: &Project, for_section: bool) -> Vec<RSlab> {
|
||||
hatch: None,
|
||||
cut: None,
|
||||
monolith: s.monolith.then(|| stair.id.clone()),
|
||||
source: SlabSource::Stair { index: si },
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -13,3 +13,4 @@ pub mod section;
|
||||
pub mod elevation;
|
||||
pub mod cache;
|
||||
pub mod extras;
|
||||
pub mod underlay;
|
||||
+144
-150
@@ -12,7 +12,7 @@ use super::style::*;
|
||||
use crate::jsmath::hypot2;
|
||||
use crate::jsnum::{atan2, max, min, round};
|
||||
use crate::model::*;
|
||||
use crate::model3d::{self, RRoofLayer, RSlab, RWall};
|
||||
use crate::model3d::{self, RSlab, RWall, SlabSource};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
/// Tinte der Schnitt-Poché-Umrisslinie (dunkles Grau).
|
||||
@@ -24,7 +24,6 @@ const SECTION_VISIBLE_MM: f64 = 0.18;
|
||||
const SECTION_GROUND_MM: f64 = 0.5;
|
||||
const SECTION_HIDDEN_MM: f64 = 0.13;
|
||||
const SECTION_HIDDEN_DASH: [f64; 2] = [0.12, 0.08];
|
||||
const OWNER_EPS: f64 = 1e-4;
|
||||
/// Achswinkel geschnittener Wände/Decken für wandrelative Muster (s. `toSection.ts`).
|
||||
const SECTION_WALL_AXIS_ANGLE_DEG: f64 = 90.0;
|
||||
const SECTION_SLAB_AXIS_ANGLE_DEG: f64 = 90.0;
|
||||
@@ -344,12 +343,9 @@ fn slab_input(s: &RSlab) -> render3d::SlabInput {
|
||||
}
|
||||
}
|
||||
|
||||
fn roof_input(r: &RRoofLayer) -> render3d::types::RoofLayerInput {
|
||||
render3d::types::RoofLayerInput { polygon: r.polygon.iter().map(|q| f32s3(*q)).collect(), normal: f32s3(r.normal), thickness: json_f32(r.thickness), color: f32s3(r.color), hatch: None, cut: None }
|
||||
}
|
||||
|
||||
// ── Besitzer (Emissions-Reihenfolge des Schnitt-Modells) ─────────────────────
|
||||
// ── Besitzer (Herkunft, die das Schnitt-Modell mitführt) ─────────────────────
|
||||
|
||||
// Öffnungs-Lage in der Wand (für die geschnittenen Fenster/Türen).
|
||||
fn opening_extent(p: &Project, w: &Wall, o: &Opening) -> (f64, f64) {
|
||||
let (zb, zt) = p.wall_vertical_extent(w);
|
||||
let sill = max(0.0, o.sill_height);
|
||||
@@ -367,55 +363,36 @@ fn opening_interval(w: &Wall, o: &Opening) -> Option<(f64, f64)> {
|
||||
Some((from, to))
|
||||
}
|
||||
|
||||
/// Je emittiertem Wand-Teilquader die Quellwand (`wallSegmentOwners`).
|
||||
pub fn wall_segment_owners(p: &Project) -> Vec<&Wall> {
|
||||
let mut owners = Vec::new();
|
||||
let by_wall = p.openings_by_wall();
|
||||
for wall in &p.walls {
|
||||
let (z_bottom, z_top) = p.wall_vertical_extent(wall);
|
||||
let axis_len = hypot2(wall.end.x - wall.start.x, wall.end.y - wall.start.y);
|
||||
if axis_len < 1e-9 || z_top - z_bottom <= OWNER_EPS {
|
||||
continue;
|
||||
}
|
||||
let mut push = |from: f64, to: f64, zb: f64, zt: f64| {
|
||||
if to - from <= OWNER_EPS || zt - zb <= OWNER_EPS {
|
||||
return;
|
||||
}
|
||||
owners.push(wall);
|
||||
};
|
||||
let mut cutouts: Vec<(f64, f64, f64, f64)> = Vec::new();
|
||||
for &op in by_wall.get(wall.id.as_str()).map_or(&[][..], |v| v.as_slice()) {
|
||||
let Some((from, to)) = opening_interval(wall, op) else { continue };
|
||||
let (ob, ot) = opening_extent(p, wall, op);
|
||||
cutouts.push((from, to, ob, ot));
|
||||
}
|
||||
// `Array.sort` mit `a.from - b.from` (stabil).
|
||||
cutouts.sort_by(|a, b| cmp_num(a.0 - b.0));
|
||||
if cutouts.is_empty() {
|
||||
push(0.0, axis_len, z_bottom, z_top);
|
||||
continue;
|
||||
}
|
||||
let mut cursor = 0.0;
|
||||
for &(from, to, ob, ot) in &cutouts {
|
||||
let seg_from = max(cursor, from);
|
||||
if from > cursor {
|
||||
push(cursor, from, z_bottom, z_top);
|
||||
}
|
||||
if to > seg_from {
|
||||
if ob > z_bottom + OWNER_EPS {
|
||||
push(seg_from, to, z_bottom, ob);
|
||||
}
|
||||
if ot < z_top - OWNER_EPS {
|
||||
push(seg_from, to, ot, z_top);
|
||||
}
|
||||
}
|
||||
cursor = max(cursor, to);
|
||||
}
|
||||
if cursor < axis_len {
|
||||
push(cursor, axis_len, z_bottom, z_top);
|
||||
}
|
||||
|
||||
/// Je emittiertem Wand-Teilquader die Quellwand (über `RWall::wall_id`).
|
||||
fn wall_owners<'a>(p: &'a Project, walls: &[RWall]) -> Vec<Option<&'a Wall>> {
|
||||
let mut by_id: HashMap<&str, &Wall> = HashMap::with_capacity(p.walls.len());
|
||||
for w in &p.walls {
|
||||
by_id.entry(w.id.as_str()).or_insert(w);
|
||||
}
|
||||
owners
|
||||
walls.iter().map(|w| by_id.get(w.wall_id.as_str()).copied()).collect()
|
||||
}
|
||||
|
||||
/// Herkunft eines Platten-Bandes: Decke (mit Schicht des Deckentyps) oder Treppe.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum SlabOwner<'a> {
|
||||
None,
|
||||
Ceiling(&'a Ceiling, Option<usize>),
|
||||
Stair(&'a Stair),
|
||||
}
|
||||
|
||||
/// Je emittierter Platte (Deckenschicht, Treppentritt, Podest) ihre Herkunft (`RSlab::source`).
|
||||
pub fn slab_owners<'a>(p: &'a Project, slabs: &[RSlab]) -> Vec<SlabOwner<'a>> {
|
||||
let ceilings = p.ceilings.as_deref().unwrap_or(&[]);
|
||||
let stairs = p.stairs.as_deref().unwrap_or(&[]);
|
||||
slabs
|
||||
.iter()
|
||||
.map(|s| match s.source {
|
||||
SlabSource::Ceiling { index, layer } => ceilings.get(index).map_or(SlabOwner::None, |c| SlabOwner::Ceiling(c, layer)),
|
||||
SlabSource::Stair { index } => stairs.get(index).map_or(SlabOwner::None, SlabOwner::Stair),
|
||||
SlabSource::None => SlabOwner::None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Ordnung eines JS-Vergleichs `(a, b) => d` (NaN/0 = gleich).
|
||||
@@ -429,22 +406,6 @@ pub fn cmp_num(d: f64) -> std::cmp::Ordering {
|
||||
}
|
||||
}
|
||||
|
||||
/// Je emittierter Deckenplatte die Quelldecke (`slabSegmentOwners`).
|
||||
pub fn slab_segment_owners(p: &Project) -> Vec<&Ceiling> {
|
||||
let mut owners = Vec::new();
|
||||
for c in p.ceilings.as_deref().unwrap_or(&[]) {
|
||||
if c.outline.len() < 3 {
|
||||
continue;
|
||||
}
|
||||
let (zb, zt) = p.ceiling_vertical_extent(c);
|
||||
if zt - zb <= OWNER_EPS {
|
||||
continue;
|
||||
}
|
||||
owners.push(c);
|
||||
}
|
||||
owners
|
||||
}
|
||||
|
||||
// ── Stil-Auflösung ────────────────────────────────────────────────────────────
|
||||
|
||||
fn sum_thickness(layers: &[Layer]) -> f64 {
|
||||
@@ -560,34 +521,17 @@ fn layer_style(
|
||||
Ok((fill, hatch))
|
||||
}
|
||||
|
||||
/// `splitSlabLayers`: liegende Teil-Rechtecke je Schicht (oben → unten).
|
||||
fn split_slab_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Ceiling) -> Result<Vec<Cut>, String> {
|
||||
let total = sum_thickness(layers);
|
||||
let [u_min, u_max, v_min, v_max] = bbox(&cp.pts);
|
||||
let v_span = v_max - v_min;
|
||||
if total <= 1e-9 || v_span <= 1e-9 {
|
||||
return Ok(vec![cp.clone()]);
|
||||
}
|
||||
let scale = v_span / total;
|
||||
/// Stil einer geschnittenen Deckenschicht (Füllung, Schraffur, Verschneidung) mit dem Override der Decke.
|
||||
/// Jede Schicht ist im Schnitt-Modell eine eigene Platte; ihr Band trägt so genau ihr Bauteil.
|
||||
fn style_slab_layer(cp: &mut Cut, p: &Project, layer: &Layer, owner: &Ceiling) -> Result<(), String> {
|
||||
let category = p.layer_category(&owner.category_code);
|
||||
let mut out = Vec::with_capacity(layers.len());
|
||||
let mut acc = 0.0;
|
||||
for layer in layers {
|
||||
let comp = p.component(&layer.component_id).ok_or_else(|| missing("Unbekanntes Bauteil-Material", &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_SLAB_AXIS_ANGLE_DEG)?;
|
||||
let v_top = v_max - acc * scale;
|
||||
acc += layer.thickness;
|
||||
let v_bottom = v_max - acc * scale;
|
||||
let mut c = Cut::new(cp.kind, cp.index, vec![[u_min, v_top], [u_max, v_top], [u_max, v_bottom], [u_min, v_bottom]]);
|
||||
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);
|
||||
}
|
||||
Ok(out)
|
||||
let comp = p.component(&layer.component_id).ok_or_else(|| missing("Unbekanntes Bauteil-Material", &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_SLAB_AXIS_ANGLE_DEG)?;
|
||||
cp.fill = Some(fill);
|
||||
cp.hatch = Some(hatch);
|
||||
cp.join_priority = Some(comp.join_priority);
|
||||
cp.component_id = Some(comp.id.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// `wallLayersReversedInU`.
|
||||
@@ -635,7 +579,7 @@ fn split_wall_layers(cp: &Cut, p: &Project, layers: &[Layer], owner: &Wall, u_wo
|
||||
}
|
||||
|
||||
/// `attachCutStyles`: Stil, Herkunft, Schicht-Bänder, Terminierung, Dominanz.
|
||||
fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[&Wall], slabs: &[&Ceiling]) -> Result<Vec<Cut>, String> {
|
||||
fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[Option<&Wall>], slabs: &[SlabOwner]) -> Result<Vec<Cut>, String> {
|
||||
if cuts.is_empty() {
|
||||
return Ok(cuts);
|
||||
}
|
||||
@@ -651,7 +595,7 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[&Wall]
|
||||
bands.push(cp);
|
||||
}
|
||||
Kind::Wall => {
|
||||
let owner = walls.get(cp.index).copied();
|
||||
let owner = walls.get(cp.index).copied().flatten();
|
||||
cp.source_id = owner.map(|o| o.id.clone());
|
||||
cp.category = owner.map(|o| o.category_code.clone());
|
||||
if let Some(o) = owner {
|
||||
@@ -670,21 +614,31 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[&Wall]
|
||||
bands.push(cp);
|
||||
}
|
||||
_ => {
|
||||
let owner = slabs.get(cp.index).copied();
|
||||
cp.source_id = owner.map(|o| o.id.clone());
|
||||
cp.category = owner.map(|o| o.category_code.clone());
|
||||
if let Some(o) = owner {
|
||||
let layers = ceiling_layers(p, o).ok_or_else(|| missing("Unbekannter Deckentyp", o.ceiling_type_id.as_deref().unwrap_or(&o.wall_type_id)))?;
|
||||
if layers.len() > 1 {
|
||||
bands.extend(split_slab_layers(&cp, p, layers, o)?);
|
||||
continue;
|
||||
match slabs.get(cp.index).copied().unwrap_or(SlabOwner::None) {
|
||||
SlabOwner::Ceiling(o, layer) => {
|
||||
cp.source_id = Some(o.id.clone());
|
||||
cp.category = Some(o.category_code.clone());
|
||||
let layers = ceiling_layers(p, o).ok_or_else(|| missing("Unbekannter Deckentyp", o.ceiling_type_id.as_deref().unwrap_or(&o.wall_type_id)))?;
|
||||
if layers.len() > 1 {
|
||||
// Schicht-Platte: Stil genau dieser Schicht; ohne Schicht (Dicke 0) ohne Stil.
|
||||
if let Some(l) = layer.and_then(|i| layers.get(i)) {
|
||||
style_slab_layer(&mut cp, p, l, o)?;
|
||||
}
|
||||
} else {
|
||||
if let Some((fill, hatch)) = ceiling_section_style(p, o) {
|
||||
cp.fill = Some(fill);
|
||||
cp.hatch = Some(hatch);
|
||||
}
|
||||
cp.join_priority = ceiling_representative_priority(p, o);
|
||||
cp.component_id = ceiling_representative_component_id(p, o);
|
||||
}
|
||||
}
|
||||
if let Some((fill, hatch)) = ceiling_section_style(p, o) {
|
||||
cp.fill = Some(fill);
|
||||
cp.hatch = Some(hatch);
|
||||
// Treppen-Prismen: Herkunft + Kategorie; Stil = Rückfall-Schraffur (Treppen haben kein Bauteil).
|
||||
SlabOwner::Stair(st) => {
|
||||
cp.stair_id = Some(st.id.clone());
|
||||
cp.category = Some(st.category_code.clone());
|
||||
}
|
||||
cp.join_priority = ceiling_representative_priority(p, o);
|
||||
cp.component_id = ceiling_representative_component_id(p, o);
|
||||
SlabOwner::None => {}
|
||||
}
|
||||
bands.push(cp);
|
||||
}
|
||||
@@ -695,7 +649,7 @@ fn attach_cut_styles(cuts: Vec<Cut>, p: &Project, plane: &Plane, walls: &[&Wall]
|
||||
}
|
||||
|
||||
/// `applyWallTermination`: Wände mit `sliceTermination` "below"/"above" enden an der Decke.
|
||||
fn apply_wall_termination(bands: Vec<Cut>, walls: &[&Wall]) -> Vec<Cut> {
|
||||
fn apply_wall_termination(bands: Vec<Cut>, walls: &[Option<&Wall>]) -> Vec<Cut> {
|
||||
const EPS_T: f64 = 1e-9;
|
||||
const TOUCH: f64 = 0.05;
|
||||
let slab_bands: Vec<([f64; 4], f64)> = bands.iter().filter(|b| b.kind == Kind::Slab).filter_map(|b| b.join_priority.map(|jp| (bbox(&b.pts), jp))).collect();
|
||||
@@ -708,7 +662,7 @@ fn apply_wall_termination(bands: Vec<Cut>, walls: &[&Wall]) -> Vec<Cut> {
|
||||
out.push(b);
|
||||
continue;
|
||||
}
|
||||
let term = walls.get(b.index).and_then(|w| w.slice_termination);
|
||||
let term = walls.get(b.index).copied().flatten().and_then(|w| w.slice_termination);
|
||||
let (Some(term @ (SliceTermination::Below | SliceTermination::Above)), Some(jp)) = (term, b.join_priority) else {
|
||||
out.push(b);
|
||||
continue;
|
||||
@@ -773,6 +727,9 @@ fn subtract_dominant_bands(bands: Vec<Cut>) -> Vec<Cut> {
|
||||
c.join_priority = src.join_priority;
|
||||
c.component_id = src.component_id.clone();
|
||||
c.source_id = src.source_id.clone();
|
||||
// Herkunft bleibt am Stück (Ebenen-Sichtbarkeit, Treppen-Pick).
|
||||
c.category = src.category.clone();
|
||||
c.stair_id = src.stair_id.clone();
|
||||
out.push(c);
|
||||
}
|
||||
i += 6;
|
||||
@@ -1128,7 +1085,7 @@ fn centroid(pts: &[Vec2]) -> Option<(f64, f64)> {
|
||||
}
|
||||
|
||||
/// `filterByDepth`: Ansichtskanten weiter als `depth` hinter der Ebene ausblenden.
|
||||
fn filter_by_depth(out: &mut Output, p: &Project, plane: &Plane, depth: f64, walls: &[&Wall], slabs: &[&Ceiling]) {
|
||||
fn filter_by_depth(out: &mut Output, p: &Project, plane: &Plane, depth: f64, walls: &[Option<&Wall>], slabs: &[SlabOwner], slabs_r: &[RSlab]) {
|
||||
if !(depth > 0.0) {
|
||||
return;
|
||||
}
|
||||
@@ -1140,8 +1097,13 @@ fn filter_by_depth(out: &mut Output, p: &Project, plane: &Plane, depth: f64, wal
|
||||
let roofs = p.roofs.as_deref().unwrap_or(&[]);
|
||||
let owner_point = |e: &Edge| -> Option<(f64, f64)> {
|
||||
match e.kind {
|
||||
Kind::Wall => walls.get(e.index).map(|w| ((w.start.x + w.end.x) / 2.0, (w.start.y + w.end.y) / 2.0)),
|
||||
Kind::Slab => slabs.get(e.index).and_then(|c| centroid(&c.outline)),
|
||||
Kind::Wall => walls.get(e.index).copied().flatten().map(|w| ((w.start.x + w.end.x) / 2.0, (w.start.y + w.end.y) / 2.0)),
|
||||
Kind::Slab => match slabs.get(e.index) {
|
||||
Some(SlabOwner::Ceiling(c, _)) => centroid(&c.outline),
|
||||
// Treppe: Mitte des Tritts bzw. Podests selbst.
|
||||
Some(SlabOwner::Stair(_)) => slabs_r.get(e.index).and_then(|s| centroid(&s.outline.iter().map(|q| Vec2 { x: q[0], y: q[1] }).collect::<Vec<_>>())),
|
||||
_ => None,
|
||||
},
|
||||
_ => roofs.get(e.index).and_then(|r| centroid(&r.outline)),
|
||||
}
|
||||
};
|
||||
@@ -1163,14 +1125,14 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R
|
||||
let walls_r = model3d::emit_walls(p, false)?;
|
||||
let mut slabs_r = model3d::emit_slabs(p);
|
||||
slabs_r.extend(model3d::emit_stairs(p, true));
|
||||
let roofs_r = model3d::emit_roof_cut_layers(p)?;
|
||||
let wi: Vec<render3d::WallInput> = walls_r.iter().map(wall_input).collect();
|
||||
let si: Vec<render3d::SlabInput> = slabs_r.iter().map(slab_input).collect();
|
||||
let ri: Vec<render3d::types::RoofLayerInput> = roofs_r.iter().map(roof_input).collect();
|
||||
// Die Ebene ging als Zahl-Argument (wasm-bindgen, `Math.fround`) hinein, nicht über JSON.
|
||||
let fr = |v: [f64; 3]| [v[0] as f32, v[1] as f32, v[2] as f32];
|
||||
let rp = render3d::SectionPlane::new(fr(plane.point), fr(plane.normal));
|
||||
let raw = render3d::cut_section(&rp, &wi, &si, &ri);
|
||||
// Dächer nicht durch render3d: deren Bänder (je Schicht × Dachfläche, ohne Stil) lagen unter den
|
||||
// gestylten aus `append_roof_sections` (doppelte Kontur, Rückfall-Schraffur, Besitzer per Index falsch).
|
||||
let raw = render3d::cut_section(&rp, &wi, &si, &[]);
|
||||
|
||||
// Gleiche f32 kommen oft vor (gemeinsame Ecken, Höhen): Umwandlung je Wert nur einmal.
|
||||
let mut conv: HashMap<u32, f64> = HashMap::new();
|
||||
@@ -1188,24 +1150,9 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R
|
||||
let hidden: Vec<Edge> = raw.hidden_edges.iter().filter(not_cut).map(&mut edge).collect();
|
||||
|
||||
append_roof_sections(&mut cuts, p, &plane);
|
||||
let walls = wall_segment_owners(p);
|
||||
let slabs = slab_segment_owners(p);
|
||||
let mut cuts = attach_cut_styles(cuts, p, &plane, &walls, &slabs)?;
|
||||
// Treppen-Prismen: Herkunft + Kategorie (bei doppelten ids gewinnt die letzte, wie `new Map`).
|
||||
let mut stairs_by_id: HashMap<&str, &Stair> = HashMap::new();
|
||||
for st in p.stairs.as_deref().unwrap_or(&[]) {
|
||||
stairs_by_id.insert(st.id.as_str(), st);
|
||||
}
|
||||
for cp in cuts.iter_mut() {
|
||||
if cp.kind != Kind::Slab {
|
||||
continue;
|
||||
}
|
||||
let id = slabs_r.get(cp.index).map_or("", |s| s.ceiling_id.as_str());
|
||||
if let Some(st) = stairs_by_id.get(id) {
|
||||
cp.stair_id = Some(st.id.clone());
|
||||
cp.category = Some(st.category_code.clone());
|
||||
}
|
||||
}
|
||||
let walls = wall_owners(p, &walls_r);
|
||||
let slabs = slab_owners(p, &slabs_r);
|
||||
let cuts = attach_cut_styles(cuts, p, &plane, &walls, &slabs)?;
|
||||
let cuts = merge_monolith_cuts(cuts, &slabs_r);
|
||||
let base = plane.base();
|
||||
let u = plane.u_model();
|
||||
@@ -1214,7 +1161,7 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R
|
||||
let mut out = Output { cuts, visible, hidden, profiles: Vec::new() };
|
||||
append_terrain_profiles(&mut out, p, base, u);
|
||||
if let Some(d) = level.depth {
|
||||
filter_by_depth(&mut out, p, &plane, d, &walls, &slabs);
|
||||
filter_by_depth(&mut out, p, &plane, d, &walls, &slabs, &slabs_r);
|
||||
}
|
||||
Ok(Some(out))
|
||||
}
|
||||
@@ -1695,13 +1642,62 @@ mod tests {
|
||||
assert!(json.contains("\"wallId\":\"W2\"") && json.contains("\"roofId\":\"RF1\""), "{json}");
|
||||
assert!(json.contains("section-ground"));
|
||||
assert!(b[2] > b[0] && b[3] > b[1]);
|
||||
// Kategorie ausgeblendet → keine Dach-Schnittflächen mehr. (Von der Dominanz beschnittene
|
||||
// Wand-/Deckenbänder verlieren ihre Kategorie und bleiben sichtbar — wie in der TS-Fassung.)
|
||||
// Kategorie ausgeblendet → keine Dach-Schnittflächen mehr.
|
||||
let vis = Visibility { has_vis: true, invisible: ["31".to_string()].into_iter().collect(), ..Default::default() };
|
||||
let (hidden, _) = section_primitives(&out, false, false, &vis);
|
||||
assert!(!serde_json::to_string(&hidden).unwrap().contains("\"roofId\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beschnittene_baender_behalten_ihre_ebene() {
|
||||
// Von der Dominanz beschnittene Wand-/Deckenstücke tragen ihre Kategorie weiter: Ebene aus → weg.
|
||||
let p = sample();
|
||||
let out = compute_section(&p, &level(&p, "schnitt-a"), &[]).unwrap().unwrap();
|
||||
assert!(out.cuts.iter().filter(|c| c.kind != Kind::Body).all(|c| c.category.is_some()), "{:#?}", out.cuts);
|
||||
let codes: Vec<String> = out.cuts.iter().filter_map(|c| c.category.clone()).collect();
|
||||
let vis = Visibility { has_vis: true, invisible: codes.into_iter().collect(), ..Default::default() };
|
||||
let (prims, _) = section_primitives(&out, false, false, &vis);
|
||||
assert!(prims.iter().all(|p| !matches!(p, Primitive::Polygon { .. })));
|
||||
}
|
||||
|
||||
/// Mehrschichtige Decke + Treppe im Schnitt: je Deckenschicht genau ein Band mit ihrem Bauteil und
|
||||
/// ihrer Dicke (nicht jedes Schicht-Prisma nochmals in alle Schichten geteilt), Treppen-Tritte ohne
|
||||
/// Decken-Besitzer (früher: Besitzer per Zählung, Index-Versatz).
|
||||
#[test]
|
||||
fn mehrschichtige_decke_und_treppe_im_schnitt() {
|
||||
let p = sample();
|
||||
let l = level(&p, "schnitt-a");
|
||||
let out = compute_section(&p, &l, &[]).unwrap().unwrap();
|
||||
let slab: Vec<&Cut> = out.cuts.iter().filter(|c| c.kind == Kind::Slab && c.stair_id.is_none()).collect();
|
||||
// Je Schicht ein Band (von stärkeren Wandschichten in Stücke geteilt): Bauteil + Höhenlage.
|
||||
let mut layers: Vec<(&str, f64, f64)> = Vec::new();
|
||||
for c in &slab {
|
||||
let b = bbox(&c.pts);
|
||||
let comp = c.component_id.as_deref().expect("Schicht-Bauteil");
|
||||
match layers.iter().find(|l| l.0 == comp) {
|
||||
Some(l) => assert!((l.1 - b[2]).abs() < 1e-5 && (l.2 - b[3]).abs() < 1e-5, "{comp}: {b:?} statt {l:?}"),
|
||||
None => layers.push((comp, b[2], b[3])),
|
||||
}
|
||||
}
|
||||
assert!(slab.iter().all(|c| c.source_id.as_deref() == Some("C1") && c.category.as_deref() == Some("30")));
|
||||
layers.sort_by(|a, b| b.2.total_cmp(&a.2));
|
||||
let names: Vec<&str> = layers.iter().map(|l| l.0).collect();
|
||||
assert_eq!(names, ["screed", "insulation", "concrete"], "{slab:#?}");
|
||||
// Schichtdicken 0.06 / 0.04 / 0.20 von oben nach unten, aneinander anschliessend.
|
||||
for (l, t) in layers.iter().zip([0.06, 0.04, 0.2]) {
|
||||
assert!((l.2 - l.1 - t).abs() < 1e-5, "{layers:?}");
|
||||
}
|
||||
assert!((layers[0].1 - layers[1].2).abs() < 1e-5 && (layers[1].1 - layers[2].2).abs() < 1e-5, "{layers:?}");
|
||||
// Stil der Schicht (Füllung + Schraffur des Bauteils), nicht die Rückfall-Schraffur ohne Füllung.
|
||||
assert!(slab.iter().all(|c| c.fill.is_some() && c.hatch.is_some() && c.join_priority.is_some()), "{slab:#?}");
|
||||
// Treppe: alle Tritt-Bänder mit Treppen-Herkunft, ohne Decken-Bauteil.
|
||||
let stair: Vec<&Cut> = out.cuts.iter().filter(|c| c.kind == Kind::Slab && c.stair_id.is_some()).collect();
|
||||
assert!(!stair.is_empty());
|
||||
assert!(stair.iter().all(|c| c.stair_id.as_deref() == Some("ST1") && c.category.as_deref() == Some("40") && c.component_id.is_none()), "{stair:#?}");
|
||||
// Kein Decken-/Treppenband bleibt ohne Herkunft.
|
||||
assert!(out.cuts.iter().filter(|c| c.kind == Kind::Slab).all(|c| c.source_id.is_some() || c.stair_id.is_some()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn puffer_hat_zwei_gruppen() {
|
||||
let p = sample();
|
||||
@@ -1735,17 +1731,15 @@ mod bench {
|
||||
let t = Instant::now();
|
||||
let mut slabs = model3d::emit_slabs(&p);
|
||||
slabs.extend(model3d::emit_stairs(&p, true));
|
||||
let roofs = model3d::emit_roof_cut_layers(&p).unwrap();
|
||||
let t_rest = t.elapsed();
|
||||
let t = Instant::now();
|
||||
let wi: Vec<render3d::WallInput> = walls.iter().map(wall_input).collect();
|
||||
let si: Vec<render3d::SlabInput> = slabs.iter().map(slab_input).collect();
|
||||
let ri: Vec<render3d::types::RoofLayerInput> = roofs.iter().map(roof_input).collect();
|
||||
let t_conv = t.elapsed();
|
||||
let pl = level.plane().unwrap();
|
||||
let fr = |v: [f64; 3]| [v[0] as f32, v[1] as f32, v[2] as f32];
|
||||
let t = Instant::now();
|
||||
let raw = render3d::cut_section(&render3d::SectionPlane::new(fr(pl.point), fr(pl.normal)), &wi, &si, &ri);
|
||||
let raw = render3d::cut_section(&render3d::SectionPlane::new(fr(pl.point), fr(pl.normal)), &wi, &si, &[]);
|
||||
let t_cut = t.elapsed();
|
||||
let t = Instant::now();
|
||||
let buf = if l.kind == DrawingLevelKind::Section {
|
||||
@@ -1850,7 +1844,7 @@ mod ts_faelle {
|
||||
assert_eq!(rings.len(), 1);
|
||||
assert!(rings[0].len() >= 8);
|
||||
assert_eq!(union_rect_outlines(&[[0.0, 1.0, 0.0, 1.0], [2.0, 3.0, 0.0, 1.0]]).len(), 2);
|
||||
let slab = |m: Option<&str>| RSlab { outline: vec![], z_bottom: 0.0, z_top: 1.0, color: [0.0; 3], ceiling_id: String::new(), hatch: None, cut: None, monolith: m.map(String::from) };
|
||||
let slab = |m: Option<&str>| RSlab { outline: vec![], z_bottom: 0.0, z_top: 1.0, color: [0.0; 3], ceiling_id: String::new(), hatch: None, cut: None, monolith: m.map(String::from), source: SlabSource::None };
|
||||
let slabs = vec![slab(None), slab(Some("ST1")), slab(Some("ST1"))];
|
||||
let mk = |i: usize, u0: f64| Cut::new(Kind::Slab, i, vec![[u0, 0.0], [u0 + 1.0, 0.0], [u0 + 1.0, 1.0], [u0, 1.0]]);
|
||||
let out = merge_monolith_cuts(vec![mk(0, 0.0), mk(1, 0.0), mk(2, 0.5)], &slabs);
|
||||
@@ -1870,7 +1864,7 @@ mod ts_faelle {
|
||||
let below = wall(Some(SliceTermination::Below));
|
||||
let above = wall(Some(SliceTermination::Above));
|
||||
let both = wall(None);
|
||||
let run = |w: &Wall, wb: Cut, sb: Cut| apply_wall_termination(vec![wb, sb], &[w]);
|
||||
let run = |w: &Wall, wb: Cut, sb: Cut| apply_wall_termination(vec![wb, sb], &[Some(w)]);
|
||||
let out = run(&below, band(0.0, 0.3, 0.0, 3.0, Some(10.0), "w"), slab_band(-1.0, 4.0, 2.6, 2.9, 100.0));
|
||||
assert_eq!(bbox(&by(&out, "w")[0].pts), [0.0, 0.3, 0.0, 2.6]);
|
||||
let out = run(&above, band(0.0, 0.3, 0.0, 3.0, Some(10.0), "w"), slab_band(-1.0, 4.0, 0.0, 0.3, 100.0));
|
||||
@@ -1894,16 +1888,16 @@ mod ts_faelle {
|
||||
Wall { id: "nah".into(), start: Vec2 { x: 0.0, y: 1.0 }, end: Vec2 { x: 4.0, y: 1.0 }, ..Default::default() },
|
||||
Wall { id: "fern".into(), start: Vec2 { x: 0.0, y: 9.0 }, end: Vec2 { x: 4.0, y: 9.0 }, ..Default::default() },
|
||||
];
|
||||
let walls: Vec<&Wall> = p.walls.iter().collect();
|
||||
let walls: Vec<Option<&Wall>> = p.walls.iter().map(Some).collect();
|
||||
let plane = Plane { point: [0.0, 0.0, 0.0], normal: [0.0, 0.0, 1.0] };
|
||||
let e = |i: usize| Edge { kind: Kind::Wall, index: i, a: [0.0, 0.0], b: [1.0, 0.0] };
|
||||
let mut out = Output { visible: vec![e(0), e(1)], hidden: vec![e(1)], ..Default::default() };
|
||||
filter_by_depth(&mut out, &p, &plane, 3.0, &walls, &[]);
|
||||
filter_by_depth(&mut out, &p, &plane, 3.0, &walls, &[], &[]);
|
||||
assert_eq!(out.visible.len(), 1);
|
||||
assert_eq!(out.visible[0].index, 0);
|
||||
assert!(out.hidden.is_empty());
|
||||
let mut all = Output { visible: vec![e(0), e(1)], ..Default::default() };
|
||||
filter_by_depth(&mut all, &p, &plane, 0.0, &walls, &[]);
|
||||
filter_by_depth(&mut all, &p, &plane, 0.0, &walls, &[], &[]);
|
||||
assert_eq!(all.visible.len(), 2, "Tiefe 0 ist kein Filter");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
//! Grundriss-Unterlage in Schnitt/Ansicht (früher `src/plan/planUnderlay.ts`): ein Geschoss-
|
||||
//! Grundriss wird AUSGERICHTET unter die Schnitt-/Ansichtsfläche gelegt — die klassische
|
||||
//! Konstruktion „Ansicht über dem Grundriss“. Die Schnittlinie wird waagrecht gedreht, die
|
||||
//! Blickrichtung zeigt im Blatt nach OBEN, und die u-Achse stimmt mit der des Schnitts überein
|
||||
//! (`Plane::u_model`): ein Punkt im Grundriss liegt senkrecht unter seiner Projektion im Schnitt.
|
||||
//!
|
||||
//! Reine Starrkörper-Abbildung (Drehung + Verschiebung, keine Spiegelung) — Kreise bleiben Kreise,
|
||||
//! Bögen behalten ihren Drehsinn. Die Unterlage ist gedimmt, ohne Auswahl-Ids (fremde Projektion:
|
||||
//! ein Klick darf nie das echte Bauteil wählen) und trägt die Schnittlinie selbst (strichpunktiert).
|
||||
//! Rechenreihenfolge wie in der TS-Fassung (bitgleich).
|
||||
|
||||
use super::prim::Primitive;
|
||||
use crate::jsmath::hypot2;
|
||||
use crate::jsnum::{atan2, max, min};
|
||||
use crate::model::Vec2;
|
||||
|
||||
/// Abstand (Meter) zwischen tiefster Schnitt-/Ansichtskante und Grundriss-Oberkante.
|
||||
pub const GAP_M: f64 = 1.5;
|
||||
|
||||
/// Abbildung Grundriss (Modell x/y) → Schnitt-Blatt (u, Höhe) (`PlanToSectionMap`).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct SectionMap {
|
||||
/// Ursprung = Startpunkt der Schnittlinie.
|
||||
pub p0: Vec2,
|
||||
/// Horizontale Schnitt-u-Achse im Grundriss (Blickrichtungs-RECHTS).
|
||||
pub u: Vec2,
|
||||
/// Blickrichtung im Grundriss (Einheit).
|
||||
pub n: Vec2,
|
||||
/// Drehwinkel (Radiant, CCW).
|
||||
pub theta: f64,
|
||||
/// Vertikaler Versatz im Blatt.
|
||||
pub dy: f64,
|
||||
}
|
||||
|
||||
/// Abbildung aus der Schnitt-/Ansichtslinie (`planToSectionMap`); `None` ohne (gültige) Linie.
|
||||
pub fn section_map(line: [Vec2; 2], direction_sign: Option<f64>) -> Option<SectionMap> {
|
||||
let [p0, p1] = line;
|
||||
let len = hypot2(p1.x - p0.x, p1.y - p0.y);
|
||||
if len < 1e-9 {
|
||||
return None;
|
||||
}
|
||||
let dx = (p1.x - p0.x) / len;
|
||||
let dy = (p1.y - p0.y) / len;
|
||||
let sign = direction_sign.unwrap_or(1.0);
|
||||
// Wie `sectionPlaneFromLevel`: Links-Normale der Linie, per directionSign gedreht.
|
||||
let n = Vec2 { x: -dy * sign, y: dx * sign };
|
||||
// Wie `sectionUAxisModel`: u = (n.y, −n.x).
|
||||
let u = Vec2 { x: n.y, y: -n.x };
|
||||
Some(SectionMap { p0, u, n, theta: atan2(n.x, u.x), dy: 0.0 })
|
||||
}
|
||||
|
||||
/// Bildet einen Grundriss-Punkt ins Schnitt-Blatt ab (`mapPlanPoint`).
|
||||
pub fn map_point(m: &SectionMap, p: Vec2) -> Vec2 {
|
||||
let rx = p.x - m.p0.x;
|
||||
let ry = p.y - m.p0.y;
|
||||
Vec2 { x: rx * m.u.x + ry * m.u.y, y: rx * m.n.x + ry * m.n.y + m.dy }
|
||||
}
|
||||
|
||||
/// Bildet ein Plan-Primitiv ab (`mapPlanPrimitive`). Achsparallele Rasterbilder lassen sich nicht
|
||||
/// drehen und entfallen — ausser die Abbildung ist eine reine Verschiebung.
|
||||
pub fn map_primitive(m: &SectionMap, pr: Primitive) -> Option<Primitive> {
|
||||
let p = |q: Vec2| map_point(m, q);
|
||||
Some(match pr {
|
||||
Primitive::Polygon { pts, mut hatch, fill, stroke, stroke_width_mm, greyed, opacity, no_stroke_edges, wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id } => {
|
||||
if hatch.origin.is_some() || m.theta != 0.0 {
|
||||
// SVG-Musterwinkel dreht im Uhrzeigersinn (Bildschirm) = −Winkel im Modell.
|
||||
hatch.angle -= (m.theta * 180.0) / std::f64::consts::PI;
|
||||
hatch.origin = hatch.origin.map(p);
|
||||
}
|
||||
Primitive::Polygon { pts: pts.into_iter().map(p).collect(), hatch, fill, stroke, stroke_width_mm, greyed, opacity, no_stroke_edges, wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id }
|
||||
}
|
||||
// `motif` ist im Strich-lokalen Raum definiert — dreht mit der Linie mit.
|
||||
Primitive::Line { a, b, cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity } => Primitive::Line { a: p(a), b: p(b), cls, weight_mm, dash, zigzag, motif, color, drawing_id, opening_id, stair_id, greyed, opacity },
|
||||
Primitive::Arc { center, from, to, r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity } => Primitive::Arc { center: p(center), from: p(from), to: p(to), r, cls, weight_mm, dash, opening_id, stair_id, greyed, opacity },
|
||||
Primitive::Text { at, doc, extra_lines, base_pt, color, room_id, greyed, opacity } => Primitive::Text { at: p(at), doc, extra_lines, base_pt, color, room_id, greyed, opacity },
|
||||
Primitive::DrawingText { at, text, height_m, angle, color, marks, wrap_width, doc, drawing_id, greyed, opacity } => Primitive::DrawingText { at: p(at), text, height_m, angle: angle + m.theta, color, marks, wrap_width, doc, drawing_id, greyed, opacity },
|
||||
Primitive::DrawingTextPath { path_pts, text, height_m, color, drawing_id, greyed, opacity } => Primitive::DrawingTextPath { path_pts: path_pts.into_iter().map(p).collect(), text, height_m, color, drawing_id, greyed, opacity },
|
||||
Primitive::DrawingCircle { center, r, fill, stroke, weight_mm, dash, drawing_id, greyed, opacity } => Primitive::DrawingCircle { center: p(center), r, fill, stroke, weight_mm, dash, drawing_id, greyed, opacity },
|
||||
Primitive::DrawingArc { center, r, a0, a1, stroke, weight_mm, dash, drawing_id, greyed, opacity } => Primitive::DrawingArc { center: p(center), r, a0: a0 + m.theta, a1: a1 + m.theta, stroke, weight_mm, dash, drawing_id, greyed, opacity },
|
||||
Primitive::DrawingImage { min: lo, max: hi, src, opacity, drawing_id, greyed } => {
|
||||
if m.theta.abs() > 1e-9 {
|
||||
return None;
|
||||
}
|
||||
let (a, b) = (p(lo), p(hi));
|
||||
Primitive::DrawingImage { min: Vec2 { x: min(a.x, b.x), y: min(a.y, b.y) }, max: Vec2 { x: max(a.x, b.x), y: max(a.y, b.y) }, src, opacity, drawing_id, greyed }
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Höchster Stützpunkt eines Primitivs (`primitivePoints`, nur y), für die Höhenlage der Unterlage.
|
||||
fn max_y(pr: &Primitive, acc: &mut f64) {
|
||||
let mut see = |y: f64| {
|
||||
if y > *acc {
|
||||
*acc = y;
|
||||
}
|
||||
};
|
||||
match pr {
|
||||
Primitive::Polygon { pts, .. } => pts.iter().for_each(|q| see(q.y)),
|
||||
Primitive::Line { a, b, .. } => {
|
||||
see(a.y);
|
||||
see(b.y);
|
||||
}
|
||||
Primitive::Arc { from, to, center, .. } => {
|
||||
see(from.y);
|
||||
see(to.y);
|
||||
see(center.y);
|
||||
}
|
||||
Primitive::Text { at, .. } | Primitive::DrawingText { at, .. } => see(at.y),
|
||||
Primitive::DrawingTextPath { path_pts, .. } => path_pts.iter().for_each(|q| see(q.y)),
|
||||
Primitive::DrawingCircle { center, r, .. } | Primitive::DrawingArc { center, r, .. } => see(center.y + r),
|
||||
Primitive::DrawingImage { min, max, .. } => {
|
||||
see(min.y);
|
||||
see(max.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Auswahl-Ids entfernen (die Geometrie stammt aus einer fremden Projektion) und dimmen.
|
||||
fn as_reference(pr: Primitive) -> Primitive {
|
||||
let mut pr = pr.with_greyed(true);
|
||||
match &mut pr {
|
||||
Primitive::Polygon { wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id, .. } => {
|
||||
for id in [wall_id, drawing_id, ceiling_id, opening_id, stair_id, room_id, extruded_solid_id, context_object_id, column_id, roof_id, section_line_id] {
|
||||
*id = None;
|
||||
}
|
||||
}
|
||||
Primitive::Line { drawing_id, opening_id, stair_id, .. } => {
|
||||
*drawing_id = None;
|
||||
*opening_id = None;
|
||||
*stair_id = None;
|
||||
}
|
||||
Primitive::Arc { opening_id, stair_id, .. } => {
|
||||
*opening_id = None;
|
||||
*stair_id = None;
|
||||
}
|
||||
Primitive::Text { room_id, .. } => *room_id = None,
|
||||
Primitive::DrawingText { drawing_id, .. }
|
||||
| Primitive::DrawingTextPath { drawing_id, .. }
|
||||
| Primitive::DrawingImage { drawing_id, .. }
|
||||
| Primitive::DrawingCircle { drawing_id, .. }
|
||||
| Primitive::DrawingArc { drawing_id, .. } => *drawing_id = None,
|
||||
}
|
||||
pr
|
||||
}
|
||||
|
||||
/// Legt die Grundriss-Primitive ausgerichtet unter einen Schnitt / eine Ansicht, deren tiefste Kante
|
||||
/// bei `section_min_y` liegt (`planUnderlayPrimitives`): gedimmt, ohne Auswahl-Ids, dazu die
|
||||
/// Schnittlinie. Ohne gültige Linie leer.
|
||||
pub fn underlay_primitives(line: Option<[Vec2; 2]>, direction_sign: Option<f64>, plan: impl IntoIterator<Item = Primitive>, section_min_y: f64) -> Vec<Primitive> {
|
||||
let Some(line) = line else { return vec![] };
|
||||
let Some(base) = section_map(line, direction_sign) else { return vec![] };
|
||||
let mut mapped = Vec::new();
|
||||
let mut top = f64::NEG_INFINITY;
|
||||
for pr in plan {
|
||||
let Some(q) = map_primitive(&base, pr) else { continue };
|
||||
max_y(&q, &mut top);
|
||||
mapped.push(q);
|
||||
}
|
||||
// Die Schnittlinie (w = 0) liegt immer mit in der Unterlage.
|
||||
if 0.0 > top {
|
||||
top = 0.0;
|
||||
}
|
||||
let shift = section_min_y - GAP_M - top;
|
||||
let o = Vec2 { x: 0.0, y: 0.0 };
|
||||
let shift_map = SectionMap { p0: o, u: Vec2 { x: 1.0, y: 0.0 }, n: Vec2 { x: 0.0, y: 1.0 }, theta: 0.0, dy: shift };
|
||||
let mut out: Vec<Primitive> = mapped.into_iter().filter_map(|q| map_primitive(&shift_map, q)).map(as_reference).collect();
|
||||
let [l0, l1] = line;
|
||||
let len = hypot2(l1.x - l0.x, l1.y - l0.y);
|
||||
out.push(Primitive::Line {
|
||||
a: Vec2 { x: 0.0, y: shift },
|
||||
b: Vec2 { x: len, y: shift },
|
||||
cls: "section-underlay-line".into(),
|
||||
weight_mm: 0.25,
|
||||
dash: Some(Some(vec![3.0, 0.8, 0.4, 0.8])),
|
||||
zigzag: None,
|
||||
motif: None,
|
||||
color: Some("#8a3b2c".into()),
|
||||
drawing_id: None,
|
||||
opening_id: None,
|
||||
stair_id: None,
|
||||
greyed: None,
|
||||
opacity: None,
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
/// Primitive eines `planDomains`-Ergebnisses in Plan-Reihenfolge: Haupt-Puffer mit den Zeichnungs-
|
||||
/// Stücken an Stelle ihrer (leeren) Gruppe 7.
|
||||
pub fn plan_out_primitives(out: &super::domains::PlanOut) -> Result<Vec<Primitive>, String> {
|
||||
use crate::plan_buf::View;
|
||||
let bad = || "planUnderlay: Plan-Puffer unlesbar".to_string();
|
||||
let v = View::parse(&out.main).ok_or_else(bad)?;
|
||||
let main = v.prims().ok_or_else(bad)?;
|
||||
let groups = v.groups().ok_or_else(bad)?;
|
||||
let at = groups.get(7).map_or(main.len(), |g| g.0);
|
||||
let mut prims = Vec::with_capacity(main.len());
|
||||
let mut it = main.into_iter();
|
||||
prims.extend(it.by_ref().take(at));
|
||||
for (_, bytes) in &out.chunks {
|
||||
let bytes = bytes.as_ref().ok_or_else(|| "planUnderlay: Zeichnungs-Stück fehlt".to_string())?;
|
||||
prims.extend(View::parse(bytes).and_then(|c| c.prims()).ok_or_else(bad)?);
|
||||
}
|
||||
prims.extend(it);
|
||||
Ok(prims)
|
||||
}
|
||||
|
||||
/// Argumente aus dem Abfrage-Text: die `planDomains`-Argumente des Geschosses plus `level` (Schnitt/
|
||||
/// Ansicht) und `minY` (tiefste Kante des Schnitts).
|
||||
pub fn parse_args(text: &str) -> Result<(Option<[Vec2; 2]>, Option<f64>, f64), String> {
|
||||
let v: serde_json::Value = serde_json::from_str(text).map_err(|e| format!("planUnderlay: {e}"))?;
|
||||
let level = super::section::LevelSpec::from_json(v.get("level").unwrap_or(&serde_json::Value::Null));
|
||||
let min_y = v.get("minY").and_then(|x| x.as_f64()).ok_or("planUnderlay: minY fehlt")?;
|
||||
Ok((level.line, level.direction_sign, min_y))
|
||||
}
|
||||
|
||||
/// Plan-Puffer (eine Gruppe) der Unterlage.
|
||||
pub fn underlay_buf(prims: &[Primitive]) -> Vec<u8> {
|
||||
let mut w = crate::plan_buf::Writer::new(false);
|
||||
w.group(prims);
|
||||
w.finish()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn v(x: f64, y: f64) -> Vec2 {
|
||||
Vec2 { x, y }
|
||||
}
|
||||
|
||||
fn line(a: Vec2, b: Vec2) -> Primitive {
|
||||
Primitive::Line { a, b, cls: "t".into(), weight_mm: 0.25, dash: None, zigzag: None, motif: None, color: None, drawing_id: Some("d".into()), opening_id: None, stair_id: None, greyed: None, opacity: None }
|
||||
}
|
||||
|
||||
/// Abfrage auf dem Dokument (Plan-Caches, Zeichnungs-Stücke) == ohne Cache.
|
||||
#[test]
|
||||
fn abfrage_mit_und_ohne_cache_gleich() {
|
||||
let text = include_str!("../../tests/fixtures/sample_project.json");
|
||||
let p: crate::model::Project = serde_json::from_str(text).unwrap();
|
||||
let mut d = crate::document::Document::from_json(text).unwrap();
|
||||
let sec = p.drawing_levels.iter().find(|l| l.line_points.is_some()).unwrap();
|
||||
for floor in p.drawing_levels.iter().filter(|l| l.kind == crate::model::DrawingLevelKind::Floor) {
|
||||
let show: Vec<&str> = p.layers.iter().map(|l| l.code.as_str()).collect();
|
||||
let args = serde_json::json!({ "floor": floor.id, "show": show, "scale": 100, "level": serde_json::to_value(sec).unwrap(), "minY": -0.25 }).to_string();
|
||||
let plain = crate::queries::run_bin(&p, "planUnderlay", &[1.0], &args).unwrap();
|
||||
for _ in 0..2 {
|
||||
assert_eq!(crate::queries::run_bin_doc(&mut d, "planUnderlay", &[1.0], &args).unwrap(), plain);
|
||||
}
|
||||
let n = crate::plan_buf::View::parse(&plain).unwrap().len();
|
||||
assert!(n > 5, "{n}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn blickrichtung_nach_oben_keine_spiegelung() {
|
||||
// Linie entlang +x, Blick nach +y: reine Verschiebung.
|
||||
let m = section_map([v(-1.0, 2.0), v(12.0, 2.0)], Some(1.0)).unwrap();
|
||||
assert!(m.theta.abs() < 1e-12);
|
||||
let q = map_point(&m, v(0.0, 5.0));
|
||||
assert!((q.x - 1.0).abs() < 1e-12 && (q.y - 3.0).abs() < 1e-12);
|
||||
// Umgekehrte Blickrichtung: 180°-Drehung.
|
||||
let r = section_map([v(-1.0, 2.0), v(12.0, 2.0)], Some(-1.0)).unwrap();
|
||||
assert!((r.theta.abs() - std::f64::consts::PI).abs() < 1e-12);
|
||||
assert!((map_point(&r, v(0.0, 0.0)).y - 2.0).abs() < 1e-12);
|
||||
assert!(section_map([v(1.0, 1.0), v(1.0, 1.0)], None).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn u_wie_schnittebene() {
|
||||
// Ein Punkt liegt senkrecht unter seiner Projektion im Schnitt (u wie `Plane::u_model`).
|
||||
for (l, p, sign) in [([v(-1.0, 2.0), v(12.0, 2.0)], v(4.0, 7.0), 1.0), ([v(3.0, 0.0), v(3.0, 9.0)], v(6.0, 2.0), -1.0), ([v(0.0, 0.0), v(5.0, 5.0)], v(1.0, 3.0), 1.0)] {
|
||||
let m = section_map(l, Some(sign)).unwrap();
|
||||
let plane = super::super::section::LevelSpec { line: Some(l), direction_sign: Some(sign), ..Default::default() }.plane().unwrap();
|
||||
let (ux, uy) = plane.u_model();
|
||||
let (bx, by) = plane.base();
|
||||
let len = hypot2(ux, uy);
|
||||
let expected = ((p.x - bx) * ux + (p.y - by) * uy) / len;
|
||||
assert!((map_point(&m, p).x - expected).abs() < 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unterlage_mit_abstand_gedimmt_ohne_ids_plus_schnittlinie() {
|
||||
let out = underlay_primitives(Some([v(-1.0, 2.0), v(12.0, 2.0)]), Some(1.0), vec![line(v(0.0, 0.0), v(11.0, 6.0))], -0.3);
|
||||
let Primitive::Line { a, b, greyed, drawing_id, .. } = &out[0] else { panic!() };
|
||||
assert_eq!((*greyed, drawing_id.as_deref()), (Some(true), None));
|
||||
// Oberste Grundriss-Kante (y = 6 → w = 4) liegt GAP unter der Schnitt-Unterkante.
|
||||
let top = a.y.max(b.y);
|
||||
assert!((top - (-0.3 - GAP_M)).abs() < 1e-9);
|
||||
assert!((a.x.min(b.x) - 1.0).abs() < 1e-9);
|
||||
let Primitive::Line { a, b, cls, greyed, dash, .. } = out.last().unwrap() else { panic!() };
|
||||
assert_eq!(cls, "section-underlay-line");
|
||||
assert_eq!(*greyed, None);
|
||||
assert_eq!(dash, &Some(Some(vec![3.0, 0.8, 0.4, 0.8])));
|
||||
assert!((b.x - a.x - 13.0).abs() < 1e-9 && (a.y - (top - 4.0)).abs() < 1e-9);
|
||||
assert!(underlay_primitives(None, None, vec![line(v(0.0, 0.0), v(1.0, 1.0))], 0.0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gedrehte_linie_dreht_schraffur_und_texte_bilder_entfallen() {
|
||||
use super::super::prim::HatchRender;
|
||||
let mut hatch: HatchRender = super::super::style::no_hatch();
|
||||
hatch.angle = 10.0;
|
||||
let poly = Primitive::Polygon { pts: vec![v(0.0, 0.0), v(1.0, 0.0), v(1.0, 1.0)], fill: "#fff".into(), stroke: "#000".into(), stroke_width_mm: 0.2, hatch, greyed: None, opacity: None, no_stroke_edges: None, wall_id: Some("W".into()), drawing_id: None, ceiling_id: None, opening_id: None, stair_id: None, room_id: None, extruded_solid_id: None, context_object_id: None, column_id: None, roof_id: None, section_line_id: None };
|
||||
let img = Primitive::DrawingImage { min: v(0.0, 0.0), max: v(1.0, 1.0), src: "x".into(), opacity: 1.0, drawing_id: None, greyed: None };
|
||||
// Linie entlang +y → Drehung um 90°.
|
||||
let out = underlay_primitives(Some([v(0.0, 0.0), v(0.0, 5.0)]), None, vec![poly, img], 0.0);
|
||||
assert_eq!(out.len(), 2, "Bild entfällt bei Drehung");
|
||||
let Primitive::Polygon { hatch, wall_id, greyed, .. } = &out[0] else { panic!() };
|
||||
assert_eq!((wall_id, *greyed), (&None, Some(true)));
|
||||
// Blick nach −x: θ = −90°, das Muster dreht um +90°.
|
||||
assert!((hatch.angle - 100.0).abs() < 1e-9, "{}", hatch.angle);
|
||||
}
|
||||
}
|
||||
@@ -153,6 +153,14 @@ pub fn run_bin(p: &Project, name: &str, args: &[f64], text: &str) -> Result<Vec<
|
||||
w.group(&drawings::level_markers(p, [args[0], args[1], args[2], args[3]]));
|
||||
Ok(w.finish())
|
||||
}
|
||||
// Grundriss-Unterlage unter Schnitt/Ansicht: `planDomains`-Argumente + `level`, `minY`.
|
||||
("planUnderlay", 1) => {
|
||||
let a = domains::PlanArgs::parse(args[0], text)?;
|
||||
let (line, sign, min_y) = crate::plan::underlay::parse_args(text)?;
|
||||
let bytes = domains::plan_domains_buf(p, &a)?;
|
||||
let prims = crate::plan_buf::View::parse(&bytes).and_then(|v| v.prims()).ok_or("planUnderlay: Plan-Puffer unlesbar")?;
|
||||
Ok(crate::plan::underlay::underlay_buf(&crate::plan::underlay::underlay_primitives(line, sign, prims, min_y)))
|
||||
}
|
||||
("sectionPlan", _) => crate::plan::section::section_plan_buf(p, args, text),
|
||||
("elevationPlan", _) => crate::plan::elevation::elevation_plan_buf(p, args, text),
|
||||
_ => Err(format!("Unbekannte Abfrage: {name}")),
|
||||
@@ -172,6 +180,15 @@ pub fn run_bin_doc(d: &mut crate::document::Document, name: &str, args: &[f64],
|
||||
let (p, revs, cache) = d.project_cached().map_err(model_err)?;
|
||||
return crate::plan::domains::plan_domains_cached(p, revs, cache, &a, &have).map(|o| o.encode());
|
||||
}
|
||||
if name == "planUnderlay" && args.len() == 1 {
|
||||
// Der Grundriss kommt aus den Plan-Caches (wie `generatePlan` desselben Geschosses).
|
||||
let a = crate::plan::domains::PlanArgs::parse(args[0], text)?;
|
||||
let (line, sign, min_y) = crate::plan::underlay::parse_args(text)?;
|
||||
let (p, revs, cache) = d.project_cached().map_err(model_err)?;
|
||||
let out = crate::plan::domains::plan_domains_cached(p, revs, cache, &a, &Default::default())?;
|
||||
let prims = crate::plan::underlay::plan_out_primitives(&out)?;
|
||||
return Ok(crate::plan::underlay::underlay_buf(&crate::plan::underlay::underlay_primitives(line, sign, prims, min_y)));
|
||||
}
|
||||
run_bin(d.project().map_err(model_err)?, name, args, text)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ mod imp {
|
||||
|
||||
impl GrowAhead {
|
||||
/// Nach einem Wachstum (Seitenzahl gestiegen) den Vorrat anlegen und gleich freigeben.
|
||||
#[inline]
|
||||
unsafe fn after(&self, before: usize) {
|
||||
let now = memory_size(0);
|
||||
if now == before {
|
||||
@@ -39,22 +38,31 @@ mod imp {
|
||||
}
|
||||
}
|
||||
|
||||
// Nie in den Aufrufer einbetten: mit LTO wurde `dealloc` (std-dlmalloc samt `validate_size`, das den
|
||||
// Chunk-Kopf VOR dem Zeiger liest) in Funktionen eingebettet, die den Block selbst angelegt hatten.
|
||||
// LLVM wertet den Lesezugriff ausserhalb der frischen Allokation als undefiniert und machte aus der
|
||||
// Prüfung eine bedingungslose Panik („psize >= size + min_overhead", z. B. in `roof::compute_canonical`
|
||||
// je nach Code-Layout). Als eigener Aufruf ist die Allokator-Hülle für LLVM undurchsichtig.
|
||||
unsafe impl GlobalAlloc for GrowAhead {
|
||||
#[inline(never)]
|
||||
unsafe fn alloc(&self, l: Layout) -> *mut u8 {
|
||||
let before = memory_size(0);
|
||||
let p = System.alloc(l);
|
||||
self.after(before);
|
||||
p
|
||||
}
|
||||
#[inline(never)]
|
||||
unsafe fn alloc_zeroed(&self, l: Layout) -> *mut u8 {
|
||||
let before = memory_size(0);
|
||||
let p = System.alloc_zeroed(l);
|
||||
self.after(before);
|
||||
p
|
||||
}
|
||||
#[inline(never)]
|
||||
unsafe fn dealloc(&self, p: *mut u8, l: Layout) {
|
||||
System.dealloc(p, l)
|
||||
}
|
||||
#[inline(never)]
|
||||
unsafe fn realloc(&self, p: *mut u8, l: Layout, n: usize) -> *mut u8 {
|
||||
let before = memory_size(0);
|
||||
let q = System.realloc(p, l, n);
|
||||
|
||||
Reference in new issue
Block a user