use glam::Vec3;
#[derive(Debug, Clone, Copy)]
pub struct Aabb {
pub min: Vec3,
pub max: Vec3,
}
impl Aabb {
pub fn empty() -> Self {
Self {
min: Vec3::splat(f32::MAX),
max: Vec3::splat(f32::MIN),
}
}
pub fn expand(&mut self, point: Vec3) {
self.min = self.min.min(point);
self.max = self.max.max(point);
}
pub fn center(&self) -> Vec3 {
(self.min + self.max) * 0.5
}
pub fn extents(&self) -> Vec3 {
self.max - self.min
}
pub fn diagonal(&self) -> f32 {
self.extents().length()
}
pub fn is_valid(&self) -> bool {
self.min.x <= self.max.x && self.min.y <= self.max.y && self.min.z <= self.max.z
}
}
impl Default for Aabb {
fn default() -> Self {
Self::empty()
}
}