From 93229b79e7cf973a228bde02c19a1bf206c4870f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Nov 2026 20:21:31 +0000 Subject: [PATCH] =?UTF-8?q?[207]=20Gef=C3=BCllte=20Kataster-Geb=C3=A4ude/G?= =?UTF-8?q?ew=C3=A4sser=20tragen=20die=20Zeichnungs-Id=20(anw=C3=A4hlbar):?= =?UTF-8?q?=20Ringe=20behalten=20ihre=20Zeichnung,=20Polygone=20nach=20dem?= =?UTF-8?q?=20Verschachteln=20ordnen=20sie=20=C3=BCber=20den=20Eckpunkt=20?= =?UTF-8?q?zu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/plan/drawings.rs | 10 ++++-- src-tauri/core/src/plan/situation.rs | 49 +++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src-tauri/core/src/plan/drawings.rs b/src-tauri/core/src/plan/drawings.rs index c3d4dc87..193c747a 100644 --- a/src-tauri/core/src/plan/drawings.rs +++ b/src-tauri/core/src/plan/drawings.rs @@ -1930,8 +1930,13 @@ pub fn plan_drawings(c: &Ctx, sink: &mut Sink, bounds: &mut Bounds) -> Result<() /// auf Klassen, die `pred` (Klassen-Code) wählt und die der Plan zeigt; je Klasse in Projekt-Reihenfolge. Quelle der /// gefüllten Kataster-Gebäude und -Gewässer im Situationsplan (`situation.rs`). pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec>)> { + closed_rings_by_class_ids(c, pred).into_iter().map(|(k, v)| (k, v.into_iter().map(|(_, r)| r).collect())).collect() +} + +/// Wie [`closed_rings_by_class`], aber jeder Ring trägt die Id seiner Zeichnung (Anwahl der gefüllten Flächen). +pub fn closed_rings_by_class_ids(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec<(String, Vec<[f64; 2]>)>)> { let mut memo = Memo::default(); - let mut out: Vec<(String, Vec>)> = Vec::new(); + let mut out: Vec<(String, Vec<(String, Vec<[f64; 2]>)>)> = Vec::new(); for d in &c.p.drawings2d { if !matches!(d.geom, Drawing2DGeom::Polyline { closed: true, .. } | Drawing2DGeom::Rect { .. }) || !pred(&d.category_code) || !on_floor(c, d) { continue; @@ -1952,9 +1957,10 @@ pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(Strin if rings.is_empty() { continue; } + let rings = rings.into_iter().map(|r| (d.id.clone(), r)); match out.iter_mut().find(|(k, _)| *k == d.category_code) { Some((_, v)) => v.extend(rings), - None => out.push((d.category_code.clone(), rings)), + None => out.push((d.category_code.clone(), rings.collect())), } } out diff --git a/src-tauri/core/src/plan/situation.rs b/src-tauri/core/src/plan/situation.rs index d49ecffa..c60c37aa 100644 --- a/src-tauri/core/src/plan/situation.rs +++ b/src-tauri/core/src/plan/situation.rs @@ -193,12 +193,31 @@ pub fn mesh_polygons(positions: &[f64], indices: &[f64]) -> Vec { /// Gefüllte Flächen: ein Polygon je Fläche; Löcher sind über Brücken eingebunden (Brückenkanten ohne Strich). fn fill_polygons(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec) { + fill_polygons_of(polys, f, context_id, greyed, out, |_| None) +} + +/// Wie [`fill_polygons`]; `drawing_of` nennt je Polygon die Zeichnung, der es gehört (Anwahl im Plan). +fn fill_polygons_of(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec, drawing_of: impl Fn(&Polygon) -> Option) { for poly in polys { - let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { continue }; + let from = out.len(); + fill_polygon(poly, f, context_id, greyed, out); + if let Some(id) = drawing_of(poly) { + for q in &mut out[from..] { + if let Primitive::Polygon { drawing_id, .. } = q { + *drawing_id = Some(id.clone()); + } + } + } + } +} + +fn fill_polygon(poly: &Polygon, f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec) { + { + let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { return }; let holes: Vec = poly.iter().skip(1).filter(|r| r.len() >= 3).cloned().collect(); if holes.is_empty() { out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed)); - continue; + return; } let merged = crate::polygon_holes::merge_holes(outer, &holes, 1e-4); let mut prim = polygon(merged.ring.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed); @@ -231,15 +250,17 @@ fn name_has(c: &Ctx, code: &str, words: &[&str]) -> bool { /// der Klasse der Zeichnung (die Klasse bestimmt über [`super::drawings::closed_rings_by_class`], ob sie erscheinen). /// Innenhöfe sind Löcher. Unterhalb der Zeichnungen; deren Linien bleiben darüber. pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec) { - let fills = |kind: fn(&Ctx, &str) -> bool| super::drawings::closed_rings_by_class(c, |code| kind(c, code)); + let fills = |kind: fn(&Ctx, &str) -> bool| super::drawings::closed_rings_by_class_ids(c, |code| kind(c, code)); if let Some(f) = colors(s.context) { for (code, rings) in fills(is_building_class) { - fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), f, None, c.greyed(&code), out); + let (polys, owner) = nest_with_owner(&rings); + fill_polygons_of(&polys, f, None, c.greyed(&code), out, owner); } } for (code, rings) in fills(is_water_class) { let from = out.len(); - fill_polygons(&crate::polygon_bool::nest_even_odd(&rings), WATER, None, c.greyed(&code), out); + let (polys, owner) = nest_with_owner(&rings); + fill_polygons_of(&polys, WATER, None, c.greyed(&code), out, owner); for q in &mut out[from..] { if let Primitive::Polygon { hatch, .. } = q { *hatch = Box::new(water_hatch(c.a.scale)); @@ -248,6 +269,24 @@ pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec) { } } +/// Verschachtelt die Ringe (gerade/ungerade) und liefert dazu die Zuordnung Polygon → Zeichnung: Der Aussenring eines +/// Polygons gehört der Zeichnung, deren Ring denselben Eckpunkt hat (kleinster Flächenunterschied bei mehreren). +fn nest_with_owner(rings: &[(String, Ring)]) -> (Vec, impl Fn(&Polygon) -> Option + '_) { + let plain: Vec = rings.iter().map(|(_, r)| r.clone()).collect(); + let area = |r: &Ring| (0..r.len()).map(|i| r[i][0] * r[(i + 1) % r.len()][1] - r[(i + 1) % r.len()][0] * r[i][1]).sum::().abs() / 2.0; + let owner = move |poly: &Polygon| -> Option { + let outer = poly.first()?; + let a = area(outer); + let p0 = *outer.first()?; + rings + .iter() + .filter(|(_, r)| r.contains(&p0)) + .min_by(|x, y| (area(&x.1) - a).abs().total_cmp(&(area(&y.1) - a).abs())) + .map(|(id, _)| id.clone()) + }; + (crate::polygon_bool::nest_even_odd(&plain), owner) +} + /// Wasser als feine waagrechte Parallelschraffur (Plangrafik-Brauch für Gewässer): bleibt in Tusche erhalten, wo die /// hellblaue Fläche weiss wird (`extras::Post`: bunte Fläche → Papier, bunte Schraffur → Tinte). Abstand auf dem /// Papier fest ([`WATER_HATCH_MM`]), unabhängig vom Massstab; Musterabstand = 8 · scale / 90 m.