[][src]Struct riddle_math::Rect

#[repr(C)]pub struct Rect<T> {
    pub location: Vector2<T>,
    pub dimensions: Vector2<T>,
}

An axis aligned 2d rectangle with both a location and size.

Fields

location: Vector2<T>

The coordinates of the min point of the rectangle.

dimensions: Vector2<T>

The size of the rectangle

Implementations

impl<T> Rect<T> where
    T: SpacialNumeric
[src]

pub fn new<V: Into<Vector2<T>>>(position: V, size: V) -> Self[src]

Create a new rect

Example

let rect = Rect::new(vec2(0,0), vec2(10,10));

pub fn min_point(&self) -> Vector2<T>[src]

Get the min point of the rect, the same as its location

Example

let rect = Rect::new(vec2(0,0), vec2(10,10));
assert_eq!(vec2(0,0), rect.min_point());

pub fn max_point(&self) -> Vector2<T>[src]

Get the max point of the rect

Example

let rect = Rect::new(vec2(5,5), vec2(10,10));
assert_eq!(vec2(15,15), rect.max_point());

pub fn intersect(&self, other: &Self) -> Option<Self>[src]

Get the intersection rect of two rectangles, if one exists

Example

let rect_a = Rect::new(vec2(0,0), vec2(10,10));
let rect_b = Rect::new(vec2(5,5), vec2(10,10));
assert_eq!(Some(Rect::new(vec2(5,5), vec2(5,5))), rect_a.intersect(&rect_b));

let rect_c = Rect::new(vec2(0, 0), vec2(1,1));
assert_eq!(None, rect_b.intersect(&rect_c));

pub fn contains_point(&self, point: Vector2<T>) -> bool[src]

Test to see whether a point lies within the rect.

Example

let rect = Rect::new(vec2(0,0), vec2(1,1));
assert_eq!(true, rect.contains_point(vec2(0,0)));
assert_eq!(false, rect.contains_point(vec2(1,1)));

impl<T> Rect<T> where
    T: SignedSpacialNumeric
[src]

pub fn intersect_relative_to_both<S: SpacialNumericConversion<T>>(
    size_a: Vector2<S>,
    size_b: Vector2<S>,
    b_relative_position: Vector2<T>
) -> Option<(Self, Self)>
[src]

Given the dimensions of two rects, and the relative offset of the second with respect to the first, calculate the intersection between the two rects, and return rects defining the intersection relative to each of the inputs.

Example

let rect_dimensions_a = vec2(4,4);
let rect_dimensions_b = vec2(5,5);
let b_relative_to_a = vec2(2,2);

let (rect_a, rect_b) = Rect::intersect_relative_to_both(rect_dimensions_a,
    rect_dimensions_b, b_relative_to_a).unwrap();

assert_eq!(Rect::new(vec2(2,2), vec2(2,2)), rect_a);
assert_eq!(Rect::new(vec2(0,0), vec2(2,2)), rect_b);

Trait Implementations

impl<T: Clone> Clone for Rect<T>[src]

impl<T: Debug> Debug for Rect<T>[src]

impl<T: PartialEq> Eq for Rect<T>[src]

impl<T: PartialEq> PartialEq<Rect<T>> for Rect<T>[src]

impl<T: SpacialNumericConversion<U>, U> SpacialNumericConversion<Rect<U>> for Rect<T>[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.