Skip to content

Commit bca228f

Browse files
CrazyboyQCDWX\shixi
andauthored
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 <shixi1@cnwxsoft.com>
1 parent 7b217a9 commit bca228f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/bevy_ui/src/focus.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ pub(crate) fn pick_rounded_rect(
352352
size: Vec2,
353353
border_radius: ResolvedBorderRadius,
354354
) -> bool {
355-
let s = point.signum();
356-
let r = (border_radius.top_left * (1. - s.x) * (1. - s.y)
357-
+ border_radius.top_right * (1. + s.x) * (1. - s.y)
358-
+ border_radius.bottom_right * (1. + s.x) * (1. + s.y)
359-
+ border_radius.bottom_left * (1. - s.x) * (1. + s.y))
360-
/ 4.;
355+
let [top, bottom] = if point.x < 0. {
356+
[border_radius.top_left, border_radius.bottom_left]
357+
} else {
358+
[border_radius.top_right, border_radius.bottom_right]
359+
};
360+
let r = if point.y < 0. { top } else { bottom };
361361

362362
let corner_to_point = point.abs() - 0.5 * size;
363363
let q = corner_to_point + r;

0 commit comments

Comments
 (0)