From 4ddbbbcc3e43155fc056ddc4e4dfcc63970fddf0 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 13 Jun 2018 16:51:33 +0200 Subject: [PATCH] Added centers of bounding box --- src/math/bounding_box.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/math/bounding_box.rs b/src/math/bounding_box.rs index ed2174e..8d5fc71 100644 --- a/src/math/bounding_box.rs +++ b/src/math/bounding_box.rs @@ -94,6 +94,7 @@ macro_rules! make_bounding_box { } ret } + } } @@ -103,6 +104,21 @@ make_bounding_box!(BoundingBox2, Vector2, 2); make_bounding_box!(BoundingBox3, Vector3, 3); make_bounding_box!(BoundingBox4, Vector4, 4); +macro_rules! impl_center { + ($name: ident, $vector: ident, $f: tt) => { + impl $name<$f> { + /// Returns the center of the bounding box. + pub fn center(&self) -> $vector<$f> { + (self.min + self.max) / 2.0 + } + } + } +} + +impl_center!(BoundingBox2, Vector2, f32); +impl_center!(BoundingBox2, Vector2, f64); + + #[cfg(test)] mod tests {