diff --git a/crates/ui-egui/src/canvas/transform_controls.rs b/crates/ui-egui/src/canvas/transform_controls.rs index 5a26a5a281..76237b1e20 100644 --- a/crates/ui-egui/src/canvas/transform_controls.rs +++ b/crates/ui-egui/src/canvas/transform_controls.rs @@ -58,10 +58,12 @@ pub(super) fn transform_controls_rect(app: &PhotocraftApp, xf: &ViewXform) -> Op Some(Rect::from_two_pos(xf.to_screen(b.x0 as f32, b.y0 as f32), xf.to_screen(b.x1 as f32, b.y1 as f32))) } +/// Express the unopened screen rectangle in the same corner order as a transform quad. fn controls_quad(r: Rect) -> [[f64; 2]; 4] { [r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom()].map(|p| [f64::from(p.x), f64::from(p.y)]) } +/// Classify screen coordinates with the fixed screen-space tolerance, without a pivot. fn controls_zone(r: Rect, p: Pos2) -> crate::transform_tool::Hit { crate::state::TransformSession::box_hit(&controls_quad(r), [f64::from(p.x), f64::from(p.y)], crate::transform_tool::HANDLE_PX) } diff --git a/crates/ui-egui/src/tools/transform_tool/pointer.rs b/crates/ui-egui/src/tools/transform_tool/pointer.rs index 735bec0658..d06f921574 100644 --- a/crates/ui-egui/src/tools/transform_tool/pointer.rs +++ b/crates/ui-egui/src/tools/transform_tool/pointer.rs @@ -19,6 +19,9 @@ pub(crate) enum Hit { /// Screen-sized corner and outward edge bands, shared with Move's unopened controls. impl TransformSession { + /// Classify a document point with screen-sized corner and outward edge zones. + /// Corners outrank free edge bands; overlapping painted handles keep nearest-handle priority. + /// Only projection-scale rounding is treated as an edge on the interior side. pub(crate) fn box_hit(quad: &[[f64; 2]; 4], p: [f64; 2], tol: f64) -> Hit { // `tol` is the existing 12 pt handle tolerance, divided by the view zoom. let corner_radius = tol * (8.0 / HANDLE_PX); @@ -119,6 +122,8 @@ pub(crate) fn hit(t: &TransformSession, p: [f64; 2], tol: f64) -> Hit { if d(t.pivot) < tol && d(t.pivot) < handle_distance { Hit::Pivot } else { h } } +/// Even-odd quad membership, independent of winding and valid for concave boxes. +/// Handles and edge-rounding tolerance are classified separately by the caller. fn inside(q: &[[f64; 2]; 4], p: [f64; 2]) -> bool { let mut c = false; for i in 0..4 { @@ -314,6 +319,8 @@ pub(crate) fn rotate_cursor_dir(app: &PhotocraftApp, p: [f64; 2]) -> Option<[f64 rotate_dir(app.ui.transform.as_ref()?, app.transform_preview.as_ref(), p, handle_tolerance(app)) } +/// Choose hover or captured rotation feedback without overriding scaling gestures. +/// Warp, Distort, Skew and Content-Aware Scale keep their own cursor behavior. pub(super) fn rotate_dir(t: &TransformSession, pv: Option<&TransformPreview>, p: [f64; 2], tol: f64) -> Option<[f64; 2]> { // Content-Aware Scale's box only scales, and Skew doesn't rotate: no rotate arrow. if !(p[0].is_finite() && p[1].is_finite()) diff --git a/crates/ui-egui/src/transform_hit_zone_tests.rs b/crates/ui-egui/src/transform_hit_zone_tests.rs index 010d4e68e9..1f9b52ae1c 100644 --- a/crates/ui-egui/src/transform_hit_zone_tests.rs +++ b/crates/ui-egui/src/transform_hit_zone_tests.rs @@ -43,6 +43,7 @@ fn near(actual: Option<[f64; 2]>, expected: [f64; 2]) { assert!((actual[0] - expected[0]).hypot(actual[1] - expected[1]) < 1e-6, "{actual:?} != {expected:?}"); } +/// Screen-sized zones must survive zoom changes; the interior control rejects an all-sided edge grab area. #[test] fn whole_edge_and_corner_priority_table_at_100_and_200_percent() { for zoom in [1.0, 2.0] { @@ -73,6 +74,7 @@ fn whole_edge_and_corner_priority_table_at_100_and_200_percent() { } } +/// An overlapping corner zone must not steal a closer painted midpoint on a small box. #[test] fn small_boxes_keep_their_painted_mid_edge_handles() { for side in [8.0, 16.0, 32.0] { @@ -89,6 +91,7 @@ fn small_boxes_keep_their_painted_mid_edge_handles() { } } +/// Reproduce inward rounding through the view transform, with a one-pixel interior control. #[test] fn an_edge_survives_the_actual_f32_view_round_trip() { for zoom in [1.0_f32, 2.0] { @@ -103,6 +106,7 @@ fn an_edge_survives_the_actual_f32_view_round_trip() { } } +/// The same small-edge press must be ignored by Distort and stretch one axis in legacy unlinked scaling. #[test] fn a_small_edge_keeps_distort_and_legacy_aspect_behavior() { for mode in [TransformMode::Distort, TransformMode::Free] { @@ -131,6 +135,7 @@ fn a_small_edge_keeps_distort_and_legacy_aspect_behavior() { } } +/// At 45 degrees, corners and edges exchange cursor axis orientation at both tested zooms. #[test] fn turned_box_zones_and_resize_cursors_follow_the_quad() { let turn = |p: [f64; 2]| { @@ -158,6 +163,7 @@ fn turned_box_zones_and_resize_cursors_follow_the_quad() { } } +/// Skewed edges and reversed winding must use actual segment geometry for hits and turn direction. #[test] fn distorted_and_flipped_quads_use_their_edges_not_an_axis_aligned_box() { let q = [[100.0, 100.0], [500.0, 140.0], [460.0, 300.0], [80.0, 260.0]]; @@ -171,6 +177,7 @@ fn distorted_and_flipped_quads_use_their_edges_not_an_axis_aligned_box() { } } +/// A concave quad whose corner mean is beyond an edge rejects center-based normal orientation. #[test] fn concave_quad_edge_direction_uses_winding_in_both_orientations() { let q = [[0.0, 0.0], [100.0, 0.0], [10.0, 10.0], [0.0, 100.0]]; @@ -179,6 +186,7 @@ fn concave_quad_edge_direction_uses_winding_in_both_orientations() { } } +/// Each outside position selects its inward turn orientation and hides the system cursor. #[test] fn outside_rotation_has_eight_edge_and_corner_orientations() { let app = app(QUAD, 1.0); @@ -199,6 +207,7 @@ fn outside_rotation_has_eight_edge_and_corner_orientations() { } } +/// Compare unopened controls with an active session at identical points, including a free interior. #[test] fn unopened_move_controls_share_the_open_sessions_zones_and_cursors() { let app = app(QUAD, 1.0); @@ -217,6 +226,7 @@ fn unopened_move_controls_share_the_open_sessions_zones_and_cursors() { assert!(!transform_controls_hit(r, r.center()), "inside remains an ordinary Move drag"); } +/// A press away from midpoint handles must scale an anchored preview without creating a history edit. #[test] fn move_whole_edge_press_enters_scaling_at_both_zooms() { for zoom in [1.0, 2.0] { @@ -250,6 +260,7 @@ fn move_whole_edge_press_enters_scaling_at_both_zooms() { } } +/// Excluded modes retain cursor ownership, and non-finite coordinates cannot activate controls. #[test] fn modes_that_do_not_rotate_and_invalid_points_do_not_hide_the_pointer() { let mut app = app(QUAD, 1.0); @@ -278,6 +289,7 @@ fn modes_that_do_not_rotate_and_invalid_points_do_not_hide_the_pointer() { } } +/// Captured rotation must retain feedback after crossing into the box, independent of hover zones. #[test] fn rotate_drag_keeps_the_arrow_when_the_pointer_enters_the_box() { let mut app = app(QUAD, 1.0);