Wave 350/509: Surface Extrude: a symmetric distance is the total, as for a solid extrude (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 9008d13f3 jyviko: Surface Extrude: a symmetric distance is the total, as for a solid extrude - de5c338e7 jyviko: Preferences: keep the older per-side reading of a symmetric surface extrude - ac70662d6 jyviko: Sweeps: a path through a drawn 3D arc follows the arc, not a spline through its three points - 7664925fb jyviko: Sketch: Project onto Surface keeps the side the projection meets first, in one curve Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -1047,12 +1047,16 @@ fn edit_feature(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
resolve_feature_names(&mut v, &s.doc, cmd)?;
|
||||
let mut nf: Feature = serde_json::from_value(v.clone()).map_err(|e| bad(cmd, format!("invalid feature: {e}")))?;
|
||||
nf.id = f.id;
|
||||
if let (FeatureKind::Extrude { extent: old, .. }, FeatureKind::Extrude { extent: new, .. }) = (&f.kind, &mut nf.kind)
|
||||
// A one-sided extrude made symmetric takes the convention a new one would: its old marker
|
||||
// never read a symmetric distance.
|
||||
let maker = if matches!(f.kind, FeatureKind::SurfaceExtrude { .. }) { "surface.extrude" } else { "solid.extrude" };
|
||||
if let (FeatureKind::Extrude { extent: old, .. }, FeatureKind::Extrude { extent: new, .. })
|
||||
| (FeatureKind::SurfaceExtrude { extent: old, .. }, FeatureKind::SurfaceExtrude { extent: new, .. }) = (&f.kind, &mut nf.kind)
|
||||
&& old.direction != solidcraft_doc::Direction::Symmetric
|
||||
&& new.direction == solidcraft_doc::Direction::Symmetric
|
||||
&& set.get("extent").and_then(|e| e.get("convention")).is_none()
|
||||
{
|
||||
new.convention = solidcraft_doc::ExtrudeConvention::TotalDistance;
|
||||
new.convention = super::features::default_extrude_convention(s, maker);
|
||||
}
|
||||
if std::mem::discriminant(&nf.kind) != std::mem::discriminant(&f.kind) {
|
||||
return Err(bad(cmd, "the feature type cannot change"));
|
||||
@@ -1410,10 +1414,10 @@ fn redefine(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
&& matches!(cid, "solid.extrude" | "surface.extrude")
|
||||
&& let Some(parameters) = params.as_object_mut()
|
||||
{
|
||||
let convention = if cid == "surface.extrude" || extent.direction == solidcraft_doc::Direction::Symmetric {
|
||||
let convention = if extent.direction == solidcraft_doc::Direction::Symmetric {
|
||||
extent.convention
|
||||
} else {
|
||||
solidcraft_doc::ExtrudeConvention::TotalDistance
|
||||
super::features::default_extrude_convention(s, cid)
|
||||
};
|
||||
parameters.entry("convention").or_insert_with(|| json!(convention));
|
||||
}
|
||||
|
||||
@@ -123,23 +123,102 @@ fn symmetric_extrude_thin_wall_uses_total_distance_and_to_object_remains_one_sid
|
||||
check(&fixture(json!({"to":[0,0,10]})), 0.0, 10.0);
|
||||
}
|
||||
|
||||
/// The z range of surface body `name`.
|
||||
fn sheet_z(s: &Session, name: &str) -> (f64, f64) {
|
||||
assert!(s.model.results.iter().all(|r| r.error.is_none()));
|
||||
let st = s.model.state();
|
||||
let bounds = st.body(name).unwrap().mesh().bounds();
|
||||
(bounds.min.z, bounds.max.z)
|
||||
}
|
||||
|
||||
fn assert_z(s: &Session, name: &str, lo: f64, hi: f64) {
|
||||
let (z0, z1) = sheet_z(s, name);
|
||||
assert!((z0 - lo).abs() < 1e-7 && (z1 - hi).abs() < 1e-7, "{name}: {z0}..{z1}, want {lo}..{hi}");
|
||||
}
|
||||
|
||||
/// A symmetric surface extrude reads its distance as a solid one does: the total, split evenly
|
||||
/// around the start plane, through a redefine and a save.
|
||||
#[test]
|
||||
fn surface_extrude_shared_extent_retains_its_existing_per_side_semantics() {
|
||||
fn surface_extrude_symmetric_distance_is_the_total_like_solid_extrude() {
|
||||
let mut s = fixture(json!({}));
|
||||
run(&mut s, "surface.extrude", json!({"sketch":"Square","distance":"10 mm","direction":"symmetric","name":"Sheet","body_name":"Sheet"}));
|
||||
let check_sheet = |s: &Session| {
|
||||
let st = s.model.state();
|
||||
let bounds = st.body("Sheet").unwrap().mesh().bounds();
|
||||
assert!((bounds.min.z + 10.0).abs() < 1e-7 && (bounds.max.z - 10.0).abs() < 1e-7);
|
||||
};
|
||||
check_sheet(&s);
|
||||
assert_z(&s, "Sheet", -5.0, 5.0);
|
||||
let FeatureKind::SurfaceExtrude { extent, .. } = &s.doc.find_feature("Sheet").unwrap().kind else { panic!("surface extrude") };
|
||||
assert_eq!(extent.convention, ExtrudeConvention::TotalDistance);
|
||||
run(
|
||||
&mut s,
|
||||
"timeline.redefine",
|
||||
json!({"feature":"Sheet","command":"surface.extrude","params":{"sketch":"Square","distance":"10 mm","direction":"symmetric","body_name":"Sheet"}}),
|
||||
);
|
||||
check_sheet(&s);
|
||||
check_sheet(&Session::new(Document::from_json(&s.doc.to_json()).unwrap()));
|
||||
assert_z(&s, "Sheet", -5.0, 5.0);
|
||||
assert_z(&Session::new(Document::from_json(&s.doc.to_json()).unwrap()), "Sheet", -5.0, 5.0);
|
||||
// A one-sided surface extrude made symmetric splits its distance too, as a solid one does.
|
||||
run(&mut s, "surface.extrude", json!({"sketch":"Square","distance":"10 mm","convention":"legacy_per_side","name":"Wall","body_name":"Wall"}));
|
||||
assert_z(&s, "Wall", 0.0, 10.0);
|
||||
run(&mut s, "timeline.edit", json!({"feature":"Wall","set":{"extent":{"direction":"symmetric"}}}));
|
||||
assert_z(&s, "Wall", -5.0, 5.0);
|
||||
}
|
||||
|
||||
/// Surface extrudes saved before they matched solid ones stored `legacy_per_side` (or, older
|
||||
/// still, no marker): they rebuild the distance on each side, and keep it through edits.
|
||||
#[test]
|
||||
fn older_symmetric_surface_extrudes_keep_the_distance_on_each_side() {
|
||||
let mut s = fixture(json!({}));
|
||||
run(
|
||||
&mut s,
|
||||
"surface.extrude",
|
||||
json!({"sketch":"Square","distance":"10 mm","direction":"symmetric","convention":"legacy_per_side","name":"Sheet","body_name":"Sheet"}),
|
||||
);
|
||||
assert_z(&s, "Sheet", -10.0, 10.0);
|
||||
let marked: Value = serde_json::from_str(&s.doc.to_json()).unwrap();
|
||||
let mut unmarked = marked.clone();
|
||||
unmarked["format"] = json!("solidcraft/21");
|
||||
unmarked.as_object_mut().unwrap().remove("format_pending");
|
||||
for f in unmarked["features"].as_array_mut().unwrap() {
|
||||
if let Some(extent) = f.get_mut("extent").and_then(Value::as_object_mut) {
|
||||
extent.remove("convention");
|
||||
}
|
||||
}
|
||||
for saved in [marked, unmarked] {
|
||||
let mut s = Session::new(Document::from_json(&saved.to_string()).unwrap());
|
||||
assert_z(&s, "Sheet", -10.0, 10.0);
|
||||
run(&mut s, "timeline.edit", json!({"feature":"Sheet","set":{"extent":{"distance":"12 mm"}}}));
|
||||
assert_z(&s, "Sheet", -12.0, 12.0);
|
||||
run(
|
||||
&mut s,
|
||||
"timeline.redefine",
|
||||
json!({"feature":"Sheet","command":"surface.extrude","params":{"sketch":"Square","distance":"10 mm","direction":"symmetric","body_name":"Sheet"}}),
|
||||
);
|
||||
assert_z(&s, "Sheet", -10.0, 10.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// The preference brings back the per-side reading for new surface extrudes only: solid
|
||||
/// extrudes and an explicit `convention` are unchanged by it.
|
||||
#[test]
|
||||
fn the_per_side_preference_keeps_the_older_surface_extrude_reading() {
|
||||
let mut s = fixture(json!({}));
|
||||
s.surface_extrude_symmetric_per_side = true;
|
||||
run(&mut s, "surface.extrude", json!({"sketch":"Square","distance":"10 mm","direction":"symmetric","name":"Sheet","body_name":"Sheet"}));
|
||||
assert_z(&s, "Sheet", -10.0, 10.0);
|
||||
let FeatureKind::SurfaceExtrude { extent, .. } = &s.doc.find_feature("Sheet").unwrap().kind else { panic!("surface extrude") };
|
||||
assert_eq!(extent.convention, ExtrudeConvention::LegacyPerSide);
|
||||
run(
|
||||
&mut s,
|
||||
"surface.extrude",
|
||||
json!({"sketch":"Square","distance":"10 mm","direction":"symmetric","convention":"total_distance","name":"Total","body_name":"Total"}),
|
||||
);
|
||||
assert_z(&s, "Total", -5.0, 5.0);
|
||||
run(&mut s, "solid.extrude", json!({"sketch":"Square","distance":"10 mm","direction":"symmetric","operation":"new","body_name":"Solid"}));
|
||||
assert_z(&s, "Solid", -5.0, 5.0);
|
||||
// The saved marker, not the preference, decides on reopening.
|
||||
s.surface_extrude_symmetric_per_side = false;
|
||||
let reopened = Session::new(Document::from_json(&s.doc.to_json()).unwrap());
|
||||
assert_z(&reopened, "Sheet", -10.0, 10.0);
|
||||
// A design opened or started keeps the user's choice.
|
||||
s.surface_extrude_symmetric_per_side = true;
|
||||
s.replace_design(Session::default());
|
||||
assert!(s.surface_extrude_symmetric_per_side);
|
||||
}
|
||||
|
||||
/// A second distance goes the other way from the first side (#2700): along the normal when the
|
||||
|
||||
@@ -25,7 +25,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.key("E")
|
||||
.contract(&EXTRUDE_CONTRACT)
|
||||
.output(output_schema_for::<FeatureResult>)
|
||||
.params("distance: expr (or through_all: true); taper?: angle expr (positive: outward, so the far end is larger along the extrusion direction; negative: inward, so the far end is smaller); corner?: preserve_curvature|tangent|round (how a taper closes a sharp corner its offset opens: each wall continues as itself, a line's plane or an arc's cone, until it meets its neighbour; each continues straight along its end tangent; or an arc about the corner. Without it, each profile preserves curvature where every curve is a line or an arc and takes tangent where another curve has a corner, and the feature's warning says so; a corner rule given is kept, and refused where the kernel cannot build it); sketch?: id|name (default: active or last sketch); profiles?: all | [index] | [{curves: [ids]}] (the profile whose outer loop is made of exactly these curves, or pieces of them; found again on every recompute, so it follows parameter changes; islands inside are its holes; an error when no profile or several match) | [{point:[x,y]}] (index and point picks are stored by their curves when that finds the same profile; a pick on a drawn profile that reference geometry, such as the projected outline of the face the sketch is on, cuts into regions takes the whole drawn profile); exact_regions?: bool (each index or point pick is exactly the region it names, as the dialogs send); default: every drawn profile, except that a loop inside another is its hole and a loop inside that hole is material again; face?: [x,y,z] (extrude a planar body face instead of a sketch profile); faces?: [[x,y,z],…] (coplanar faces of one body); face_body?: name (whose face, where faces of several bodies meet at the point); direction?: positive|negative|symmetric (distance is total thickness, split evenly around the start plane); convention?: total_distance|legacy_per_side (default total_distance; legacy preserves older symmetric extents); distance2?: expr (Two Sides: a second distance the other way from the first side, which may be through_all or to; with direction: negative the first side goes against the normal and distance2 along it); start_offset?: expr (along the sketch normal, also with direction: negative); to?: [x,y,z] (To Object: a face, vertex or point; to_offset?: expr past it); from?: [x,y,z] (From Object: start at that face or point); operation?: new|join|cut|intersect|auto (cut into a body, otherwise join existing solids; new in an empty component); touching?: separate|one_body (what a join makes of pieces that share no face: separate, the default, makes each piece that touches another only along an edge or at a point a body of its own and keeps pieces that touch nothing in one body; one_body keeps every piece in one body); targets?: [body] (Join from a face, or from a sketch on a body's face, defaults to that face's body; explicit targets or participants override); name?; body_name?; thin?: true (Thin: a wall along sketch curves instead of the profiles) with curves?: [curve ids] (open chains and closed loops, joined where they meet end to end; default: every drawn curve of the sketch), thickness: expr, side?: center|inside|outside|two_sides (a closed loop's inside is the area it encloses, an open chain's the side it bends toward, a straight line's the left of its first curve as drawn; default center), thickness2?: expr (two_sides: the thickness outside); corners are mitred, crossing walls are one"),
|
||||
.params("distance: expr (or through_all: true); taper?: angle expr (positive: outward, so the far end is larger along the extrusion direction; negative: inward, so the far end is smaller); corner?: preserve_curvature|tangent|round (how a taper closes a sharp corner its offset opens: each wall continues as itself, a line's plane or an arc's cone, until it meets its neighbour; each continues straight along its end tangent; or an arc about the corner. Without it, each profile preserves curvature where every curve is a line or an arc and takes tangent where another curve has a corner, and the feature's warning says so; a corner rule given is kept, and refused where the kernel cannot build it); sketch?: id|name (default: active or last sketch); profiles?: all | [index] | [{curves: [ids]}] (the profile whose outer loop is made of exactly these curves, or pieces of them; found again on every recompute, so it follows parameter changes; islands inside are its holes; an error when no profile or several match) | [{point:[x,y]}] (index and point picks are stored by their curves when that finds the same profile; a pick on a drawn profile that reference geometry, such as the projected outline of the face the sketch is on, cuts into regions takes the whole drawn profile); exact_regions?: bool (each index or point pick is exactly the region it names, as the dialogs send); default: every drawn profile, except that a loop inside another is its hole and a loop inside that hole is material again; face?: [x,y,z] (extrude a planar body face instead of a sketch profile); faces?: [[x,y,z],…] (coplanar faces of one body); face_body?: name (whose face, where faces of several bodies meet at the point); direction?: positive|negative|symmetric (distance is total thickness, split evenly around the start plane); convention?: total_distance|legacy_per_side (how a symmetric distance is read; default total_distance, split evenly around the start plane; legacy_per_side: the distance on each side, as older symmetric extrudes keep); distance2?: expr (Two Sides: a second distance the other way from the first side, which may be through_all or to; with direction: negative the first side goes against the normal and distance2 along it); start_offset?: expr (along the sketch normal, also with direction: negative); to?: [x,y,z] (To Object: a face, vertex or point; to_offset?: expr past it); from?: [x,y,z] (From Object: start at that face or point); operation?: new|join|cut|intersect|auto (cut into a body, otherwise join existing solids; new in an empty component); touching?: separate|one_body (what a join makes of pieces that share no face: separate, the default, makes each piece that touches another only along an edge or at a point a body of its own and keeps pieces that touch nothing in one body; one_body keeps every piece in one body); targets?: [body] (Join from a face, or from a sketch on a body's face, defaults to that face's body; explicit targets or participants override); name?; body_name?; thin?: true (Thin: a wall along sketch curves instead of the profiles) with curves?: [curve ids] (open chains and closed loops, joined where they meet end to end; default: every drawn curve of the sketch), thickness: expr, side?: center|inside|outside|two_sides (a closed loop's inside is the area it encloses, an open chain's the side it bends toward, a straight line's the left of its first curve as drawn; default center), thickness2?: expr (two_sides: the thickness outside); corners are mitred, crossing walls are one"),
|
||||
CommandSpec::new("solid.revolve", "Revolve", revolve)
|
||||
.at("SOLID", "CREATE")
|
||||
.icon("revolve")
|
||||
@@ -1120,6 +1120,18 @@ fn thin_regions(s: &Session, ss: &solidcraft_doc::SolvedSketch, thin: &ThinWall)
|
||||
solidcraft_sketch::thin_wall_regions(&curves, inside, outside).map_err(|e| format!("thin wall: {e}"))
|
||||
}
|
||||
|
||||
/// How a new extent of `cmd` (`solid.extrude` or `surface.extrude`) reads a symmetric distance
|
||||
/// when the call doesn't say: the total, split evenly around the start plane, for both. A surface
|
||||
/// extrude reads it on each side, as surface extrudes did before, while the user's preference
|
||||
/// says so ([`Session::surface_extrude_symmetric_per_side`]).
|
||||
pub(crate) fn default_extrude_convention(s: &Session, cmd: &str) -> solidcraft_doc::ExtrudeConvention {
|
||||
if cmd == "surface.extrude" && s.surface_extrude_symmetric_per_side {
|
||||
solidcraft_doc::ExtrudeConvention::LegacyPerSide
|
||||
} else {
|
||||
solidcraft_doc::ExtrudeConvention::TotalDistance
|
||||
}
|
||||
}
|
||||
|
||||
/// An extrude's extent from its parameters: distance (or through all, or to an object), the
|
||||
/// side(s), a second distance, a start offset, a taper, and from an object.
|
||||
pub(super) fn extent_param(s: &Session, p: &Value, cmd: &str) -> Result<Extent> {
|
||||
@@ -1156,9 +1168,7 @@ pub(super) fn extent_param(s: &Session, p: &Value, cmd: &str) -> Result<Extent>
|
||||
check_expr(s, d, Kind::Length, cmd, "start_offset")?;
|
||||
}
|
||||
let convention = match p.get("convention") {
|
||||
// Surface Extrude shares Extent but retains its existing per-side distance semantics.
|
||||
None if cmd == "surface.extrude" => solidcraft_doc::ExtrudeConvention::LegacyPerSide,
|
||||
None => solidcraft_doc::ExtrudeConvention::TotalDistance,
|
||||
None => default_extrude_convention(s, cmd),
|
||||
Some(value) => serde_json::from_value(value.clone()).map_err(|_| bad(cmd, "`convention` must be total_distance or legacy_per_side"))?,
|
||||
};
|
||||
Ok(Extent {
|
||||
|
||||
@@ -379,14 +379,28 @@ fn three_d_sketch_curves() {
|
||||
let src = s.doc.features.last().unwrap().id;
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY"}));
|
||||
let r = run(&mut s, "sketch.project_to_surface", json!({"curves": [{"sketch": src, "curve": l}], "face": [0, 0, 20]}));
|
||||
// The line's projection where it first meets the sphere: the arc of the great circle in y = 0
|
||||
// from x = -10 to 10 over the top (z = √(400 − x²)), one wire though SMLib splits it at the
|
||||
// pole, and no curve on the far side.
|
||||
assert_eq!(r["links"][0]["wires"].as_array().unwrap().len(), 1, "{r}");
|
||||
let wid = r["links"][0]["wires"][0].as_str().unwrap().to_string();
|
||||
let st = s.model.state();
|
||||
let sk = &st.sketch(s.active_sketch.unwrap()).unwrap().sketch;
|
||||
let w = &sk.wires[sk.wire_index(&wid).unwrap()];
|
||||
assert!(w.pts.len() > 20);
|
||||
for p in &w.pts {
|
||||
assert!((p.len() - 20.0).abs() < 0.1, "{p:?}");
|
||||
assert!(p.z > 0.0);
|
||||
assert!(!w.exact.is_empty());
|
||||
// SMLib makes projected curves to a millionth of the body's size (the sphere's 40 mm box).
|
||||
let tol = 40.0 * 1e-6;
|
||||
let ends = [*w.pts.first().unwrap(), *w.pts.last().unwrap()];
|
||||
let top = 300f64.sqrt();
|
||||
assert!(ends.iter().all(|e| (e.x.abs() - 10.0).abs() < tol && e.y.abs() < tol && (e.z - top).abs() < tol), "{ends:?}");
|
||||
assert!((ends[0].x + ends[1].x).abs() < tol, "{ends:?}");
|
||||
// Along its exact curves (the wire's points are its spans' polygon), on the sphere's top.
|
||||
for c in &w.exact {
|
||||
let eval = solidcraft_geom::brep::eval::CurveEval::new(&c.curve).unwrap();
|
||||
for k in 0..=32 {
|
||||
let p = eval.point(c.interval[0] + (c.interval[1] - c.interval[0]) * f64::from(k) / 32.0).unwrap();
|
||||
assert!((p.len() - 20.0).abs() < tol && p.y.abs() < tol && p.z >= top - tol, "{p:?}");
|
||||
}
|
||||
}
|
||||
// Delete the wire.
|
||||
run(&mut s, "sketch.delete", json!({"entities": [wid]}));
|
||||
|
||||
@@ -39,7 +39,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
CommandSpec::new("surface.extrude", "Surface Extrude", surface_extrude)
|
||||
.at("SURFACE", "CREATE")
|
||||
.icon("surface_extrude")
|
||||
.params("sketch?: id|name; curves?: [curve ids] (open or closed chains of curves meeting end to end) and/or profiles? (their boundaries; the default when no curves are given); distance: expr; direction?: positive|negative|symmetric; distance2?: expr; start_offset?: expr; name?, body_name? (a surface body: walls only, no caps)"),
|
||||
.params("sketch?: id|name; curves?: [curve ids] (open or closed chains of curves meeting end to end) and/or profiles? (their boundaries; the default when no curves are given); distance: expr; direction?: positive|negative|symmetric (symmetric: distance is the total, split evenly around the start plane, as solid.extrude); convention?: total_distance|legacy_per_side (as solid.extrude; default total_distance, or legacy_per_side, the distance on each side, under the user's preference for the older reading); distance2?: expr; start_offset?: expr; name?, body_name? (a surface body: walls only, no caps)"),
|
||||
CommandSpec::new("surface.revolve", "Surface Revolve", surface_revolve)
|
||||
.at("SURFACE", "CREATE")
|
||||
.icon("surface_revolve")
|
||||
@@ -797,7 +797,8 @@ mod tests {
|
||||
// The line's wall and the half circle's (radius 5): length × height.
|
||||
let want = (10.0 + std::f64::consts::PI * 5.0) * 4.0;
|
||||
assert!((area(&s, "Wall") - want).abs() < want * 1e-3, "{} vs {want}", area(&s, "Wall"));
|
||||
run(&mut s, "surface.extrude", json!({"sketch": "S", "curves": ["l1"], "distance": 2, "direction": "symmetric", "body_name": "Both"}));
|
||||
// Symmetric: the distance is the total, split evenly around the sketch plane.
|
||||
run(&mut s, "surface.extrude", json!({"sketch": "S", "curves": ["l1"], "distance": 4, "direction": "symmetric", "body_name": "Both"}));
|
||||
let bb = solidcraft_kernel::measure(&s.world_state().unwrap().body("Both").unwrap().body).unwrap().bbox;
|
||||
assert!((bb.min.z + 2.0).abs() < 1e-9 && (bb.max.z - 2.0).abs() < 1e-9, "{bb:?}");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
|
||||
Reference in New Issue
Block a user