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/material/dielectric.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/material/dielectric.rs') diff --git a/src/material/dielectric.rs b/src/material/dielectric.rs index 1a49f73..af6f9b0 100644 --- a/src/material/dielectric.rs +++ b/src/material/dielectric.rs @@ -1,9 +1,9 @@ use std::ops::Neg; use super::Material; -use crate::{hittable::HitRecord, vec3::Vec3}; -use crate::vec3::Color; use crate::ray::Ray; +use crate::vec3::Color; +use crate::{hittable::HitRecord, vec3::Vec3}; pub struct DielectricAttenuation { pub albedo: Color, @@ -25,7 +25,13 @@ impl Dielectric { } impl Material for Dielectric { - fn scatter(&self, ray_in: &Ray, hit_record: &HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool { + fn scatter( + &self, + ray_in: &Ray, + hit_record: &HitRecord, + attenuation: &mut Color, + scattered: &mut Ray, + ) -> bool { if let Some(props) = &self.attenuation { let outward_normal = if hit_record.front_face { hit_record.normal.clone() @@ -40,9 +46,17 @@ impl Material for Dielectric { *attenuation = props.albedo.clone(); } } else { - *attenuation = Color { x: 1.0, y: 1.0, z: 1.0 }; + *attenuation = Color { + x: 1.0, + y: 1.0, + z: 1.0, + }; } - let refraction_ratio = if hit_record.front_face { 1.0 / self.index_of_refraction } else { self.index_of_refraction }; + let refraction_ratio = if hit_record.front_face { + 1.0 / self.index_of_refraction + } else { + self.index_of_refraction + }; let unit_direction = ray_in.direction.unit_vector(); let cos_theta = hit_record.normal.dot(&-&unit_direction).min(1.0); let sin_theta = (1.0 - cos_theta * cos_theta).sqrt(); @@ -50,13 +64,18 @@ impl Material for Dielectric { let cannot_refract = refraction_ratio * sin_theta > 1.0; let direction: Vec3; - if cannot_refract || Self::reflectance(cos_theta, refraction_ratio) > rand::random::() { + if cannot_refract || Self::reflectance(cos_theta, refraction_ratio) > rand::random::() + { direction = unit_direction.reflect(&hit_record.normal) } else { direction = unit_direction.refract(&hit_record.normal, refraction_ratio) } - *scattered = Ray { origin: hit_record.p.clone(), direction, time: ray_in.time }; + *scattered = Ray { + origin: hit_record.p.clone(), + direction, + time: ray_in.time, + }; true } } -- cgit v1.2.3