parry3d/bounding_volume/
aabb_ball.rs

1use crate::bounding_volume::Aabb;
2use crate::math::{Isometry, Point, Real, Vector};
3use crate::shape::Ball;
4
5/// Computes the Axis-Aligned Bounding Box of a ball transformed by `center`.
6#[inline]
7pub fn ball_aabb(center: &Point<Real>, radius: Real) -> Aabb {
8    Aabb::new(
9        *center + Vector::repeat(-radius),
10        *center + Vector::repeat(radius),
11    )
12}
13
14/// Computes the Axis-Aligned Bounding Box of a ball.
15#[inline]
16pub fn local_ball_aabb(radius: Real) -> Aabb {
17    let half_extents = Point::from(Vector::repeat(radius));
18
19    Aabb::new(-half_extents, half_extents)
20}
21
22impl Ball {
23    /// Computes the world-space [`Aabb`] of this ball transformed by `pos`.
24    #[inline]
25    pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
26        ball_aabb(&Point::<Real>::from(pos.translation.vector), self.radius)
27    }
28
29    /// Computes the local-space [`Aabb`] of this ball.
30    #[inline]
31    pub fn local_aabb(&self) -> Aabb {
32        local_ball_aabb(self.radius)
33    }
34}