[207] Gefüllte Kataster-Gebäude/Gewässer tragen die Zeichnungs-Id (anwählbar): Ringe behalten ihre Zeichnung, Polygone nach dem Verschachteln ordnen sie über den Eckpunkt zu
This commit is contained in:
2 files changed
+52
-7
No files matched your search
@@ -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
|
/// 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`).
|
/// 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<Vec<[f64; 2]>>)> {
|
pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(String, Vec<Vec<[f64; 2]>>)> {
|
||||||
|
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 memo = Memo::default();
|
||||||
let mut out: Vec<(String, Vec<Vec<[f64; 2]>>)> = Vec::new();
|
let mut out: Vec<(String, Vec<(String, Vec<[f64; 2]>)>)> = Vec::new();
|
||||||
for d in &c.p.drawings2d {
|
for d in &c.p.drawings2d {
|
||||||
if !matches!(d.geom, Drawing2DGeom::Polyline { closed: true, .. } | Drawing2DGeom::Rect { .. }) || !pred(&d.category_code) || !on_floor(c, d) {
|
if !matches!(d.geom, Drawing2DGeom::Polyline { closed: true, .. } | Drawing2DGeom::Rect { .. }) || !pred(&d.category_code) || !on_floor(c, d) {
|
||||||
continue;
|
continue;
|
||||||
@@ -1952,9 +1957,10 @@ pub fn closed_rings_by_class(c: &Ctx, pred: impl Fn(&str) -> bool) -> Vec<(Strin
|
|||||||
if rings.is_empty() {
|
if rings.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let rings = rings.into_iter().map(|r| (d.id.clone(), r));
|
||||||
match out.iter_mut().find(|(k, _)| *k == d.category_code) {
|
match out.iter_mut().find(|(k, _)| *k == d.category_code) {
|
||||||
Some((_, v)) => v.extend(rings),
|
Some((_, v)) => v.extend(rings),
|
||||||
None => out.push((d.category_code.clone(), rings)),
|
None => out.push((d.category_code.clone(), rings.collect())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out
|
out
|
||||||
|
|||||||
@@ -193,12 +193,31 @@ pub fn mesh_polygons(positions: &[f64], indices: &[f64]) -> Vec<Polygon> {
|
|||||||
|
|
||||||
/// Gefüllte Flächen: ein Polygon je Fläche; Löcher sind über Brücken eingebunden (Brückenkanten ohne Strich).
|
/// 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<Primitive>) {
|
fn fill_polygons(polys: &[Polygon], f: (&str, &str), context_id: Option<&str>, greyed: bool, out: &mut Vec<Primitive>) {
|
||||||
|
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<Primitive>, drawing_of: impl Fn(&Polygon) -> Option<String>) {
|
||||||
for poly in polys {
|
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<Primitive>) {
|
||||||
|
{
|
||||||
|
let Some(outer) = poly.first().filter(|r| r.len() >= 3) else { return };
|
||||||
let holes: Vec<Ring> = poly.iter().skip(1).filter(|r| r.len() >= 3).cloned().collect();
|
let holes: Vec<Ring> = poly.iter().skip(1).filter(|r| r.len() >= 3).cloned().collect();
|
||||||
if holes.is_empty() {
|
if holes.is_empty() {
|
||||||
out.push(polygon(outer.iter().map(|q| v2(*q)).collect(), f.0, f.1, OUTLINE_MM, context_id, greyed));
|
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 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);
|
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).
|
/// 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.
|
/// Innenhöfe sind Löcher. Unterhalb der Zeichnungen; deren Linien bleiben darüber.
|
||||||
pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>) {
|
pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>) {
|
||||||
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) {
|
if let Some(f) = colors(s.context) {
|
||||||
for (code, rings) in fills(is_building_class) {
|
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) {
|
for (code, rings) in fills(is_water_class) {
|
||||||
let from = out.len();
|
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..] {
|
for q in &mut out[from..] {
|
||||||
if let Primitive::Polygon { hatch, .. } = q {
|
if let Primitive::Polygon { hatch, .. } = q {
|
||||||
*hatch = Box::new(water_hatch(c.a.scale));
|
*hatch = Box::new(water_hatch(c.a.scale));
|
||||||
@@ -248,6 +269,24 @@ pub fn cadastre_prims(c: &Ctx, s: &Opts, out: &mut Vec<Primitive>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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<Polygon>, impl Fn(&Polygon) -> Option<String> + '_) {
|
||||||
|
let plain: Vec<Ring> = 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::<f64>().abs() / 2.0;
|
||||||
|
let owner = move |poly: &Polygon| -> Option<String> {
|
||||||
|
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
|
/// 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
|
/// 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.
|
/// Papier fest ([`WATER_HATCH_MM`]), unabhängig vom Massstab; Musterabstand = 8 · scale / 90 m.
|
||||||
|
|||||||
Reference in new issue
Block a user