ncollide3d/shape/
ball.rs
1use na::{RealField, Unit};
2
3use crate::math::{Isometry, Point, Vector};
4use crate::shape::SupportMap;
5
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[derive(PartialEq, Debug, Copy, Clone)]
9pub struct Ball<N: RealField + Copy> {
10 pub radius: N,
12}
13
14impl<N: RealField + Copy> Ball<N> {
15 #[inline]
17 pub fn new(radius: N) -> Ball<N> {
18 Ball { radius }
19 }
20
21 #[inline]
23 #[deprecated(note = "use the `self.radius` public field directly.")]
24 pub fn radius(&self) -> N {
25 self.radius
26 }
27}
28
29impl<N: RealField + Copy> SupportMap<N> for Ball<N> {
30 #[inline]
31 fn support_point(&self, m: &Isometry<N>, dir: &Vector<N>) -> Point<N> {
32 self.support_point_toward(m, &Unit::new_normalize(*dir))
33 }
34
35 #[inline]
36 fn support_point_toward(&self, m: &Isometry<N>, dir: &Unit<Vector<N>>) -> Point<N> {
37 Point::from(m.translation.vector) + **dir * self.radius
38 }
39
40 #[inline]
41 fn local_support_point(&self, dir: &Vector<N>) -> Point<N> {
42 self.local_support_point_toward(&Unit::new_normalize(*dir))
43 }
44
45 #[inline]
46 fn local_support_point_toward(&self, dir: &Unit<Vector<N>>) -> Point<N> {
47 Point::from(**dir * self.radius)
48 }
49}