Parameters: walk through a flipped plane to its base's expressions (#3481)
`PlaneRef::walk_exprs` stopped at `Flipped`, so a sketch created with
`flip` on an offset plane (`{plane: "XZ", offset: "d", flip: "x"}`) did
not list the offset as an input. Changing `d` rebuilt nothing that read
the sketch, and the model went stale.
`Flipped` now continues to its base, as `Offset` and `AtAngle` do, in
both `walk_exprs` and `walk_exprs_mut`.
Test: a loft between XZ and a flipped XZ plane offset by `d` has the
volume for d = 30, and for d = 50 after `parameters.change`.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -332,6 +332,9 @@ impl Walk for PlaneRef {
|
||||
p = base;
|
||||
}
|
||||
PlaneRef::AlongPath { t, .. } => return f(("Distance (0 to 1)", t, Kind::Unitless, ExprRole::Input)),
|
||||
// A plane seen from behind keeps its base's expressions (a sketch made with
|
||||
// `flip` on an offset plane did not follow the offset's parameter).
|
||||
PlaneRef::Flipped { base, .. } => p = base,
|
||||
PlaneRef::Placed { origin, .. } => {
|
||||
for (label, e) in ["X", "Y", "Z"].into_iter().zip(origin) {
|
||||
f((label, e, Kind::Length, ExprRole::Placement));
|
||||
@@ -355,6 +358,9 @@ impl Walk for PlaneRef {
|
||||
p = base;
|
||||
}
|
||||
PlaneRef::AlongPath { t, .. } => return f(("Distance (0 to 1)", t, Kind::Unitless, ExprRole::Input)),
|
||||
// A plane seen from behind keeps its base's expressions (a sketch made with
|
||||
// `flip` on an offset plane did not follow the offset's parameter).
|
||||
PlaneRef::Flipped { base, .. } => p = base,
|
||||
PlaneRef::Placed { origin, .. } => {
|
||||
for (label, e) in ["X", "Y", "Z"].into_iter().zip(origin) {
|
||||
f((label, e, Kind::Length, ExprRole::Placement));
|
||||
|
||||
@@ -655,3 +655,21 @@ fn several_parameters_change_in_one_rebuild_and_one_undo() {
|
||||
assert_eq!((expr_of(&mut s, "len"), expr_of(&mut s, "h")), ("60 mm".to_string(), "10 mm".to_string()));
|
||||
assert!(rel(volume(&mut s), 40.0 * 30.0 * 10.0) < 1e-9);
|
||||
}
|
||||
|
||||
/// A sketch made with `flip` on an offset plane follows the offset's parameter (the parameter
|
||||
/// walk stopped at the flipped plane, so a change rebuilt nothing).
|
||||
#[test]
|
||||
fn flipped_offset_sketch_plane_follows_its_parameter() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "parameters.add", json!({"name": "d", "expression": "30 mm"}));
|
||||
run(&mut s, "sketch.create", json!({"plane": "XZ", "name": "Near"}));
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-10, -10], "p1": [10, 10]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "sketch.create", json!({"plane": "XZ", "offset": "d", "flip": "x", "name": "Far"}));
|
||||
run(&mut s, "sketch.rectangle.two_point", json!({"p0": [-10, -10], "p1": [10, 10]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "solid.loft", json!({"sections": [{"sketch": "Near"}, {"sketch": "Far"}]}));
|
||||
assert!((volume(&mut s) - 400.0 * 30.0).abs() < 1e-6);
|
||||
run(&mut s, "parameters.change", json!({"name": "d", "expression": "50 mm"}));
|
||||
assert!((volume(&mut s) - 400.0 * 50.0).abs() < 1e-6, "{}", volume(&mut s));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user