1use super::Hittable;2use crate::math::Interval;34pub struct HittableList {5 list: Vec<Box<dyn Hittable + Send + Sync>>,6}78impl HittableList {9 pub fn new() -> HittableList {10 HittableList { list: Vec::new() }11 }1213 pub fn push(&mut self, h: Box<dyn Hittable + Send + Sync>) {14 self.list.push(h);15 }16}1718impl Hittable for HittableList {19 fn hit(&self, r: &crate::math::Ray, range: &Interval) -> Option<super::HitRecord> {20 self.list21 .iter()22 .fold((None, range.clone()), |(hit, range), h| {23 match h.hit(r, &range) {24 Some(hit) => {25 let range = Interval::new(0., hit.t.get()).unwrap();26 (Some(hit), range)27 }28 None => (hit, range),29 }30 })31 .032 }33}