Skip to content

Commit

Permalink
Optimize the values for EMPTY rect. (bevyengine#13470)
Browse files Browse the repository at this point in the history
I am unsure if this needs changing, so let me know if I need to change
anything else.

# Objective

Fixes bevyengine#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.
  • Loading branch information
Olle-Lukowski authored May 22, 2024
1 parent 5dbd827 commit 1ec5cdf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions crates/bevy_math/src/rects/irect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions crates/bevy_math/src/rects/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
7 changes: 5 additions & 2 deletions crates/bevy_math/src/rects/urect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1ec5cdf

Please sign in to comment.