From bca228fdaa2945b9c4528e5514ed8732d3c70b24 Mon Sep 17 00:00:00 2001 From: CrazyboyQCD <53971641+CrazyboyQCD@users.noreply.github.com> Date: Mon, 9 Sep 2024 23:40:00 +0800 Subject: [PATCH] Simplify `pick_rounded_rect` (#15065) # Objective Simplify `pick_rounded_rect` with multiple `if` statements to make it more readable and efficient([Godbolt link](https://godbolt.org/z/W5vPEvT5c)). Co-authored-by: WX\shixi --- crates/bevy_ui/src/focus.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index 387d47c06cec4..c7feeca10fb6c 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -352,12 +352,12 @@ pub(crate) fn pick_rounded_rect( size: Vec2, border_radius: ResolvedBorderRadius, ) -> bool { - let s = point.signum(); - let r = (border_radius.top_left * (1. - s.x) * (1. - s.y) - + border_radius.top_right * (1. + s.x) * (1. - s.y) - + border_radius.bottom_right * (1. + s.x) * (1. + s.y) - + border_radius.bottom_left * (1. - s.x) * (1. + s.y)) - / 4.; + let [top, bottom] = if point.x < 0. { + [border_radius.top_left, border_radius.bottom_left] + } else { + [border_radius.top_right, border_radius.bottom_right] + }; + let r = if point.y < 0. { top } else { bottom }; let corner_to_point = point.abs() - 0.5 * size; let q = corner_to_point + r;