use crate::{ aabb::AABB, hitable::{Hit, HitRecord}, ray::Ray, }; #[derive(Debug)] pub struct Scale where H: Hit, { hitable: H, scale: f32, } impl Scale where H: Hit, { pub fn new(hitable: H, scale: f32) -> Scale { Scale { hitable, scale } } } impl Hit for Scale where H: Hit, { fn hit(&self, r: Ray, t_min: f32, t_max: f32) -> Option { let moved_r = Ray::new(r.origin / self.scale, r.direction, r.time); if let Some(rec) = self.hitable.hit(moved_r, t_min, t_max) { return Some(HitRecord { p: rec.p * self.scale, t: rec.t * self.scale, ..rec }); } None } fn bounding_box(&self, t_min: f32, t_max: f32) -> Option { if let Some(bbox) = self.hitable.bounding_box(t_min, t_max) { return Some(AABB::new(bbox.min() * self.scale, bbox.max() * self.scale)); } None } }