beevee: aabb: add Bounded trait implementation
This commit is contained in:
parent
58ee42d21d
commit
0ce49bb3a3
53
beevee/src/aabb/bounded.rs
Normal file
53
beevee/src/aabb/bounded.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use super::AABB;
|
||||
use crate::Point;
|
||||
|
||||
/// A trait for objects that can be bounded using an [`AABB`]
|
||||
///
|
||||
/// [`AABB`]: struct.AABB.html
|
||||
pub trait Bounded {
|
||||
/// Return the [`AABB`] surrounding self.
|
||||
///
|
||||
/// [`AABB`]: struct.AABB.html
|
||||
fn aabb(&self) -> AABB;
|
||||
}
|
||||
|
||||
/// Implementation of [`Bounded`] for [`AABB`]
|
||||
///
|
||||
/// [`Bounded`]: trait.Bounded.html
|
||||
/// [`AABB`]: struct.Point.html
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use beevee::Point;
|
||||
/// use beevee::aabb::{AABB, Bounded};
|
||||
///
|
||||
/// let low = Point::new(0., 0., 0.);
|
||||
/// let high = Point::new(1., 2., 3.);
|
||||
/// let aabb = AABB::with_bounds(low, high);
|
||||
/// assert_eq!(aabb, aabb.aabb());
|
||||
/// ```
|
||||
impl Bounded for AABB {
|
||||
fn aabb(&self) -> AABB {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of [`Bounded`] for [`Point`]
|
||||
///
|
||||
/// [`Bounded`]: trait.Bounded.html
|
||||
/// [`Point`]: ../type.Point.html
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use beevee::Point;
|
||||
/// use beevee::aabb::Bounded;
|
||||
///
|
||||
/// let point = Point::new(1., 2., 3.);
|
||||
/// let aabb = point.aabb();
|
||||
/// assert!(aabb.contains(&point));
|
||||
/// ```
|
||||
impl Bounded for Point {
|
||||
fn aabb(&self) -> AABB {
|
||||
AABB::with_bounds(*self, *self)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
//! The module relating to Axis-Aligned Bounding Boxes.
|
||||
|
||||
mod bounded;
|
||||
pub use bounded::*;
|
||||
|
||||
mod bounding_box;
|
||||
pub use bounding_box::*;
|
||||
|
|
Loading…
Reference in a new issue