pub struct Rect {
pub x_min: f32,
pub y_min: f32,
pub x_max: f32,
pub y_max: f32,
}
Expand description
Axis-aligned rectangle
Fields§
§x_min: f32
§y_min: f32
§x_max: f32
§y_max: f32
Implementations§
Source§impl Rect
impl Rect
Sourcepub const QUADRANT_NEIGHBOR_LAYOUT: [[usize; 2]; 4]
pub const QUADRANT_NEIGHBOR_LAYOUT: [[usize; 2]; 4]
For all quadrants, contains indices of the two neighbors of the quadrant at that index.
pub fn try_new(x_min: f32, y_min: f32, x_max: f32, y_max: f32) -> Result<Self>
pub fn from_diagonal_corners(c1: Point, c2: Point) -> Result<Self>
Sourcepub fn relation_to(&self, other: Rect) -> GeoRelation
pub fn relation_to(&self, other: Rect) -> GeoRelation
Returns the geometric relation between self
and another Rect
.
Sourcepub fn almost_relation_to(&self, other: Rect) -> GeoRelation
pub fn almost_relation_to(&self, other: Rect) -> GeoRelation
Returns the GeoRelation
between self
and another Rect
, with a tolerance for floating point precision.
In edge cases, this method will lean towards Surrounding
and Enclosed
instead of Intersecting
.
Sourcepub fn inflate_to_square(&self) -> Rect
pub fn inflate_to_square(&self) -> Rect
Returns a new rectangle with the same centroid but inflated
to be the minimum square that contains self
.
Sourcepub fn scale(self, factor: f32) -> Self
pub fn scale(self, factor: f32) -> Self
Returns a new rectangle with the same centroid but scaled by factor
.
Sourcepub fn resize_by(self, dx: f32, dy: f32) -> Option<Self>
pub fn resize_by(self, dx: f32, dy: f32) -> Option<Self>
Returns a new rectangle with the same centroid as self
but expanded by dx
in both x-directions and by dy
in both y-directions.
If the new rectangle is invalid (x_min >= x_max or y_min >= y_max), returns None.
Sourcepub fn quadrants(&self) -> [Self; 4]
pub fn quadrants(&self) -> [Self; 4]
Returns the 4 quadrants of self
.
Ordered in the same way as quadrants in a cartesian plane:
https://en.wikipedia.org/wiki/Quadrant_(plane_geometry)
Sourcepub fn corners(&self) -> [Point; 4]
pub fn corners(&self) -> [Point; 4]
Returns the four corners of self
, in the same order as Rect::quadrants.
Sourcepub fn edges(&self) -> [Edge; 4]
pub fn edges(&self) -> [Edge; 4]
Returns the four edges that make up self
, in the same order as Rect::quadrants.
pub fn width(&self) -> f32
pub fn height(&self) -> f32
Sourcepub fn intersection(a: Rect, b: Rect) -> Option<Rect>
pub fn intersection(a: Rect, b: Rect) -> Option<Rect>
Returns the largest rectangle that is contained in both a
and b
.
Sourcepub fn bounding_rect(a: Rect, b: Rect) -> Rect
pub fn bounding_rect(a: Rect, b: Rect) -> Rect
Returns the smallest rectangle that contains both a
and b
.
pub fn centroid(&self) -> Point
pub fn area(&self) -> f32
pub fn diameter(&self) -> f32
Trait Implementations§
Source§impl AlmostCollidesWith<Point> for Rect
impl AlmostCollidesWith<Point> for Rect
fn almost_collides_with(&self, point: &Point) -> bool
Source§impl AlmostCollidesWith<Rect> for Rect
impl AlmostCollidesWith<Rect> for Rect
fn almost_collides_with(&self, other: &Rect) -> bool
Source§impl CollidesWith<Edge> for Rect
impl CollidesWith<Edge> for Rect
fn collides_with(&self, edge: &Edge) -> bool
Source§impl CollidesWith<Point> for Rect
impl CollidesWith<Point> for Rect
fn collides_with(&self, point: &Point) -> bool
Source§impl CollidesWith<Rect> for Circle
impl CollidesWith<Rect> for Circle
fn collides_with(&self, rect: &Rect) -> bool
Source§impl CollidesWith<Rect> for Edge
impl CollidesWith<Rect> for Edge
fn collides_with(&self, other: &Rect) -> bool
Source§impl CollidesWith<Rect> for Rect
impl CollidesWith<Rect> for Rect
fn collides_with(&self, other: &Rect) -> bool
Source§impl DistanceTo<Point> for Rect
impl DistanceTo<Point> for Rect
Source§fn distance_to(&self, point: &Point) -> f32
fn distance_to(&self, point: &Point) -> f32
Source§fn sq_distance_to(&self, point: &Point) -> f32
fn sq_distance_to(&self, point: &Point) -> f32
Source§impl SeparationDistance<Point> for Rect
impl SeparationDistance<Point> for Rect
Source§fn separation_distance(&self, point: &Point) -> (GeoPosition, f32)
fn separation_distance(&self, point: &Point) -> (GeoPosition, f32)
self
and other
, returns GeoPosition::Interior and the minimum distance to separate the two primitives.
Otherwise, returns GeoPosition::Exterior and the minimum distance between the two primitives. (similar to DistanceTo::distance_to)Source§fn sq_separation_distance(&self, point: &Point) -> (GeoPosition, f32)
fn sq_separation_distance(&self, point: &Point) -> (GeoPosition, f32)
impl Copy for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations§
impl Freeze for Rect
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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