Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integer equivalents for Rect #7984

Merged
merged 21 commits into from
Jun 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/bevy_math/src/rects/urect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ impl URect {
}

/// Create a new rectangle with a constant inset.
///
/// # Panics
///
/// This method panics if the inset is larger than the rect's min x or y
///
/// The inset is the extra border on all sides. A positive inset produces a larger rectangle,
/// while a negative inset is allowed and produces a smaller rectangle. If the inset is negative
Expand All @@ -309,8 +313,14 @@ impl URect {
#[inline]
pub fn inset(&self, inset: i32) -> Self {
let mut r = Self {
min: (self.min.as_ivec2() - inset).as_uvec2(),
max: (self.max.as_ivec2() + inset).as_uvec2(),
min: UVec2::new(
self.min.x.checked_add_signed(-inset).unwrap(),
LiamGallagher737 marked this conversation as resolved.
Show resolved Hide resolved
self.min.y.checked_add_signed(-inset).unwrap(),
),
max: UVec2::new(
self.max.x.checked_add_signed(inset).unwrap(),
self.max.y.checked_add_signed(inset).unwrap(),
),
};
// Collapse min over max to enforce invariants and ensure e.g. width() or
// height() never return a negative value.
Expand Down