From f372cbcff34261790c06c99fb7cdc16b67fa5b2e Mon Sep 17 00:00:00 2001 From: Zinadin Zidan Date: Sat, 7 Nov 2026 02:09:09 +0600 Subject: [PATCH] Shapes: hovering a box side skips the outline test of shapes out of reach (#11473 review) The side band asks on every hover frame whether another shape is under the pointer, and the pick sampled every shape layer's curves to find out. It now skips that sampling for a shape whose control-point box, grown by the pick tolerance, doesn't hold the point, since none of its outline can be in reach there. What it picks is unchanged, Path Selection's clicks included; a test pins hits just past a shape's box and on a stroke's pixels past its path. --- crates/ui-egui/src/shape_bounds_box_tests.rs | 31 +++++++++++++++++++ .../ui-egui/src/tools/vector_ui/path_ops.rs | 14 ++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/shape_bounds_box_tests.rs b/crates/ui-egui/src/shape_bounds_box_tests.rs index d4b74aaa3a..9c4d4ff322 100644 --- a/crates/ui-egui/src/shape_bounds_box_tests.rs +++ b/crates/ui-egui/src/shape_bounds_box_tests.rs @@ -454,3 +454,34 @@ fn a_press_on_a_neighbouring_shape_or_past_the_band_stays_the_tools() { near(bounds(&app, b), [420.0, 318.0, 723.0, 451.0]); } } + +/// #11473 review: the pick under the side band skips a shape's outline test where the point is +/// out of reach of it, and still finds every shape it found before: an outline within the pick +/// tolerance just past the shape's box, and a fill's pixels past the path (an outside stroke). +#[test] +fn the_pick_still_finds_shapes_just_past_their_path_bounds() { + use crate::vector_ui::pick_shape_at; + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 1000, "height": 700, "background": "white"})).unwrap(); + // A stroke-only ellipse 200,200–400,300: picked by its outline alone. + app.run("shape.create", json!({"kind": "ellipse", "rect": [200, 200, 200, 100], "fill": null, "stroke": {"width": 2}})).unwrap(); + let e = app.session.active().unwrap().active_layer.unwrap(); + // A filled rectangle 500,400–600,500 with a 20 px stroke outside its path. + app.run("shape.create", json!({"kind": "rect", "rect": [500, 400, 100, 100], "fill": "#20a040", "stroke": {"width": 20, "align": "outside"}})).unwrap(); + let r = app.session.active().unwrap().active_layer.unwrap(); + let doc = &app.session.active().unwrap().doc; + let pick = |p: [f64; 2], tol: f64| pick_shape_at(doc, p, tol); + // Within the tolerance of the ellipse's extreme anchors, outside its box. + assert_eq!(pick([405.5, 250.0], 6.0), Some(e)); + assert_eq!(pick([300.0, 194.5], 6.0), Some(e)); + assert_eq!(pick([406.5, 250.0], 6.0), None); + assert_eq!(pick([300.0, 193.5], 6.0), None); + // Within it of a curve, off the anchors: the ellipse's outline at 45°. + let (cx, cy) = (300.0 + 100.0 * std::f64::consts::FRAC_1_SQRT_2, 250.0 + 50.0 * std::f64::consts::FRAC_1_SQRT_2); + assert_eq!(pick([cx + 4.0, cy], 6.0), Some(e)); + // The stroke's pixels up to 20 px past the rectangle's path, far past the tolerance. + assert_eq!(pick([612.0, 450.0], 1.0), Some(r)); + assert_eq!(pick([550.0, 381.5], 1.0), Some(r)); + assert_eq!(pick([625.0, 450.0], 1.0), None); + assert_eq!(pick([550.0, 378.5], 1.0), None); +} diff --git a/crates/ui-egui/src/tools/vector_ui/path_ops.rs b/crates/ui-egui/src/tools/vector_ui/path_ops.rs index e6c3a1a6cc..7ce80f1973 100644 --- a/crates/ui-egui/src/tools/vector_ui/path_ops.rs +++ b/crates/ui-egui/src/tools/vector_ui/path_ops.rs @@ -253,7 +253,7 @@ pub fn pick_shape_at(doc: &Document, at: [f64; 2], tol: f64) -> Option Option bool { + let Some((x0, y0, x1, y1)) = path.control_bounds() else { return false }; + let pad = tol * 1.001 + 1e-9 * (1.0 + at[0].abs() + at[1].abs()); + // Written so a NaN bound keeps the check (`edit::hit` decides), as an infinite one does. + !(at[0] < x0 - pad || at[0] > x1 + pad || at[1] < y0 - pad || at[1] > y1 + pad) +} + pub fn path_selection_finish(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) { let (dx, dy) = (end[0] - start[0], end[1] - start[1]); let tol = 6.0 / f64::from(app.point_zoom().max(0.01));