Struct libreda_db::layout::prelude::Rect [−][src]
pub struct Rect<T> where
T: CoordinateType, {
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
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));
Get the lower left corner.
Get the upper left corner.
Get the upper right corner.
Get the lower right corner.
Get the center point of the rectangle. When using integer coordinates the resulting coordinates will be truncated to the next integers.
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)));
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)));
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));
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));
Test if the both rectangles touch each other, i.e. if they either share a boundary or are overlapping.
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);
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)));
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
Get bounding box of rectangle (which is equal to the rectangle itself).
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Rect<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub 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
Calculate doubled oriented area of rectangle.
Create a polygon from a rectangle.
Performs the conversion.
Create a polygon from a rectangle.
Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.
Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.
Point wise transformation of the two corner points.
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub 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
Convert the geometric object into a polygon.
Get bounding box of rectangle (always exists).
impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
Auto Trait Implementations
impl<T> RefUnwindSafe for Rect<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Rect<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate the geometrical shape by a multiple of 90 degrees.