rtiow: AABB more compact Debug representation. Loosen assertions.

This commit is contained in:
Bill Thiede 2023-02-02 16:56:43 -08:00
parent 6ab3021403
commit f7c5f29e67

View File

@ -2,7 +2,7 @@ use std::fmt;
use crate::{ray::Ray, vec3::Vec3};
#[derive(Default, Debug, Copy, Clone, PartialEq)]
#[derive(Default, Copy, Clone, PartialEq)]
pub struct AABB {
bounds: [Vec3; 2],
}
@ -29,13 +29,25 @@ fn max(x: f32, y: f32) -> f32 {
}
}
impl fmt::Debug for AABB {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"AABB: <{} - {}> Vol: {}",
self.bounds[0],
self.bounds[1],
self.volume()
)
}
}
impl AABB {
pub fn new<V: Into<Vec3>>(min: V, max: V) -> AABB {
let min: Vec3 = min.into();
let max: Vec3 = max.into();
assert!(min.x < max.x);
assert!(min.y < max.y);
assert!(min.z < max.z);
assert!(min.x <= max.x);
assert!(min.y <= max.y);
assert!(min.z <= max.z);
AABB { bounds: [min, max] }
}