Struct oxygengine_ha_renderer::math::Aabb
source · pub struct Aabb<T> {
pub min: Vec3<T>,
pub max: Vec3<T>,
}
Expand description
Axis-aligned Bounding Box (3D), 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: Vec3<T>
Minimum coordinates of bounds.
max: Vec3<T>
Maximum coordinates of bounds.
Implementations§
source§impl<T> Aabb<T>
impl<T> Aabb<T>
sourcepub fn is_valid(&self) -> boolwhere
T: PartialOrd<T>,
pub fn is_valid(&self) -> boolwhere T: PartialOrd<T>,
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<T>,
pub fn make_valid(&mut self)where T: PartialOrd<T>,
Makes this bounding shape valid by swapping elements of self.min
with self.max
as needed.
sourcepub fn made_valid(self) -> Aabb<T>where
T: PartialOrd<T>,
pub fn made_valid(self) -> Aabb<T>where T: PartialOrd<T>,
Returns this bounding shape made valid by swapping elements of self.min
with self.max
as needed.
sourcepub fn new_empty(p: Vec3<T>) -> Aabb<T>where
T: Copy,
pub fn new_empty(p: Vec3<T>) -> Aabb<T>where T: Copy,
Creates a new bounding shape from a single point.
sourcepub fn into_rect3(self) -> Rect3<T, T>where
T: Copy + Sub<T, Output = T>,
pub fn into_rect3(self) -> Rect3<T, T>where T: Copy + Sub<T, Output = T>,
Converts this bounding shape to the matching rectangle representation.
sourcepub fn center(self) -> Vec3<T>where
T: Copy + One + Add<T, Output = T> + Div<T, Output = T>,
pub fn center(self) -> Vec3<T>where T: Copy + One + Add<T, Output = T> + Div<T, Output = T>,
Gets this bounding shape’s center.
sourcepub fn size(self) -> Extent3<T>where
T: Copy + Sub<T, Output = T>,
pub fn size(self) -> Extent3<T>where T: Copy + Sub<T, Output = T>,
Gets this bounding shape’s total size.
sourcepub fn half_size(self) -> Extent3<T>where
T: Copy + Sub<T, Output = T> + One + Div<T, Output = T> + Add<T, Output = T>,
pub fn half_size(self) -> Extent3<T>where T: Copy + Sub<T, Output = T> + One + Div<T, Output = T> + Add<T, Output = T>,
Gets this bounding shape’s half size.
sourcepub fn union(self, other: Aabb<T>) -> Aabb<T>where
T: PartialOrd<T>,
pub fn union(self, other: Aabb<T>) -> Aabb<T>where T: PartialOrd<T>,
Gets the smallest bounding shape that contains both this one and another.
sourcepub fn intersection(self, other: Aabb<T>) -> Aabb<T>where
T: PartialOrd<T>,
pub fn intersection(self, other: Aabb<T>) -> Aabb<T>where T: PartialOrd<T>,
Gets the largest bounding shape contained by both this one and another.
sourcepub fn expand_to_contain(&mut self, other: Aabb<T>)where
T: Copy + PartialOrd<T>,
pub fn expand_to_contain(&mut self, other: Aabb<T>)where T: Copy + PartialOrd<T>,
Sets this bounding shape to the union of itself with another.
sourcepub fn intersect(&mut self, other: Aabb<T>)where
T: Copy + PartialOrd<T>,
pub fn intersect(&mut self, other: Aabb<T>)where T: Copy + PartialOrd<T>,
Sets this bounding shape to the intersection of itself with another.
sourcepub fn expanded_to_contain_point(self, p: Vec3<T>) -> Aabb<T>where
T: Copy + PartialOrd<T>,
pub fn expanded_to_contain_point(self, p: Vec3<T>) -> Aabb<T>where T: Copy + PartialOrd<T>,
Gets a copy of this shape so that it contains the given point.
sourcepub fn expand_to_contain_point(&mut self, p: Vec3<T>)where
T: Copy + PartialOrd<T>,
pub fn expand_to_contain_point(&mut self, p: Vec3<T>)where T: Copy + PartialOrd<T>,
Expands this shape so that it contains the given point.
sourcepub fn contains_point(self, p: Vec3<T>) -> boolwhere
T: PartialOrd<T>,
pub fn contains_point(self, p: Vec3<T>) -> boolwhere T: PartialOrd<T>,
Does this bounding shape contain the given point ?
sourcepub fn contains_aabb(self, other: Aabb<T>) -> boolwhere
T: PartialOrd<T>,
pub fn contains_aabb(self, other: Aabb<T>) -> boolwhere T: PartialOrd<T>,
Does this bounding shape fully contain another ?
sourcepub fn collides_with_aabb(self, other: Aabb<T>) -> boolwhere
T: PartialOrd<T>,
pub fn collides_with_aabb(self, other: Aabb<T>) -> boolwhere T: PartialOrd<T>,
Does this bounding shape collide with another ?
sourcepub fn collision_vector_with_aabb(self, other: Aabb<T>) -> Vec3<T>where
T: Copy + PartialOrd<T> + Sub<T, Output = T> + One + Add<T, Output = T> + Div<T, Output = T>,
pub fn collision_vector_with_aabb(self, other: Aabb<T>) -> Vec3<T>where T: Copy + PartialOrd<T> + Sub<T, Output = T> + One + Add<T, Output = T> + Div<T, Output = T>,
Gets a vector that tells how much self
penetrates other
.
sourcepub fn projected_point(self, p: Vec3<T>) -> Vec3<T>where
T: Clamp<T>,
pub fn projected_point(self, p: Vec3<T>) -> Vec3<T>where T: Clamp<T>,
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: Vec3<T>) -> Twhere
T: Clamp<T> + Real<Output = T> + Add<T> + RelativeEq<T>,
pub fn distance_to_point(self, p: Vec3<T>) -> Twhere T: Clamp<T> + Real<Output = T> + Add<T> + RelativeEq<T>,
Get the smallest distance between the bounding shape and a point.
sourcepub fn split_at_x(self, sp: T) -> [Aabb<T>; 2]where
T: Copy + PartialOrd<T>,
pub fn split_at_x(self, sp: T) -> [Aabb<T>; 2]where T: Copy + PartialOrd<T>,
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) -> [Aabb<T>; 2]where
T: Copy + PartialOrd<T>,
pub fn split_at_y(self, sp: T) -> [Aabb<T>; 2]where T: Copy + PartialOrd<T>,
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 split_at_z(self, sp: T) -> [Aabb<T>; 2]where
T: Copy + PartialOrd<T>,
pub fn split_at_z(self, sp: T) -> [Aabb<T>; 2]where T: Copy + PartialOrd<T>,
Splits this shape in two, by a straight plane along the
z
axis.
The returned tuple is (low, high)
.
Panics
sp
is assumed to be a position along the
z
axis that is within this shape’s bounds.
sourcepub fn map<D, F>(self, f: F) -> Aabb<D>where
F: FnMut(T) -> D,
pub fn map<D, F>(self, f: F) -> Aabb<D>where F: FnMut(T) -> D,
Returns this bounding shape, converted element-wise using the given closure.
sourcepub fn as_<D>(self) -> Aabb<D>where
T: AsPrimitive<D>,
D: 'static + Copy,
pub fn as_<D>(self) -> Aabb<D>where T: AsPrimitive<D>, D: 'static + Copy,
Converts this rectangle to a rectangle of another type, using the as
conversion.
Trait Implementations§
source§impl<'de, T> Deserialize<'de> for Aabb<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Aabb<T>where T: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Aabb<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<Aabb<T>, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl<T> PartialEq<Aabb<T>> for Aabb<T>where
T: PartialEq<T>,
impl<T> PartialEq<Aabb<T>> for Aabb<T>where T: PartialEq<T>,
source§impl<T> Serialize for Aabb<T>where
T: Serialize,
impl<T> Serialize for Aabb<T>where T: Serialize,
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
impl<T> Copy for Aabb<T>where T: Copy,
impl<T> Eq for Aabb<T>where T: Eq,
impl<T> StructuralEq for Aabb<T>
impl<T> StructuralPartialEq for Aabb<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for Aabb<T>where T: RefUnwindSafe,
impl<T> Send for Aabb<T>where T: Send,
impl<T> Sync for Aabb<T>where T: Sync,
impl<T> Unpin for Aabb<T>where T: Unpin,
impl<T> UnwindSafe for Aabb<T>where T: UnwindSafe,
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
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.