From 46f678425612a94598a725ef7a3bbe35fbf2d9d8 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 19 Aug 2025 18:26:41 -0500 Subject: [PATCH] Run fixes recommended by cargo-clippy --- src/primitives.rs | 6 +++--- src/renderer.rs | 2 +- src/scene.rs | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/primitives.rs b/src/primitives.rs index ccf7861..7cd37aa 100644 --- a/src/primitives.rs +++ b/src/primitives.rs @@ -176,7 +176,7 @@ impl Vec3 { } pub fn rand_unit_vector(srng: &mut SmallRng) -> Vec3 { - return Vec3::as_unit(Vec3::rand_in_unit_sphere(srng)); + Vec3::as_unit(Vec3::rand_in_unit_sphere(srng)) } pub fn length(&self) -> f32 { @@ -204,11 +204,11 @@ impl Vec3 { pub fn near_zero(&self) -> bool { let epsilon: f32 = 1e-4; - return self.x.abs() < epsilon && self.y.abs() < epsilon && self.z.abs() < epsilon; + self.x.abs() < epsilon && self.y.abs() < epsilon && self.z.abs() < epsilon } pub fn reflect(v: Vec3, n: Vec3) -> Vec3 { - return v - n * Vec3::dot(v, n) * 2.0; + v - n * Vec3::dot(v, n) * 2.0 } pub fn refract(uv: Vec3, n: Vec3, etai_over_etat: f32) -> Vec3 { diff --git a/src/renderer.rs b/src/renderer.rs index 1b09b33..b19e134 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -50,7 +50,7 @@ fn ray_color(r: Ray, surface: &Hittable, depth: u32, rng: &mut SmallRng) -> Vec3 // when nothing is struck, return sky color let unitdir = Vec3::as_unit(r.dir); let t = 0.5 * (unitdir.y + 1.0); - return Vec3::ones() * (1.0 - t) + SKY_COLOR * t; + Vec3::ones() * (1.0 - t) + SKY_COLOR * t } } diff --git a/src/scene.rs b/src/scene.rs index a19dc78..c3b3a29 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -13,7 +13,7 @@ pub struct HitRecord { } impl HitRecord { - pub fn set_face_normal(&mut self, r: Ray, outward_normal: Vec3) -> () { + pub fn set_face_normal(&mut self, r: Ray, outward_normal: Vec3) { self.front_face = Vec3::dot(r.dir, outward_normal) < 0.0; self.normal = if self.front_face { outward_normal @@ -129,7 +129,7 @@ impl Material { dir: scatter_dir, }; *attenuation = *albedo; // deref on both sides? Wacky - return true; + true } Material::Metal { albedo, fuzz } => { let reflected = Vec3::reflect(Vec3::as_unit(ray_in.dir), rec.normal); @@ -138,7 +138,7 @@ impl Material { dir: reflected + Vec3::rand_in_unit_sphere(srng) * *fuzz, }; *attenuation = *albedo; - return Vec3::dot(scattered.dir, rec.normal) > 0.0; + Vec3::dot(scattered.dir, rec.normal) > 0.0 } Material::Dielectric { index_refraction } => { *attenuation = Vec3::ones(); @@ -166,7 +166,7 @@ impl Material { orig: rec.p, dir: direction, }; - return true; + true } } } @@ -175,7 +175,7 @@ impl Material { // Schlick's approximation for reflectance. let r0 = (1.0 - ref_idx) / (1.0 + ref_idx); let r0 = r0 * r0; - return r0 + (1.0 - r0) * (1.0 - cosine).powf(5.0); + r0 + (1.0 - r0) * (1.0 - cosine).powf(5.0) } } @@ -294,7 +294,7 @@ impl Scene { world.push(Hittable::Sphere { center, radius: 0.2, - material: material, + material, }); } else { // glass @@ -304,7 +304,7 @@ impl Scene { world.push(Hittable::Sphere { center, radius: 0.2, - material: material, + material, }); }; }