shape_core/elements/rectangles/rectangle_3d/
mod.rs

1use super::*;
2
3/// A Cuboid is a
4///
5/// # Notice
6///
7/// The constructor will not check the legality of the parameters, call [`is_valid`] to ensure that the rectangle_2d is legal.
8///
9/// # Examples
10///
11/// ```
12/// # use shape_core::Square;
13/// let rect = Square::new(0.0, 0.0, 1.0);
14/// ```
15pub struct Cuboid<T> {
16    /// The origin x of the cuboid.
17    pub min: Point3D<T>,
18    /// The width of the cuboid.
19    pub max: Point3D<T>,
20}
21
22impl<T> Debug for Cuboid<T>
23where
24    T: Debug + Clone + Sub<Output = T>,
25{
26    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
27        f.debug_struct("Cuboid")
28            .field("origin", &self.origin())
29            .field("width", &self.width())
30            .field("height", &self.height())
31            .field("length", &self.length())
32            .finish()
33    }
34}
35
36impl<T> Cuboid<T> {
37    /// Create a cuboid from 6 properties
38    pub fn origin(&self) -> Point3D<&T> {
39        self.min.ref_inner()
40    }
41    /// Delta x
42    pub fn width(&self) -> T
43    where
44        T: Clone + Sub<Output = T>,
45    {
46        self.max.x.clone() - self.min.x.clone()
47    }
48    /// delta y
49    pub fn height(&self) -> T
50    where
51        T: Clone + Sub<Output = T>,
52    {
53        self.max.y.clone() - self.min.y.clone()
54    }
55    /// Delta z
56    pub fn length(&self) -> T
57    where
58        T: Clone + Sub<Output = T>,
59    {
60        self.max.z.clone() - self.min.z.clone()
61    }
62}