ncollide3d/shape/
cylinder.rs1use crate::math::{Point, Vector};
4use crate::shape::SupportMap;
5use na::{self, RealField};
6
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9#[derive(PartialEq, Debug, Copy, Clone)]
10pub struct Cylinder<N> {
11 pub half_height: N,
13 pub radius: N,
15}
16
17impl<N: RealField + Copy> Cylinder<N> {
18 pub fn new(half_height: N, radius: N) -> Cylinder<N> {
24 assert!(half_height.is_positive() && radius.is_positive());
25
26 Cylinder {
27 half_height,
28 radius,
29 }
30 }
31
32 #[inline]
34 #[deprecated(note = "use the `self.half_height` field directly.")]
35 pub fn half_height(&self) -> N {
36 self.half_height
37 }
38
39 #[inline]
41 #[deprecated(note = "use the `self.radius` field directly.")]
42 pub fn radius(&self) -> N {
43 self.radius
44 }
45}
46
47impl<N: RealField + Copy> SupportMap<N> for Cylinder<N> {
48 fn local_support_point(&self, dir: &Vector<N>) -> Point<N> {
49 let mut vres = *dir;
50
51 vres[1] = na::zero();
52
53 if vres.normalize_mut().is_zero() {
54 vres = na::zero()
55 } else {
56 vres = vres * self.radius;
57 }
58
59 vres[1] = self.half_height.copysign(dir[1]);
60
61 Point::from(vres)
62 }
63}