diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index 44c249d56..1a0214c73 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -208,10 +208,18 @@ fn auto_operation_in(s: &Session, p: &Value, world_faces: bool) -> Option<&'stat } else { extrude_base(s, p)? }; + // The extrude starts at its From Object or start offset, not at the profile: probe from + // there (#467). To an object it then reaches only from that start. + let start = match p.get("from").and_then(vec3) { + Some(from) if grouped.is_none() => (from - base).dot(n), + _ => expr(p, "start_offset").and_then(|e| s.doc.eval(&e, Kind::Length).ok()).unwrap_or(0.0), + }; + let start = if start.is_finite() { start } else { 0.0 }; + let base = base + n * start; let d = if grouped.is_some() && p.get("to").is_some() { (p.get("to").and_then(vec3)? - base).dot(n) } else if let Some(d) = extrude_reach(s, p) { - d + if p.get("to").is_some() { d - start } else { d } } else { through_all_reach(&st, p, base)? }; diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index dd44f7279..b094d649a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -1385,6 +1385,30 @@ fn extrude_auto_operation() { assert!(rel(volume(&mut s), 40.0 * 30.0 * 15.0 - 100.0 * 8.0) < 1e-6); } +/// #467: the automatic operation is decided where the extrude starts. A profile on a plate's top +/// going down cuts; started From Object at the plate's bottom (or 15 mm lower by a start offset) +/// the same distance goes out of it, and joins. +#[test] +fn extrude_auto_operation_counts_from_the_start() { + let mut s = Session::default(); + run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 10, "corner": [0, 0, 0]})); + run(&mut s, "sketch.create", json!({"plane": {"origin": [0, 0, 10], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}})); + run(&mut s, "sketch.rectangle.two_point", json!({"p0": [5, 5], "p1": [15, 15]})); + run(&mut s, "sketch.finish", json!({})); + let down = json!({"profiles": [{"point": [10, 10]}], "distance": -5}); + assert_eq!(auto_operation(&s, &down), Some("cut")); + let mut from = down.clone(); + from["from"] = json!([20, 15, 0]); + assert_eq!(auto_operation(&s, &from), Some("join")); + let mut offset = down.clone(); + offset["start_offset"] = json!("-15 mm"); + assert_eq!(auto_operation(&s, &offset), Some("join")); + // Up from the bottom face into the plate it cuts again. + let mut up = from.clone(); + up["distance"] = json!(5); + assert_eq!(auto_operation(&s, &up), Some("cut")); +} + /// #1666: a loft between two 18-point polylines has twisted (bilinear) side faces. Each was /// meshed as two flat triangles, which cross the surface; the mesh volume was 16 800.6 mm³ /// against the B-rep's 17 884. Divided to the chord tolerance, the mesh matches the B-rep. diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index fe0d2fd77..8afc9c605 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2414,6 +2414,15 @@ fn auto_operation(app: &SolveApp, d: &mut Dialog) { return; } let Some(params) = dialog_commands(app, d).ok().and_then(|c| c.into_iter().next()).map(|(_, p)| p) else { return }; + // A new start (From Object, a start offset) puts the extrude somewhere else: the latch was + // decided for the old one (#467). + let start = json!([params.get("from"), params.get("start_offset")]); + if let Kind::Extrude { smart, .. } = &mut d.kind + && smart.start != start + { + smart.start = start; + smart.latch = None; + } // To an object, the extrude goes to it on whichever side it is: that is the side (#1633). if params.get("to").is_some() && let Some(reach) = solidcraft_engine::extrude_reach(&app.session, ¶ms) diff --git a/crates/ui-egui/src/smart_extrude.rs b/crates/ui-egui/src/smart_extrude.rs index 03c31cd26..8dd2259dc 100644 --- a/crates/ui-egui/src/smart_extrude.rs +++ b/crates/ui-egui/src/smart_extrude.rs @@ -10,7 +10,8 @@ //! into a body is a Cut and stays one however far it goes, through the far side included; //! one that starts as a Join does not turn into a Cut when it reaches another body. When //! the distance passes through zero onto the other side (a drag reversed past the start, or -//! Reverse), the operation is decided afresh for that side and latched there. A zero +//! Reverse), the operation is decided afresh for that side and latched there. So is a new +//! start (From Object, a start offset): it moves the extrude to other bodies (#467). A zero //! distance changes nothing. Choosing an operation by hand ends the automatic choice for //! the rest of the extrude. @@ -28,6 +29,8 @@ pub struct Smart { pub latch: Option<(usize, i8)>, /// The To Object target the distance was last set from. pub target: Option, + /// Where the extrude starts (its From Object and start offset) when the latch was decided. + pub start: serde_json::Value, /// Picks off the profile plane become the To Object target (Preferences › Design). pub auto_to_object: bool, } diff --git a/crates/ui-egui/src/smart_extrude_ui_tests.rs b/crates/ui-egui/src/smart_extrude_ui_tests.rs index f1d451fac..aa15dbb94 100644 --- a/crates/ui-egui/src/smart_extrude_ui_tests.rs +++ b/crates/ui-egui/src/smart_extrude_ui_tests.rs @@ -124,6 +124,32 @@ fn an_explicit_reverse_keeps_the_operation() { assert_eq!(state(&h), (1, JOIN, false)); } +/// A Cut latched for a drag into the box gives way once the extrude starts from the bottom +/// face: from there the same distance goes out of the box, so it joins (#467). +#[test] +fn a_new_start_object_decides_the_operation_again() { + let mut h = box_with_top_extrude(false); + drag_to(&mut h, 5.0); + assert_eq!(state(&h), (0, CUT, true), "into the box: Cut"); + // Start: From Object, the box's bottom face (as the Start choice and a pick there make it). + let st = h.app.session.world_state(); + let b = st.bodies.first().expect("the box"); + let bottom = + (0..64).find(|i| b.body.planar_face(*i).is_some_and(|p| p.normal().z < -0.99 && p.origin.z.abs() < 1e-9)).expect("the box's bottom face"); + let face = solidcraft_engine::Sel::Face { body: b.name.clone(), index: bottom, point: solidcraft_engine::geom::Vec3::new(10.0, 10.0, 0.0) }; + if let Some(d) = &mut h.app.dialog { + let mut from = crate::selection::SelInput::new("From Object", crate::selection::FACES | crate::selection::VERTICES, false); + from.items.push(face); + d.inputs.push(from); + } + h.frames(2); + assert_eq!(h.app.dialog.as_ref().unwrap().inputs.last().unwrap().items.len(), 1, "the bottom face is the start"); + assert_eq!(state(&h), (0, JOIN, true), "from the bottom face, 5 mm down: Join"); + h.step(&json!({"key":"Enter"})).unwrap(); + assert!(h.app.dialog.is_none()); + assert!((volume(&h) - (4000.0 + 500.0)).abs() < 1e-6, "a 10 x 10 x 5 block under the box: {}", volume(&h)); +} + /// Press Pull on a hole's wall shows an arrow along the wall's normal: dragged 2 mm towards the /// axis, the 5 mm hole closes to 3 mm (#2873). #[test]