use crate::{
bounding_volume::Aabb,
math::{Pose, Vector},
shape::Triangle,
};
impl Triangle {
#[inline]
pub fn aabb(&self, pos: &Pose) -> Aabb {
self.transformed(pos).local_aabb()
}
#[inline]
pub fn local_aabb(&self) -> Aabb {
let a = self.a;
let b = self.b;
let c = self.c;
let mut min = Vector::ZERO;
let mut max = Vector::ZERO;
for_each_dim! {
min[ii] = a[ii].min(b[ii]).min(c[ii]);
max[ii] = a[ii].max(b[ii]).max(c[ii]);
}
Aabb::new(min, max)
}
}
#[cfg(test)]
#[cfg(feature = "dim3")]
mod test {
use crate::{
bounding_volume::details::support_map_aabb,
math::{Pose, Real, Rotation, Vector},
shape::Triangle,
};
use core::f64::consts::FRAC_PI_2;
#[test]
fn triangle_aabb_matches_support_map_aabb() {
let t = Triangle::new(
Vector::new(0.3, -0.1, 0.2),
Vector::new(-0.7, 1.0, 0.0),
Vector::new(-0.7, 1.5, 0.0),
);
let m = Pose::from_parts(
Vector::new(-0.2, 5.0, 0.2),
Rotation::from_euler(glamx::EulerRot::XYZ, 0.0, FRAC_PI_2 as Real, 0.0),
);
assert_eq!(t.aabb(&m), support_map_aabb(&m, &t));
}
}