parry2d/bounding_volume/
aabb_ball.rs

1use crate::bounding_volume::Aabb;
2use crate::math::{Pose, 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: Vector, radius: Real) -> Aabb {
8    Aabb::new(
9        center + Vector::splat(-radius),
10        center + Vector::splat(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 = Vector::splat(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: &Pose) -> Aabb {
26        ball_aabb(pos.translation, 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}