use alga::general::Real; use na::Unit; use shape::SupportMap; use math::{Isometry, Point}; /// A Ball shape. #[derive(PartialEq, Debug, Clone)] pub struct Ball { radius: N, } impl Ball { /// Creates a new ball from its radius and center. #[inline] pub fn new(radius: N) -> Ball { assert!( radius > N::zero(), "A ball radius must be strictly positive." ); Ball { radius: radius } } /// The ball radius. #[inline] pub fn radius(&self) -> N { self.radius } } impl> SupportMap for Ball { #[inline] fn support_point(&self, m: &M, dir: &P::Vector) -> P { self.support_point_toward(m, &Unit::new_normalize(*dir)) } #[inline] fn support_point_toward(&self, m: &M, dir: &Unit) -> P { m.translate_point(&P::origin()) + **dir * self.radius() } }