pub struct Rect<T> {
pub x: Range<T>,
pub y: Range<T>,
}
Expand description
An axis aligned rectangle. Stored as two Ranges.
Fields§
§x: Range<T>
§y: Range<T>
Implementations§
source§impl<S> Rect<S>
impl<S> Rect<S>
pub fn inner_into<A>(self) -> Rect<A>where S: Into<A>,
pub fn inner_try_into<A>(self) -> Result<Rect<A>, S::Error>where S: TryInto<A>,
source§impl<T: Copy + Sub<Output = T> + Add<Output = T>> Rect<T>
impl<T: Copy + Sub<Output = T> + Add<Output = T>> Rect<T>
sourcepub fn from_point(point: Vec2<T>, radius: Vec2<T>) -> Rect<T>
pub fn from_point(point: Vec2<T>, radius: Vec2<T>) -> Rect<T>
Create a rectangle from a point and radius.
source§impl<T: Copy> Rect<T>
impl<T: Copy> Rect<T>
source§impl<T: PartialOrd + Copy> Rect<T>
impl<T: PartialOrd + Copy> Rect<T>
sourcepub fn contains_point(&self, a: Vec2<T>) -> bool
pub fn contains_point(&self, a: Vec2<T>) -> bool
Returns true if the point is contained in the the ranges of both axis.
source§impl<T: Copy + PartialOrd + Sub<Output = T> + Mul<Output = T> + Add<Output = T>> Rect<T>
impl<T: Copy + PartialOrd + Sub<Output = T> + Mul<Output = T> + Add<Output = T>> Rect<T>
sourcepub fn distance_squared_to_point(&self, point: Vec2<T>) -> Option<T>
pub fn distance_squared_to_point(&self, point: Vec2<T>) -> Option<T>
If the point is outside the rectangle, returns the squared distance from the closest corner of the rectangle. If the point is inside the rectangle, it will return None.
sourcepub fn furthest_distance_squared_to_point(&self, point: Vec2<T>) -> T
pub fn furthest_distance_squared_to_point(&self, point: Vec2<T>) -> T
If the point is outside the rectangle, returns the squared distance from a point to the furthest corner of the rectangle.
source§impl<T: PartialOrd + Copy> Rect<T>
impl<T: PartialOrd + Copy> Rect<T>
sourcepub fn subdivide<A: Axis>(&self, axis: A, divider: T) -> (Rect<T>, Rect<T>)
pub fn subdivide<A: Axis>(&self, axis: A, divider: T) -> (Rect<T>, Rect<T>)
Subdivides the rectangle.
No floating point calculations are done.
Important to note that a point that was in the original rectangle,
could actually be inside both subdivded rectangles.
This is because the ranges are inclusive on both sides [start,end]
.
sourcepub fn contains_rect(&self, rect: &Rect<T>) -> bool
pub fn contains_rect(&self, rect: &Rect<T>) -> bool
Returns true if the specified rect is inside of this rect.
pub fn grow_to_fit_point(&mut self, point: Vec2<T>) -> &mut Self
sourcepub fn grow_to_fit(&mut self, rect: &Rect<T>) -> &mut Self
pub fn grow_to_fit(&mut self, rect: &Rect<T>) -> &mut Self
Grow the rectangle to fit the specified rectangle by replacing values with the specified rectangle. No floating point computations.
pub fn intersects_rect(&self, other: &Rect<T>) -> bool
source§impl<T: PartialOrd + Copy> Rect<T>
impl<T: PartialOrd + Copy> Rect<T>
sourcepub fn get_intersect_rect(&self, other: &Rect<T>) -> Option<Rect<T>>
pub fn get_intersect_rect(&self, other: &Rect<T>) -> Option<Rect<T>>
Get an intersecting rectangle. No floating point calculations as the new rectangle is made up of values from this rectangle and the specified rectangle.