Struct libreda_db::layout::prelude::Rect [−][src]
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,
[src]
T: CoordinateType,
pub fn new<C>(c1: C, c2: C) -> Rect<T> where
C: Into<Point<T>>,
[src]
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>
[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: &Rect<T>) -> 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: &Rect<T>) -> 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(¬_inner));
pub fn touches(&self, other: &Rect<T>) -> 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: &Rect<T>) -> Option<Rect<T>>
[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>) -> Rect<T>
[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: &Rect<T>) -> Rect<T>
[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> BoundingBox<T> for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn bounding_box(&self) -> Rect<T>
[src]
Get bounding box of rectangle (which is equal to the rectangle itself).
impl<T> Clone for Rect<T> where
T: Clone + CoordinateType,
[src]
T: Clone + CoordinateType,
impl<T> Copy for Rect<T> where
T: Copy + CoordinateType,
[src]
T: Copy + CoordinateType,
impl<T> Debug for Rect<T> where
T: Debug + CoordinateType,
[src]
T: Debug + CoordinateType,
impl<T> DoubledOrientedArea<T> for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn area_doubled_oriented(&self) -> T
[src]
Calculate doubled oriented area of rectangle.
impl<T> Eq for Rect<T> where
T: Eq + CoordinateType,
[src]
T: Eq + CoordinateType,
impl<'_, T> From<&'_ Rect<T>> for Polygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
Create a polygon from a rectangle.
impl<T> From<Rect<T>> for Geometry<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T> From<Rect<T>> for Polygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
Create a polygon from a rectangle.
impl<T> From<Rect<T>> for SimpleRPolygon<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn from(r: Rect<T>) -> SimpleRPolygon<T>
[src]
impl<T> Hash for Rect<T> where
T: Hash + CoordinateType,
[src]
T: Hash + CoordinateType,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a, T> IntoIterator for &'a Rect<T> where
T: CoordinateType,
[src]
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?
pub fn into_iter(self) -> <&'a Rect<T> as IntoIterator>::IntoIter
[src]
impl<T> MapPointwise<T> for Rect<T> where
T: CoordinateType,
[src]
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>,
[src]
F: Fn(Point<T>) -> Point<T>,
Point wise transformation.
impl<T> PartialEq<Rect<T>> for Rect<T> where
T: PartialEq<T> + CoordinateType,
[src]
T: PartialEq<T> + CoordinateType,
impl<T> StructuralEq for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T> StructuralPartialEq for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T> ToPolygon<T> for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn to_polygon(&self) -> Polygon<T>
[src]
impl<T> TryBoundingBox<T> for Rect<T> where
T: CoordinateType,
[src]
T: CoordinateType,
pub fn try_bounding_box(&self) -> Option<Rect<T>>
[src]
Get bounding box of rectangle (always exists).
impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
[src]
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
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<S, T> Mirror<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
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
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
pub fn rotate_ortho(&self, a: Angle) -> S
[src]
impl<S, T> Scale<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
impl<T> TextType for T where
T: Clone + Eq + Debug + Hash,
[src]
T: Clone + Eq + Debug + Hash,
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<S, T> Translate<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
[src]
S: MapPointwise<T>,
T: CoordinateType,
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>,