parry3d/bounding_volume/
bounding_sphere_voxels.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::bounding_volume::BoundingSphere;
use crate::math::{Isometry, Real, Translation};
use crate::shape::{Cuboid, Voxels};

impl Voxels {
    /// Computes the world-space bounding sphere of this set of voxels, transformed by `pos`.
    #[inline]
    pub fn bounding_sphere(&self, pos: &Isometry<Real>) -> BoundingSphere {
        let shift = Translation::from(self.domain_center().coords);
        Cuboid::new(self.extents() / 2.0).bounding_sphere(&(pos * shift))
    }

    /// Computes the local-space bounding sphere of this set of voxels.
    #[inline]
    pub fn local_bounding_sphere(&self) -> BoundingSphere {
        Cuboid::new(self.extents() / 2.0)
            .local_bounding_sphere()
            .translated(&(self.domain_center().coords))
    }
}