pub struct Aabb { /* private fields */ }Expand description
A three-dimensional axis-aligned bounding box, or “AABB”.
The AABB is defined by two points—min and max. min is less than or
equal to max componentwise.
Implementations§
Source§impl Aabb
impl Aabb
pub const ZERO: Self
Sourcepub fn new(min: DVec3, max: DVec3) -> Self
pub fn new(min: DVec3, max: DVec3) -> Self
Constructs a new AABB from min and max points.
§Panics
Panics if debug_assertions are enabled and min is not less than or
equal to max componentwise.
pub fn from_bottom_size(bottom: DVec3, size: DVec3) -> Self
pub const fn min(self) -> DVec3
pub const fn max(self) -> DVec3
pub fn union(self, other: Self) -> Self
Sourcepub fn intersects(self, other: Self) -> bool
pub fn intersects(self, other: Self) -> bool
Does this bounding box intersect with another bounding box (including touching)?
See Aabb::intersects_strict if you don’t want to include touching.
Sourcepub fn intersects_strict(self, other: Self) -> bool
pub fn intersects_strict(self, other: Self) -> bool
Does this bounding box intersect with another bounding box (not including touching)?
See Aabb::intersects if you want to include touching.
Sourcepub fn contains_point(self, p: DVec3) -> bool
pub fn contains_point(self, p: DVec3) -> bool
Does this bounding box contain the given point?
Sourcepub fn projected_point(self, p: DVec3) -> DVec3
pub fn projected_point(self, p: DVec3) -> DVec3
Returns the closest point in the AABB to the given point.
Sourcepub fn distance_to_point(self, p: DVec3) -> f64
pub fn distance_to_point(self, p: DVec3) -> f64
Returns the smallest distance from the AABB to the point.
Sourcepub fn ray_intersection(
self,
origin: DVec3,
direction: DVec3,
) -> Option<[f64; 2]>
pub fn ray_intersection( self, origin: DVec3, direction: DVec3, ) -> Option<[f64; 2]>
Calculates the intersection between this AABB and a ray
defined by its origin point and direction vector.
If an intersection occurs, Some([near, far]) is returned. near and
far are the values of t in the equation origin + t * direction = point where point is the nearest or furthest intersection point to
the origin. If no intersection occurs, then None is returned.
In other words, if direction is normalized, then near and far are
the distances to the nearest and furthest intersection points.