#[repr(C)]pub struct Aabb {
pub min: Vec3,
pub max: Vec3,
}
Expand description
Represents an Axis-Aligned Bounding Box (AABB).
An AABB is a rectangular prism aligned with the coordinate axes, defined by its minimum and maximum corner points. It is a simple but highly efficient volume for broad-phase collision detection and visibility culling.
Fields§
§min: Vec3
The corner of the box with the smallest coordinates on all axes.
max: Vec3
The corner of the box with the largest coordinates on all axes.
Implementations§
Source§impl Aabb
impl Aabb
Sourcepub const INVALID: Self
pub const INVALID: Self
An invalid Aabb
where min
components are positive infinity and max
are negative infinity.
This is useful as a neutral starting point for merging operations. Merging any
valid Aabb
with INVALID
will result in that valid Aabb
.
Sourcepub fn from_min_max(min_pt: Vec3, max_pt: Vec3) -> Self
pub fn from_min_max(min_pt: Vec3, max_pt: Vec3) -> Self
Creates a new Aabb
from two corner points.
This constructor automatically ensures that the min
field holds the
component-wise minimum and max
holds the component-wise maximum,
regardless of the order the points are passed in.
Sourcepub fn from_center_half_extents(center: Vec3, half_extents: Vec3) -> Self
pub fn from_center_half_extents(center: Vec3, half_extents: Vec3) -> Self
Creates a new Aabb
from a center point and its half-extents.
The half-extents represent the distance from the center to the faces of the box.
The provided half_extents
will be made non-negative.
Sourcepub fn from_point(point: Vec3) -> Self
pub fn from_point(point: Vec3) -> Self
Creates a degenerate Aabb
containing a single point (min and max are the same).
Sourcepub fn from_points(points: &[Vec3]) -> Option<Self>
pub fn from_points(points: &[Vec3]) -> Option<Self>
Creates an Aabb
that tightly encloses a given set of points.
§Returns
Returns Some(Aabb)
if the input slice is not empty, otherwise None
.
Sourcepub fn half_extents(&self) -> Vec3
pub fn half_extents(&self) -> Vec3
Calculates the half-extents (half the size on each axis) of the Aabb
.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Checks if the Aabb
is valid (i.e., min
<= max
on all axes).
Degenerate boxes where min == max
are considered valid.
Sourcepub fn contains_point(&self, point: Vec3) -> bool
pub fn contains_point(&self, point: Vec3) -> bool
Checks if a point is contained within or on the boundary of the Aabb
.
Sourcepub fn intersects_aabb(&self, other: &Aabb) -> bool
pub fn intersects_aabb(&self, other: &Aabb) -> bool
Checks if this Aabb
intersects with another Aabb
.
Two Aabb
s intersect if they overlap on all three axes. Boxes that only
touch at the boundary are considered to be intersecting.
Sourcepub fn merge(&self, other: &Aabb) -> Self
pub fn merge(&self, other: &Aabb) -> Self
Creates a new Aabb
that encompasses both this Aabb
and another one.
Sourcepub fn merged_with_point(&self, point: Vec3) -> Self
pub fn merged_with_point(&self, point: Vec3) -> Self
Creates a new Aabb
that encompasses both this Aabb
and an additional point.
Sourcepub fn transform(&self, matrix: &Mat4) -> Self
pub fn transform(&self, matrix: &Mat4) -> Self
Computes the bounding box that encloses this Aabb
after a transformation.
This method is more efficient than transforming all 8 corners of the box for affine transformations. It works by transforming the center of the box and then calculating the new extents by projecting the original extents onto the axes of the transformed space.
§Note
This method is designed for affine transformations (like rotation, translation, scale). It may not produce the tightest-fitting box for transformations involving perspective.