Struct iron_shapes::rect::Rect
source · [−]Expand description
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
sourceimpl<T: PartialOrd + Copy> Rect<T>
impl<T: PartialOrd + Copy> Rect<T>
sourcepub fn new<C>(c1: C, c2: C) -> Self where
C: Into<Point<T>>,
pub fn new<C>(c1: C, c2: C) -> Self 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));
sourceimpl<T: Copy> Rect<T>
impl<T: Copy> Rect<T>
sourcepub fn lower_left(&self) -> Point<T>
pub fn lower_left(&self) -> Point<T>
Get the lower left corner.
sourcepub fn upper_left(&self) -> Point<T>
pub fn upper_left(&self) -> Point<T>
Get the upper left corner.
sourcepub fn upper_right(&self) -> Point<T>
pub fn upper_right(&self) -> Point<T>
Get the upper right corner.
sourcepub fn lower_right(&self) -> Point<T>
pub fn lower_right(&self) -> Point<T>
Get the lower right corner.
sourceimpl<T: PartialOrd + Copy> Rect<T>
impl<T: PartialOrd + Copy> Rect<T>
sourcepub fn contains_point(&self, p: Point<T>) -> bool
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)));
sourcepub fn contains_point_exclusive(&self, p: Point<T>) -> bool
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)));
sourcepub fn contains_rectangle(&self, other: &Self) -> bool
pub fn contains_rectangle(&self, other: &Self) -> 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));
sourcepub fn contains_rectangle_exclusive(&self, other: &Self) -> bool
pub fn contains_rectangle_exclusive(&self, other: &Self) -> 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(¬_inner));
sourcepub fn touches(&self, other: &Self) -> bool
pub fn touches(&self, other: &Self) -> bool
Test if the both rectangles touch each other, i.e. if they either share a boundary or are overlapping.
sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Compute the boolean intersection of two rectangles.
This function excludes the boundaries, hence a zero-area intersection is considered None
.
See intersection_inclusive_bounds()
zero-area intersections should be returned as Some(rectangle)
.
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);
sourcepub fn intersection_inclusive_bounds(&self, other: &Self) -> Option<Self>
pub fn intersection_inclusive_bounds(&self, other: &Self) -> Option<Self>
Compute the boolean intersection of two rectangles and include the boundaries. This allows to get zero-area intersection results for example if the two rectangles touch on a boundary or one of the rectangle is already zero-area.
Example
use iron_shapes::prelude::*;
// Create two rectangles which intersect in a single point.
let a = Rect::new((0, 0), (2, 2));
let b = Rect::new((2, 2), (3, 3));
// Compute the intersection.
assert_eq!(a.intersection_inclusive_bounds(&b), Some(Rect::new((2, 2), (2, 2))));
sourceimpl<T: Copy + PartialOrd> Rect<T>
impl<T: Copy + PartialOrd> Rect<T>
Trait Implementations
sourceimpl<T: Copy> BoundingBox<T> for Rect<T>
impl<T: Copy> BoundingBox<T> for Rect<T>
sourcefn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
Get bounding box of rectangle (which is equal to the rectangle itself).
sourceimpl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T>> DoubledOrientedArea<T> for Rect<T>
impl<T: Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T>> DoubledOrientedArea<T> for Rect<T>
sourcefn area_doubled_oriented(&self) -> T
fn area_doubled_oriented(&self) -> T
Calculate doubled oriented area of rectangle.
sourceimpl<T: CoordinateType> From<Rect<T>> for SimpleRPolygon<T>
impl<T: CoordinateType> From<Rect<T>> for SimpleRPolygon<T>
sourceimpl<T: CoordinateType> IntoEdges<T> for &Rect<T>
impl<T: CoordinateType> IntoEdges<T> for &Rect<T>
type EdgeIter = RectEdgeIterator<T>
type EdgeIter = RectEdgeIterator<T>
Iterator type.
sourcefn into_edges(self) -> Self::EdgeIter
fn into_edges(self) -> Self::EdgeIter
Get an iterator over edges.
sourceimpl<'a, T> IntoIterator for &'a Rect<T> where
T: Copy,
impl<'a, T> IntoIterator for &'a Rect<T> where
T: Copy,
Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.
sourceimpl<T> IntoIterator for Rect<T> where
T: Copy,
impl<T> IntoIterator for Rect<T> where
T: Copy,
Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.
sourceimpl<C> IntoPoints<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> IntoPoints<C> for Rect<C::Coord> where
C: CoordinateConcept,
type Point = Point<<C as CoordinateBase>::Coord>
type Point = Point<<C as CoordinateBase>::Coord>
Type of the points.
type PointIter = <Rect<<C as CoordinateBase>::Coord> as IntoIterator>::IntoIter
type PointIter = <Rect<<C as CoordinateBase>::Coord> as IntoIterator>::IntoIter
Iterator over points.
sourcefn into_points(self) -> Self::PointIter
fn into_points(self) -> Self::PointIter
Iterate over points.
sourceimpl<C> IntoSegments<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> IntoSegments<C> for Rect<C::Coord> where
C: CoordinateConcept,
type Segment = REdge<<C as CoordinateBase>::Coord>
type Segment = REdge<<C as CoordinateBase>::Coord>
Type which represents the segments.
type SegmentIter = RectEdgeIterator<<C as CoordinateBase>::Coord>
type SegmentIter = RectEdgeIterator<<C as CoordinateBase>::Coord>
Iterator over segments.
sourcefn into_segments(self) -> Self::SegmentIter
fn into_segments(self) -> Self::SegmentIter
Iterate over segments/edges of a polygon.
sourceimpl<T: Copy + PartialOrd> MapPointwise<T> for Rect<T>
impl<T: Copy + PartialOrd> MapPointwise<T> for Rect<T>
Point wise transformation of the two corner points.
sourceimpl<C> Polygon<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> Polygon<C> for Rect<C::Coord> where
C: CoordinateConcept,
sourceimpl<C> Polygon90<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> Polygon90<C> for Rect<C::Coord> where
C: CoordinateConcept,
type CompactIterator = IntoIter<<C as CoordinateBase>::Coord, Global>
type CompactIterator = IntoIter<<C as CoordinateBase>::Coord, Global>
Iterator over alternating x/y coordinates of the points. Starts with an x coordinate.
sourcefn compact_iter(&self) -> Self::CompactIterator
fn compact_iter(&self) -> Self::CompactIterator
Iterate over alternating x/y coordinates of the polygon vertices. Start with an x coordinate.
sourceimpl<C> PolygonSet<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> PolygonSet<C> for Rect<C::Coord> where
C: CoordinateConcept,
type Point = Point<<C as CoordinateBase>::Coord>
type Point = Point<<C as CoordinateBase>::Coord>
Point type used for the vertices.
type Segment = REdge<<C as CoordinateBase>::Coord>
type Segment = REdge<<C as CoordinateBase>::Coord>
Type used for the polygon segments.
type AllPoints = <Rect<<C as CoordinateBase>::Coord> as IntoIterator>::IntoIter
type AllPoints = <Rect<<C as CoordinateBase>::Coord> as IntoIterator>::IntoIter
Iterator over all points.
sourcefn num_polygons(&self) -> usize
fn num_polygons(&self) -> usize
Get number of polygons.
sourcefn all_points(&self) -> Self::AllPoints
fn all_points(&self) -> Self::AllPoints
Iterate over all vertices.
sourceimpl<C> PolygonWithHoles<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> PolygonWithHoles<C> for Rect<C::Coord> where
C: CoordinateConcept,
sourceimpl<C> Rectangle<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> Rectangle<C> for Rect<C::Coord> where
C: CoordinateConcept,
type Interval = Interval<<C as CoordinateBase>::Coord>
type Interval = Interval<<C as CoordinateBase>::Coord>
Type used for representing a one-dimensional interval.
sourcefn get(&self, orientation: Orientation2D) -> Self::Interval
fn get(&self, orientation: Orientation2D) -> Self::Interval
Get the interval which is spanned by the rectangle in the given orientation.
sourceimpl<T: Copy> ToPolygon<T> for Rect<T>
impl<T: Copy> ToPolygon<T> for Rect<T>
sourcefn to_polygon(&self) -> Polygon<T>
fn to_polygon(&self) -> Polygon<T>
Convert the geometric object into a polygon.
sourceimpl<T: Copy> TryBoundingBox<T> for Rect<T>
impl<T: Copy> TryBoundingBox<T> for Rect<T>
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Get bounding box of rectangle (always exists).
sourceimpl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Rect<T>
impl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Rect<T>
impl<T: Copy> Copy for Rect<T>
impl<T: PartialEq> Eq for Rect<T>
impl<C> Polygon90Set<C> for Rect<C::Coord> where
C: CoordinateConcept,
impl<C> Polygon90WithHoles<C> for Rect<C::Coord> where
C: CoordinateConcept,
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
impl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
sourcefn rotate_ortho(&self, a: Angle) -> S
fn rotate_ortho(&self, a: Angle) -> S
Rotate the geometrical shape by a multiple of 90 degrees.