Skip to main content

Rectangle

Struct Rectangle 

Source
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>

Source

pub fn new(min: Point<T, T>, max: Point<T, T>) -> Self

Creates a new rectangle from min and max points

§Arguments
  • min - The minimum (bottom-left) corner
  • max - The maximum (top-right) corner
§Examples
use physdes::{Point, vlsi_ops::Rectangle};

let rect = Rectangle::new(
    Point::new(0, 0),
    Point::new(10, 20)
);
Source

pub fn from_dimensions(origin: Point<T, T>, width: T, height: T) -> Self

Creates a rectangle from origin, width, and height

Source

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

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}$$

Source

pub fn contains_point(&self, point: &Point<T, T>) -> bool

Checks if this rectangle contains a point

Source

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

Source

pub fn area(&self) -> T
where T: Sub<Output = T> + Mul<Output = T>,

Computes the area of the rectangle

$$A = w \times h = (x_{\max} - x_{\min}) \times (y_{\max} - y_{\min})$$

Source

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})]$$

Source

pub fn to_polygon(&self) -> Polygon<T>
where T: Clone + Add<Output = T> + Num + AddAssign + Ord,

Converts to a Polygon

Trait Implementations§

Source§

impl<T: Clone> Clone for Rectangle<T>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Rectangle<T>

Source§

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

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

impl<T: Eq> Eq for Rectangle<T>

Source§

impl<T: PartialEq> PartialEq for Rectangle<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialEq> StructuralPartialEq for Rectangle<T>

Auto Trait Implementations§

§

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

§

impl<T> RefUnwindSafe for Rectangle<T>
where T: RefUnwindSafe,

§

impl<T> Send for Rectangle<T>
where T: Send,

§

impl<T> Sync for Rectangle<T>
where T: Sync,

§

impl<T> Unpin for Rectangle<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Rectangle<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Rectangle<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.