From 8285fb2ec3c9962613835cd03f423f2e531e6906 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sat, 10 Oct 2026 12:37:39 -0400 Subject: [PATCH] Polygonal Lasso: make the Shift constraint helper visible to its tests; cargo fmt Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/canvas.rs | 8 ++------ crates/ui-egui/src/polygon_lasso_tests.rs | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 04ee4341f..62a3532e7 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -4221,7 +4221,7 @@ pub(crate) fn selection_mode(app: &PhotocraftApp, m: egui::Modifiers) -> &'stati /// Shift constrains a Polygonal Lasso segment to Photoshop's 45° directions. /// Work in document coordinates so zoom, view rotation and mirroring cannot skew it. -fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64; 2] { +pub(crate) fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64; 2] { let dx = point[0] - from[0]; let dy = point[1] - from[1]; if !dx.is_finite() || !dy.is_finite() { @@ -4256,11 +4256,7 @@ fn polygon_click(app: &mut PhotocraftApp, x: f64, y: f64, mods: egui::Modifiers) } // Only constrain segments after the first vertex; the first click still sets selection intent. // Alt-drag is freehand and must not snap to an angle. - let point = if mods.shift && !mods.alt { - app.ui.polygon.last().copied().map_or([x, y], |last| constrained_polygon_point(last, [x, y])) - } else { - [x, y] - }; + let point = if mods.shift && !mods.alt { app.ui.polygon.last().copied().map_or([x, y], |last| constrained_polygon_point(last, [x, y])) } else { [x, y] }; app.ui.polygon.push(point); } diff --git a/crates/ui-egui/src/polygon_lasso_tests.rs b/crates/ui-egui/src/polygon_lasso_tests.rs index ec026a6e7..f370073c6 100644 --- a/crates/ui-egui/src/polygon_lasso_tests.rs +++ b/crates/ui-egui/src/polygon_lasso_tests.rs @@ -367,8 +367,7 @@ fn shift_constrains_polygonal_lasso_segments_but_unmodified_clicks_remain_free() #[test] fn shift_polygonal_lasso_snap_has_all_eight_directions_and_handles_zero_length() { let origin = [200.0, 150.0]; - let directions = [[40.0, 1.0], [40.0, 25.0], [1.0, 40.0], [-40.0, 25.0], - [-40.0, -1.0], [-40.0, -25.0], [-1.0, -40.0], [40.0, -25.0]]; + let directions = [[40.0, 1.0], [40.0, 25.0], [1.0, 40.0], [-40.0, 25.0], [-40.0, -1.0], [-40.0, -25.0], [-1.0, -40.0], [40.0, -25.0]]; for delta in directions { let end = crate::canvas::constrained_polygon_point(origin, [origin[0] + delta[0], origin[1] + delta[1]]); let dx = end[0] - origin[0];