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/material/lambertian.rs | |
parent | 89a5c9a8a0cdf627cda0e31da454f83ca21315ce (diff) |
fmt and tidy
Diffstat (limited to 'src/material/lambertian.rs')
-rw-r--r-- | src/material/lambertian.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/material/lambertian.rs b/src/material/lambertian.rs index 95f698e..fed26f9 100644 --- a/src/material/lambertian.rs +++ b/src/material/lambertian.rs @@ -1,10 +1,10 @@ use std::sync::Arc; use super::Material; -use crate::{hittable::HitRecord, texture::Texture, vec3::Vec3}; -use crate::vec3::Color; -use crate::texture::SolidColor; use crate::ray::Ray; +use crate::texture::SolidColor; +use crate::vec3::Color; +use crate::{hittable::HitRecord, texture::Texture, vec3::Vec3}; pub struct Lambertian { pub albedo: Arc<dyn Texture>, @@ -13,13 +13,21 @@ pub struct Lambertian { impl Lambertian { pub fn from_color(color: Color) -> Self { Self { - albedo: Arc::new(SolidColor { color_value: color.clone() }), + albedo: Arc::new(SolidColor { + color_value: color.clone(), + }), } } } impl Material for Lambertian { - 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 { let mut scatter_direction = &hit_record.normal + Vec3::random_unit_vector(); // Catch zero-vector scatter directions that will generate issues later @@ -27,7 +35,11 @@ impl Material for Lambertian { scatter_direction = hit_record.normal.clone(); } - *scattered = Ray { origin: hit_record.p.clone(), direction: scatter_direction, time: ray_in.time }; + *scattered = Ray { + origin: hit_record.p.clone(), + direction: scatter_direction, + time: ray_in.time, + }; *attenuation = self.albedo.value(hit_record.u, hit_record.v, &hit_record.p); true } |