aboutsummaryrefslogtreecommitdiff
path: root/src/hittable/instance/rotate_z.rs
diff options
context:
space:
mode:
authorlamp2024-01-21 17:03:07 +0000
committerlamp2024-01-21 17:03:07 +0000
commit45fafbcd4b41a5388ece377c4e051b5846407288 (patch)
tree2192c471ca3b47671f0906e27f6f6088f40b3d8a /src/hittable/instance/rotate_z.rs
parent89a5c9a8a0cdf627cda0e31da454f83ca21315ce (diff)
fmt and tidy
Diffstat (limited to 'src/hittable/instance/rotate_z.rs')
-rw-r--r--src/hittable/instance/rotate_z.rs54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/hittable/instance/rotate_z.rs b/src/hittable/instance/rotate_z.rs
index 119baca..38601ce 100644
--- a/src/hittable/instance/rotate_z.rs
+++ b/src/hittable/instance/rotate_z.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 RotateZ {
hittable: Arc<dyn Hittable>,
@@ -14,11 +19,25 @@ impl RotateZ {
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 RotateZ {
let new_x = cos_theta * x + sin_theta * y;
let new_y = -sin_theta * x + cos_theta * y;
- let tester = Vec3 { x: new_x, z, y: new_y };
+ let tester = Vec3 {
+ x: new_x,
+ z,
+ y: new_y,
+ };
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 RotateZ {
origin.x = self.cos_theta * ray.origin.x - self.sin_theta * ray.origin.y;
origin.y = self.sin_theta * ray.origin.x + self.cos_theta * ray.origin.y;
-
+
direction.x = self.cos_theta * ray.direction.x - self.sin_theta * ray.direction.y;
direction.y = self.sin_theta * ray.direction.x + self.cos_theta * ray.direction.y;
- 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();