Skip to main content

collider_shape/
cylinder.rs

1use crate::shape::Shape;
2
3/// A cylinder shape aligned along the `z`-axis.
4///
5/// The base of the cylinder is at `(0, 0, -half_length)` and the top is at `(0, 0, half_length)`.
6#[derive(PartialEq, Debug, Copy, Clone)]
7pub struct Cylinder {
8    /// The radius of the cylinder.
9    pub radius: f32,
10    /// The half length of the cylinder along the `z`-axis.
11    pub half_length: f32,
12}
13
14impl Cylinder {
15    /// Creates a new cylinder with given radius and half height.
16    ///
17    /// # Arguments
18    ///
19    /// * `radius` - The radius of the cylinder.
20    /// * `half_length` - The half length of the cylinder along the `z`-axis.
21    pub fn new(radius: f32, half_length: f32) -> Self {
22        Cylinder {
23            radius,
24            half_length,
25        }
26    }
27}
28
29impl Shape for Cylinder {
30    fn is_convex(&self) -> bool {
31        true
32    }
33
34    fn clone_box(&self) -> Box<dyn Shape + Send + Sync> {
35        Box::new(*self)
36    }
37
38    fn get_shape_type(&self) -> crate::shape::ShapeType {
39        crate::shape::ShapeType::Cylinder
40    }
41
42    fn get_radius(&self) -> Option<f32> {
43        Some(self.radius)
44    }
45
46    fn get_half_length(&self) -> Option<f32> {
47        Some(self.half_length)
48    }
49}