ncollide3d/bounding_volume/
aabb_ball.rs

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