From 1ec5cdf3f2aac4d40cb641aa438531264cf4a0fe Mon Sep 17 00:00:00 2001 From: Olle Lukowski <63189113+Olle-Lukowski@users.noreply.github.com> Date: Wed, 22 May 2024 15:34:23 +0200 Subject: [PATCH] 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. --- crates/bevy_math/src/rects/irect.rs | 7 +++++-- crates/bevy_math/src/rects/rect.rs | 9 ++++++--- crates/bevy_math/src/rects/urect.rs | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/bevy_math/src/rects/irect.rs b/crates/bevy_math/src/rects/irect.rs index d99a4ae080..786f39cdd4 100644 --- a/crates/bevy_math/src/rects/irect.rs +++ b/crates/bevy_math/src/rects/irect.rs @@ -20,9 +20,12 @@ pub struct IRect { impl IRect { /// An empty `IRect`, represented by maximum and minimum corner points - /// with all `i32::MAX` values. + /// with `max == IVec2::MIN` and `min == IVec2::MAX`, so the + /// rect has an extremely large negative size. + /// This is useful, because when taking a union B of a non-empty `IRect` A and + /// this empty `IRect`, B will simply equal A. pub const EMPTY: Self = Self { - max: IVec2::MAX, + max: IVec2::MIN, min: IVec2::MAX, }; /// Create a new rectangle from two corner points. diff --git a/crates/bevy_math/src/rects/rect.rs b/crates/bevy_math/src/rects/rect.rs index 786c57588f..82aa9d8574 100644 --- a/crates/bevy_math/src/rects/rect.rs +++ b/crates/bevy_math/src/rects/rect.rs @@ -20,10 +20,13 @@ pub struct Rect { impl Rect { /// An empty `Rect`, represented by maximum and minimum corner points - /// with all `f32::MAX` values. + /// at `Vec2::NEG_INFINITY` and `Vec2::INFINITY`, respectively. + /// This is so the `Rect` has a infinitely negative size. + /// This is useful, because when taking a union B of a non-empty `Rect` A and + /// this empty `Rect`, B will simply equal A. pub const EMPTY: Self = Self { - max: Vec2::MAX, - min: Vec2::MAX, + max: Vec2::NEG_INFINITY, + min: Vec2::INFINITY, }; /// Create a new rectangle from two corner points. /// diff --git a/crates/bevy_math/src/rects/urect.rs b/crates/bevy_math/src/rects/urect.rs index 2903dc163d..80fdbe7760 100644 --- a/crates/bevy_math/src/rects/urect.rs +++ b/crates/bevy_math/src/rects/urect.rs @@ -20,9 +20,12 @@ pub struct URect { impl URect { /// An empty `URect`, represented by maximum and minimum corner points - /// with all `u32::MAX` values. + /// with `max == UVec2::MIN` and `min == UVec2::MAX`, so the + /// rect has an extremely large negative size. + /// This is useful, because when taking a union B of a non-empty `URect` A and + /// this empty `URect`, B will simply equal A. pub const EMPTY: Self = Self { - max: UVec2::MAX, + max: UVec2::MIN, min: UVec2::MAX, }; /// Create a new rectangle from two corner points.