# Struct libreda_pnr::db::Rect

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

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.

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(&not_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);``````

Compute the width of the rectangle.

Compute the height of the rectangle.

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

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

assert_eq!(r3, Rect::new((0,0), (6,7)));
``````

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

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`.

## Trait Implementations

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

Returns a copy of the value. Read more

Performs copy-assignment from `source`. Read more

Formats the value using the given formatter. Read more

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.

Performs the conversion.

Performs the conversion.

Create a polygon from a rectangle.

Performs the conversion.

Feeds this value into the given `Hasher`. Read more

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

Type of edge which will be returned.

Iterator type.

Get an iterator over edges.

Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Iterate over all points of the rectangle. Starts with the lower left corner and iterates counter clock-wise.

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Point wise transformation of the two corner points.

Point wise transformation.

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

This method tests for `!=`.

Serialize this value into the given Serde serializer. Read more

Convert the geometric object into a polygon.

Get bounding box of rectangle (always exists).

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

Try to cast to target data type. Read more

Cast to target data type. Read more

## Blanket Implementations

Gets the `TypeId` of `self`. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls `U::from(self)`.

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

Return the geometrical object mirrored at the `x` axis.

Return the geometrical object mirrored at the `y` axis.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Rotate the geometrical shape by a multiple of 90 degrees.

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

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

Translate the geometrical object by a vector `v`.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.