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