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
use crate::math::{Point, Real};
use crate::utils;
use na::{self, ComplexField};

/// Computes the bounding sphere of a set of point, given its center.
// TODO: return a bounding sphere?
#[inline]
pub fn point_cloud_bounding_sphere_with_center(
    pts: &[Point<Real>],
    center: Point<Real>,
) -> (Point<Real>, Real) {
    let mut sqradius = 0.0;

    for pt in pts.iter() {
        let distance_squared = na::distance_squared(pt, &center);

        if distance_squared > sqradius {
            sqradius = distance_squared
        }
    }

    (center, ComplexField::sqrt(sqradius))
}

/// Computes a bounding sphere of the specified set of point.
// TODO: return a bounding sphere?
#[inline]
pub fn point_cloud_bounding_sphere(pts: &[Point<Real>]) -> (Point<Real>, Real) {
    point_cloud_bounding_sphere_with_center(pts, utils::center(pts))
}