Struct libreda_db::layout::prelude::Rect

source ·
pub struct Rect<T> {
    pub lower_left: Point<T>,
    pub upper_right: Point<T>,
}
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§

source§

impl<T> Rect<T>
where T: PartialOrd + Copy,

source

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));
source§

impl<T> Rect<T>
where T: Copy,

source

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

Get the lower left corner.

source

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

Get the upper left corner.

source

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

Get the upper right corner.

source

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

Get the lower right corner.

source§

impl<T> Rect<T>
where T: PartialOrd + Copy,

source

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)));
source

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)));
source

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));
source

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));
source

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.

source

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

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);
source

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

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))));
source

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)));
source

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)));
source§

impl<T> Rect<T>
where T: Sub<Output = T> + Copy + Ord + Zero,

source

pub fn distance_to_point(&self, p: Point<T>) -> Vector<T>

Compute the shortest from the rectangle to the point p. The distance is zero if the point is inside the rectangle.

§Example
use iron_shapes::prelude::*;

let r = Rect::new((0,0), (10, 10));

assert_eq!(r.distance_to_point((5, 15).into()), Vector::new(0, 5));

// Distance to point inside the rectangle is zero.
assert_eq!(r.distance_to_point((5, 5).into()), Vector::new(0, 0));
source§

impl<T> Rect<T>
where T: Copy + Sub<Output = T>,

source

pub fn width(&self) -> T

Compute the width of the rectangle.

source

pub fn height(&self) -> T

Compute the height of the rectangle.

source§

impl<T> Rect<T>
where T: Add<Output = T> + Div<Output = T> + Copy + One,

source

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

Get the center point of the rectangle. When using integer coordinates the resulting coordinates will be truncated to the next integers.

source§

impl<T> Rect<T>
where T: Add<Output = T> + Sub<Output = T> + Copy + PartialOrd,

source

pub fn sized(&self, add_x: T, add_y: T) -> Rect<T>

Create an enlarged copy of this rectangle. The vertical boundaries will be shifted towards the outside by add_x. The horizontal boundaries will be shifted towards the outside by add_y.

source

pub fn sized_isotropic(&self, add: T) -> Rect<T>

Create an enlarged copy of this rectangle.

Trait Implementations§

source§

impl<T> BoundingBox<T> for Rect<T>
where T: Copy,

source§

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

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

source§

impl<T> Clone for Rect<T>
where T: Clone,

source§

fn clone(&self) -> Rect<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Rect<T>
where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for Rect<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Rect<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> DoubledOrientedArea<T> for Rect<T>
where T: Sub<Output = T> + Copy + Mul<Output = T> + Add<Output = T>,

source§

fn area_doubled_oriented(&self) -> T

Calculate doubled oriented area of rectangle.

source§

impl<T> From<&Rect<T>> for Polygon<T>
where T: Copy,

Create a polygon from a rectangle.

source§

fn from(rect: &Rect<T>) -> Polygon<T>

Converts to this type from the input type.
source§

impl<T> From<Rect<T>> for Geometry<T>

source§

fn from(x: Rect<T>) -> Geometry<T>

Converts to this type from the input type.
source§

impl<T> From<Rect<T>> for Polygon<T>
where T: Copy,

Create a polygon from a rectangle.

source§

fn from(rect: Rect<T>) -> Polygon<T>

Converts to this type from the input type.
source§

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

source§

fn from(r: Rect<T>) -> SimpleRPolygon<T>

Converts to this type from the input type.
source§

impl<T> Hash for Rect<T>
where T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> IntoEdges<T> for &Rect<T>
where T: CoordinateType,

§

type Edge = REdge<T>

Type of edge which will be returned.
§

type EdgeIter = RectEdgeIterator<T>

Iterator type.
source§

fn into_edges(self) -> <&Rect<T> as IntoEdges<T>>::EdgeIter

Get an iterator over edges.
source§

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.

§

type Item = Point<T>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<&'a Rect<T> as IntoIterator>::Item, 4>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <&'a Rect<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

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.

§

type Item = Point<T>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<Rect<T> as IntoIterator>::Item, 4>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> <Rect<T> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<C> IntoPoints<C> for Rect<<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

Iterator over points.
source§

fn into_points( self, ) -> <Rect<<C as CoordinateBase>::Coord> as IntoPoints<C>>::PointIter

Iterate over points.
source§

impl<C> IntoSegments<C> for Rect<<C as CoordinateBase>::Coord>

§

type Segment = REdge<<C as CoordinateBase>::Coord>

Type which represents the segments.
§

type SegmentIter = RectEdgeIterator<<C as CoordinateBase>::Coord>

Iterator over segments.
source§

fn into_segments( self, ) -> <Rect<<C as CoordinateBase>::Coord> as IntoSegments<C>>::SegmentIter

Iterate over segments/edges of a polygon.
source§

impl<T> MapPointwise<T> for Rect<T>
where T: Copy + PartialOrd,

Point wise transformation of the two corner points.

source§

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

Point wise transformation.

source§

impl<T> PartialEq for Rect<T>
where T: PartialEq,

source§

fn eq(&self, other: &Rect<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C> Polygon<C> for Rect<<C as CoordinateBase>::Coord>

source§

fn set( &mut self, _iter: impl Iterator<Item = <Rect<<C as CoordinateBase>::Coord> as PolygonSet<C>>::Point>, )

Set points from an iterator.
source§

impl<C> Polygon90<C> for Rect<<C as CoordinateBase>::Coord>

§

type CompactIterator = IntoIter<<C as CoordinateBase>::Coord>

Iterator over alternating x/y coordinates of the points. Starts with an x coordinate.
source§

fn compact_iter( &self, ) -> <Rect<<C as CoordinateBase>::Coord> as Polygon90<C>>::CompactIterator

Iterate over alternating x/y coordinates of the polygon vertices. Start with an x coordinate.
source§

impl<C> PolygonSet<C> for Rect<<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 used for the polygon segments.
§

type AllPoints = <Rect<<C as CoordinateBase>::Coord> as IntoIterator>::IntoIter

Iterator over all points.
source§

fn num_polygons(&self) -> usize

Get number of polygons.
source§

fn convolved( self, p: &<Rect<<C as CoordinateBase>::Coord> as PolygonSet<C>>::Point, ) -> Rect<<C as CoordinateBase>::Coord>

Add the point p to all vertices.
source§

fn convolve( &mut self, p: &<Rect<<C as CoordinateBase>::Coord> as PolygonSet<C>>::Point, )

Add the point p to all vertices.
source§

fn scaled( self, scale: <C as CoordinateBase>::Coord, ) -> Rect<<C as CoordinateBase>::Coord>

Multiply all vertices with a factor.
source§

fn scale(&mut self, scale: <C as CoordinateBase>::Coord)

Multiply all vertices with a factor.
source§

fn all_points( &self, ) -> <Rect<<C as CoordinateBase>::Coord> as PolygonSet<C>>::AllPoints

Iterate over all vertices.
source§

impl<C> PolygonWithHoles<C> for Rect<<C as CoordinateBase>::Coord>

source§

fn num_holes(&self) -> usize

Get the number of holes.
source§

impl<C> Rectangle<C> for Rect<<C as CoordinateBase>::Coord>

§

type Interval = Interval<<C as CoordinateBase>::Coord>

Type used for representing a one-dimensional interval.
source§

fn get( &self, orientation: Orientation2D, ) -> <Rect<<C as CoordinateBase>::Coord> as Rectangle<C>>::Interval

Get the interval which is spanned by the rectangle in the given orientation.
source§

impl<T> Serialize for Rect<T>
where T: Serialize,

source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T> ToPolygon<T> for Rect<T>
where T: Copy,

source§

fn to_polygon(&self) -> Polygon<T>

Convert the geometric object into a polygon.
source§

impl<T> TryBoundingBox<T> for Rect<T>
where T: Copy,

source§

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

Get bounding box of rectangle (always exists).

source§

impl<T, Dst> TryCastCoord<T, Dst> for Rect<T>

§

type Output = Rect<Dst>

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

fn try_cast(&self) -> Option<<Rect<T> as TryCastCoord<T, Dst>>::Output>

Try to cast to target data type. Read more
source§

fn cast(&self) -> Self::Output

Cast to target data type. Read more
source§

impl<T> Copy for Rect<T>
where T: Copy,

source§

impl<T> Eq for Rect<T>
where T: Eq,

source§

impl<C> Polygon90Set<C> for Rect<<C as CoordinateBase>::Coord>

source§

impl<C> Polygon90WithHoles<C> for Rect<<C as CoordinateBase>::Coord>

source§

impl<T> StructuralPartialEq for Rect<T>

Auto Trait Implementations§

§

impl<T> Freeze for Rect<T>
where T: Freeze,

§

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<S, T> Mirror<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPointwise<T>,

source§

fn mirror_x(&self) -> S

Return the geometrical object mirrored at the x axis.

source§

fn mirror_y(&self) -> S

Return the geometrical object mirrored at the y axis.

source§

impl<S, T> RotateOrtho<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPointwise<T>,

source§

fn rotate_ortho(&self, a: Angle) -> S

Rotate the geometrical shape by a multiple of 90 degrees.
source§

impl<S, T> Scale<T> for S
where T: Copy + Mul<Output = T>, S: MapPointwise<T>,

source§

fn scale(&self, factor: T) -> S

Scale the geometrical shape. Scaling center is the origin (0, 0).
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<S, T> Translate<T> for S
where T: Copy + Add<Output = T>, S: MapPointwise<T>,

source§

fn translate(&self, v: Vector<T>) -> S

Translate the geometrical object by a vector v.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> IdType for T
where T: Debug + Clone + Eq + Hash + 'static,

source§

impl<T> IdTypeMT for T
where T: IdType + Sync + Send,

source§

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