Struct iron_shapes::rect::Rect[][src]

pub struct Rect<T> where
    T: CoordinateType
{ pub lower_left: Point<T>, pub upper_right: Point<T>, }

A rectangle which is oriented along the x an y axis and represented by its lower left and upper right corner.

Fields

lower_left: Point<T>

Lower left corner of the rectangle.

upper_right: Point<T>

Upper right corner of the rectangle.

Implementations

impl<T: CoordinateType> Rect<T>[src]

pub fn new<C>(c1: C, c2: C) -> Self where
    C: Into<Point<T>>, 
[src]

Construct the bounding box of the two points. Order does not matter.

Examples

use iron_shapes::prelude::*;

// Create a rectangle based on two corner points.
let rect1 = Rect::new(Point::new(0, 0), Point::new(1, 2));
// Any type that implements `Into<Point<T>>` can be used for the corner points.
let rect2 = Rect::new((1, 2), (0, 0));
// Ordering of the corner points does not matter.
assert_eq!(rect1, rect2);
// Even though `(0, 0)` was passed as second argument it is recognized as lower left corner.
assert_eq!(rect2.lower_left(), Point::new(0, 0));

pub fn lower_left(&self) -> Point<T>[src]

Get the lower left corner.

pub fn upper_left(&self) -> Point<T>[src]

Get the upper left corner.

pub fn upper_right(&self) -> Point<T>[src]

Get the upper right corner.

pub fn lower_right(&self) -> Point<T>[src]

Get the lower right corner.

pub fn width(&self) -> T[src]

Compute the width of the rectangle.

pub fn height(&self) -> T[src]

Compute the height of the rectangle.

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

Check if rectangle contains the point. Inclusive boundaries.

Example

use iron_shapes::prelude::*;
let rect = Rect::new((0, 0), (10, 20));
// Contains point somewhere in the center.
assert!(rect.contains_point(Point::new(5, 5)));
// Also contains point on the boundaries.
assert!(rect.contains_point(Point::new(0, 0)));
// Does not contain point outside of the rectangle.
assert!(!rect.contains_point(Point::new(10, 21)));

pub fn contains_point_exclusive(&self, p: Point<T>) -> bool[src]

Check if rectangle contains the point. Exclusive boundaries.

Example

use iron_shapes::prelude::*;
let rect = Rect::new((0, 0), (10, 20));
// Contains point somewhere in the center.
assert!(rect.contains_point_exclusive(Point::new(5, 5)));
// Does not contain points on boundaries.
assert!(!rect.contains_point_exclusive(Point::new(0, 0)));
// Does not contain point outside of the rectangle.
assert!(!rect.contains_point_exclusive(Point::new(10, 21)));

pub fn contains_rectangle(&self, other: &Self) -> bool[src]

Check if rectangle contains other rectangle. Inclusive boundaries.

Example

use iron_shapes::prelude::*;

let outer = Rect::new((0, 0), (2, 2));
let inner = Rect::new((0, 0), (1, 1));
assert!(outer.contains_rectangle(&inner));
assert!(!inner.contains_rectangle(&outer));

pub fn contains_rectangle_exclusive(&self, other: &Self) -> bool[src]

Check if rectangle contains other rectangle. Exclusive boundaries.

Example

use iron_shapes::prelude::*;

let outer = Rect::new((0, 0), (3, 3));
let inner = Rect::new((1, 1), (2, 2));
assert!(outer.contains_rectangle_exclusive(&inner));
assert!(!inner.contains_rectangle_exclusive(&outer));

let not_inner = Rect::new((0, 0), (1, 1)); // This shares the boundary with `outer`.
assert!(!outer.contains_rectangle_exclusive(&not_inner));

pub fn touches(&self, other: &Self) -> bool[src]

Test if the both rectangles touch each other, i.e. if they either share a boundary or are overlapping.

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

Compute the boolean intersection of two rectangles.

Example

use iron_shapes::prelude::*;

// Create two overlapping rectangles.
let a = Rect::new((0, 0), (2, 2));
let b = Rect::new((1, 1), (3, 3));

// Compute the intersection.
assert_eq!(a.intersection(&b), Some(Rect::new((1, 1), (2, 2))));

// Create a non-overlapping rectangle.
let c = Rect::new((100, 100), (200, 200));
// The intersection with a non-overlapping rectangle is `None`.
assert_eq!(a.intersection(&c), None);

pub fn add_point(&self, point: Point<T>) -> Self[src]

Create the smallest Rect that contains the original Rect and the point.

Example

use iron_shapes::prelude::*;

let r1 = Rect::new((0,0), (1,2));

let r2 = r1.add_point(Point::new(10, 11));

assert_eq!(r2, Rect::new((0,0), (10,11)));

pub fn add_rect(&self, rect: &Self) -> Self[src]

Get the smallest Rect that contains both rectangles self and rect.

Example

use iron_shapes::prelude::*;

let r1 = Rect::new((0,0), (1,2));
let r2 = Rect::new((4,5), (6,7));

let r3 = r1.add_rect(&r2);

assert_eq!(r3, Rect::new((0,0), (6,7)));

Trait Implementations

impl<T: CoordinateType> BoundingBox<T> for Rect<T>[src]

fn bounding_box(&self) -> Rect<T>[src]

Get bounding box of rectangle (which is equal to the rectangle itself).

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

impl<T: Copy> Copy for Rect<T> where
    T: CoordinateType
[src]

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

impl<T: CoordinateType> DoubledOrientedArea<T> for Rect<T>[src]

fn area_doubled_oriented(&self) -> T[src]

Calculate doubled oriented area of rectangle.

impl<T: Eq> Eq for Rect<T> where
    T: CoordinateType
[src]

impl<T> From<&'_ Rect<T>> for Polygon<T> where
    T: CoordinateType
[src]

Create a polygon from a rectangle.

impl<T: CoordinateType> From<Rect<T>> for SimpleRPolygon<T>[src]

impl<T> From<Rect<T>> for Polygon<T> where
    T: CoordinateType
[src]

Create a polygon from a rectangle.

impl<T: CoordinateType> From<Rect<T>> for Geometry<T>[src]

impl<T: Hash> Hash for Rect<T> where
    T: CoordinateType
[src]

impl<'a, T> IntoIterator for &'a Rect<T> where
    T: CoordinateType
[src]

Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.

type Item = Point<T>

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

impl<T> MapPointwise<T> for Rect<T> where
    T: CoordinateType
[src]

Point wise transformation of the two corner points.

fn transform<F>(&self, transformation: F) -> Self where
    F: Fn(Point<T>) -> Point<T>, 
[src]

Point wise transformation.

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

impl<T> StructuralEq for Rect<T> where
    T: CoordinateType
[src]

impl<T> StructuralPartialEq for Rect<T> where
    T: CoordinateType
[src]

impl<T: CoordinateType> ToPolygon<T> for Rect<T>[src]

impl<T: CoordinateType> TryBoundingBox<T> for Rect<T>[src]

fn try_bounding_box(&self) -> Option<Rect<T>>[src]

Get bounding box of rectangle (always exists).

impl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Rect<T>[src]

type Output = Rect<Dst>

Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more

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<S, T> Mirror<T> for S where
    T: CoordinateType,
    S: MapPointwise<T>, 
[src]

pub fn mirror_x(&Self) -> S[src]

Return the geometrical object mirrored at the x axis.

pub fn mirror_y(&Self) -> S[src]

Return the geometrical object mirrored at the y axis.

impl<S, T> RotateOrtho<T> for S where
    T: CoordinateType,
    S: MapPointwise<T>, 
[src]

impl<S, T> Scale<T> for S where
    T: CoordinateType,
    S: MapPointwise<T>, 
[src]

impl<T> TextType for T where
    T: Clone + Eq + Debug + Hash
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<S, T> Translate<T> for S where
    T: CoordinateType,
    S: MapPointwise<T>, 
[src]

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.