SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Naming: a piece name finds its face once the face is whole again (#11731) (#13147)
dudedagger428f1143b94042
diff --git a/crates/doc/src/history_names.rs b/crates/doc/src/history_names.rsindex 2e1f75a1e1..d5da1c0a54 100644--- a/crates/doc/src/history_names.rs+++ b/crates/doc/src/history_names.rs@@ -571,9 +571,12 @@ pub(crate) fn matches(names: &Names, index: usize, name: &str) -> Option<Match>if descends(current, name) {return Some(Match::Piece);}- // The named piece, told apart by the faces around it: they still bound this piece.+ // The named piece, told apart by the faces around it: they still bound this piece. Or the+ // face it was a piece of, whole again since, which they still bound: the piece is all of it+ // (#11731). Only a piece told apart by faces: a numbered one (`#2`, nothing told it apart)+ // says nothing about which part of the whole face it was.if let Some((stem, around)) = crate::piece_names::piece_parts(name)- && crate::naming::parent_piece(current) == Some(stem)+ && (crate::naming::parent_piece(current) == Some(stem) || (current == stem && !around.is_empty() && name.ends_with(']')))&& info.is_some_and(|i| around.iter().all(|f| i.bounds.contains(*f))){return Some(Match::Piece);diff --git a/crates/doc/src/history_names_tests.rs b/crates/doc/src/history_names_tests.rsindex b9bbaaba0a..2ea4745cc2 100644--- a/crates/doc/src/history_names_tests.rs+++ b/crates/doc/src/history_names_tests.rs@@ -171,3 +171,21 @@ fn a_linked_designs_face_names_keep_their_pieces_and_nothing_else() {let _ = role(n);}}++/// A face that was split when a name was stored and is whole again (#11731): the stored piece+/// is all of it, when the face still touches the faces that told the piece apart.+#[test]+fn a_piece_name_finds_its_face_once_it_is_whole_again() {+ let faces = named(&["top", "left", "right", "start"]);+ let names = qualify(faces, &[(0, 1), (0, 3)]);+ assert_eq!(names.faces[0], "top");+ assert_eq!(matches(&names, 0, "top#[left]"), Some(Match::Piece));+ assert_eq!(matches(&names, 0, "top#[left,start]"), Some(Match::Piece));+ // It no longer touches a face the qualifier names: some other piece, gone since.+ assert_eq!(matches(&names, 0, "top#[right]"), Some(Match::Stem));+ assert_eq!(matches(&names, 0, "top#[left]@F9.1"), None, "a copy's piece");+ // A numbered piece (nothing told it apart, or a tie) says nothing about which part it was.+ assert_eq!(matches(&names, 0, "top#1"), Some(Match::Stem));+ assert_eq!(matches(&names, 0, "top#[left]#2"), Some(Match::Stem));+ assert_eq!(matches(&names, 0, "top#[]"), Some(Match::Stem));+}diff --git a/crates/doc/src/named_projection_tests.rs b/crates/doc/src/named_projection_tests.rsindex 2b83ed2732..5d4f6792bb 100644--- a/crates/doc/src/named_projection_tests.rs+++ b/crates/doc/src/named_projection_tests.rs@@ -243,3 +243,57 @@ fn numbered_projection_refuses_a_pick_inside_a_hole_in_the_named_face() {assert_eq!(pick(5.).map(|(index, _)| index), Some(top));assert!(pick(0.).is_none(), "the pick is on the plane but inside the hole");}++/// An edge picked when its side face was split in two keeps the piece in its name+/// (`F2:side:l1#[F2:start]`); once the side is one face again the edge is still found (#11731).+#[test]+fn an_edge_named_by_a_piece_of_a_face_that_is_whole_again_is_found() {+ let doc = Document {+ features: serde_json::from_value(serde_json::json!([+ {+ "id": 1, "name": "Sketch1", "type": "sketch", "plane": {"name": "XY", "type": "origin"},+ "sketch": {+ "points": [+ {"fixed": true, "id": "origin", "pos": [0., 0.]},+ {"fixed": false, "id": "p1", "pos": [0., 0.]},+ {"fixed": false, "id": "p2", "pos": [10., 0.]},+ {"fixed": false, "id": "p3", "pos": [10., 16.1]},+ {"fixed": false, "id": "p4", "pos": [0., 16.1]}+ ],+ "curves": [+ {"a": 1, "b": 2, "construction": false, "id": "l1", "type": "line"},+ {"a": 2, "b": 3, "construction": false, "id": "l2", "type": "line"},+ {"a": 3, "b": 4, "construction": false, "id": "l3", "type": "line"},+ {"a": 4, "b": 1, "construction": false, "id": "l4", "type": "line"}+ ],+ "constraints": [],+ "counters": {"k": 0, "l": 4, "p": 4}+ }+ },+ {+ "id": 2, "name": "Extrude1", "type": "extrude", "body_names": ["Body1"],+ "extent": {"convention": "total_distance", "direction": "positive", "distance": "5"},+ "operation": "new_body", "profiles": {"loops": [["l1", "l2", "l3", "l4"]], "type": "curves"}, "sketch": 1+ }+ ]))+ .unwrap(),+ ..Document::default()+ };+ let doc = crate::format::read(&doc.to_json()).unwrap();+ let mut model = crate::Model::new();+ model.evaluate(&doc);+ let state = model.state();+ let body = state.body("Body1").unwrap();+ // The side along x = 0 meets the start cap in the edge under the pick.+ let near = Vec3::new(0., 8.05, 0.);+ let names = crate::naming::edge_names(body);+ let whole = names.iter().find(|n| n.contains("F2:start") && n.contains("F2:side:l4")).expect("the side's edge on the start cap");+ let piece = whole.replace("F2:side:l4", "F2:side:l4#[F2:start]");+ let hit = crate::name_lookup::locate_edge(body, &piece, near).unwrap_or_else(|e| panic!("{piece}: {e}"));+ assert!(hit.on_point, "the edge under the saved pick");+ assert_eq!(hit.point, near);+ assert_eq!(names.get(hit.edge), Some(whole));+ // A piece told apart by a face the side never touches (the opposite side) is still refused.+ let gone = whole.replace("F2:side:l4", "F2:side:l4#[F2:side:l2]");+ assert!(crate::name_lookup::locate_edge(body, &gone, near).is_err(), "{gone}");+}