From fcd3c2966c55122f1497fbeafb64bde69a41fbf2 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Wed, 11 Nov 2026 17:55:28 +0100 Subject: [PATCH 1/2] Shape tools: Shift draws the square or circle from the shorter side of the drag (#13222) Shift-dragging with the Ellipse tool took the longer side of the drag, so a 200 x 100 drag made a 200 x 200 circle; Photoshop makes a 100 x 100 one, and Shift+Alt centres that circle on the press. `shape_geometry` now takes the shorter side. The rule is shared by every box-drawn shape tool (the issue measured the Rectangle tool to follow the same rule), so the Rectangle and Star tests that pinned the longer side now expect the shorter one. The drag preview and Space repositioning go through `shape_bounds`, which calls the same function, so they show the same box as the result. --- crates/ui-egui/src/star_tool_tests.rs | 2 +- crates/ui-egui/src/tools/vector_ui.rs | 3 + .../vector_ui/ellipse_shift_circle_tests.rs | 76 +++++++++++++++++++ crates/ui-egui/src/tools/vector_ui/shapes.rs | 3 +- crates/ui-egui/src/tools/vector_ui/tests.rs | 8 +- 5 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs diff --git a/crates/ui-egui/src/star_tool_tests.rs b/crates/ui-egui/src/star_tool_tests.rs index b83bb15d83..8a476690c8 100644 --- a/crates/ui-egui/src/star_tool_tests.rs +++ b/crates/ui-egui/src/star_tool_tests.rs @@ -109,7 +109,7 @@ fn shift_and_alt_constrain_and_centre_the_star_like_the_polygon_tool() { app.ui.tool = Tool::Star; drag(&mut app, [100.0, 100.0], [140.0, 120.0], Modifiers::SHIFT | Modifiers::ALT); match live_shape(&app) { - Some(LiveShape::Polygon { rect, .. }) => assert_eq!(rect, [60.0, 60.0, 80.0, 80.0], "a square box drawn from the centre"), + Some(LiveShape::Polygon { rect, .. }) => assert_eq!(rect, [80.0, 80.0, 40.0, 40.0], "a square box of the shorter side drawn from the centre (#13222)"), other => panic!("a live star shape, got {other:?}"), } } diff --git a/crates/ui-egui/src/tools/vector_ui.rs b/crates/ui-egui/src/tools/vector_ui.rs index 54fe6527ce..382947e5de 100644 --- a/crates/ui-egui/src/tools/vector_ui.rs +++ b/crates/ui-egui/src/tools/vector_ui.rs @@ -231,6 +231,9 @@ mod delete_anchor_options_bar_tests; #[cfg(test)] mod pen_enter_deselects_tests; +#[cfg(test)] +mod ellipse_shift_circle_tests; + pub(crate) use pen::freeform_locked_shape; /// Where a Pen draft goes, captured at its first anchor. diff --git a/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs b/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs new file mode 100644 index 0000000000..d57cb42eea --- /dev/null +++ b/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs @@ -0,0 +1,76 @@ +//! #13222: ⇧ while dragging with the Ellipse tool makes a circle from the shorter side of the +//! drag, as in Photoshop, not the longer one; ⇧⌥ centres that circle on the press. The drag +//! preview (`shape_bounds`) shows the same box as the layer the drag makes. + +use egui::Modifiers; +use photocraft_doc::{LayerContent, LiveShape}; +use serde_json::json; + +use super::shape_bounds; +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + app.sync_views(); + app.ui.tool = Tool::EllipseShape; + app +} + +/// A drag pressed without modifiers, with `mods` pressed after the start (so the press picks no +/// path operation or eyedropper). +fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2], mods: Modifiers) { + tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, Modifiers::NONE); + tool_event(app, ToolEvent::Move { x: (from[0] + to[0]) / 2.0, y: (from[1] + to[1]) / 2.0, pressure: 1.0 }, mods); + tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, mods); + tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, mods); +} + +/// The active layer's live ellipse `[x, y, w, h]`. +fn ellipse_rect(app: &PhotocraftApp) -> [f64; 4] { + let st = app.session.active().unwrap(); + match &st.doc.layer(st.active_layer.unwrap()).unwrap().content { + LayerContent::Shape(s) => match &s.live { + Some(LiveShape::Ellipse { rect }) => *rect, + other => panic!("a live ellipse, got {other:?}"), + }, + _ => panic!("a shape layer"), + } +} + +fn preview(app: &PhotocraftApp, from: [f64; 2], to: [f64; 2], mods: Modifiers) -> [f64; 4] { + shape_bounds(&app.ui.tool_options, Tool::EllipseShape, from, to, mods).expect("a box") +} + +#[test] +fn shift_makes_a_circle_from_the_shorter_side() { + let mut app = app(); + drag(&mut app, [400.0, 300.0], [600.0, 400.0], Modifiers::SHIFT); + assert_eq!(ellipse_rect(&app), [400.0, 300.0, 100.0, 100.0]); + assert_eq!(preview(&app, [400.0, 300.0], [600.0, 400.0], Modifiers::SHIFT), [400.0, 300.0, 500.0, 400.0]); +} + +#[test] +fn shift_uses_the_shorter_side_when_the_drag_is_taller_than_wide() { + let mut app = app(); + drag(&mut app, [400.0, 300.0], [450.0, 500.0], Modifiers::SHIFT); + assert_eq!(ellipse_rect(&app), [400.0, 300.0, 50.0, 50.0]); + assert_eq!(preview(&app, [400.0, 300.0], [450.0, 500.0], Modifiers::SHIFT), [400.0, 300.0, 450.0, 350.0]); +} + +#[test] +fn shift_alt_centres_the_shorter_side_circle_on_the_press() { + let mut app = app(); + let mods = Modifiers::SHIFT | Modifiers::ALT; + drag(&mut app, [400.0, 300.0], [600.0, 400.0], mods); + assert_eq!(ellipse_rect(&app), [300.0, 200.0, 200.0, 200.0]); + assert_eq!(preview(&app, [400.0, 300.0], [600.0, 400.0], mods), [300.0, 200.0, 500.0, 400.0]); +} + +#[test] +fn shift_keeps_the_drag_direction_up_and_left() { + let app = app(); + assert_eq!(preview(&app, [400.0, 300.0], [200.0, 200.0], Modifiers::SHIFT), [300.0, 200.0, 400.0, 300.0]); +} diff --git a/crates/ui-egui/src/tools/vector_ui/shapes.rs b/crates/ui-egui/src/tools/vector_ui/shapes.rs index 0776227d04..83fc490ee3 100644 --- a/crates/ui-egui/src/tools/vector_ui/shapes.rs +++ b/crates/ui-egui/src/tools/vector_ui/shapes.rs @@ -103,7 +103,8 @@ pub(super) fn shape_geometry(o: &ToolOptions, tool: Tool, start: [f64; 2], end: } else { let (mut w, mut h) = (end[0] - start[0], end[1] - start[1]); if mods.shift { - let m = w.abs().max(h.abs()); + // The shorter side of the drag sets the square, as in Photoshop (#13222). + let m = w.abs().min(h.abs()); (w, h) = (m * w.signum(), m * h.signum()); } let (x0, y0) = if mods.alt { (start[0] - w, start[1] - h) } else { (start[0], start[1]) }; diff --git a/crates/ui-egui/src/tools/vector_ui/tests.rs b/crates/ui-egui/src/tools/vector_ui/tests.rs index b7d19a4d5f..3b85a4757e 100644 --- a/crates/ui-egui/src/tools/vector_ui/tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/tests.rs @@ -491,7 +491,7 @@ fn shape_drag_creates_layers_with_modifiers() { finish_shape(&mut app, Tool::Rectangle, [10.0, 10.0], [60.0, 30.0], egui::Modifiers::SHIFT); let st = app.session.active().unwrap(); let b = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().content_bounds(); - assert_eq!((b.width(), b.height()), (50, 50), "shift = square"); + assert_eq!((b.width(), b.height()), (20, 20), "shift = square of the shorter side (#13222)"); finish_shape(&mut app, Tool::EllipseShape, [100.0, 100.0], [120.0, 110.0], egui::Modifiers::ALT); let st = app.session.active().unwrap(); let b = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().content_bounds(); @@ -693,9 +693,9 @@ fn shift_pressed_during_a_shape_drag_constrains_it() { let l = st.doc.layer(st.active_layer.unwrap()).unwrap(); assert!(matches!(l.content, LayerContent::Shape(_)), "{tool:?} ({sides} sides): a shape layer"); let b = l.surface().unwrap().content_bounds(); - // The drag is 60 × 30; constrained, the shape's box is 60 × 60 (a hexagon is narrower - // than its box, so the height tells). - assert!(b.height().abs_diff(60) <= 1 && b.width() <= 61, "{tool:?}: ⇧ mid-drag keeps proportions: {b:?}"); + // The drag is 60 × 30; constrained, the shape's box is 30 × 30, the shorter side (#13222) + // (a hexagon is narrower than its box, so the height tells). + assert!(b.height().abs_diff(30) <= 1 && b.width() <= 31, "{tool:?}: ⇧ mid-drag keeps proportions: {b:?}"); } } From 2124972069052354f53b8ee65c83aece547ab196 Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 13 Nov 2026 02:50:13 +0100 Subject: [PATCH 2/2] PR #13248: name the reference application in the new comments The two comments the PR adds named the reference product by its trademark; public text says "reference application". Co-Authored-By: RickiNano <81099017+RickiNano@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- .../ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs | 4 ++-- crates/ui-egui/src/tools/vector_ui/shapes.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs b/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs index d57cb42eea..0d134ece1a 100644 --- a/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/ellipse_shift_circle_tests.rs @@ -1,6 +1,6 @@ //! #13222: ⇧ while dragging with the Ellipse tool makes a circle from the shorter side of the -//! drag, as in Photoshop, not the longer one; ⇧⌥ centres that circle on the press. The drag -//! preview (`shape_bounds`) shows the same box as the layer the drag makes. +//! drag, as in the reference application, not the longer one; ⇧⌥ centres that circle on the +//! press. The drag preview (`shape_bounds`) shows the same box as the layer the drag makes. use egui::Modifiers; use photocraft_doc::{LayerContent, LiveShape}; diff --git a/crates/ui-egui/src/tools/vector_ui/shapes.rs b/crates/ui-egui/src/tools/vector_ui/shapes.rs index 3adcecc2de..cd05a26036 100644 --- a/crates/ui-egui/src/tools/vector_ui/shapes.rs +++ b/crates/ui-egui/src/tools/vector_ui/shapes.rs @@ -116,7 +116,7 @@ pub(super) fn shape_geometry(o: &ToolOptions, tool: Tool, start: [f64; 2], end: } else { let (mut w, mut h) = (end[0] - start[0], end[1] - start[1]); if mods.shift { - // The shorter side of the drag sets the square, as in Photoshop (#13222). + // The drag's shorter side sets the square, as in the reference application (#13222). let m = w.abs().min(h.abs()); (w, h) = (m * w.signum(), m * h.signum()); }