pub struct URect {
pub position: UVec2,
pub size: UVec2,
}
Expand description
A rectangle with unsigned integer dimensions.
This struct represents a rectangle on a 2D grid with its position and size.
§Examples
use int_math::prelude::*;
let rect = URect::new(10, 20, 30, 40);
println!("{:?}", rect); // Output: URect { position: UVec2 { x: 10, y: 20 }, size: UVec2 { x: 30, y: 40 } }
§Fields
position
: The lower-left corner of the rectangle as aUVec2
.size
: The width and height of the rectangle as aUVec2
.
Fields§
§position: UVec2
§size: UVec2
Implementations§
Source§impl URect
impl URect
Sourcepub const fn new(x: u16, y: u16, width: u16, height: u16) -> URect
pub const fn new(x: u16, y: u16, width: u16, height: u16) -> URect
Creates a new URect
instance with the specified position and size.
§Arguments
x
: The x-coordinate of the bottom-left corner.y
: The y-coordinate of the bottom-left corner.width
: The width of the rectangle.height
: The height of the rectangle.
§Examples
use int_math::prelude::*;
let rect = URect::new(10, 20, 30, 40);
assert_eq!(rect.position.x, 10);
assert_eq!(rect.position.y, 20);
assert_eq!(rect.size.x, 30);
assert_eq!(rect.size.y, 40);
Sourcepub const fn with_position_and_size(position: UVec2, size: UVec2) -> URect
pub const fn with_position_and_size(position: UVec2, size: UVec2) -> URect
Creates a new URect
instance with the specified position and size.
§Arguments
position
: The bottom-left corner of the rectangle as aUVec2
.size
: The width and height of the rectangle as aUVec2
.
§Examples
use int_math::prelude::*;
let position = UVec2::new(10, 20);
let size = UVec2::new(30, 40);
let rect = URect::with_position_and_size(position, size);
assert_eq!(rect.position, position);
assert_eq!(rect.size, size);
Sourcepub const fn center(self) -> UVec2
pub const fn center(self) -> UVec2
Computes and returns the center of the rectangle.
The center is calculated as the midpoint of the rectangle’s width and height from its bottom-left corner.
§Examples
use int_math::prelude::*;
let rect = URect::new(10, 20, 30, 40);
let center = rect.center();
assert_eq!(center, UVec2::new(25, 40));
§Note
This method performs integer division, which means that if the size of the rectangle is odd, the center coordinates may not be exact integers.
Sourcepub fn with_offset(self, offset: UVec2) -> URect
pub fn with_offset(self, offset: UVec2) -> URect
Returns a new URect
instance with the specified offset applied to its position.
The new rectangle will have the same size but its position will be adjusted by the given offset
.
§Arguments
offset
: TheUVec2
to add to the rectangle’s bottom-left position.
§Examples
use int_math::prelude::*;
let rect = URect::new(10, 20, 30, 40);
let offset = UVec2::new(5, 5);
let new_rect = rect.with_offset(offset);
assert_eq!(new_rect.position, UVec2::new(15, 25));
Trait Implementations§
impl Copy for URect
Auto Trait Implementations§
impl Freeze for URect
impl RefUnwindSafe for URect
impl Send for URect
impl Sync for URect
impl Unpin for URect
impl UnwindSafe for URect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more