Added centers of bounding box

This commit is contained in:
Thomas Forgione 2018-06-13 16:51:33 +02:00
parent 8062de7e21
commit 4ddbbbcc3e
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 16 additions and 0 deletions

View File

@ -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 {