SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Section Analysis: view.pick skips edges and vertices in the removed half (#10704) (#10712)
Dahak Builds5336007c2bfe
diff --git a/crates/ui-egui/src/view_pick.rs b/crates/ui-egui/src/view_pick.rsindex 2c864fc924..65b940581e 100644--- a/crates/ui-egui/src/view_pick.rs+++ b/crates/ui-egui/src/view_pick.rs@@ -150,9 +150,22 @@ pub fn pick_command(app: &mut SolveApp, p: &Value) -> Result<Value, String> {.and_then(|(so, sn)| section_cap(app, &st, &bounds, input, so, sn, kept.first().map(|c| c.t), include_ghosted, replaced, &active_bodies));let face_t = kept.first().map(|c| c.t).or(cap.as_ref().map(|(t, _, _)| *t));let (edge, vertex) = match (edges_on, input.pixel) {- (true, Some(pos)) => {- near_edges(app, &st, &bounds, &proj, input, pos, face_t, edge_px, &active_bodies, replaced, include_ghosted, wireframe, slack)- }+ (true, Some(pos)) => near_edges(+ app,+ &st,+ &bounds,+ &proj,+ input,+ pos,+ face_t,+ edge_px,+ &active_bodies,+ replaced,+ include_ghosted,+ wireframe,+ slack,+ section,+ ),_ => (None, None),};hits.push(match (all, cap, kept) {@@ -382,11 +395,16 @@ fn near_edges(include_ghosted: bool,wireframe: bool,slack: f64,+ section: Option<(Vec3, Vec3)>,) -> (Option<EdgeHit>, Option<VertexHit>) {let reach = crate::pick_index::reach(proj, pos, edge_px.max(6.0));+ // The section removes a half-space and nothing there is drawn, so the mouse picker skips+ // edges and vertices in it; a pick must not answer with what the user cannot see (#10704,+ // the same `kept` test `viewport::pick` applies).+ let kept = |p: Vec3| section.is_none_or(|(so, sn)| sn.dot(p) <= sn.dot(so) + SECTION_EPS);// `slack` is the body's own: what counts as lying on the face in front depends on how// coarsely that body is meshed, never on where the camera stands.- let visible = |p: Vec3, slack: f64| wireframe || face_t.is_none_or(|t| (p - input.o).dot(input.d) <= t + slack);+ let visible = |p: Vec3, slack: f64| kept(p) && (wireframe || face_t.is_none_or(|t| (p - input.o).dot(input.d) <= t + slack));let mut best_e: Option<EdgeHit> = None;let mut best_v: Option<VertexHit> = None;for (i, b) in st.bodies.iter().enumerate() {diff --git a/crates/ui-egui/src/view_pick_tests.rs b/crates/ui-egui/src/view_pick_tests.rsindex 16148beadc..46c493e1dc 100644--- a/crates/ui-egui/src/view_pick_tests.rs+++ b/crates/ui-egui/src/view_pick_tests.rs@@ -237,3 +237,40 @@ fn the_mouse_picker_stops_at_a_section_cap() {other => panic!("the top face: {other:?}"),}}++/// With a Section Analysis on, `view.pick` must not answer with edges or vertices in the+/// half the section removes: the mouse picker has skipped them since #6722, and an agent+/// must not get an answer the user cannot see (#10704).+#[test]+fn a_section_pick_skips_edges_and_vertices_in_the_removed_half() {+ let mut h = Harness::new();+ h.call("engine.execute", json!({"command": "solid.box", "params": {"length": 40, "width": 30, "height": 20}}));+ h.app.cam = Camera {+ target: Vec3::new(20.0, 15.0, 10.0),+ yaw: 0.0,+ pitch: std::f64::consts::FRAC_PI_2,+ roll: 0.0,+ distance: 200.0,+ fov: 0.0,+ up: Default::default(),+ };+ // Section XZ at 15 mm: keeps y 0..15, removes y 15..30.+ h.call("engine.execute", json!({"command": "inspect.section", "params": {"plane": {"origin": [0, 15, 0], "normal": [0, 1, 0]}}}));+ // The same projection the model-frame pick builds, so a world point's pixel can be picked.+ let rect = egui::Rect::from_min_size(egui::pos2(0.0, 0.0), egui::vec2(960.0, 600.0));+ let cam = h.app.cam;+ let proj = crate::viewport::Proj { cam, vp: cam.view_proj(960.0 / 600.0, crate::viewport::scene_radius(&h.app)), rect };+ let px = |p: [f64; 3]| {+ let sp = proj.to_screen(Vec3::new(p[0], p[1], p[2])).unwrap();+ json!([sp.x as f64, sp.y as f64])+ };+ // Top-view pixels on the removed half's top edge, corner, and mid-edge: nothing is drawn+ // there, so the pick answers with nothing (it used to return the edge, with `body: null`).+ for w in [[40.0, 25.0, 20.0], [40.0, 30.0, 20.0], [20.0, 30.0, 20.0]] {+ let r = pick(&mut h, json!({"pixels": [px(w)]}));+ assert_eq!(r["hits"][0], serde_json::Value::Null, "the removed half must pick nothing at {w:?}: {}", r["hits"][0]);+ }+ // The same pick on the kept half's edge (y < 15) still answers with that edge.+ let r = pick(&mut h, json!({"pixels": [px([40.0, 5.0, 20.0])]}));+ assert!(r["hits"][0]["edge"].get("index").is_some(), "the kept half's edge must still pick: {}", r["hits"][0]);+}