Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Revolve: keep the angle grab point when the sweep is zero (#9601) (#9602)

Thodoris Tsagkogeorgas0ad74f2577a5
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index caffae2f9d..6f3b328e99 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -5014,6 +5014,29 @@ pub fn revolve_extent_with_convention(
symmetric: bool,
to: Option<Vec3>,
convention: crate::RevolveConvention,
+) -> Result<RevolveExtent> {
+ let extent = revolve_extent_for_handle(st, plane, regions, (origin, axis), (angle, angle2), symmetric, to, convention)?;
+ // A solid needs an open sweep inside one full turn. Zero and a turn past 360° keep a
+ // handle frame (`revolve_extent_for_handle`) and still fail here, with the same message.
+ if !(extent.sweep.abs() > 1e-9 && extent.sweep.abs() <= std::f64::consts::TAU + 1e-9) {
+ return Err(DocError::Invalid("the revolve angle must be more than 0 and at most 360°".into()));
+ }
+ Ok(extent)
+}
+
+/// Where the angle handle sits. A sweep of zero, or past a full turn, builds no solid and
+/// [`revolve_extent_with_convention`] refuses it. The boundary is still a point on the circle,
+/// and the grab point stays there so the angle can be dragged back into range.
+#[allow(clippy::too_many_arguments)]
+pub fn revolve_extent_for_handle(
+ st: &ModelState,
+ plane: &Plane,
+ regions: &[Region2],
+ (origin, axis): (Vec3, Vec3),
+ (angle, angle2): (f64, Option<f64>),
+ symmetric: bool,
+ to: Option<Vec3>,
+ convention: crate::RevolveConvention,
) -> Result<RevolveExtent> {
let (start, sweep) = match (to, angle2, symmetric) {
(Some(point), _, _) => {
@@ -5053,7 +5076,7 @@ pub fn revolve_extent_with_convention(
(None, None, true) => (-angle / 2.0, angle),
(None, None, false) => (0.0, angle),
};
- if !(sweep.is_finite() && start.is_finite() && sweep.abs() > 1e-9 && sweep.abs() <= std::f64::consts::TAU + 1e-9) {
+ if !(sweep.is_finite() && start.is_finite()) {
return Err(DocError::Invalid("the revolve angle must be more than 0 and at most 360°".into()));
}
let points: Vec<Vec2> = regions.iter().flat_map(|r| r.outer.polyline(1e-2)).collect();
diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs
index fbd94b407b..bd89b493b9 100644
--- a/crates/doc/src/lib.rs
+++ b/crates/doc/src/lib.rs
@@ -87,9 +87,9 @@ pub use document::*;
pub use eval::{
EdgeRef, FeatureResult, Model, ModelBody, ModelState, PlacedBodies, RevolveExtent, SavedModel, SolvedSketch, ThreadInfo, curve_pick_error,
edge_names_for, edge_refs, face_point_names, face_point_state, hole_direction_at, import_body_names, join_pieces_added, map_wire,
- metric_thread_sizes, object_height, parse_metric_thread, pattern_matrices, revolve_extent, revolve_extent_with_convention, select_profiles,
- sketch_hole_direction, sketch_line_plane, state_in_frame, state_in_frame_at, suggested_thread, tangent_face_chain, through_all_distance,
- world_state, world_state_reusing,
+ metric_thread_sizes, object_height, parse_metric_thread, pattern_matrices, revolve_extent, revolve_extent_for_handle,
+ revolve_extent_with_convention, select_profiles, sketch_hole_direction, sketch_line_plane, state_in_frame, state_in_frame_at, suggested_thread,
+ tangent_face_chain, through_all_distance, world_state, world_state_reusing,
};
pub use eval::{EvalCache, KeptResults};
pub use expr::Expr;
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 8e284097e0..15cde8dc4e 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -1862,7 +1862,9 @@ fn revolve_display_extent(app: &SolveApp, d: &Dialog, axis: (Vec3, Vec3)) -> Opt
.ok()?;
(angle, other)
};
- solidcraft_engine::doc::revolve_extent_with_convention(
+ // The solid refuses 0° and a sweep past a full turn, and the dialog says so. The handle
+ // still uses that boundary, so the grab point stays and the angle can be dragged back.
+ solidcraft_engine::doc::revolve_extent_for_handle(
&state,
&plane,
&regions,
diff --git a/crates/ui-egui/src/revolve_manipulator_tests.rs b/crates/ui-egui/src/revolve_manipulator_tests.rs
index a9d493af2e..324cbbf7c4 100644
--- a/crates/ui-egui/src/revolve_manipulator_tests.rs
+++ b/crates/ui-egui/src/revolve_manipulator_tests.rs
@@ -225,6 +225,44 @@ fn free_drag_and_invalid_expression_stay_editable_before_commit() {
assert!((volume(&h) - expected_volume(60.0)).abs() < 0.03);
}
+/// Typing 0° builds no solid, and the dialog keeps the range error. The grab point stays on
+/// the profile, and dragging it brings the angle back.
+#[test]
+fn zero_angle_keeps_the_grab_point_and_a_drag_brings_the_angle_back() {
+ for (params, handle, drag_to, entered_angle, committed) in
+ [(json!({}), "revolve", 45.0, "45 deg", 45.0), (json!({"direction": "symmetric"}), "revolve2", -45.0, "90 deg", 90.0)]
+ {
+ let mut h = fixture(Harness::new(), params.clone());
+ open(&mut h);
+ h.step(&json!({"click":{"handle":"dialog:Angle"}})).unwrap();
+ h.step(&json!({"key":"A","cmd":true})).unwrap();
+ h.step(&json!({"text":"0 deg"})).unwrap();
+ h.frames(4);
+ handle_at(&mut h, "revolve", at_angle(0.0));
+ // A preview refusal stays on the preview while the angle field is still being typed in.
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
+ while h.app.preview.busy {
+ assert!(std::time::Instant::now() < deadline, "the preview did not finish");
+ h.frames(1);
+ }
+ let error = h.app.dialog.as_ref().and_then(|dialog| dialog.error.clone()).or_else(|| h.app.preview.error.clone()).unwrap_or_default();
+ assert!(error.contains("more than 0"), "{error}");
+ h.step(&json!({"widget":"OK"})).unwrap();
+ assert!(h.app.dialog.is_some(), "a zero angle still builds no solid");
+ h.step(&json!({"drag":[{"handle":handle},{"world":at_angle(drag_to)}]})).unwrap();
+ let crate::dialogs::Kind::Revolve { angle: entered, .. } = &h.app.dialog.as_ref().unwrap().kind else { panic!("revolve") };
+ assert_eq!(entered, entered_angle);
+ h.step(&json!({"widget":"OK"})).unwrap();
+ assert!(h.app.dialog.is_none(), "{:?}", h.app.dialog.as_ref().map(|dialog| &dialog.error));
+ assert_eq!(angle(&h), entered_angle);
+ let got = volume(&h);
+ let want = expected_volume(committed);
+ // A symmetric drag that starts with both handles stacked at 0° lands within a tenth of a
+ // cubic millimetre of the analytic quarter turn.
+ assert!((got - want).abs() < 0.1, "params={params} got={got} want={want}");
+ }
+}
+
#[test]
fn second_side_can_be_dragged_to_zero_without_becoming_full_turn() {
let mut h = fixture(Harness::new(), json!({"angle":"60 deg","angle2":"30 deg"}));