diff --git a/crates/doc/src/construct.rs b/crates/doc/src/construct.rs index dc41296c3..4ab6a9783 100644 --- a/crates/doc/src/construct.rs +++ b/crates/doc/src/construct.rs @@ -215,10 +215,16 @@ fn named_vertex(st: &ModelState, at: Vec3, names: &[String]) -> Option { let ends: Vec<[Vec3; 2]> = names .iter() .map(|n| { - // The edge with that name itself, never the one nearest the old pick. - let on = bodies(st).find_map(|b| crate::naming::find_edge(b, n, at).ok())?.0; - let pts = edge_points(st, on, &None).ok()?; - Some([*pts.first()?, *pts.last()?]) + // The edge with that name itself, never the one nearest the old pick, and its ends + // on the body that has it: picked again by a point on it, a corner found the first + // edge of any body through that corner, such as another body's edge running past + // it, so a vertex took that edge's end (#8650). + bodies(st).find_map(|b| { + let hit = crate::name_lookup::locate_edge(b, n, at).ok()?; + let m = b.mesh(); + let pts = m.edges.get(hit.edge)?; + Some([*pts.first()?, *pts.last()?]) + }) }) .collect::>()?; let (first, rest) = ends.split_first()?; diff --git a/crates/engine/src/construct_tests.rs b/crates/engine/src/construct_tests.rs index a124cd4b6..3fe9f2c49 100644 --- a/crates/engine/src/construct_tests.rs +++ b/crates/engine/src/construct_tests.rs @@ -380,6 +380,29 @@ fn a_plane_through_three_vertices_follows_them() { } } +/// A corner of one box where another box's edge runs past it, as where a wall meets the side +/// wall it stands against (the render-studio example, #8650): the vertex stays that corner. Its +/// edges were found by name and then picked again by a point, which took the first edge through +/// the corner of any body, the side wall's, and so its end 3 mm away. Three such corners were +/// "on one line". +#[test] +fn a_vertex_where_another_bodys_edge_runs_past_stays_its_corner() { + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"corner": [29, -22, 4], "length": 3, "width": 44, "height": 19, "body_name": "Side"})); + run(&mut s, "solid.box", json!({"corner": [-29, 19, 4], "length": 58, "width": 3, "height": 19, "body_name": "Back"})); + run(&mut s, "construct.point.vertex", json!({"point": {"vertex": [29, 19, 23]}, "name": "P"})); + assert!(near(point(&s, "P"), Vec3::new(29.0, 19.0, 23.0)), "{:?}", point(&s, "P")); + run( + &mut s, + "construct.plane.three_points", + json!({"a": {"vertex": [29, 22, 23]}, "b": {"vertex": [29, 22, 4]}, "c": {"vertex": [29, 19, 23]}, "name": "T"}), + ); + let t = plane(&s, "T"); + for p in [Vec3::new(29.0, 22.0, 23.0), Vec3::new(29.0, 22.0, 4.0), Vec3::new(29.0, 19.0, 23.0)] { + assert!(on_plane(&t, p), "{p:?} is off {t:?}"); + } +} + /// In a component moved 50 mm along X, picks given in the world land on its geometry, and the /// axis and point move with the occurrence. #[test]