strafe-client/src/aabb.rs

43 lines
981 B
Rust
Raw Normal View History

2023-09-27 09:12:20 +00:00
use crate::integer::Planar64Vec3;
2023-10-06 03:32:02 +00:00
#[derive(Clone)]
2023-09-27 09:12:20 +00:00
pub struct Aabb{
pub min:Planar64Vec3,
pub max:Planar64Vec3,
2023-10-06 03:32:02 +00:00
}
2023-10-06 05:50:16 +00:00
impl Default for Aabb {
2023-09-27 09:12:20 +00:00
fn default()->Self {
Self{min:Planar64Vec3::MAX,max:Planar64Vec3::MIN}
2023-10-06 05:50:16 +00:00
}
}
2023-09-27 09:12:20 +00:00
impl Aabb{
pub fn grow(&mut self,point:Planar64Vec3){
2023-10-06 03:32:02 +00:00
self.min=self.min.min(point);
self.max=self.max.max(point);
}
2023-09-27 09:12:20 +00:00
pub fn join(&mut self,aabb:&Aabb){
2023-10-06 03:32:25 +00:00
self.min=self.min.min(aabb.min);
self.max=self.max.max(aabb.max);
}
2023-09-27 09:12:20 +00:00
pub fn inflate(&mut self,hs:Planar64Vec3){
2023-10-06 05:50:16 +00:00
self.min-=hs;
self.max+=hs;
}
pub fn intersects(&self,aabb:&Aabb)->bool{
(self.min.cmplt(aabb.max)&aabb.min.cmplt(self.max)).all()
}
2023-09-27 09:12:20 +00:00
pub fn center(&self)->Planar64Vec3{
return self.min.midpoint(self.max)
2023-10-06 03:32:25 +00:00
}
//probably use floats for area & volume because we don't care about precision
2023-09-27 09:12:20 +00:00
// pub fn area_weight(&self)->f32{
// let d=self.max-self.min;
// d.x*d.y+d.y*d.z+d.z*d.x
// }
// pub fn volume(&self)->f32{
// let d=self.max-self.min;
// d.x*d.y*d.z
// }
2023-10-06 03:32:02 +00:00
}