1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::bounding_volume::Aabb;
use crate::math::{Isometry, Point, Real, Vector};
use crate::shape::Ball;

/// Computes the Axis-Aligned Bounding Box of a ball transformed by `center`.
#[inline]
pub fn ball_aabb(center: &Point<Real>, radius: Real) -> Aabb {
    Aabb::new(
        *center + Vector::repeat(-radius),
        *center + Vector::repeat(radius),
    )
}

/// Computes the Axis-Aligned Bounding Box of a ball.
#[inline]
pub fn local_ball_aabb(radius: Real) -> Aabb {
    let half_extents = Point::from(Vector::repeat(radius));

    Aabb::new(-half_extents, half_extents)
}

impl Ball {
    /// Computes the world-space [`Aabb`] of this ball transformed by `pos`.
    #[inline]
    pub fn aabb(&self, pos: &Isometry<Real>) -> Aabb {
        ball_aabb(&Point::<Real>::from(pos.translation.vector), self.radius)
    }

    /// Computes the local-space [`Aabb`] of this ball.
    #[inline]
    pub fn local_aabb(&self) -> Aabb {
        local_ball_aabb(self.radius)
    }
}