Struct Rect

Source
pub struct Rect {
    pub min: Vect,
    pub max: Vect,
}
Expand description

Rect is Rectangular shape or AABB for detecting collisions in 2D space

Fields§

§min: Vect§max: Vect

Implementations§

Source§

impl Rect

Source

pub const ZERO: Rect

Source

pub const INVERTED_MAX_RECT: Rect

Source

pub const MAX_RECT: Rect

Source

pub fn new(x0: f32, y0: f32, x1: f32, y1: f32) -> Rect

new is rect constructor

Source

pub fn wh(x: f32, y: f32, w: f32, h: f32) -> Rect

wn lets you specify width and height of rectangle rather then two points

Source

pub fn centered(c: Vect, w: f32, h: f32) -> Rect

centered returns rect that has center in c

Source

pub fn cube(c: Vect, rad: f32) -> Rect

cube is similar to centered but you specify just radius of cube with means that if rad is 5 then width and height are 10

Source

pub fn from_vec(v: Vect) -> Rect

from_vec turns vector to rectangle. This works properly only for purely positive otherwise normalization is required

Source

pub fn bounds_for(points: &[Vect]) -> Rect

bounds for returns rectangle where all points from slice fits in

Source

pub fn verts(&self) -> [Vect; 4]

verts returns corner points of rectangle

Source

pub fn union(&self, o: &Rect) -> Rect

union returns smallest rectangle in witch both self and o fits in

Source

pub fn center(&self) -> Vect

center returns center of rectangle

Source

pub fn loc_verts(&self) -> [Vect; 4]

loc_verts returns corners of rectangle relative to its center

Source

pub fn to_local(&self) -> Rect

to_local returns rect centered around coordinate origin (0, 0)

Source

pub fn width(&self) -> f32

width returns rectangles width

Source

pub fn height(&self) -> f32

height returns rectangles height

Source

pub fn respective(&self, pos: Vect) -> Sides

respective returns where the point is respective to rectangle

Source

pub fn normalized(self) -> Rect

normalized normalizes rectangle so the min is lower them max

Source

pub fn contains(&self, pos: Vect) -> bool

contains returns whether rect contains the points

Source

pub fn fits_in(&self, o: &Rect) -> bool

fits_in returns whether self fits in o

Source

pub fn radius(&self) -> f32

radius returns distance from rect center to max

Source

pub fn moved(&self, delta: Vect) -> Self

moved returns rectangle moved by delta

Source

pub fn centered_to(&self, pos: Vect) -> Self

Source

pub fn area(&self) -> f32

Source

pub fn to_rays(&self) -> [Ray; 4]

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

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

impl Default for Rect

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Intersection<Circ> for Rect

Source§

fn intersects(&self, o: &Circ) -> bool

returns whether rectangle intersects circle

Source§

impl Intersection<Ray> for Rect

Source§

fn intersects(&self, o: &Ray) -> bool

returns whether rectangle intersects ray

Source§

impl Intersection<Rect> for Circ

Source§

fn intersects(&self, o: &Rect) -> bool

Source§

impl Intersection<Rect> for Ray

Source§

fn intersects(&self, o: &Rect) -> bool

Source§

impl Intersection<Rect> for Rect

Source§

fn intersects(&self, o: &Rect) -> bool

returns whether rectangle intersects another rectangle

Source§

impl IntersectionPoints<Ray> for Rect

Source§

fn intersects_points(&self, o: &Ray) -> [Option<Vect>; 2]

returns intersection points of rectangle and ray

Source§

impl IntersectionPoints<Rect> for Ray

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V