Struct riddle_math::Rect [−][src]
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]
T: SpacialNumeric,
pub fn new<V: Into<Vector2<T>>>(position: V, size: V) -> Self
[src]
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]
T: SignedSpacialNumeric,
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]
size_a: Vector2<S>,
size_b: Vector2<S>,
b_relative_position: Vector2<T>
) -> Option<(Self, Self)>
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,
T: RefUnwindSafe,
impl<T> Send for Rect<T> where
T: Send,
T: Send,
impl<T> Sync for Rect<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Rect<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Rect<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,