* claim: #419 * fix(#419): a face shared by two bodies is resolved in the active occurrence
This commit is contained in:
@@ -181,9 +181,24 @@ type FacePick = (std::sync::Arc<Mesh>, u32, f64, String);
|
||||
|
||||
/// The face under a point of `only` (any body when `None`). Where faces of several bodies are
|
||||
/// equally near (bodies touching flush), the pick is ambiguous: `Err` names those bodies.
|
||||
/// A pick of the running command was resolved against the placed model, so the body under it
|
||||
/// wins: a body that only shares its place in the model is not in the way (#419). A named
|
||||
/// body still wins over that.
|
||||
fn face_at_in(s: &Session, p: Vec3, only: Option<&str>) -> std::result::Result<Option<FacePick>, Vec<String>> {
|
||||
let st = s.model.state();
|
||||
face_at_state(&st, p, only)
|
||||
match (crate::frames::picked(p), only) {
|
||||
(Some(names), None) if names.len() > 1 => Err(model_names(&st, &names)),
|
||||
(Some(names), None) => {
|
||||
let under = names.first().and_then(|n| st.bodies.iter().find(|b| b.definition_name() == n.as_str()).map(|b| b.name.clone()));
|
||||
face_at_state(&st, p, under.as_deref())
|
||||
}
|
||||
(_, only) => face_at_state(&st, p, only),
|
||||
}
|
||||
}
|
||||
|
||||
/// The names the model gives the bodies a pick met.
|
||||
fn model_names(st: &solidcraft_doc::ModelState, names: &[String]) -> Vec<String> {
|
||||
names.iter().map(|n| st.bodies.iter().find(|b| b.definition_name() == n.as_str()).map(|b| b.name.clone()).unwrap_or_else(|| n.clone())).collect()
|
||||
}
|
||||
|
||||
pub(super) fn face_at_state(st: &solidcraft_doc::ModelState, p: Vec3, only: Option<&str>) -> std::result::Result<Option<FacePick>, Vec<String>> {
|
||||
|
||||
@@ -126,6 +126,44 @@ fn face_join_of_a_step_import_keeps_all_32_neighbours_unchanged() {
|
||||
assert_eq!(targets, &["Wall"]);
|
||||
}
|
||||
|
||||
/// #419: a face pick is resolved against the placed state: a leaf of an assembly that its
|
||||
/// joint swung away does not make the pick ambiguous, even though both leaves are built at
|
||||
/// the same local place. The pick lands on the leaf that is shown there.
|
||||
#[test]
|
||||
fn a_face_pick_on_an_assembly_leaf_is_resolved_where_the_leaf_is_shown() {
|
||||
let mut s = Session::default();
|
||||
for leaf in ["Leaf A", "Leaf B"] {
|
||||
run(&mut s, "component.activate", json!({"component": "root"}));
|
||||
run(&mut s, "component.create", json!({"name": leaf}));
|
||||
run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 3, "corner": [0, 0, 0]}));
|
||||
run(&mut s, "solid.cylinder", json!({"base": [0, 33, 4], "axis": [1, 0, 0], "radius": 4, "height": 40, "operation": "new"}));
|
||||
}
|
||||
run(&mut s, "component.activate", json!({"component": "root"}));
|
||||
run(&mut s, "occurrence.ground", json!({"occurrence": "Leaf A:1", "grounded": true}));
|
||||
run(
|
||||
&mut s,
|
||||
"joint.create",
|
||||
json!({
|
||||
"type": "revolute",
|
||||
"name": "Hinge",
|
||||
"a": {"occurrence": "Leaf A:1", "circle": [1, 37, 4]},
|
||||
"b": {"occurrence": "Leaf B:1", "circle": [1, 37, 4]},
|
||||
"limits": [["0 deg", "180 deg"]]
|
||||
}),
|
||||
);
|
||||
run(&mut s, "joint.drive", json!({"joint": "Hinge", "value": 60}));
|
||||
// Leaf B is swung 60° away, so the pick is on Leaf A's top face, where it is shown.
|
||||
let result = run(
|
||||
&mut s,
|
||||
"solid.extrude",
|
||||
json!({"face": [13.002403831300967, 9.849781594495369, 3.0], "distance": "10 mm", "direction": "positive", "operation": "join"}),
|
||||
);
|
||||
assert_eq!(result["changed_bodies"], json!(["Body1"]));
|
||||
let state = s.model.state();
|
||||
let volume = solidcraft_kernel::measure(&state.body("Body1").unwrap().body).unwrap().volume;
|
||||
assert!((volume - 15_600.0).abs() < 1e-6, "{volume}");
|
||||
}
|
||||
|
||||
/// #1349: a profile sketched on a body's face joins that body, and leaves alone a neighbour
|
||||
/// whose face it lies on too: a rib on the side of a bracket, drawn down over the motor the
|
||||
/// bracket sits on, welded the motor in (a join that ran for minutes on the imported motor and
|
||||
|
||||
Reference in New Issue
Block a user