diff options
author | lamp | 2024-01-21 17:03:07 +0000 |
---|---|---|
committer | lamp | 2024-01-21 17:03:07 +0000 |
commit | 45fafbcd4b41a5388ece377c4e051b5846407288 (patch) | |
tree | 2192c471ca3b47671f0906e27f6f6088f40b3d8a /src/hittable/instance/moving.rs | |
parent | 89a5c9a8a0cdf627cda0e31da454f83ca21315ce (diff) |
fmt and tidy
Diffstat (limited to 'src/hittable/instance/moving.rs')
-rw-r--r-- | src/hittable/instance/moving.rs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/hittable/instance/moving.rs b/src/hittable/instance/moving.rs index 418fdbb..062af86 100644 --- a/src/hittable/instance/moving.rs +++ b/src/hittable/instance/moving.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use crate::{ray::Ray, vec3::Vec3}; use crate::hittable::{HitRecord, Hittable, AABB}; +use crate::{ray::Ray, vec3::Vec3}; pub struct Moving { pub hittable: Arc<dyn Hittable>, @@ -13,13 +13,19 @@ pub struct Moving { impl Moving { fn offset_at(&self, time: f64) -> Vec3 { - &self.offset_start + ((time - self.time_start) / (self.time_end - self.time_start)) * (&self.offset_end - &self.offset_start) + &self.offset_start + + ((time - self.time_start) / (self.time_end - self.time_start)) + * (&self.offset_end - &self.offset_start) } } impl Hittable for Moving { fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> { - let moved_ray = Ray { origin: &ray.origin - &self.offset_at(ray.time), direction: ray.direction.clone(), time: ray.time }; + let moved_ray = Ray { + origin: &ray.origin - &self.offset_at(ray.time), + direction: ray.direction.clone(), + time: ray.time, + }; let mut hit_record = self.hittable.hit(&moved_ray, t_min, t_max)?; hit_record.p += self.offset_at(ray.time).clone(); let normal = hit_record.normal.clone(); @@ -29,12 +35,15 @@ impl Hittable for Moving { fn bounding_box(&self, time_start: f64, time_end: f64) -> Option<AABB> { let output_box = self.hittable.bounding_box(time_start, time_end)?; - Some(AABB { - minimum: &output_box.minimum + &self.offset_at(time_start), - maximum: &output_box.maximum + &self.offset_at(time_start), - }.surrounding_box(&AABB { - minimum: &output_box.minimum + &self.offset_at(time_end), - maximum: &output_box.maximum + &self.offset_at(time_end), - })) + Some( + AABB { + minimum: &output_box.minimum + &self.offset_at(time_start), + maximum: &output_box.maximum + &self.offset_at(time_start), + } + .surrounding_box(&AABB { + minimum: &output_box.minimum + &self.offset_at(time_end), + maximum: &output_box.maximum + &self.offset_at(time_end), + }), + ) } } |