Extrude: a cut made while bodies are hidden leaves them alone (#3961) (#5148)

A cut (or intersect) that names no bodies went through every body it met,
hidden ones too: a body hidden to keep it out of the cut was cut anyway. When
some of the active component's bodies are hidden, the cut now stores the shown
ones as its targets, so the hidden bodies stay as they are, and stay so once
shown again (the model never depends on what is shown). With nothing hidden it
goes through every body it meets, as before.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dudedagger42
2026-10-27 02:23:48 +00:00
committed by GitHub
parent 3726959d82
commit b99761a3f7
2 changed files with 43 additions and 0 deletions
+14
View File
@@ -828,6 +828,9 @@ fn extrude(s: &mut Session, p: &Value) -> Result<Value> {
} else if let Some(parts) = cut_scope(s, &p, operation, sketch, face_body)? {
p.to_mut()["participants"] = json!(parts);
}
if matches!(operation, Operation::Cut | Operation::Intersect) && targets.is_empty() && string_list(&p, "participants").is_empty() {
targets = shown_scope(s);
}
let kind = FeatureKind::Extrude {
sketch: SketchId(sketch),
profiles: match face_profile {
@@ -972,6 +975,17 @@ fn face_body_reached(s: &Session, sketch: u64) -> Result<Option<String>> {
Ok(Some(body.name.clone()))
}
/// A cut or intersect that names no bodies leaves hidden bodies alone, as hiding a body to keep
/// it out of a cut is the usual way to (#3961): while some of the active component's bodies
/// are hidden, its shown ones, stored as the feature's targets so showing the others again
/// later changes nothing. Empty (every body, as before) when none is hidden, or all are.
fn shown_scope(s: &Session) -> Vec<String> {
let st = s.model.state();
let scope = active_scope(s, &st);
let shown: Vec<String> = scope.iter().filter(|b| s.body_visible(&b.name)).map(|b| b.name.clone()).collect();
if shown.len() == scope.len() { Vec::new() } else { shown }
}
/// The body whose face `sketch` is attached to (on the face itself, not offset from it), when
/// it is one the active component works on ([`active_scope`]).
fn sketch_face_body(s: &Session, sketch: u64) -> Option<String> {
+29
View File
@@ -4464,3 +4464,32 @@ fn parallel_pipe_large_nominals_support_shallow_and_thin_cylindrical_holes() {
}
}
}
/// #3961: a cut made while a body is hidden leaves that body alone, and keeps doing so once it
/// is shown again (the shown bodies are stored as the cut's targets); with nothing hidden, a
/// cut still goes through every body it meets.
#[test]
fn a_cut_leaves_hidden_bodies_alone() {
let setup = |hide: bool| {
let mut s = Session::default();
run(&mut s, "solid.box", json!({"length": 20, "width": 20, "height": 10, "body_name": "Below"}));
run(&mut s, "solid.box", json!({"length": 20, "width": 20, "height": 10, "corner": [0, 0, 10], "body_name": "Above", "operation": "new"}));
if hide {
run(&mut s, "browser.visibility", json!({"items": ["Below"], "visible": false}));
}
run(&mut s, "sketch.create", json!({"plane": {"face": [10, 10, 20]}}));
run(&mut s, "sketch.circle.center", json!({"center": [10, 10], "radius": 3}));
run(&mut s, "sketch.finish", json!({}));
run(&mut s, "solid.extrude", json!({"distance": 30, "direction": "negative", "operation": "cut"}));
s
};
let vol = |s: &Session, name: &str| solidcraft_kernel::measure(&s.world_state().body(name).unwrap().body).unwrap().volume;
let full = 20.0 * 20.0 * 10.0;
let mut hidden = setup(true);
assert!((vol(&hidden, "Below") - full).abs() < 1e-6, "the hidden body is not cut");
assert!(vol(&hidden, "Above") < full - 1.0, "the shown one is");
run(&mut hidden, "browser.visibility", json!({"items": ["Below"], "visible": true}));
assert!((vol(&hidden, "Below") - full).abs() < 1e-6, "shown again, it stays as it was");
let shown = setup(false);
assert!(vol(&shown, "Below") < full - 1.0 && vol(&shown, "Above") < full - 1.0, "with nothing hidden, both are cut");
}