parry2d/bounding_volume/
bounding_sphere_utils.rs1use crate::math::{ComplexField, Real, Vector};
2use crate::utils;
3
4use super::BoundingSphere;
5
6#[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#[inline]
23pub fn point_cloud_bounding_sphere(pts: &[Vector]) -> BoundingSphere {
24 point_cloud_bounding_sphere_with_center(pts, utils::center(pts))
25}