parry3d/bounding_volume/
bounding_sphere_utils.rs

1use crate::math::{Point, Real};
2use crate::utils;
3use na::{self, ComplexField};
4
5use super::BoundingSphere;
6
7/// Computes the bounding sphere of a set of point, given its center.
8#[inline]
9pub fn point_cloud_bounding_sphere_with_center(
10    pts: &[Point<Real>],
11    center: Point<Real>,
12) -> BoundingSphere {
13    let mut sqradius = 0.0;
14
15    for pt in pts.iter() {
16        let distance_squared = na::distance_squared(pt, &center);
17
18        if distance_squared > sqradius {
19            sqradius = distance_squared
20        }
21    }
22    BoundingSphere::new(center, ComplexField::sqrt(sqradius))
23}
24
25/// Computes a bounding sphere of the specified set of point.
26#[inline]
27pub fn point_cloud_bounding_sphere(pts: &[Point<Real>]) -> BoundingSphere {
28    point_cloud_bounding_sphere_with_center(pts, utils::center(pts))
29}