Skip to content

Commit 1ec5cdf

Browse files
Optimize the values for EMPTY rect. (#13470)
I am unsure if this needs changing, so let me know if I need to change anything else. # Objective Fixes #13461. ## Solution I applied the changes as suggested in the issue, and updated the doc comments accordingly ## Testing I don't think this needs too much testing, but there are no `cargo test` failures.
1 parent 5dbd827 commit 1ec5cdf

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

crates/bevy_math/src/rects/irect.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ pub struct IRect {
2020

2121
impl IRect {
2222
/// An empty `IRect`, represented by maximum and minimum corner points
23-
/// with all `i32::MAX` values.
23+
/// with `max == IVec2::MIN` and `min == IVec2::MAX`, so the
24+
/// rect has an extremely large negative size.
25+
/// This is useful, because when taking a union B of a non-empty `IRect` A and
26+
/// this empty `IRect`, B will simply equal A.
2427
pub const EMPTY: Self = Self {
25-
max: IVec2::MAX,
28+
max: IVec2::MIN,
2629
min: IVec2::MAX,
2730
};
2831
/// Create a new rectangle from two corner points.

crates/bevy_math/src/rects/rect.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ pub struct Rect {
2020

2121
impl Rect {
2222
/// An empty `Rect`, represented by maximum and minimum corner points
23-
/// with all `f32::MAX` values.
23+
/// at `Vec2::NEG_INFINITY` and `Vec2::INFINITY`, respectively.
24+
/// This is so the `Rect` has a infinitely negative size.
25+
/// This is useful, because when taking a union B of a non-empty `Rect` A and
26+
/// this empty `Rect`, B will simply equal A.
2427
pub const EMPTY: Self = Self {
25-
max: Vec2::MAX,
26-
min: Vec2::MAX,
28+
max: Vec2::NEG_INFINITY,
29+
min: Vec2::INFINITY,
2730
};
2831
/// Create a new rectangle from two corner points.
2932
///

crates/bevy_math/src/rects/urect.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ pub struct URect {
2020

2121
impl URect {
2222
/// An empty `URect`, represented by maximum and minimum corner points
23-
/// with all `u32::MAX` values.
23+
/// with `max == UVec2::MIN` and `min == UVec2::MAX`, so the
24+
/// rect has an extremely large negative size.
25+
/// This is useful, because when taking a union B of a non-empty `URect` A and
26+
/// this empty `URect`, B will simply equal A.
2427
pub const EMPTY: Self = Self {
25-
max: UVec2::MAX,
28+
max: UVec2::MIN,
2629
min: UVec2::MAX,
2730
};
2831
/// Create a new rectangle from two corner points.

0 commit comments

Comments
 (0)