30 lines
917 B
Rust
30 lines
917 B
Rust
use super::{BoundingBox, HasBoundingBox, Intersect, IntersectionInfo, Primitive, Ray};
|
|
use crate::math::Affine3;
|
|
|
|
impl HasBoundingBox for Vec<Box<dyn Primitive>> {
|
|
fn bounding_box(&self) -> BoundingBox {
|
|
self.iter().fold(BoundingBox::empty(), |acc, elem| {
|
|
acc.union(&elem.bounding_box())
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Intersect for Vec<Box<dyn Primitive>> {
|
|
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
|
self.iter()
|
|
.flat_map(|primitive| primitive.intersect(ray))
|
|
.min_by(
|
|
|a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) {
|
|
None => std::cmp::Ordering::Less,
|
|
Some(ordering) => ordering,
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Primitive for Vec<Box<dyn Primitive>> {
|
|
fn transform(&self, transformation: &Affine3<f64>) -> Box<dyn Primitive> {
|
|
todo!()
|
|
}
|
|
}
|