Struct fyrox_math::Rect

source ·
pub struct Rect<T> {
    pub position: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>,
    pub size: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>,
}
Expand description

A rectangle defined by position and size.

Fields§

§position: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Position of the rectangle.

§size: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Size of the rectangle, where X - width, Y - height.

Implementations§

source§

impl<T> Rect<T>
where T: Number,

source

pub fn new(x: T, y: T, w: T, h: T) -> Rect<T>

Creates a new rectangle from X, Y, width, height.

source

pub fn with_position( self, position: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>> ) -> Rect<T>

Sets the new position of the rectangle.

source

pub fn with_size( self, size: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>> ) -> Rect<T>

Sets the new size of the rectangle.

source

pub fn inflate(&self, dw: T, dh: T) -> Rect<T>

Inflates the rectangle by the given amounts. It offsets the rectangle by (-dw, -dh) and increases its size by (2 * dw, 2 * dh).

source

pub fn deflate(&self, dw: T, dh: T) -> Rect<T>

Deflates the rectangle by the given amounts. It offsets the rectangle by (dw, dh) and decreases its size by (2 * dw, 2 * dh).

source

pub fn contains( &self, pt: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>> ) -> bool

Checks if the given point lies within the bounds of the rectangle.

source

pub fn center(&self) -> Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Returns center point of the rectangle.

source

pub fn push(&mut self, p: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>)

Extends the rectangle to contain the given point.

§Notes

To build bounding rectangle you should correctly initialize initial rectangle:


let vertices = [Vector2::new(1.0, 2.0), Vector2::new(-3.0, 5.0)];

// This is important part, it must have "invalid" state to correctly
// calculate bounding rect. Rect::default will give invalid result!
let mut bounding_rect = Rect::new(f32::MAX, f32::MAX, 0.0, 0.0);

for &v in &vertices {
    bounding_rect.push(v);
}
source

pub fn clip_by(&self, other: Rect<T>) -> Rect<T>

Clips the rectangle by some other rectangle and returns a new rectangle that corresponds to the intersection of both rectangles. If the rectangles does not intersects, the method returns this rectangle.

source

pub fn intersects(&self, other: Rect<T>) -> bool

Checks if the rectangle intersects with some other rectangle.

source

pub fn translate( &self, translation: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>> ) -> Rect<T>

Offsets the given rectangle and returns a new rectangle.

source

pub fn intersects_circle( &self, center: Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>, radius: T ) -> bool

Checks if the rectangle intersects a circle represented by a center point and a radius.

source

pub fn extend_to_contain(&mut self, other: Rect<T>)

Extends the rectangle so it will contain the other rectangle.

source

pub fn left_top_corner( &self ) -> Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Returns the top left corner of the rectangle.

source

pub fn right_top_corner( &self ) -> Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Returns the top right corner of the rectangle.

source

pub fn right_bottom_corner( &self ) -> Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Returns the bottom right corner of the rectangle.

source

pub fn left_bottom_corner( &self ) -> Matrix<T, Const<2>, Const<1>, ArrayStorage<T, 2, 1>>

Returns the bottom left corner of the rectangle.

source

pub fn w(&self) -> T

Returns width of the rectangle.

source

pub fn h(&self) -> T

Returns height of the rectangle.

source

pub fn x(&self) -> T

Returns horizontal position of the rectangle.

source

pub fn y(&self) -> T

Returns vertical position of the rectangle.

source

pub fn transform( &self, matrix: &Matrix<T, Const<3>, Const<3>, ArrayStorage<T, 3, 3>> ) -> Rect<T>

Applies an arbitrary affine transformation to the rectangle.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Rect<T>

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<T> Debug for Rect<T>
where T: Debug,

source§

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

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

impl<T> Default for Rect<T>
where T: Number,

source§

fn default() -> Rect<T>

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

impl<T> PartialEq for Rect<T>
where T: PartialEq,

source§

fn eq(&self, other: &Rect<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Copy for Rect<T>
where T: Copy,

source§

impl<T> Eq for Rect<T>
where T: Eq,

source§

impl<T> StructuralPartialEq for Rect<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Rect<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for Rect<T>
where T: Unpin,

§

impl<T> UnwindSafe for Rect<T>
where T: UnwindSafe,

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

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>,

§

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>,

§

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> Scalar for T
where T: 'static + Clone + PartialEq + Debug,