From aeb1ad78148729a65512337a2b074ca9a4ae1ccd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 17 Nov 2026 17:26:49 -0800 Subject: [PATCH] Shapes: a centered Circle tool release draws the circle it shows With From Center, a second press moved less than 2 screen points now draws the outline through the pointer the preview follows, not through the point of the press. A second click on the center still places nothing. --- crates/tools/src/circle.rs | 5 +++-- crates/tools/src/circle/tests.rs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/tools/src/circle.rs b/crates/tools/src/circle.rs index 8f16210542..99ec88f6e7 100644 --- a/crates/tools/src/circle.rs +++ b/crates/tools/src/circle.rs @@ -285,9 +285,10 @@ impl Tool for CircleTool { // a drag from there draws the circle on the diameter it drags out. (Some(Press::Second { on_first: true, dragged: false, .. }), ..) => vec![], (Some(Press::Second { on_first: true, dragged: true, .. }), Some(a), Some(c)) => self.draw(&[a, c]), + // From a center: the outline passes through the point the tool shows it on, where + // the drag ends or, within DRAG_PX of the press, where the pointer last was. + (Some(Press::Second { .. }), Some(a), Some(c)) if self.centered => self.draw(&[a, c]), (Some(Press::Second { at, dragged: false, .. }), Some(a), _) => self.draw(&[a, at]), - // From a center: the outline passes through the point the drag ends on. - (Some(Press::Second { dragged: true, .. }), Some(a), Some(c)) if self.centered => self.draw(&[a, c]), // Three points: Alt's rounding of the diameter does not apply. (Some(Press::Second { snapped, dragged: true, .. }), Some(a), Some(c)) => self.draw(&[a, snapped, c]), _ => vec![], diff --git a/crates/tools/src/circle/tests.rs b/crates/tools/src/circle/tests.rs index 0b2336f278..32875b186d 100644 --- a/crates/tools/src/circle/tests.rs +++ b/crates/tools/src/circle/tests.rs @@ -409,6 +409,27 @@ fn from_center_two_clicks_draw_the_circle_through_the_second() { assert_eq!(drag(&mut t, &cx, (330.0, 340.0), &[(360.0, 300.0)], Mods::default()), centered((300.0, 300.0), (360.0, 300.0))); } +/// With From Center, the release draws the circle the tool shows: a drag from the center ends +/// where it is let go, and a second press moved less than 2 screen points draws the outline +/// through the pointer, not through the point of the press. +#[test] +fn from_center_the_release_draws_the_circle_shown() { + let (d, _) = doc_with_rect(); + let (s, p) = (Selection::default(), paint()); + let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) }; + let mut t = from_center(); + t.pointer(&cx, &ev(PointerKind::Down, (300.0, 300.0), Mods::default())); + t.pointer(&cx, &ev(PointerKind::Drag, (380.0, 300.0), Mods::default())); + assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (400.0, 300.0), Mods::default())), centered((300.0, 300.0), (400.0, 300.0))); + click(&mut t, &cx, (300.0, 300.0)); + t.pointer(&cx, &ev(PointerKind::Down, (330.0, 340.0), Mods::default())); + t.pointer(&cx, &ev(PointerKind::Drag, (331.0, 340.0), Mods::default())); + let shown = preview(&t.overlays(&cx)).expect("the circle is shown"); + let r = Point::new(300.0, 300.0).distance(Point::new(331.0, 340.0)); + assert!(near(shown, Rect::new(300.0 - r, 300.0 - r, 300.0 + r, 300.0 + r)), "{:?}", t.overlays(&cx)); + assert_eq!(t.pointer(&cx, &ev(PointerKind::Up, (331.0, 340.0), Mods::default())), centered((300.0, 300.0), (331.0, 340.0))); +} + /// With From Center, Shift keeps the point at 45° steps from the center, and Alt rounds the /// diameter, twice the radius, to the rulers' ticks (every 5 pt at 100% in points). #[test]