Struct libreda_pnr::db::Rect[]

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> Rect<T> where
    T: CoordinateType

pub fn new<C>(c1: C, c2: C) -> Rect<T> where
    C: Into<Point<T>>, 

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>

Get the lower left corner.

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

Get the upper left corner.

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

Get the upper right corner.

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

Get the lower right corner.

pub fn width(&self) -> T

Compute the width of the rectangle.

pub fn height(&self) -> T

Compute the height of the rectangle.

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

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

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: &Rect<T>) -> bool

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: &Rect<T>) -> bool

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: &Rect<T>) -> bool

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

pub fn intersection(&self, other: &Rect<T>) -> Option<Rect<T>>

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>) -> Rect<T>

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: &Rect<T>) -> Rect<T>

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> BoundingBox<T> for Rect<T> where
    T: CoordinateType

pub fn bounding_box(&self) -> Rect<T>

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

impl<T> Clone for Rect<T> where
    T: Clone + CoordinateType

impl<T> Copy for Rect<T> where
    T: Copy + CoordinateType

impl<T> Debug for Rect<T> where
    T: Debug + CoordinateType

impl<T> DoubledOrientedArea<T> for Rect<T> where
    T: CoordinateType

pub fn area_doubled_oriented(&self) -> T

Calculate doubled oriented area of rectangle.

impl<T> Eq for Rect<T> where
    T: Eq + CoordinateType

impl<'_, T> From<&'_ Rect<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a rectangle.

impl<T> From<Rect<T>> for Geometry<T> where
    T: CoordinateType

impl<T> From<Rect<T>> for Polygon<T> where
    T: CoordinateType

Create a polygon from a rectangle.

impl<T> From<Rect<T>> for SimpleRPolygon<T> where
    T: CoordinateType

impl<T> Hash for Rect<T> where
    T: Hash + CoordinateType

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

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<<&'a Rect<T> as IntoIterator>::Item, Global>

Which kind of iterator are we turning this into?

impl<T> MapPointwise<T> for Rect<T> where
    T: CoordinateType

Point wise transformation of the two corner points.

pub fn transform<F>(&self, transformation: F) -> Rect<T> where
    F: Fn(Point<T>) -> Point<T>, 

Point wise transformation.

impl<T> PartialEq<Rect<T>> for Rect<T> where
    T: PartialEq<T> + CoordinateType

impl<T> StructuralEq for Rect<T> where
    T: CoordinateType

impl<T> StructuralPartialEq for Rect<T> where
    T: CoordinateType

impl<T> ToPolygon<T> for Rect<T> where
    T: CoordinateType

impl<T> TryBoundingBox<T> for Rect<T> where
    T: CoordinateType

pub fn try_bounding_box(&self) -> Option<Rect<T>>

Get bounding box of rectangle (always exists).

impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast

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
    S: MapPointwise<T>,
    T: CoordinateType

pub fn mirror_x(&self) -> S

Return the geometrical object mirrored at the x axis.

pub fn mirror_y(&self) -> S

Return the geometrical object mirrored at the y axis.

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

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

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

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
    S: MapPointwise<T>,
    T: CoordinateType

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.