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