Merge [207] Situation/Schwarzplan 1:500

This commit is contained in:
Claude committed 2026-11-12 19:46:59 +00:00
commit d4e7597000
32 files changed
+812 -38

No files matched your search

+1
View File
@@ -22,6 +22,7 @@ Herkunft, kein Wegweiser.
| `drawings.rs` | freie 2D-Zeichnungen (Linie bis Bild, Bemassung, Blöcke), Zeichnungs-Stücke, kompakte Linien-Unterlage |
| `context.rs` | Kontext (Höhenlinien, Fussabdrücke importierter Gebäude, Gelände) und Schnittführungs-Symbole |
| `mesh_plan.rs` | importierte Netze und ([G1]) freie Körper über ihr Kern-Netz im Grundriss: geschnitten, darunter, darüber |
| `situation.rs` | Situationsplan/Schwarzplan ([207]): Modelldarstellung mit `situation` ersetzt die Bauteile durch den gefüllten Umriss des eigenen Gebäudes (Klasse 83), füllt Kontextnetze (Klasse des Netzes) und zeichnet Nordpfeil/Massstabsbalken (Klasse 84) |
| `ceiling_plan.rs` | Deckenspiegel als eigene Ebenen-Art |
| `floor_finish.rs` | Bodenbelag-Muster nach Massstab |
| `model_view.rs` | Modelldarstellung ([173]): Optionen je Bauteilart über dem Detailgrad, Rangfolge Element > Typ > Stufe > Basis |
+20 -2
View File
@@ -73,10 +73,23 @@ pub fn plan_context_with(c: &Ctx, out: &mut Vec<Primitive>, drawing_obstacles: &
let mut late: Vec<Primitive> = Vec::new();
// [140]/[150] Höhenlinien, Böschungsschraffur und Beschriftungen enden am Fussabdruck des Geschosses.
let mut house_cache: Option<Vec<Vec<Vec2>>> = None;
let mut house = || -> Vec<Vec<Vec2>> { house_cache.get_or_insert_with(|| terrain_footprint(c.p, &c.a.floor)).clone() };
// [207] Situationsplan: Kontextgebäude gefüllt; die Höhenlinien enden auch an ihnen.
let sit = super::situation::opts(c);
let mut house = || -> Vec<Vec<Vec2>> {
house_cache
.get_or_insert_with(|| {
let mut h = terrain_footprint(c.p, &c.a.floor);
if let Some(s) = &sit {
h.extend(super::situation::own_rings(c.p));
h.extend(super::situation::context_rings(c, s));
}
h
})
.clone()
};
let mut label_obst: Option<super::stamp_place::Obstacles> = None;
// [152] Importierte Netze im Geschoss nach dem Ansichtsbereich (`mesh_plan.rs`); sonst Fussabdruck.
let meshes_done = super::mesh_plan::plan_meshes(c, out);
let meshes_done = sit.is_none() && super::mesh_plan::plan_meshes(c, out);
for obj in c.p.context.as_deref().unwrap_or(&[]) {
if meshes_done && matches!(obj, ContextObject::ImportedMesh(_)) {
continue;
@@ -121,6 +134,11 @@ pub fn plan_context_with(c: &Ctx, out: &mut Vec<Primitive>, drawing_obstacles: &
}
}
}
ContextObject::ImportedMesh(m) if sit.is_some() => {
if let Some(s) = &sit {
super::situation::context_mesh(c, s, m, out);
}
}
ContextObject::ImportedMesh(m) => {
let f = crate::plan::misc::context_footprint(&m.positions, &m.indices);
let n = f.first().copied().unwrap_or(0.0) as usize;
+27 -2
View File
@@ -189,6 +189,11 @@ impl<'a> Ctx<'a> {
})
}
/// [207] Situationsplan der wirksamen Modelldarstellung (`None` = gewöhnlicher Grundriss).
pub fn situation(&self) -> Option<&ModelViewSituation> {
self.mv_sel.and_then(|m| m.situation.as_ref())
}
/// [173] Aufgelöste Darstellungsoptionen dieser Plan-Erzeugung (`plan/model_view.rs`).
pub fn mv(&self) -> &super::model_view::Options {
&self.mv
@@ -1739,6 +1744,12 @@ fn domains_before(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds) -> Result
if super::ceiling_plan::domains(c, out, bounds)? {
return Ok(());
}
// [207] Situationsplan: das eigene Gebäude als gefüllter Umriss statt der Bauteile (nur Bäume bleiben).
if let Some(s) = super::situation::opts(c) {
super::situation::own_prims(c, &s, &mut out.roofs, bounds);
super::trees::plan_trees(c, &mut out.columns);
return Ok(());
}
ceilings(c, &mut out.ceilings, bounds)?;
roofs(c, &mut out.roofs, bounds);
super::walls::plan_walls(c, c.a.reference_lines, &mut out.walls, bounds)?;
@@ -1770,7 +1781,9 @@ fn domains_after(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds, marks: &mu
return;
}
let drawn = drawing_obstacles(c);
if c.a.global {
// [207] Situationsplan: keine Schnittführungen, Räume und Bodenbeläge; dafür Nordpfeil und Massstabsbalken.
let sit = super::situation::opts(c);
if c.a.global && sit.is_none() {
// [150] Schnittführungen zuerst: ihre Beschriftungen sind Hindernisse der Höhenlinien-Beschriftungen.
super::context::plan_section_lines(c, &mut out.sections);
// [157] Marken und Beschriftungen der Schnittführungen gehören zum Ausmass (sonst oben abgeschnitten).
@@ -1802,7 +1815,9 @@ fn domains_after(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds, marks: &mu
}
let obstacles = stamp_obstacles_with(out, drawn.clone());
let mut top = Vec::new();
rooms(c, &mut out.rooms, &mut top, bounds, &obstacles);
if sit.is_none() {
rooms(c, &mut out.rooms, &mut top, bounds, &obstacles);
}
if c.a.global {
let mut o = drawn;
for q in out.sections.iter().filter(|q| matches!(q, Primitive::DrawingText { .. })) {
@@ -1830,6 +1845,12 @@ fn domains_after(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds, marks: &mu
}
super::trees::plan_tree_labels(c, &o, &mut out.columns);
}
if let Some(s) = &sit {
if c.a.global {
super::situation::symbol_prims(c, s, &mut out.sections, bounds);
}
return;
}
// [156] Bodenbelag nach den Raumstempeln (spart sie aus), zuunterst in der Gruppe der Decken.
let mut finish = Vec::new();
floor_finishes(c, &stamp_prims(&out.rooms, &top), &mut finish);
@@ -1909,6 +1930,10 @@ fn extras_of(p: &Project, a: &PlanArgs) -> (Vec<(Primitive, u32)>, Vec<Primitive
if a.global {
// [66] Baurecht (Parzelle, Baubereich, Verstösse) gehört zur Vermessung: ausgeblendete Kategorie „01" ⇒ ohne.
let site = crate::standards::derived_visible(p, super::extras::SITE_CATEGORY, |k| a.show.contains(k));
// [207] Situationsplan: nur die Parzellengrenze, ohne Baubereich, Verstösse und Schatten.
if super::situation::active(p, a) {
return (if site { super::extras::parcel_only(p) } else { Vec::new() }, Vec::new());
}
// [180] Sonnenschatten auf der Klasse „Schatten".
let sun_when = a.sun_when.filter(|_| crate::standards::derived_visible(p, crate::standards::SHADOW_CATEGORY, |k| a.show.contains(k)));
super::extras::site_and_shadow(p, &a.floor, sun_when, a.scale, site)
+10
View File
@@ -217,6 +217,16 @@ pub fn site_and_shadow(p: &Project, floor: &str, when_ms: Option<f64>, scale: f6
(under, violations)
}
/// [207] Situationsplan: nur die Parzellengrenze des Baurechts (ohne Baubereich, Verstösse und Schatten), auf der
/// Klasse „01"; Strichstärke wie im Baurecht.
pub fn parcel_only(p: &Project) -> Vec<(Primitive, u32)> {
let mut under = Vec::new();
if let Some(rules) = p.site_rules.as_ref().filter(|r| r.parcel.len() >= 3) {
ring_lines(&mut under, &rules.parcel, SITE_PARCEL_CLS, PARCEL_COLOR, 0.35, &PARCEL_DASH, 1);
}
under
}
// ── Abzugskörper ────────────────────────────────────────────────────────────────────────────────
const EPS: f64 = 1e-7;
+1
View File
@@ -41,6 +41,7 @@ pub mod model_view;
pub mod trees;
pub mod cameras;
pub mod mesh_plan;
pub mod situation;
pub mod arc_fit;
pub(crate) mod seams;
pub(crate) mod wall_columns;
+2 -2
View File
@@ -262,7 +262,7 @@ fn mitgelieferte_stufen_aus_den_standards() {
.map(|v| serde_json::from_value(v).unwrap())
.collect();
let names: Vec<&str> = add.iter().map(|m| m.name.as_str()).collect();
assert_eq!(names, ["Wettbewerb 1:200", "Baueingabe 1:100", "Ausführung 1:50", "Rohbau/Statik"]);
assert_eq!(names, ["Wettbewerb 1:200", "Baueingabe 1:100", "Ausführung 1:50", "Situation WBW", "Schwarzplan", "Rohbau/Statik"]);
// Alles bekannt (keine verlorenen Felder) und unterscheidbar.
for m in &add {
assert!(m.extra.0.is_empty(), "{}: {:?}", m.name, m.extra);
@@ -271,7 +271,7 @@ fn mitgelieferte_stufen_aus_den_standards() {
let w = resolve(Some(&add[0]), crate::plan::style::Detail::Mittel, 200.0);
assert_eq!(w.dims.chains, DimChains::Total);
assert_eq!(w.stamp.number, Some(false));
let r = resolve(Some(&add[3]), crate::plan::style::Detail::Mittel, 100.0);
let r = resolve(add.iter().find(|m| m.name == "Rohbau/Statik"), crate::plan::style::Detail::Mittel, 100.0);
assert_eq!(r.wall.layers, LayerMode::Core);
let a = resolve(Some(&add[2]), crate::plan::style::Detail::Fein, 50.0);
assert!(a.stair.step_numbers && a.stamp.height == Some(true));
+314
View File
@@ -0,0 +1,314 @@
//! [207] Situationsplan / Schwarzplan (Wettbewerb, 1:500): eine Modelldarstellung mit `situation` ersetzt im
//! Grundriss die Bauteile durch Flächen.
//!
//! - **Eigenes Gebäude** (Klasse „83 Situation Gebäude", [`OWN_CATEGORY`]): Umriss über alle Geschosse ab dem
//! Erdgeschoss (Wände, Decken, freie Körper) und die Dächer (mit Überstand, Dachaufsicht), vereinigt und
//! gefüllt (Standard schwarz).
//! - **Kontextgebäude** (importierte Netze, [181]; Klasse des Netzes, z. B. „12 Gebäude"): Grundfläche aus der
//! Aufsicht (Vereinigung der Dreiecke), gefüllt (Standard grau, „Schwarzplan": schwarz).
//! - **Planzeichen** (Klasse „84 Planzeichen", [`SYMBOL_CATEGORY`]): Nordpfeil und Massstabsbalken unter der
//! Lage, Grösse in Papier-mm.
//!
//! Wände, Treppen, Räume, Stützen, Körper, Bodenbeläge und Schnittmarken entfallen (`domains.rs`); Parzelle,
//! Strassen, Höhenlinien und Beschriftungen sind gewöhnliche Zeichnungen/Kontext auf ihren Klassen und
//! bleiben, solange die Klasse sichtbar ist (Ansichtsvorlage „Situation WBW", `standards.rs`).
//! Löcher (Innenhöfe) der Umrisse füllt eine weisse Fläche darüber.
use super::domains::{Bounds, Ctx};
use super::drawings::mm_to_model;
use super::prim::Primitive;
use super::style::no_hatch;
use crate::flat::{Polygon, Ring};
use crate::model::*;
/// Klasse des eigenen Gebäudes im Situationsplan.
pub const OWN_CATEGORY: &str = crate::standards::SITUATION_CATEGORY;
/// Klasse von Nordpfeil und Massstabsbalken.
pub const SYMBOL_CATEGORY: &str = crate::standards::SYMBOL_CATEGORY;
const BLACK: (&str, &str) = ("#000000", "#000000");
const GREY: (&str, &str) = ("#b8b8b8", "#7c7c7c");
const OUTLINE_MM: f64 = 0.1;
/// Eine Dreiecksfläche unter 1 cm² trägt nichts zur Aufsicht bei (senkrechte Wände, Splitter).
const MIN_TRI_AREA: f64 = 1e-4;
/// Aufgelöste Optionen des Situationsplans.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Opts {
pub own: SituationFill,
pub context: SituationFill,
pub symbols: bool,
}
impl Opts {
pub fn of(s: &ModelViewSituation) -> Opts {
let fill = |f: Option<SituationFill>, d: SituationFill| match f {
Some(SituationFill::Unknown) | None => d,
Some(f) => f,
};
Opts { own: fill(s.own, SituationFill::Black), context: fill(s.context, SituationFill::Grey), symbols: s.symbols.unwrap_or(true) }
}
}
fn colors(f: SituationFill) -> Option<(&'static str, &'static str)> {
match f {
SituationFill::Black => Some(BLACK),
SituationFill::Grey => Some(GREY),
_ => None,
}
}
fn v2(q: [f64; 2]) -> Vec2 {
Vec2 { x: q[0], y: q[1] }
}
fn polygon(pts: Vec<Vec2>, fill: &str, stroke: &str, w: f64, context_id: Option<&str>, greyed: bool) -> Primitive {
Primitive::Polygon {
pts,
fill: fill.into(),
stroke: stroke.into(),
stroke_width_mm: w,
hatch: Box::new(no_hatch()),
greyed: greyed.then_some(true),
opacity: None,
no_stroke_edges: None,
wall_id: None,
drawing_id: None,
ceiling_id: None,
opening_id: None,
stair_id: None,
room_id: None,
extruded_solid_id: None,
context_object_id: context_id.map(String::from),
column_id: None,
roof_id: None,
section_line_id: None,
}
}
fn line(a: Vec2, b: Vec2, w: f64) -> Primitive {
Primitive::Line { a, b, cls: "situation-symbol".into(), weight_mm: w, dash: None, zigzag: None, motif: None, color: Some("#000000".into()), drawing_id: None, opening_id: None, stair_id: None, greyed: None, opacity: None }
}
fn text(at: Vec2, s: &str, h: f64) -> Primitive {
Primitive::DrawingText { at, text: s.into(), height_m: h, angle: 0.0, color: "#000000".into(), marks: None, wrap_width: None, doc: None, drawing_id: None, greyed: None, opacity: None }
}
/// Die Situation dieser Plan-Erzeugung (`None` = gewöhnlicher Grundriss).
pub fn opts(c: &Ctx) -> Option<Opts> {
c.situation().map(Opts::of)
}
/// Ist für diese Plan-Argumente der Situationsplan gewählt (ohne [`Ctx`], für die Zutaten)?
pub fn active(p: &Project, a: &super::domains::PlanArgs) -> bool {
super::model_view::selected_id(p, &a.floor, a.model_view.as_deref()).and_then(|id| super::model_view::find(p, id)).is_some_and(|m| m.situation.is_some())
}
/// Bodenhöhe des Erdgeschosses (Geschoss nächst ±0.00); `None` ohne Geschosse.
fn ground_base(p: &Project) -> Option<f64> {
super::extras::ground_floor_id(p).and_then(|id| p.floor(id)).map(|l| l.base_elevation.unwrap_or(0.0))
}
/// Eigenes Gebäude über dem Terrain: Wände, Decken und freie Körper der Geschosse ab dem Erdgeschoss
/// (Untergeschosse zählen nicht) und alle Dächer samt Überstand, vereinigt (Aussenringe mit Löchern).
pub fn own_polygons(p: &Project) -> Vec<Polygon> {
let base = ground_base(p);
let above = |floor: &str| match (base, p.floor(floor)) {
(Some(g), Some(l)) => l.base_elevation.unwrap_or(0.0) >= g - 0.05,
_ => true,
};
let ok = |q: &[f64; 2]| q[0].is_finite() && q[1].is_finite();
let mut parts: Vec<Polygon> = Vec::new();
for w in p.walls.iter().filter(|w| above(&w.floor_id)) {
if let Some(f) = crate::site_rules::wall_footprint(p, w).filter(|f| f.len() >= 3 && f.iter().all(ok)) {
parts.push(vec![f]);
}
}
for c in p.ceilings.as_deref().unwrap_or(&[]).iter().filter(|c| above(&c.floor_id)) {
let r = c.ring_xy();
if r.len() >= 3 && r.iter().all(ok) {
parts.push(vec![r]);
}
}
for s in p.extruded_solids.as_deref().unwrap_or(&[]).iter().filter(|s| above(&s.level_id) && s.operation.as_deref() != Some("subtract")) {
let r: Ring = s.points.iter().map(|q| [q.x, q.y]).collect();
if r.len() >= 3 && r.iter().all(ok) {
parts.push(vec![r]);
}
}
for r in p.roofs.as_deref().unwrap_or(&[]) {
let g = crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r));
if g.eaves.len() >= 3 && g.eaves.iter().all(ok) {
let mut poly = vec![g.eaves.clone()];
poly.extend(g.eaves_holes.iter().filter(|h| h.len() >= 3 && h.iter().all(ok)).cloned());
parts.push(poly);
}
}
if parts.is_empty() {
return Vec::new();
}
crate::polygon_bool::union(&parts)
}
/// Aussenringe des eigenen Gebäudes (Höhenlinien enden an ihnen).
pub fn own_rings(p: &Project) -> Vec<Vec<Vec2>> {
own_polygons(p).iter().filter_map(|poly| poly.first().filter(|r| r.len() >= 3)).map(|r| r.iter().map(|q| v2(*q)).collect()).collect()
}
/// Grundfläche eines Netzes aus der Aufsicht: Vereinigung der Dreiecke in der Projektion (senkrechte Flächen
/// fallen weg). Ein Netz ohne Fläche ⇒ leer.
pub fn mesh_polygons(positions: &[f64], indices: &[f64]) -> Vec<Polygon> {
let n = positions.len() / 3;
let mut tris: Vec<Polygon> = Vec::new();
for t in indices.chunks_exact(3) {
if t.iter().any(|i| !(*i >= 0.0) || i.fract() != 0.0 || *i as usize >= n) {
continue;
}
let q = |i: f64| [positions[i as usize * 3], positions[i as usize * 3 + 1]];
let (a, b, c) = (q(t[0]), q(t[1]), q(t[2]));
if ![a, b, c].iter().all(|p| p[0].is_finite() && p[1].is_finite()) {
continue;
}
let area = ((b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1])) / 2.0;
if area.abs() < MIN_TRI_AREA {
continue;
}
// Gegen den Uhrzeigersinn (die Vereinigung verlangt einheitlichen Umlaufsinn).
tris.push(vec![if area > 0.0 { vec![a, b, c] } else { vec![a, c, b] }]);
}
if tris.is_empty() {
return Vec::new();
}
crate::polygon_bool::union(&tris)
}
/// Gefüllte Flächen: Aussenring in der Füllung, jedes Loch als weisse Fläche darüber.
fn fill_polygons(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec<Primitive>) {
for poly in polys {
let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { continue };
out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed));
for hole in poly.iter().skip(1).filter(|r| r.len() >= 3) {
out.push(polygon(hole.iter().map(|q| v2(*q)).collect(), "#ffffff", f.1, OUTLINE_MM, None, greyed));
}
}
}
fn acc_polys(polys: &[Polygon], bounds: &mut Bounds) {
for q in polys.iter().filter_map(|p| p.first()).flatten() {
bounds.acc(q[0], q[1]);
}
}
/// Eigenes Gebäude als gefüllter Umriss (Gruppe „Dächer", unterhalb der Zeichnungen); Klasse „83".
pub fn own_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>, bounds: &mut Bounds) {
let Some(f) = colors(s.own) else { return };
if !c.derived_shown(OWN_CATEGORY) {
return;
}
let polys = own_polygons(c.p);
acc_polys(&polys, bounds);
fill_polygons(&polys, f, None, c.greyed(OWN_CATEGORY), out);
}
/// Aussenringe der Kontextgebäude, die diese Ansicht zeigt (Höhenlinien enden an ihnen).
pub fn context_rings(c: &Ctx, s: &Opts) -> Vec<Vec<Vec2>> {
let mut out = Vec::new();
if colors(s.context).is_none() {
return out;
}
for m in imported_meshes(c) {
for poly in mesh_polygons(&m.positions, &m.indices) {
if let Some(o) = poly.first().filter(|r| r.len() >= 3) {
out.push(o.iter().map(|q| v2(*q)).collect());
}
}
}
out
}
/// Die importierten Netze, deren Klasse sichtbar ist.
fn imported_meshes<'a>(c: &'a Ctx) -> impl Iterator<Item = &'a ImportedMesh> {
c.p.context.as_deref().unwrap_or(&[]).iter().filter_map(move |o| match o {
ContextObject::ImportedMesh(m) if c.shown(&m.category_code) => Some(m),
_ => None,
})
}
/// Ein Kontextgebäude als gefüllte Grundfläche (auf der Klasse des Netzes; Pick-Id = das Netz).
pub fn context_mesh(c: &Ctx, s: &Opts, m: &ImportedMesh, out: &mut Vec<Primitive>) {
let Some(f) = colors(s.context) else { return };
let polys = mesh_polygons(&m.positions, &m.indices);
fill_polygons(&polys, f, Some(&m.id), c.greyed(&m.category_code), out);
}
/// Nordpfeil und Massstabsbalken unter der Lage (Klasse „84"), rechtsbündig zum Ausmass von Gebäude, Parzelle
/// und Kontext. Ohne Gebäude kein Anhaltspunkt ⇒ keine Zeichen.
pub fn symbol_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>, bounds: &mut Bounds) {
if !s.symbols || !c.derived_shown(SYMBOL_CATEGORY) {
return;
}
let mut bb = Bounds::new();
acc_polys(&own_polygons(c.p), &mut bb);
for m in imported_meshes(c) {
acc_polys(&mesh_polygons(&m.positions, &m.indices), &mut bb);
}
if let Some(r) = c.p.site_rules.as_ref().map(|r| &r.parcel) {
for q in r {
bb.acc(q.x, q.y);
}
}
let Some([_, min_y, max_x, _]) = bb.get() else { return };
out.extend(symbols(c.a.scale, max_x, min_y));
for q in out.iter() {
match q {
Primitive::Polygon { pts, .. } => pts.iter().for_each(|p| bounds.acc(p.x, p.y)),
Primitive::Line { a, b, .. } => {
bounds.acc(a.x, a.y);
bounds.acc(b.x, b.y);
}
Primitive::DrawingText { at, .. } => bounds.acc(at.x, at.y),
_ => {}
}
}
}
/// Länge des Massstabsbalkens (m): die grösste runde Länge, die auf dem Papier höchstens 50 mm misst.
pub fn scalebar_total(scale: f64) -> f64 {
const TOTALS: [f64; 10] = [1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 500.0, 1000.0];
TOTALS.iter().rev().copied().find(|m| m * 1000.0 / scale <= 50.0).unwrap_or(TOTALS[0])
}
/// Nordpfeil und Massstabsbalken; `right`/`below` = rechter Rand und Oberkante der Lage (Modell-Meter), die
/// Zeichen stehen darunter (Papierabstand 12 mm). Norden = +y.
pub fn symbols(scale: f64, right: f64, below: f64) -> Vec<Primitive> {
let mm = |v: f64| mm_to_model(v, scale);
let mut out = Vec::new();
// Massstabsbalken: vier Felder, abwechselnd gefüllt; Beschriftung 0 / halbe Länge / Länge.
let total = scalebar_total(scale);
let len = total;
let (y1, h) = (below - mm(12.0), mm(1.6));
let x0 = right - len;
for i in 0..4 {
let (a, b) = (x0 + len * i as f64 / 4.0, x0 + len * (i + 1) as f64 / 4.0);
let fill = if i % 2 == 0 { "#000000" } else { "#ffffff" };
out.push(polygon(vec![Vec2 { x: a, y: y1 - h }, Vec2 { x: b, y: y1 - h }, Vec2 { x: b, y: y1 }, Vec2 { x: a, y: y1 }], fill, "#000000", 0.18, None, false));
}
let th = mm(2.5);
let label = |v: f64| if v.fract() == 0.0 { format!("{v:.0}") } else { format!("{v}") };
out.push(text(Vec2 { x: x0 - mm(0.6), y: y1 - h - th * 1.4 }, "0", th));
out.push(text(Vec2 { x: x0 + len / 2.0 - mm(1.0), y: y1 - h - th * 1.4 }, &label(total / 2.0), th));
out.push(text(Vec2 { x: right - mm(1.0) * (label(total).len() as f64 + 2.0), y: y1 - h - th * 1.4 }, &format!("{} m", label(total)), th));
// Nordpfeil links vom Balken: halb gefüllte Spitze, „N" darüber.
let (cx, cy, r) = (x0 - mm(14.0), y1 - h / 2.0 - mm(3.0), mm(6.0));
let top = Vec2 { x: cx, y: cy + r };
let mid = Vec2 { x: cx, y: cy - r * 0.35 };
out.push(polygon(vec![top, Vec2 { x: cx + r * 0.45, y: cy - r * 0.75 }, mid], "#000000", "#000000", 0.18, None, false));
out.push(polygon(vec![top, mid, Vec2 { x: cx - r * 0.45, y: cy - r * 0.75 }], "#ffffff", "#000000", 0.18, None, false));
out.push(line(top, Vec2 { x: cx, y: cy - r }, 0.18));
out.push(text(Vec2 { x: cx - mm(1.0), y: cy + r + mm(1.2) }, "N", mm(3.5)));
out
}
#[cfg(test)]
#[path = "situation_tests.rs"]
mod tests;
+149
View File
@@ -0,0 +1,149 @@
//! [207] Situationsplan / Schwarzplan: eigenes Gebäude schwarz, Kontext grau (bzw. schwarz), Klassen, Planzeichen.
use super::*;
use crate::plan::domains::{plan_domains_buf, PlanArgs};
use crate::standards::{derived_categories, model_views, SITUATION_CATEGORY, SYMBOL_CATEGORY};
use serde_json::{json, Value};
/// Würfel 10 × 6 × 8 m an (x0, y0), Dreiecke wie beim Import (aussen, ohne Boden-Duplikate).
fn box_mesh(id: &str, category: &str, x0: f64, y0: f64) -> Value {
let (x1, y1) = (x0 + 10.0, y0 + 6.0);
let positions = [x0, y0, 0.0, x1, y0, 0.0, x1, y1, 0.0, x0, y1, 0.0, x0, y0, 8.0, x1, y0, 8.0, x1, y1, 8.0, x0, y1, 8.0];
let indices = [0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 0, 1, 5, 0, 5, 4, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 0, 4, 3, 4, 7];
json!({"type": "importedMesh", "id": id, "name": id, "categoryCode": category, "positions": positions.to_vec(), "indices": indices.to_vec()})
}
fn project() -> Project {
let mut v: Value = serde_json::from_str(include_str!("../../tests/fixtures/sample_project.json")).unwrap();
v["layers"].as_array_mut().unwrap().extend(derived_categories());
v["layers"].as_array_mut().unwrap().push(json!({"code": "12", "name": "Gebäude", "color": "#888888", "lw": 0.18, "visible": true, "locked": false}));
// Untergeschoss mit einer Wand ausserhalb des Hauses: zählt nicht zum Gebäude über dem Terrain.
v["drawingLevels"].as_array_mut().unwrap().push(json!({"id": "ug", "name": "UG", "kind": "floor", "visible": true, "locked": false, "baseElevation": -2.7}));
v["walls"].as_array_mut().unwrap().push(json!({"id": "w-ug", "type": "wall", "floorId": "ug", "categoryCode": "20", "start": {"x": 20, "y": 0}, "end": {"x": 25, "y": 0}, "wallTypeId": "aw", "height": 2.6}));
v["modelViewOptions"] = Value::Array(model_views());
v["context"] = json!([box_mesh("nachbar-1", "12", 12.0, -1.0), box_mesh("nachbar-2", "12", -14.0, 5.0)]);
serde_json::from_value(v).unwrap()
}
fn codes(p: &Project) -> Vec<String> {
p.flat_categories().iter().map(|c| c.code.clone()).collect()
}
fn plan(p: &Project, show: &[String], model_view: &str) -> Vec<Primitive> {
let a = PlanArgs::parse(1.0, &json!({"floor": "eg", "show": show, "global": true, "scale": 500, "modelView": model_view}).to_string()).unwrap();
let buf = plan_domains_buf(p, &a).unwrap();
crate::plan::buf::View::parse(&buf).unwrap().prims().unwrap()
}
fn without(codes: &[String], code: &str) -> Vec<String> {
codes.iter().filter(|c| *c != code).cloned().collect()
}
fn fills<'a>(ps: &'a [Primitive], color: &str) -> Vec<&'a Primitive> {
ps.iter().filter(|q| matches!(q, Primitive::Polygon { fill, .. } if fill == color)).collect()
}
fn ring_area(pts: &[Vec2]) -> f64 {
(0..pts.len()).map(|i| (pts[i].x * pts[(i + 1) % pts.len()].y - pts[(i + 1) % pts.len()].x * pts[i].y) / 2.0).sum::<f64>().abs()
}
#[test]
fn eigenes_gebaeude_schwarz_ohne_bauteile() {
let p = project();
let ps = plan(&p, &codes(&p), "std-mv-situation-wbw");
// Keine Wand-Poché, keine Raumstempel, keine Schnittmarken.
assert!(!ps.iter().any(|q| matches!(q, Primitive::Polygon { wall_id: Some(_), .. })), "Wände entfallen");
assert!(!ps.iter().any(|q| matches!(q, Primitive::Text { room_id: Some(_), .. })), "Raumstempel entfallen");
let black: Vec<_> = fills(&ps, "#000000").into_iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, stroke_width_mm, .. } if *stroke_width_mm == 0.1)).collect();
assert_eq!(black.len(), 1, "ein schwarzer Umriss (UG-Wand zählt nicht)");
let Primitive::Polygon { pts, .. } = black[0] else { unreachable!() };
assert!(pts.iter().all(|q| q.x < 6.0), "nur das Haus über dem Terrain: {pts:?}");
let a = ring_area(pts);
assert!(a > 15.0 && a < 40.0, "Fläche des Hauses: {a}");
}
#[test]
fn kontext_grau_und_schwarzplan_schwarz() {
let p = project();
let wbw = plan(&p, &codes(&p), "std-mv-situation-wbw");
let grey: Vec<_> = wbw.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), fill, .. } if fill == "#b8b8b8")).collect();
assert_eq!(grey.len(), 2, "zwei Nachbarn grau");
let Primitive::Polygon { pts, context_object_id, .. } = grey[0] else { unreachable!() };
assert_eq!(context_object_id.as_deref(), Some("nachbar-1"));
assert!((ring_area(pts) - 60.0).abs() < 1e-6, "Grundfläche aus der Aufsicht: {}", ring_area(pts));
let sp = plan(&p, &codes(&p), "std-mv-schwarzplan");
let black_ctx = sp.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), fill, .. } if fill == "#000000")).count();
assert_eq!(black_ctx, 2, "Schwarzplan: Nachbarn schwarz");
}
#[test]
fn alles_auf_klassen() {
let p = project();
let all = codes(&p);
let own = |ps: &[Primitive]| ps.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: None, fill, stroke_width_mm, .. } if fill == "#000000" && *stroke_width_mm == 0.1)).count();
let ctx = |ps: &[Primitive]| ps.iter().filter(|q| matches!(q, Primitive::Polygon { context_object_id: Some(_), .. })).count();
let north = |ps: &[Primitive]| ps.iter().any(|q| matches!(q, Primitive::DrawingText { text, .. } if text == "N"));
let base = plan(&p, &all, "std-mv-situation-wbw");
assert!(own(&base) == 1 && ctx(&base) == 2 && north(&base));
let no_own = plan(&p, &without(&all, SITUATION_CATEGORY), "std-mv-situation-wbw");
assert!(own(&no_own) == 0 && ctx(&no_own) == 2 && north(&no_own), "Klasse 83 schaltet das eigene Gebäude");
let no_ctx = plan(&p, &without(&all, "12"), "std-mv-situation-wbw");
assert!(own(&no_ctx) == 1 && ctx(&no_ctx) == 0, "Klasse der Netze schaltet den Kontext");
let no_sym = plan(&p, &without(&all, SYMBOL_CATEGORY), "std-mv-situation-wbw");
assert!(own(&no_sym) == 1 && !north(&no_sym), "Klasse 84 schaltet Nordpfeil und Massstabsbalken");
}
#[test]
fn gewoehnlicher_grundriss_bleibt() {
let p = project();
let ps = plan(&p, &codes(&p), "mittel");
assert!(ps.iter().any(|q| matches!(q, Primitive::Polygon { wall_id: Some(_), .. })));
assert!(fills(&ps, "#b8b8b8").is_empty());
assert!(!ps.iter().any(|q| matches!(q, Primitive::DrawingText { text, .. } if text == "N")));
}
#[test]
fn dachaufsicht_zaehlt_zum_gebaeude() {
let p = project();
let Some(r) = p.roofs.as_deref().and_then(|r| r.first()) else { panic!("Fixture hat ein Dach") };
let g = crate::roof::roof_geometry(&r.params(), p.roof_base_elevation(r));
let polys = own_polygons(&p);
let (min_x, max_x) = g.eaves.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |a, q| (a.0.min(q[0]), a.1.max(q[0])));
let xs: Vec<f64> = polys.iter().flat_map(|q| q[0].iter().map(|r| r[0])).collect();
assert!(xs.iter().cloned().fold(f64::INFINITY, f64::min) <= min_x + 1e-6 && xs.iter().cloned().fold(f64::NEG_INFINITY, f64::max) >= max_x - 1e-6, "Umriss deckt die Traufe");
}
#[test]
fn netz_flaeche_ohne_senkrechte() {
// Nur senkrechte Dreiecke: keine Fläche in der Aufsicht.
let pos = [0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 5.0, 0.0, 3.0];
assert!(mesh_polygons(&pos, &[0.0, 1.0, 2.0]).is_empty());
// Ungültige Indizes und NaN: ohne Panic leer.
assert!(mesh_polygons(&[0.0, 0.0, 0.0, f64::NAN, 0.0, 0.0, 1.0, 1.0, 0.0], &[0.0, 1.0, 2.0, 0.0, 9.0, 1.0]).is_empty());
}
#[test]
fn massstabsbalken_rund_und_im_papiermass() {
assert_eq!(scalebar_total(500.0), 20.0);
assert_eq!(scalebar_total(1000.0), 50.0);
assert_eq!(scalebar_total(200.0), 10.0);
let s = symbols(500.0, 40.0, -10.0);
// Vier Balkenfelder + zwei Spitzenhälften, alle unter der Lage (Papierabstand 12 mm = 6 m).
let polys: Vec<_> = s.iter().filter_map(|q| if let Primitive::Polygon { pts, .. } = q { Some(pts) } else { None }).collect();
assert_eq!(polys.len(), 6);
assert!(polys.iter().flat_map(|p| p.iter()).all(|q| q.y < -10.0), "unter der Oberkante der Lage");
}
#[test]
fn baurecht_nur_parzellengrenze() {
let mut p = project();
p.site_rules = Some(serde_json::from_value(json!({"parcel": [{"x": -8, "y": -8}, {"x": 16, "y": -8}, {"x": 16, "y": 12}, {"x": -8, "y": 12}], "setbacks": [3, 3, 3, 3], "defaultSetback": 3, "show": true})).unwrap());
let mut all = codes(&p);
all.push("01".into());
let ps = plan(&p, &all, "std-mv-situation-wbw");
let cls = |c: &str| ps.iter().filter(|q| matches!(q, Primitive::Line { cls, .. } if cls == c)).count();
assert!(cls("site-parcel") >= 4, "Parzellengrenze bleibt");
assert_eq!(cls("site-allowed"), 0, "kein Baubereich");
let normal = plan(&p, &all, "mittel");
assert!(normal.iter().filter(|q| matches!(q, Primitive::Line { cls, .. } if cls == "site-allowed")).count() > 0, "im gewöhnlichen Grundriss schon");
}