ncollide3d/bounding_volume/
bounding_sphere_utils.rs
1use crate::math::Point;
2use crate::utils;
3use na::{self, RealField};
4
5#[inline]
8pub fn point_cloud_bounding_sphere_with_center<N: RealField + Copy>(
9 pts: &[Point<N>],
10 center: Point<N>,
11) -> (Point<N>, N) {
12 let mut sqradius = na::zero();
13
14 for pt in pts.iter() {
15 let distance_squared = na::distance_squared(pt, ¢er);
16
17 if distance_squared > sqradius {
18 sqradius = distance_squared
19 }
20 }
21
22 (center, sqradius.sqrt())
23}
24
25#[inline]
28pub fn point_cloud_bounding_sphere<N: RealField + Copy>(pts: &[Point<N>]) -> (Point<N>, N) {
29 point_cloud_bounding_sphere_with_center(pts, utils::center(pts))
30}