From d25f8198fa2791c31a704b65e0531280e9e35692 Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Wed, 4 Nov 2026 05:59:42 +0000 Subject: [PATCH] Pieces of a cut keep their names when the design is evaluated again (#11658) A cut that leaves a body in pieces names them after their faces (`order_lumps`): the piece whose least face name sorts first takes the first name, and so on. It moved the names but left the pieces where the kernel put them. The session then pinned the feature's body names in that state order, and the next full evaluation (opening the design, or editing a parameter upstream) handed them out again in a different order: two pieces swapped names, and a later feature that named one met the other. Found by a local model fuzzer. The pieces now also take the family's places in name order, so the names pinned are the order the next evaluation hands them out in. A design saved before keeps the names a fresh evaluation gave it. Co-authored-by: Claude Opus 5.5 --- crates/doc/src/lineage.rs | 17 +++++++++--- crates/engine/src/naming_history_tests.rs | 34 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/crates/doc/src/lineage.rs b/crates/doc/src/lineage.rs index 94557d611..386e1c333 100644 --- a/crates/doc/src/lineage.rs +++ b/crates/doc/src/lineage.rs @@ -757,10 +757,19 @@ pub(crate) fn order_lumps(bodies: &mut [crate::ModelBody], origin: &Arc = members.iter().filter_map(|i| bodies.get(*i).map(|b| (b.name.clone(), b.feature))).collect(); - for ((name, feature), (_, i)) in names.into_iter().zip(keys) { - if let Some(b) = bodies.get_mut(i) { - b.name = name; - b.feature = feature; + // The pieces take the family's places in that order too, so the state lists them as + // their names run. The session pins a feature's body names in state order, and the next + // evaluation hands them out in this order: listed in the kernel's order, the pieces + // swapped names once the design was evaluated again from its pinned names (opened). + let moved: Vec = keys.iter().filter_map(|(_, i)| bodies.get(*i).cloned()).collect(); + if moved.len() != members.len() || names.len() != members.len() { + continue; + } + for ((mut b, (name, feature)), place) in moved.into_iter().zip(names).zip(&members) { + b.name = name; + b.feature = feature; + if let Some(slot) = bodies.get_mut(*place) { + *slot = b; } } } diff --git a/crates/engine/src/naming_history_tests.rs b/crates/engine/src/naming_history_tests.rs index 616668746..bd7ea0f7b 100644 --- a/crates/engine/src/naming_history_tests.rs +++ b/crates/engine/src/naming_history_tests.rs @@ -264,6 +264,40 @@ fn pieces_of_a_cut_body_keep_their_body_names_when_the_cut_moves() { } } +/// A hole that cuts a body in three pieces names them as the design names them when it is +/// evaluated again from the names it pinned, as on opening it. Found by the model fuzzer: the two +/// smaller pieces swapped names there, so a later feature naming one of them met the other. +#[test] +fn pieces_of_a_cut_keep_their_names_when_the_design_is_evaluated_again() { + let mut s = Session::default(); + run(&mut s, "construct.plane.offset", json!({"base": "XZ", "name": "P8", "offset": 5})); + run(&mut s, "sketch.create", json!({"plane": "P8"})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-7, -9], "p1": [5, -7]})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"distance": 5, "operation": "join"})); + run(&mut s, "sketch.create", json!({"plane": "XZ"})); + run(&mut s, "sketch.circle.center", json!({"center": [7, -3], "radius": 4})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"distance": 5, "operation": "join"})); + run(&mut s, "solid.hole", json!({"depth": 14, "diameter": 5, "position": [-1, 10, 8]})); + // Each body by name, with where it is (two pieces have the same volume). + let pieces = |st: &solidcraft_doc::ModelState| -> Vec<(String, String)> { + st.bodies + .iter() + .map(|b| { + let m = solidcraft_kernel::measure(&b.body).unwrap(); + (b.name.clone(), format!("{:.3} {:.3} {:.3} {:.3}", m.volume, m.centroid.x, m.centroid.y, m.centroid.z)) + }) + .collect() + }; + let live = pieces(&s.model.state()); + assert_eq!(live.len(), 3, "{live:?}"); + let mut again = solidcraft_doc::Model::new(); + again.no_cache = true; + again.evaluate(&s.doc); + assert_eq!(pieces(&again.state()), live); +} + #[test] fn a_name_of_a_body_without_history_is_found_by_geometry_and_says_so_once_it_moves() { let mut s = Session::default();