[−][src]Struct rgx::rect::Rect
A generic rectangle with bottom left and top right coordinates.
Fields
x1: T
y1: T
x2: T
y2: T
Methods
impl<T> Rect<T>
[src]
pub const fn new(x1: T, y1: T, x2: T, y2: T) -> Self
[src]
pub fn sized(x1: T, y1: T, w: T, h: T) -> Self where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
pub fn zero() -> Self where
T: Zero,
[src]
T: Zero,
pub fn origin(w: T, h: T) -> Self where
T: Zero,
[src]
T: Zero,
pub fn map<F, S>(self, f: F) -> Rect<S> where
F: Fn(T) -> S,
[src]
F: Fn(T) -> S,
pub fn scale(&self, x: T, y: T) -> Self where
T: Mul<Output = T> + Copy,
[src]
T: Mul<Output = T> + Copy,
pub fn with_origin(&self, x: T, y: T) -> Self where
T: Add<Output = T> + Sub<Output = T> + Copy,
[src]
T: Add<Output = T> + Sub<Output = T> + Copy,
Return the rectangle with a different origin.
Examples
use rgx::rect::Rect; let r = Rect::new(1, 1, 4, 4); assert_eq!(r.with_origin(0, 0), Rect::new(0, 0, 3, 3));
pub fn with_size(&self, w: T, h: T) -> Self where
T: Add<Output = T> + Sub<Output = T> + Copy,
[src]
T: Add<Output = T> + Sub<Output = T> + Copy,
Return the rectangle with a different size.
Examples
use rgx::rect::Rect; let r = Rect::new(1, 1, 4, 4); assert_eq!(r.with_size(9, 9), Rect::new(1, 1, 10, 10));
pub fn expand(&self, x1: T, y1: T, x2: T, y2: T) -> Self where
T: Add<Output = T> + Sub<Output = T> + PartialOrd + Copy,
[src]
T: Add<Output = T> + Sub<Output = T> + PartialOrd + Copy,
Return an expanded rectangle by a constant amount.
Examples
use rgx::rect::Rect; let r = Rect::new(0, 0, 3, 3); assert_eq!(r.expand(1, 1, 1, 1), Rect::new(-1, -1, 4, 4)); let r = Rect::new(3, 3, 0, 0); assert_eq!(r.expand(1, 1, 1, 1), Rect::new(4, 4, -1, -1)); let r = Rect::new(-1, 1, 1, -1); assert_eq!(r.expand(4, 4, 4, 4), Rect::new(-5, 5, 5, -5));
pub fn flip_y(&self) -> Self where
T: Copy,
[src]
T: Copy,
Return the rectangle flipped in the Y axis.
pub fn flip_x(&self) -> Self where
T: Copy,
[src]
T: Copy,
Return the rectangle flipped in the X axis.
pub fn area(&self) -> T where
T: Copy + Sub<Output = T> + PartialOrd + Mul<Output = T>,
[src]
T: Copy + Sub<Output = T> + PartialOrd + Mul<Output = T>,
Return the area of a rectangle.
pub fn is_empty(&self) -> bool where
T: PartialEq,
[src]
T: PartialEq,
pub fn is_zero(&self) -> bool where
T: Zero,
[src]
T: Zero,
pub fn width(&self) -> T where
T: Copy + PartialOrd + Sub<Output = T>,
[src]
T: Copy + PartialOrd + Sub<Output = T>,
Return the width of the rectangle.
Examples
use rgx::rect::Rect; let r = Rect::new(0, 0, 3, 3); assert_eq!(r.width(), 3);
pub fn height(&self) -> T where
T: Copy + PartialOrd + Sub<Output = T>,
[src]
T: Copy + PartialOrd + Sub<Output = T>,
Return the height of the rectangle.
Examples
use rgx::rect::Rect; let r = Rect::origin(-6, -6); assert_eq!(r.height(), 6);
pub fn min(&self) -> Point2<T> where
T: PartialOrd + Copy,
[src]
T: PartialOrd + Copy,
Return the minimum point of a rectangle.
Examples
use rgx::rect::Rect; use rgx::math::Point2; let r = Rect::new(0, 0, 1, -1); assert_eq!(r.min(), Point2::new(0, -1));
pub fn max(&self) -> Point2<T> where
T: PartialOrd + Copy,
[src]
T: PartialOrd + Copy,
Return the maximum point of a rectangle.
Examples
use rgx::rect::Rect; use rgx::math::Point2; let r = Rect::origin(-1, 1); assert_eq!(r.max(), Point2::new(0, 1));
pub fn center(&self) -> Point2<T> where
T: Div<Output = T> + Copy + Ord + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,
[src]
T: Div<Output = T> + Copy + Ord + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,
Return the center of the rectangle.
Examples
use rgx::rect::Rect; use rgx::math::Point2; let r = Rect::origin(8, 8); assert_eq!(r.center(), Point2::new(4, 4)); let r = Rect::new(0, 0, -8, -8); assert_eq!(r.center(), Point2::new(-4, -4));
pub fn radius(&self) -> T where
T: Div<Output = T> + Copy + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,
[src]
T: Div<Output = T> + Copy + From<i16> + PartialOrd + Zero + Neg<Output = T> + Sub<Output = T>,
pub fn contains(&self, p: Point2<T>) -> bool where
T: Copy + PartialOrd,
[src]
T: Copy + PartialOrd,
Check whether the given point is contained in the rectangle.
use rgx::rect::Rect; use rgx::math::Point2; let r = Rect::origin(6, 6); assert!(r.contains(Point2::new(0, 0))); assert!(r.contains(Point2::new(3, 3))); assert!(!r.contains(Point2::new(6, 6))); let r = Rect::new(0, 0, -6, -6); assert!(r.contains(Point2::new(-3, -3)));
pub fn intersects(&self, other: Rect<T>) -> bool where
T: PartialOrd,
[src]
T: PartialOrd,
pub fn abs(&self) -> Rect<T> where
T: Ord + Copy,
[src]
T: Ord + Copy,
Return the absolute rectangle.
Examples
use rgx::rect::Rect; let r = Rect::new(3, 3, 1, 1).abs(); assert_eq!(r, Rect::new(1, 1, 3, 3)); let r = Rect::new(-1, -1, 1, 1).abs(); assert_eq!(r, Rect::new(-1, -1, 1, 1));
pub fn intersection(&self, other: Rect<T>) -> Self where
T: Ord + Copy,
[src]
T: Ord + Copy,
Return the intersection between two rectangles.
Examples
use rgx::rect::Rect; let other = Rect::new(0, 0, 3, 3); let r = Rect::new(1, 1, 6, 6); assert_eq!(r.intersection(other), Rect::new(1, 1, 3, 3)); let r = Rect::new(1, 1, 2, 2); assert_eq!(r.intersection(other), Rect::new(1, 1, 2, 2)); let r = Rect::new(-1, -1, 3, 3); assert_eq!(r.intersection(other), Rect::new(0, 0, 3, 3)); let r = Rect::new(-1, -1, 4, 4); assert_eq!(r.intersection(other), other); let r = Rect::new(4, 4, 5, 5); assert!(r.intersection(other).is_empty());
Trait Implementations
impl Geometry for Rect<f32>
[src]
impl<T: Clone> Clone for Rect<T>
[src]
impl<T: Copy> Copy for Rect<T>
[src]
impl<T: Eq> Eq for Rect<T>
[src]
impl<T: PartialEq> PartialEq<Rect<T>> for Rect<T>
[src]
impl<T: Debug> Debug for Rect<T>
[src]
impl<T> Sub<Vector2<T>> for Rect<T> where
T: Sub<Output = T> + Copy,
[src]
T: Sub<Output = T> + Copy,
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, vec: Vector2<T>) -> Self
[src]
impl<T> Add<Vector2<T>> for Rect<T> where
T: Add<Output = T> + Copy,
[src]
T: Add<Output = T> + Copy,
type Output = Self
The resulting type after applying the +
operator.
fn add(self, vec: Vector2<T>) -> Self
[src]
impl<T> Mul<T> for Rect<T> where
T: Mul<Output = T> + Copy,
[src]
T: Mul<Output = T> + Copy,
impl<T> AddAssign<Vector2<T>> for Rect<T> where
T: AddAssign<T> + Copy,
[src]
T: AddAssign<T> + Copy,
fn add_assign(&mut self, vec: Vector2<T>)
[src]
impl<T> SubAssign<Vector2<T>> for Rect<T> where
T: SubAssign<T> + Copy,
[src]
T: SubAssign<T> + Copy,
fn sub_assign(&mut self, vec: Vector2<T>)
[src]
impl<T> StructuralPartialEq for Rect<T>
[src]
impl<T> StructuralEq for Rect<T>
[src]
Auto Trait Implementations
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,
impl<T> RefUnwindSafe for Rect<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
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.
fn to_owned(&self) -> T
[src]
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 = !
The type returned in the event of a conversion error.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,