Struct beebox::Aabb
[−]
[src]
pub struct Aabb { /* fields omitted */ }
An axis-aligned bounding box in 3D space.
The box can, for the most part, be thought of as being defined by two corners, a minimum corner and a maximum corner. All coordinates are 32-bit floats.
This representation does not allow empty boxes, which are occasionally useful. However, one can abuse the corner vectors and set the "minimum corner" to positive infinity and the "maximum corner" to negative infinity. Most AABB operations will handle this without extra work if they're written carefully, but it's an unnatural special case to keep in mind when working with the corners.
Aabb
can be empty, which is implemented using the aforementioned trick, but as far as the
interface is concerned, it upholds the "min corner, max corner" view: empty Aabb
s cannot be
constructed by specifying nonsensical corners (there is a separate constructor, empty()
), and
there is no minimum or maximum corner for an empty bounding box (the accessors panic).
Methods
impl Aabb
[src]
fn new<I>(points: I) -> Self where
I: IntoIterator<Item = Vector3<f32>>,
I: IntoIterator<Item = Vector3<f32>>,
Constructs a bounding box from a set of points.
Empty sets of points are valid and result in an empty bounding box.
fn min(&self) -> Vector3<f32>
Returns the "minimum corner", i.e., the coordinate-wise minimum of the region of space described by the AABB.
Panics
Empty AABBs have no meaningful minimum, so calling this functions on an empty AABB panics.
fn max(&self) -> Vector3<f32>
Returns the "maximum corner", i.e., the coordinate-wise maximum of the region of space described by the AABB.
Panics
Empty AABBs have no meaningful maximum, so calling this functions on an empty AABB panics.
fn from_corners(min: Vector3<f32>, max: Vector3<f32>) -> Self
Constructs a bounding box by supplying the minimum and maximum coordinates directly.
Empty AABBs cannot be created through this function, consider using Aabb::empty()
.
Panics
Panics when the corners aren't really minimum and maximum, i.e. min[i] > max[i]
in
any dimension i
.
fn empty() -> Self
Constructs an empty AABB which does not contain any points and can be union
'd with
other AABBs without affecting them.
fn is_empty(&self) -> bool
Returns true
if the box is empty, i.e., encompasses no space and not even a single point.
fn add_point(&mut self, p: Vector3<f32>)
Expand the bounding box to also encompass the point p
.
fn add_box(&mut self, other: Self)
Updates the AABB to also encompass other
.
This is an in-place version of union
.
fn union(&self, other: Self) -> Self
Returns the smallest AABB that encompasses both self
and other
.
fn surface_area(&self) -> f32
Returns the surface area of the box. This is useful for construction of bounding volume hierarchies.
Panics
Panics if the box is empty. While it might be possible to meaningfully assign surface area 0 to a non-existing surface, it's not 100% clear whether this is mathematically kosher and in the context of BVH construction, needing the surface area of an empty box probably indicates a bug.
fn intersects(&self, r: &RayData, t0: f32, t1: f32) -> bool
Returns true
if the [t0, t1]
segment of the ray intersects this AABB.
In other words, returns true
if the ray intersects the AABB and the intersection point
is r(t) := o + t * d
for t
in the interval [t0, t1]
.
(As usual, o
denotes the ray origin and d
the ray direction.)
The code is derived from Physically based rendering (cited in the crate documentation) and implements the algorithm from:
Williams, Amy, et al. "An efficient and robust ray-box intersection algorithm." ACM SIGGRAPH 2005 Courses.
fn centroid(&self) -> Vector3<f32>
fn largest_axis(&self) -> usize
Returns the axis along which the AABB is largest.
In case multiple axes are largest (e.g., because the AABB is empty or a cube), the result is one of the largest axes, but it is unspecified which one is returned.
Trait Implementations
impl Copy for Aabb
[src]
impl Clone for Aabb
[src]
fn clone(&self) -> Aabb
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more