From b27ae3356d6ebb7fcd59785f6de262879cc37451 Mon Sep 17 00:00:00 2001 From: Dan Whitman Date: Fri, 22 Mar 2024 08:23:47 -0400 Subject: [PATCH] Adds the `Box3D::from_origin_and_size` associated function. (#520) Co-authored-by: Dan Whitman --- src/box3d.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/box3d.rs b/src/box3d.rs index 7640af2..e802515 100644 --- a/src/box3d.rs +++ b/src/box3d.rs @@ -84,6 +84,22 @@ impl Box3D { Box3D { min, max } } + /// Constructor. + #[inline] + pub fn from_origin_and_size(origin: Point3D, size: Size3D) -> Self + where + T: Copy + Add, + { + Box3D { + min: origin, + max: point3( + origin.x + size.width, + origin.y + size.height, + origin.z + size.depth, + ), + } + } + /// Creates a Box3D of the given size, at offset zero. #[inline] pub fn from_size(size: Size3D) -> Self