Skip to content

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

Sketch Center Point Arc: a click places each point, typed values stay optional (#12208) (#12696)

PaddleStroke46438b14a7a1
diff --git a/crates/ui-egui/src/sketch_dims.rs b/crates/ui-egui/src/sketch_dims.rs
index ff83751b9a..defc0ac82b 100644
--- a/crates/ui-egui/src/sketch_dims.rs
+++ b/crates/ui-egui/src/sketch_dims.rs
@@ -341,8 +341,11 @@ fn live(app: &SolveApp, t: &Tool, e: Vec2, px: f64) -> Vec<(f64, Vec2)> {
("sketch.circle.two_tangent", 2) => {
vec![(crate::sketch_tools::two_tangent_default_radius(app, t), (first + a) * 0.5 + dir_or_x(a - first).perp() * off)]
}
- ("sketch.arc.center_point" | "sketch.slot.arc_center", 1)
- | ("sketch.polygon.inscribed" | "sketch.polygon.circumscribed" | "sketch.polygon.edge", 1) => {
+ // Out along the radius, beyond the cursor, as the sweep box: at the radius's middle the
+ // box covered the cursor of a short radius and took the click meant for the start point,
+ // so the arc waited for Enter (#12208).
+ ("sketch.arc.center_point" | "sketch.slot.arc_center", 1) => vec![((e - a).len(), e + dir_or_x(e - a) * (2.5 * off))],
+ ("sketch.polygon.inscribed" | "sketch.polygon.circumscribed" | "sketch.polygon.edge", 1) => {
vec![((e - a).len(), (a + e) * 0.5), (6.0, a + (e - a) * 0.5 + (e - a).perp() * 0.3)]
}
("sketch.arc.center_point" | "sketch.slot.arc_center", 2) => {
@@ -735,20 +738,45 @@ pub(crate) fn over_tool_boxes(app: &SolveApp, ctx: &egui::Context, p: egui::Pos2
/// Where a value box whose top left would be `pos` goes so it stays in the drawing area `view`:
/// as it is when it fits; else mirrored through the pointer (a box set off the cursor, past the
/// view's edge, goes to the cursor's other side, still clear of it, #2201); else pushed inside.
+/// A box that would still sit on the pointer moves beside it: there it would take the click meant
+/// for the next point, and the shape would wait for Enter (#12208).
fn in_view(pos: Pos2, view: Option<egui::Rect>, pointer: Option<Pos2>) -> Pos2 {
let Some(view) = view else { return pos };
let fits = |p: Pos2| view.contains_rect(egui::Rect::from_min_size(p, BOX));
- if fits(pos) {
+ let placed = if fits(pos) {
+ pos
+ } else if let Some(mirrored) = pointer.map(|c| c + (c - (pos + BOX * 0.5)) - BOX * 0.5).filter(|p| fits(*p)) {
+ mirrored
+ } else {
+ let max = (view.max - BOX).max(view.min);
+ pos.clamp(view.min, max)
+ };
+ off_pointer(placed, pointer, fits)
+}
+
+/// Gap between the pointer and a value box moved off it.
+const POINTER_GAP: f32 = 12.0;
+
+/// The most a value box spans from its top left: wider than `BOX`, as a box grows with its label
+/// and value ("Radius 12.345").
+const REACH: egui::Vec2 = egui::vec2(110.0, BOX.y);
+
+/// `pos` when the box there is clear of the pointer; else the box beside the pointer (right,
+/// left, below, above, the first that `fits`), keeping its other coordinate.
+fn off_pointer(pos: Pos2, pointer: Option<Pos2>, fits: impl Fn(Pos2) -> bool) -> Pos2 {
+ let Some(c) = pointer else { return pos };
+ if !egui::Rect::from_min_size(pos, REACH).expand(2.0).contains(c) {
return pos;
}
- if let Some(c) = pointer {
- let mirrored = c + (c - (pos + BOX * 0.5)) - BOX * 0.5;
- if fits(mirrored) {
- return mirrored;
- }
- }
- let max = (view.max - BOX).max(view.min);
- pos.clamp(view.min, max)
+ [
+ egui::pos2(c.x + POINTER_GAP, pos.y),
+ egui::pos2(c.x - POINTER_GAP - REACH.x, pos.y),
+ egui::pos2(pos.x, c.y + POINTER_GAP),
+ egui::pos2(pos.x, c.y - POINTER_GAP - REACH.y),
+ ]
+ .into_iter()
+ .find(|p| fits(*p))
+ .unwrap_or(pos)
}
#[cfg(test)]
diff --git a/crates/ui-egui/src/sketch_typed_intent_tests.rs b/crates/ui-egui/src/sketch_typed_intent_tests.rs
index 107c681cd6..dccb313947 100644
--- a/crates/ui-egui/src/sketch_typed_intent_tests.rs
+++ b/crates/ui-egui/src/sketch_typed_intent_tests.rs
@@ -330,3 +330,41 @@ fn the_arc_end_pick_snaps_to_a_point_under_the_value_box() {
assert!(snapped, "{command}: the third pick snapped to the line's end: {:?}", sketch.constraints.iter().map(|c| &c.kind).collect::<Vec<_>>());
}
}
+
+/// A Center Point Arc is drawn with three clicks, its value boxes optional: the Radius box never
+/// sits under the cursor, so the second click places the start point instead of landing in the
+/// box and waiting for Enter (#12208, #12205). Small radii in every direction, where a box at the
+/// radius's middle covered the cursor.
+#[test]
+fn a_center_point_arc_takes_three_clicks_without_enter() {
+ for (radius, angle) in [(2.0f64, 0.0f64), (4.0, 0.0), (4.0, 90.0), (4.0, 180.0), (4.0, 270.0), (6.0, 45.0), (15.0, 0.0)] {
+ let mut h = Harness::new();
+ h.app.run("sketch.create", json!({"plane":"XY"})).unwrap();
+ h.call("ui.view", json!({"view":"top"}));
+ h.app.cam.distance = 60.0;
+ h.app.cam.target = solidcore_record::Vec3::new(0.0, 0.0, 0.0);
+ h.settle();
+ h.step(&json!({"start":"sketch.arc.center_point"})).unwrap();
+ h.step(&json!({"click":{"world":[0, 0, 0]}})).unwrap();
+ let (s, c) = angle.to_radians().sin_cos();
+ let start = [radius * c, radius * s];
+ h.step(&json!({"move":{"world":[start[0], start[1], 0]}})).unwrap();
+ let cursor = h.at(&json!({"world":[start[0], start[1], 0]})).unwrap();
+ let cursor = egui::pos2(cursor[0] as f32, cursor[1] as f32);
+ let blocking = h.ctx.memory(|m| m.area_rect(egui::Id::unique(("sc_dim_area", 0usize)))).filter(|r| r.expand(2.0).contains(cursor));
+ assert!(blocking.is_none(), "radius {radius} at {angle} deg: the Radius box {blocking:?} sits under the cursor {cursor:?}");
+ h.step(&json!({"click":{"world":[start[0], start[1], 0]}})).unwrap();
+ assert_eq!(h.app.tool.as_ref().unwrap().pts.len(), 2, "radius {radius} at {angle} deg: the click placed the start point");
+ let (s, c) = (angle + 90.0).to_radians().sin_cos();
+ h.step(&json!({"move":{"world":[radius * c, radius * s, 0]}})).unwrap();
+ h.step(&json!({"click":{"world":[radius * c, radius * s, 0]}})).unwrap();
+ let state = h.app.session.world_state().unwrap();
+ let sketch = &state.sketch(h.app.session.active_sketch.unwrap()).unwrap().sketch;
+ let arc = sketch.curves.iter().find_map(|curve| match curve.kind {
+ CurveKind::Arc { c, a, .. } => Some(sketch.points[a].pos.dist(sketch.points[c].pos)),
+ _ => None,
+ });
+ assert!(arc.is_some_and(|r| (r - radius).abs() < 0.5), "radius {radius} at {angle} deg: three clicks made the arc, got {arc:?}");
+ assert!(!sketch.constraints.iter().any(|c| c.kind.is_dimension()), "radius {radius} at {angle} deg: clicks alone add no typed dimension");
+ }
+}