solid.mirror: a plane's {origin} takes length expressions and follows them (#1492) (#1501)

Thanks @erkexzcx.
This commit is contained in:
Erikas authored and GitHub committed 2026-10-15 22:37:08 -04:00
1 parent daf618c344
commit a422fb1a4b
10 files changed
+120 -14

No files matched your search

+35
View File
@@ -39,6 +39,41 @@ fn mirror_across_a_construction_plane_follows_it() {
}
}
/// A plane `{origin, normal}` takes length expressions in its origin, as a primitive's corner
/// does, and the mirror follows them through parameter changes, renames and a save (#1492).
#[test]
fn mirror_plane_origin_follows_its_parameters() {
let mut s = Session::default();
run(&mut s, "parameters.add", json!({"name": "half", "expression": "50 mm"}));
run(&mut s, "solid.box", json!({"length": 20, "width": 20, "height": 20}));
run(&mut s, "solid.mirror", json!({"features": ["Box1"], "plane": {"origin": ["half", 0, 0], "normal": [1, 0, 0]}, "name": "Twin"}));
let at = |s: &Session| min_x(s, &last_body(s));
// The box spans x = 0…20; mirrored about x = 50 it spans 80…100.
assert!((at(&s) - 80.0).abs() < 1e-6, "{}", at(&s));
run(&mut s, "parameters.change", json!({"name": "half", "expression": "30 mm"}));
assert!((at(&s) - 40.0).abs() < 1e-6, "{}", at(&s));
run(&mut s, "parameters.rename", json!({"name": "half", "new_name": "mid"}));
run(&mut s, "parameters.change", json!({"name": "mid", "expression": "25 mm"}));
assert!((at(&s) - 30.0).abs() < 1e-6, "{}", at(&s));
// Saved and opened again, the plane still names the parameter.
let mut s2 = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
assert!(s2.doc.to_json().contains("\"mid\""));
run(&mut s2, "parameters.change", json!({"name": "mid", "expression": "60 mm"}));
assert!((at(&s2) - 100.0).abs() < 1e-6, "{}", at(&s2));
// A parameter the plane uses can't be deleted from under it.
assert!(s2.execute("parameters.delete", &json!({"name": "mid"})).is_err());
// Plain numbers still make a fixed plane.
let r = run(&mut s2, "solid.mirror", json!({"features": ["Box1"], "plane": {"origin": [-10, 0, 0], "normal": [1, 0, 0]}}));
let id = r["feature"].as_u64().unwrap();
let f = s2.doc.feature(id).unwrap();
assert!(matches!(f.kind, solidcraft_doc::FeatureKind::Mirror { plane: solidcraft_doc::PlaneRef::Custom { .. }, .. }), "{:?}", f.kind);
assert!((at(&s2) + 40.0).abs() < 1e-6, "{}", at(&s2));
}
fn last_body(s: &Session) -> String {
s.model.state().bodies.last().map(|b| b.name.clone()).unwrap()
}
#[test]
fn unknown_mirror_planes_are_refused_with_the_choices() {
let mut s = Session::default();