[][src]Struct rgx::rect::Rect

pub struct Rect<T> {
    pub x1: T,
    pub y1: T,
    pub x2: T,
    pub y2: T,
}

A generic rectangle with bottom left and top right coordinates.

Fields

x1: Ty1: Tx2: Ty2: 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]

pub fn zero() -> Self where
    T: Zero
[src]

pub fn origin(w: T, h: T) -> Self where
    T: Zero
[src]

pub fn map<F, S>(self, f: F) -> Rect<S> where
    F: Fn(T) -> S, 
[src]

pub fn scale(&self, x: T, y: T) -> Self where
    T: Mul<Output = T> + Copy
[src]

pub fn with_origin(&self, x: T, y: T) -> Self where
    T: Add<Output = T> + Sub<Output = T> + Copy
[src]

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]

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]

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]

Return the rectangle flipped in the Y axis.

pub fn flip_x(&self) -> Self where
    T: Copy
[src]

Return the rectangle flipped in the X axis.

pub fn area(&self) -> T where
    T: Copy + Sub<Output = T> + PartialOrd + Mul<Output = T>, 
[src]

Return the area of a rectangle.

pub fn is_empty(&self) -> bool where
    T: PartialEq
[src]

pub fn is_zero(&self) -> bool where
    T: Zero
[src]

pub fn width(&self) -> T where
    T: Copy + PartialOrd + Sub<Output = T>, 
[src]

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]

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]

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]

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]

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]

pub fn contains(&self, p: Point2<T>) -> bool where
    T: Copy + PartialOrd
[src]

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]

pub fn abs(&self) -> Rect<T> where
    T: Ord + Copy
[src]

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]

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]

type Output = Self

The resulting type after applying the - operator.

impl<T> Add<Vector2<T>> for Rect<T> where
    T: Add<Output = T> + Copy
[src]

type Output = Self

The resulting type after applying the + operator.

impl<T> Mul<T> for Rect<T> where
    T: Mul<Output = T> + Copy
[src]

type Output = Self

The resulting type after applying the * operator.

impl<T> AddAssign<Vector2<T>> for Rect<T> where
    T: AddAssign<T> + Copy
[src]

impl<T> SubAssign<Vector2<T>> for Rect<T> where
    T: SubAssign<T> + Copy
[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

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

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

Blanket Implementations

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 = !

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.

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

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

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