pub struct Rectangle<T> {
pub min: Point<T, T>,
pub max: Point<T, T>,
}Expand description
Represents a rectangle in 2D space defined by its minimum (bottom-left) and maximum (top-right) corner points.
Fields§
§min: Point<T, T>The minimum (bottom-left) corner point
max: Point<T, T>The maximum (top-right) corner point
Implementations§
Source§impl<T: Clone + Ord + Copy + Add<Output = T>> Rectangle<T>
impl<T: Clone + Ord + Copy + Add<Output = T>> Rectangle<T>
Sourcepub fn from_dimensions(origin: Point<T, T>, width: T, height: T) -> Self
pub fn from_dimensions(origin: Point<T, T>, width: T, height: T) -> Self
Creates a rectangle from origin, width, and height
Sourcepub fn overlaps(&self, other: &Self) -> bool
pub fn overlaps(&self, other: &Self) -> bool
Checks if this rectangle overlaps with another
Two rectangles overlap iff their projections on both axes overlap:
$$[a_x,b_x] \cap [c_x,d_x] \neq \varnothing \land [a_y,b_y] \cap [c_y,d_y] \neq \varnothing$$
§Examples
use physdes::{Point, vlsi_ops::Rectangle};
let rect1 = Rectangle::new(Point::new(0, 0), Point::new(10, 10));
let rect2 = Rectangle::new(Point::new(5, 5), Point::new(15, 15));
assert!(rect1.overlaps(&rect2));
let rect3 = Rectangle::new(Point::new(20, 20), Point::new(30, 30));
assert!(!rect1.overlaps(&rect3));Sourcepub fn contains(&self, other: &Self) -> bool
pub fn contains(&self, other: &Self) -> bool
Checks if this rectangle contains another rectangle
$$A \supseteq B \iff A_{\min x} \le B_{\min x} \land A_{\max x} \ge B_{\max x}$$
Sourcepub fn contains_point(&self, point: &Point<T, T>) -> bool
pub fn contains_point(&self, point: &Point<T, T>) -> bool
Checks if this rectangle contains a point
Sourcepub fn intersect(&self, other: &Self) -> Option<Self>where
T: Add<Output = T>,
pub fn intersect(&self, other: &Self) -> Option<Self>where
T: Add<Output = T>,
Computes the intersection with another rectangle
$$A \cap B = [\max(x_{A\min}, x_{B\min}),; \min(x_{A\max}, x_{B\max})] \times [\max(y_{A\min}, y_{B\min}),; \min(y_{A\max}, y_{B\max})]$$
Returns None if the rectangles don’t overlap
Sourcepub fn area(&self) -> T
pub fn area(&self) -> T
Computes the area of the rectangle
$$A = w \times h = (x_{\max} - x_{\min}) \times (y_{\max} - y_{\min})$$
Sourcepub fn bounding_rect(&self, other: &Self) -> Self
pub fn bounding_rect(&self, other: &Self) -> Self
Computes the bounding rectangle of two rectangles
$$\text{bbox}(A,B) = [\min(x_{A\min}, x_{B\min}),; \max(x_{A\max}, x_{B\max})] \times [\min(y_{A\min}, y_{B\min}),; \max(y_{A\max}, y_{B\max})]$$