pub struct Aabr<T> {
pub min: Vec2<T>,
pub max: Vec2<T>,
}
Expand description
Axis-aligned Bounding Rectangle (2D), represented by min
and max
points.
N.B: You are responsible for ensuring that all respective elements of
min
are indeed less than or equal to those of max
.
The is_valid()
, make_valid()
and made_valid()
methods are designed to help you
with this.
Fields§
§min: Vec2<T>
Minimum coordinates of bounds.
max: Vec2<T>
Maximum coordinates of bounds.
Implementations§
source§impl<T> Aabr<T>
impl<T> Aabr<T>
sourcepub fn is_valid(&self) -> boolwhere
T: PartialOrd,
pub fn is_valid(&self) -> boolwhere
T: PartialOrd,
Is this bounding shape valid ?
True only if all elements of self.min
are less than or equal to those of self.max
.
sourcepub fn make_valid(&mut self)where
T: PartialOrd,
pub fn make_valid(&mut self)where
T: PartialOrd,
Makes this bounding shape valid by swapping elements of self.min
with self.max
as needed.
sourcepub fn made_valid(self) -> Selfwhere
T: PartialOrd,
pub fn made_valid(self) -> Selfwhere
T: PartialOrd,
Returns this bounding shape made valid by swapping elements of self.min
with self.max
as needed.
sourcepub fn new_empty(p: Vec2<T>) -> Selfwhere
T: Copy,
pub fn new_empty(p: Vec2<T>) -> Selfwhere
T: Copy,
Creates a new bounding shape from a single point.
sourcepub fn into_rect(self) -> Rect<T, T>
pub fn into_rect(self) -> Rect<T, T>
Converts this bounding shape to the matching rectangle representation.
sourcepub fn union(self, other: Self) -> Selfwhere
T: PartialOrd,
pub fn union(self, other: Self) -> Selfwhere
T: PartialOrd,
Gets the smallest bounding shape that contains both this one and another.
sourcepub fn intersection(self, other: Self) -> Selfwhere
T: PartialOrd,
pub fn intersection(self, other: Self) -> Selfwhere
T: PartialOrd,
Gets the largest bounding shape contained by both this one and another.
sourcepub fn expand_to_contain(&mut self, other: Self)where
T: Copy + PartialOrd,
pub fn expand_to_contain(&mut self, other: Self)where
T: Copy + PartialOrd,
Sets this bounding shape to the union of itself with another.
sourcepub fn intersect(&mut self, other: Self)where
T: Copy + PartialOrd,
pub fn intersect(&mut self, other: Self)where
T: Copy + PartialOrd,
Sets this bounding shape to the intersection of itself with another.
sourcepub fn expanded_to_contain_point(self, p: Vec2<T>) -> Selfwhere
T: Copy + PartialOrd,
pub fn expanded_to_contain_point(self, p: Vec2<T>) -> Selfwhere
T: Copy + PartialOrd,
Gets a copy of this shape so that it contains the given point.
sourcepub fn expand_to_contain_point(&mut self, p: Vec2<T>)where
T: Copy + PartialOrd,
pub fn expand_to_contain_point(&mut self, p: Vec2<T>)where
T: Copy + PartialOrd,
Expands this shape so that it contains the given point.
sourcepub fn contains_point(self, p: Vec2<T>) -> boolwhere
T: PartialOrd,
pub fn contains_point(self, p: Vec2<T>) -> boolwhere
T: PartialOrd,
Does this bounding shape contain the given point ?
sourcepub fn contains_aabr(self, other: Self) -> boolwhere
T: PartialOrd,
pub fn contains_aabr(self, other: Self) -> boolwhere
T: PartialOrd,
Does this bounding shape fully contain another ?
sourcepub fn collides_with_aabr(self, other: Self) -> boolwhere
T: PartialOrd,
pub fn collides_with_aabr(self, other: Self) -> boolwhere
T: PartialOrd,
Does this bounding shape collide with another ?
sourcepub fn collision_vector_with_aabr(self, other: Self) -> Vec2<T>
pub fn collision_vector_with_aabr(self, other: Self) -> Vec2<T>
Gets a vector that tells how much self
penetrates other
.
sourcepub fn projected_point(self, p: Vec2<T>) -> Vec2<T>where
T: Clamp,
pub fn projected_point(self, p: Vec2<T>) -> Vec2<T>where
T: Clamp,
Project the given point into the bounding shape (equivalent to ‘snapping’ the point to the closest point in the bounding shape).
sourcepub fn distance_to_point(self, p: Vec2<T>) -> T
pub fn distance_to_point(self, p: Vec2<T>) -> T
Get the smallest distance between the bounding shape and a point.
sourcepub fn split_at_x(self, sp: T) -> [Self; 2]where
T: Copy + PartialOrd,
pub fn split_at_x(self, sp: T) -> [Self; 2]where
T: Copy + PartialOrd,
Splits this shape in two, by a straight plane along the
x
axis.
The returned tuple is (low, high)
.
§Panics
sp
is assumed to be a position along the
x
axis that is within this shape’s bounds.
sourcepub fn split_at_y(self, sp: T) -> [Self; 2]where
T: Copy + PartialOrd,
pub fn split_at_y(self, sp: T) -> [Self; 2]where
T: Copy + PartialOrd,
Splits this shape in two, by a straight plane along the
y
axis.
The returned tuple is (low, high)
.
§Panics
sp
is assumed to be a position along the
y
axis that is within this shape’s bounds.
sourcepub fn map<D, F>(self, f: F) -> Aabr<D>where
F: FnMut(T) -> D,
pub fn map<D, F>(self, f: F) -> Aabr<D>where
F: FnMut(T) -> D,
Returns this bounding shape, converted element-wise using the given closure.
sourcepub fn as_<D>(self) -> Aabr<D>where
T: AsPrimitive<D>,
D: 'static + Copy,
pub fn as_<D>(self) -> Aabr<D>where
T: AsPrimitive<D>,
D: 'static + Copy,
Converts this rectangle to a rectangle of another type, using the as
conversion.