Skip to main content

collider_shape/
cuboid.rs

1use nalgebra::Vector3;
2
3use crate::shape::Shape;
4
5/// A cuboid shape.
6///
7/// The cuboid is zero-centered and defined by its half extents along the `x`, `y`, and `z` axes.
8#[derive(PartialEq, Debug, Clone, Copy)]
9pub struct Cuboid {
10    /// The half extents of the cuboid.
11    pub half_extents: Vector3<f32>,
12}
13
14impl Cuboid {
15    /// Creates a new cuboid with given half extents.
16    ///
17    /// # Arguments
18    ///
19    /// * `half_extents` - The half extents of the cuboid along the `x`, `y`, and `z` axes.
20    pub fn new(half_extents: Vector3<f32>) -> Self {
21        Cuboid { half_extents }
22    }
23}
24
25impl Shape for Cuboid {
26    fn is_convex(&self) -> bool {
27        true
28    }
29
30    fn clone_box(&self) -> Box<dyn Shape + Send + Sync> {
31        Box::new(*self)
32    }
33
34    fn get_shape_type(&self) -> crate::shape::ShapeType {
35        crate::shape::ShapeType::Cuboid
36    }
37
38    fn get_half_extents(&self) -> Option<Vector3<f32>> {
39        Some(self.half_extents)
40    }
41}