Skip to main content

collider_shape/
sphere.rs

1use crate::{ShapeType, shape::Shape};
2
3/// A sphere shape, defined by its radius.
4#[derive(PartialEq, Debug, Copy, Clone)]
5pub struct Sphere {
6    ///  The radius of the sphere.
7    pub radius: f32,
8}
9
10impl Sphere {
11    /// Creates a new sphere with given radius.
12    ///
13    /// # Arguments
14    ///
15    /// * `radius` - The radius of the sphere.
16    pub fn new(radius: f32) -> Self {
17        Sphere { radius }
18    }
19}
20
21impl Shape for Sphere {
22    fn is_convex(&self) -> bool {
23        true
24    }
25
26    fn clone_box(&self) -> Box<dyn Shape + Send + Sync> {
27        Box::new(*self)
28    }
29
30    fn get_shape_type(&self) -> ShapeType {
31        ShapeType::Sphere
32    }
33
34    fn get_radius(&self) -> Option<f32> {
35        Some(self.radius)
36    }
37}