From 45fafbcd4b41a5388ece377c4e051b5846407288 Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 21 Jan 2024 17:03:07 +0000 Subject: fmt and tidy --- src/hittable/instance/rotate_y.rs | 54 +++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'src/hittable/instance/rotate_y.rs') diff --git a/src/hittable/instance/rotate_y.rs b/src/hittable/instance/rotate_y.rs index 8611616..8f34c09 100644 --- a/src/hittable/instance/rotate_y.rs +++ b/src/hittable/instance/rotate_y.rs @@ -1,6 +1,11 @@ use std::sync::Arc; -use crate::{hittable::{HitRecord, Hittable, AABB}, ray::Ray, util::degrees_to_radians, vec3::{Point3, Vec3}}; +use crate::{ + hittable::{HitRecord, Hittable, AABB}, + ray::Ray, + util::degrees_to_radians, + vec3::{Point3, Vec3}, +}; pub struct RotateY { hittable: Arc, @@ -14,11 +19,25 @@ impl RotateY { let radians = degrees_to_radians(angle); let sin_theta = radians.sin(); let cos_theta = radians.cos(); - match hittable.bounding_box(0.0, 1.0) { // TODO: passing in 0.0 and 1.0 for time seems suspicious. - None => Self { hittable, sin_theta, cos_theta, aabb: None }, + match hittable.bounding_box(0.0, 1.0) { + // TODO: passing in 0.0 and 1.0 for time seems suspicious. + None => Self { + hittable, + sin_theta, + cos_theta, + aabb: None, + }, Some(aabb) => { - let mut min = Point3 { x: f64::INFINITY, y: f64::INFINITY, z: f64::INFINITY }; - let mut max = Point3 { x: -f64::INFINITY, y: -f64::INFINITY, z: -f64::INFINITY }; + let mut min = Point3 { + x: f64::INFINITY, + y: f64::INFINITY, + z: f64::INFINITY, + }; + let mut max = Point3 { + x: -f64::INFINITY, + y: -f64::INFINITY, + z: -f64::INFINITY, + }; for i in 0..2 { for j in 0..2 { for k in 0..2 { @@ -28,15 +47,24 @@ impl RotateY { let new_x = cos_theta * x + sin_theta * z; let new_z = -sin_theta * x + cos_theta * z; - let tester = Vec3 { x: new_x, y, z: new_z }; + let tester = Vec3 { + x: new_x, + y, + z: new_z, + }; for c in 0..3 { - *min.get_mut(c).unwrap() = min.get(c).unwrap().min(*tester.get(c).unwrap()); - *max.get_mut(c).unwrap() = max.get(c).unwrap().max(*tester.get(c).unwrap()); + *min.get_mut(c).unwrap() = + min.get(c).unwrap().min(*tester.get(c).unwrap()); + *max.get_mut(c).unwrap() = + max.get(c).unwrap().max(*tester.get(c).unwrap()); } } } } - let aabb = AABB { minimum: min, maximum: max }; + let aabb = AABB { + minimum: min, + maximum: max, + }; Self { hittable, @@ -56,11 +84,15 @@ impl Hittable for RotateY { origin.x = self.cos_theta * ray.origin.x - self.sin_theta * ray.origin.z; origin.z = self.sin_theta * ray.origin.x + self.cos_theta * ray.origin.z; - + direction.x = self.cos_theta * ray.direction.x - self.sin_theta * ray.direction.z; direction.z = self.sin_theta * ray.direction.x + self.cos_theta * ray.direction.z; - let rotated_ray = Ray { origin, direction, time: ray.time }; + let rotated_ray = Ray { + origin, + direction, + time: ray.time, + }; let mut hit_record = self.hittable.hit(&rotated_ray, t_min, t_max)?; let mut p = hit_record.p.clone(); -- cgit v1.2.3