rtiow: aabb add area/grow methods and infinite constructor.
This commit is contained in:
parent
3c28466d68
commit
df928e1779
@ -42,6 +42,13 @@ impl fmt::Debug for AABB {
|
||||
}
|
||||
|
||||
impl AABB {
|
||||
// Create AABB with min = f32::MAX and max = -f32::MAX. It is expected the caller will use grow to create
|
||||
// a vaild AABB.
|
||||
pub fn infinite() -> AABB {
|
||||
AABB {
|
||||
bounds: [Vec3::from(f32::MAX), -Vec3::from(f32::MAX)],
|
||||
}
|
||||
}
|
||||
pub fn new<V: Into<Vec3>>(min: V, max: V) -> AABB {
|
||||
let min: Vec3 = min.into();
|
||||
let max: Vec3 = max.into();
|
||||
@ -51,12 +58,21 @@ impl AABB {
|
||||
AABB { bounds: [min, max] }
|
||||
}
|
||||
|
||||
pub fn area(&self) -> f32 {
|
||||
let e = self.max() - self.min();
|
||||
e.x * e.y + e.y * e.z + e.z * e.x
|
||||
}
|
||||
pub fn volume(&self) -> f32 {
|
||||
(self.min().x - self.max().x).abs()
|
||||
* (self.min().y - self.max().y).abs()
|
||||
* (self.min().z - self.max().z).abs()
|
||||
}
|
||||
|
||||
pub fn grow(&mut self, v: Vec3) {
|
||||
self.bounds[0] = vec3::min(self.bounds[0], v);
|
||||
self.bounds[1] = vec3::max(self.bounds[1], v);
|
||||
}
|
||||
|
||||
pub fn longest_axis(&self) -> usize {
|
||||
let xd = (self.min().x - self.max().x).abs();
|
||||
let yd = (self.min().y - self.max().y).abs();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user