swamp_render::prelude

Struct URect

Source
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 a UVec2.
  • size: The width and height of the rectangle as a UVec2.

Fields§

§position: UVec2§size: UVec2

Implementations§

Source§

impl URect

Source

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);
Source

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 a UVec2.
  • size: The width and height of the rectangle as a UVec2.
§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);
Source

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.

Source

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: The UVec2 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§

Source§

impl Clone for URect

Source§

fn clone(&self) -> URect

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for URect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<(u16, u16, u16, u16)> for URect

Source§

fn from(value: (u16, u16, u16, u16)) -> URect

Converts to this type from the input type.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,