From d146e66c71477346cbe09c3d088982f7cedebe7f Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 12 Nov 2026 20:56:04 +0000 Subject: [PATCH] =?UTF-8?q?[207]=20Netz-Pick=20im=20Grundriss=20je=20zusam?= =?UTF-8?q?menh=C3=A4ngendem=20Teil=20statt=20einer=20H=C3=BCllbox=20?= =?UTF-8?q?=C3=BCber=20alle=20(Klick=20in=20den=20Garten=20w=C3=A4hlte=20d?= =?UTF-8?q?ie=20Nachbargeb=C3=A4ude)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/core/src/plan/mesh_plan.rs | 69 ++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/src-tauri/core/src/plan/mesh_plan.rs b/src-tauri/core/src/plan/mesh_plan.rs index 9ca102b9..df183423 100644 --- a/src-tauri/core/src/plan/mesh_plan.rs +++ b/src-tauri/core/src/plan/mesh_plan.rs @@ -202,15 +202,76 @@ pub fn plan_meshes(c: &Ctx, out: &mut Vec) -> bool { return true; } draw_items(c, &range, &items, out); - // Pick-Flächen (Hüllbox) zuletzt: Klick wählt das Netz. + // Pick-Flächen zuletzt: je zusammenhängendem Teil des Netzes eine Hüllbox (nicht eine Box über alles — sonst + // wählt ein Klick in den Garten zwischen mehreren Nachbarbauten eines Netzes das Netz, [204]/[207]). for it in &items { - let b = &it.m.info.bbox; - let pts = vec![Vec2 { x: b[0], y: b[1] }, Vec2 { x: b[3], y: b[1] }, Vec2 { x: b[3], y: b[4] }, Vec2 { x: b[0], y: b[4] }]; - out.push(super::context::pick_band(pts, Some(&it.m.mesh.id), None)); + for b in part_boxes(&it.m.mesh.positions, &it.m.mesh.indices) { + let pts = vec![Vec2 { x: b[0], y: b[1] }, Vec2 { x: b[2], y: b[1] }, Vec2 { x: b[2], y: b[3] }, Vec2 { x: b[0], y: b[3] }]; + out.push(super::context::pick_band(pts, Some(&it.m.mesh.id), None)); + } } true } +/// Hüllboxen `[x0, y0, x1, y1]` der zusammenhängenden Teile eines Netzes (Dreiecke mit gemeinsamer Ecke gehören +/// zusammen; Union-Find über die Indizes, linear). Kaputte Indizes/Koordinaten werden übersprungen. +pub(crate) fn part_boxes(positions: &[f64], indices: &[f64]) -> Vec<[f64; 4]> { + let n = positions.len() / 3; + let mut parent: Vec = (0..n).collect(); + fn find(p: &mut [usize], mut i: usize) -> usize { + while p[i] != i { + p[i] = p[p[i]]; + i = p[i]; + } + i + } + let ok = |i: f64| i >= 0.0 && i.fract() == 0.0 && (i as usize) < n; + let mut used = vec![false; n]; + for t in indices.chunks_exact(3) { + if !t.iter().all(|i| ok(*i)) { + continue; + } + let (a, b, c) = (t[0] as usize, t[1] as usize, t[2] as usize); + for v in [a, b, c] { + used[v] = true; + } + let (ra, rb) = (find(&mut parent, a), find(&mut parent, b)); + parent[rb] = ra; + let (ra, rc) = (find(&mut parent, a), find(&mut parent, c)); + parent[rc] = ra; + } + let mut boxes: std::collections::BTreeMap = std::collections::BTreeMap::new(); + for v in (0..n).filter(|v| used[*v]) { + let (x, y) = (positions[3 * v], positions[3 * v + 1]); + if !(x.is_finite() && y.is_finite()) { + continue; + } + let r = find(&mut parent, v); + let b = boxes.entry(r).or_insert([x, y, x, y]); + b[0] = b[0].min(x); + b[1] = b[1].min(y); + b[2] = b[2].max(x); + b[3] = b[3].max(y); + } + boxes.into_values().collect() +} + +#[cfg(test)] +mod part_box_tests { + use super::part_boxes; + + /// Zwei getrennte Dreiecke ⇒ zwei Boxen (der Raum dazwischen ist nicht anwählbar); kaputte Indizes ⇒ übersprungen. + #[test] + fn getrennte_teile_eigene_boxen() { + let pos = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 10.0, 10.0, 0.0, 11.0, 10.0, 0.0, 10.0, 11.0, 0.0]; + let mut b = part_boxes(&pos, &[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 9.0, 1.0, f64::NAN]); + b.sort_by(|a, c| a[0].total_cmp(&c[0])); + assert_eq!(b, vec![[0.0, 0.0, 1.0, 1.0], [10.0, 10.0, 11.0, 11.0]]); + // verbundene Dreiecke (gemeinsame Ecke) ⇒ eine Box + assert_eq!(part_boxes(&pos[..12], &[0.0, 1.0, 2.0, 1.0, 3.0, 2.0]).len(), 1); + } +} + /// [G1] Freie Körper des Geschosses über ihr Kern-Netz (`solid_mesh::body_mesh`), wie importierte Netze: /// geschnitten ⇒ Ebenenschnitt als Poché (mit Eckenradius/Fase, Löchern, Verjüngung, B-Rep-Grundkörpern; /// Füllung/SIA-Schraffur aus `componentId`, ab 1:100 schwarz) und der Teil darunter als Aufsicht; ganz