Persistent naming: shell, draft, offset-face and replace-face faces and hole placements store their faces' names (Feature.face_names) and are moved onto the named face before evaluating (a split face: the nearest piece, with a warning; a vanished face: the picked point, with a warning)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
bherbruckandClaude Opus 5.5 committed 2026-10-08 11:37:33 +00:00
1 parent 99886594e7
commit e7aff4fef0
6 files changed
+114

No files matched your search

+4
View File
@@ -193,6 +193,10 @@ fn edit_feature(s: &mut Session, p: &Value) -> Result<Value> {
nf.edge_refs = solvecraft_doc::edge_refs(&before, body, a);
nf.edge_names = solvecraft_doc::edge_names_for(&before, body, a);
}
// New face points: their faces' names now.
if nf.kind.face_points() != f.kind.face_points() {
nf.face_names = solvecraft_doc::naming::face_names_at(&s.model.state_before(id), &nf.kind.face_points());
}
if let Some(slot) = s.doc_mut().feature_mut(id) {
*slot = nf;
}
+5
View File
@@ -251,10 +251,15 @@ pub(super) fn add_feature(s: &mut Session, p: &Value, kind: FeatureKind) -> Resu
}
_ => (Vec::new(), Vec::new()),
};
let face_names = {
let pts = kind.face_points();
if pts.is_empty() { Vec::new() } else { solvecraft_doc::naming::face_names_at(&s.model.state(), &pts) }
};
let id = s.doc_mut().add_feature(kind, name)?;
if let Some(f) = s.doc_mut().feature_mut(id) {
f.edge_refs = refs;
f.edge_names = names;
f.face_names = face_names;
}
s.doc_mut().name_feature_inputs(id);
let comp = s.active_component;
+15
View File
@@ -1325,4 +1325,19 @@ mod naming {
let sk = s.model.state().sketch(s.doc.find_feature("Top").map(|f| f.id).unwrap_or(0)).map(|x| x.plane.origin.z);
assert_eq!(sk.map(|z| (z * 1e6).round() / 1e6), Some(10.0));
}
#[test]
fn shell_and_hole_faces_follow_by_name() {
let mut s = Session::default();
run(&mut s, "PrimitiveBox", json!({"length": 40, "width": 30, "height": 20, "name": "Base"}));
run(&mut s, "FusionShellBodyCommand", json!({"faces": [[20, 15, 20]], "thickness": 2, "name": "Hollow"}));
let shell = |h: f64| 40.0 * 30.0 * h - 36.0 * 26.0 * (h - 2.0);
assert!((volume(&mut s) - shell(20.0)).abs() < 0.5, "{}", volume(&mut s));
// Taller: the picked point is 5 mm under the open face now; its name still finds it.
run(&mut s, "timeline.edit", json!({"feature": "Base", "set": {"height": "25"}}));
assert!((volume(&mut s) - shell(25.0)).abs() < 0.5, "{}", volume(&mut s));
assert_eq!(warning(&s, "Hollow"), None);
let h = s.doc.find_feature("Hollow").map(|f| f.face_names.clone()).unwrap_or_default();
assert_eq!(h, vec!["F1:+z".to_string()]);
}
}