Skip to main content

collider_shape/
cone.rs

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