swamp_render::prelude

Struct Rect

Source
pub struct Rect {
    pub position: Vec2,
    pub size: UVec2,
}
Expand description

A 2D rectangle with integer coordinates for position and unsigned integer dimensions.

This struct represents a rectangle in a 2D space where the position is specified using Vec2 for integer coordinates, and the size (width and height) is represented using UVec2 for unsigned integer dimensions.

§Fields

  • position: The bottom-left corner of the rectangle as a Vec2.
  • size: The width and height of the rectangle as a UVec2.

§Examples

use int_math::prelude::*;

// Create a rectangle with bottom-left corner at (10, 20) and size (30, 40)
let rect = Rect {
    position: Vec2::new(10, 20),
    size: UVec2::new(30, 40),
};

assert_eq!(rect.position, Vec2::new(10, 20));
assert_eq!(rect.size, UVec2::new(30, 40));

Fields§

§position: Vec2§size: UVec2

Implementations§

Source§

impl Rect

Source

pub const fn new(x: i16, y: i16, width: u16, height: u16) -> Rect

Creates a new Rect instance with the specified position and size.

§Arguments
  • x: The x-coordinate of the bottom-left corner of the rectangle.
  • y: The y-coordinate of the bottom-left corner of the rectangle.
  • width: The width of the rectangle.
  • height: The height of the rectangle.
§Examples
use int_math::prelude::*;

let rect = Rect::new(10, 20, 30, 40);
assert_eq!(rect.position, Vec2::new(10, 20));
assert_eq!(rect.size, UVec2::new(30, 40));
Source

pub const fn with_position_and_size(position: Vec2, size: UVec2) -> Rect

Creates a new Rect instance with the specified position and size.

§Arguments
  • position: The bottom-left corner of the rectangle as a Vec2.
  • size: The width and height of the rectangle as a UVec2.
§Examples
use int_math::prelude::*;

let position = Vec2::new(10, 20);
let size = UVec2::new(30, 40);
let rect = Rect::with_position_and_size(position, size);
assert_eq!(rect.position, position);
assert_eq!(rect.size, size);
Source

pub const fn center(self) -> Vec2

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 = Rect::new(10, 20, 30, 40);
let center = rect.center();
assert_eq!(center, Vec2::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: Vec2) -> Rect

Returns a new Rect 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 Vec2 to add to the rectangle’s position.
§Examples
use int_math::prelude::*;

let rect = Rect::new(10, 20, 30, 40);
let offset = Vec2::new(5, -5);
let new_rect = rect.with_offset(offset);
assert_eq!(new_rect.position, Vec2::new(15, 15));

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

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 Rect

Source§

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

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

impl From<(i16, i16, u16, u16)> for Rect

Source§

fn from(value: (i16, i16, u16, u16)) -> Rect

Converts to this type from the input type.
Source§

impl Copy for Rect

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

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,