Skip to content

Commit 2877dda

Browse files
peterbradenclaude
andauthored
Cleanup (#36)
* Fix lint errors and code warnings - Fix redundant field names in struct initializations - Remove redundant serde_json import in scenefile.rs - Fix collapsible else-if blocks in bbox.rs - Remove needless return statements in box_terrain.rs - Fix syntax error in ocean.rs amplitude function 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix lint errors in material and geometry modules - Fix needless return statements in various material modules - Fix redundant field names in struct initializations - Fix indentation issues and syntax errors in rendercontext.rs - Update legacy numeric constants with newer syntax - Fix conditional return structure to avoid compiler errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix more lint errors throughout the codebase - Fix needless returns in procedural modules - Fix manual_clamp warnings by using .clamp() in color.rs and noise.rs - Fix wrong_self_convention warnings in Color methods - Fix op_ref warnings by removing unnecessary references - Fix indentation and syntax errors in participatingmedia.rs - Fix let_and_return in noise.rs - Fix needless borrow issues in rendercontext.rs - Convert write! with newline to writeln! in paint.rs - Fix redundant closure with map/Arc::new in fireworks.rs - Fix unnecessary casts in rendercontext.rs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix syntax error in participatingmedia.rs - Fix missing enclosing brace for HomogenousFog::intersects function - Fix variable resolution issue in Color class for as_vec and as_u8 methods - Fix semicolon in FireworkMaterial::scatter that was causing return type mismatch - Update method invocations to use the renamed methods 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Clippy fix * Fix BBox lint warnings - Remove needless return statements - Remove unnecessary references - Replace if-return chains with if-else expressions - Fix control flow in entry_face and exit_face methods 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix clippy lints for borrowed_box in texture.rs, needless_late_init in functions.rs, and remove legacy numeric constants in several files * Fix remaining clippy lints: - Replace &Vec with &[T] in octree.rs and ocean.rs - Replace std::f64 legacy constants with f64::constants in infinite.rs and repeating_mesh.rs - Fix documentation comments in ocean.rs - Add type definition for complex return type in ocean.rs * Fix compilation errors in: - octree.rs: Use _max and _min in recursive call - ocean.rs: Fix transpose function to use to_vec() - fireworks.rs and csg.rs: Add explicit Vec type for collected Arc values * Fix remaining clippy warnings: - Replace if-else chains with logical expressions in BBox methods - Replace while loop with while-let in csg.rs - Fix documentation comment in model.rs - Suppress too_many_arguments warning in create_particles * Add Clippy to CI workflow to ensure code quality --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 33dd1a4 commit 2877dda

42 files changed

Lines changed: 660 additions & 673 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/rust.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build, Tests and Examples
1+
name: Build, Tests, Lint and Examples
22

33
on: [push]
44

@@ -9,6 +9,10 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v1
12+
- name: Install Clippy
13+
run: rustup component add clippy
14+
- name: Run Clippy
15+
run: cargo clippy -- -D errors
1216
- name: Build
1317
run: cargo build --verbose
1418
- name: Run tests

demo/demo.png

-827 KB
Loading

src/camera.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ impl SimpleCamera {
3737
//let viewPlaneHalfHeight = aspectRatio*viewPlaneHalfWidth
3838

3939
SimpleCamera {
40-
location: location,
40+
location,
4141

42-
camz: camz,
42+
camz,
4343
camx: camx * aspect_ratio,
44-
camy: camy,
44+
camy,
4545

4646
tax: angle.tan(),
4747
tay: angle.tan()
@@ -197,17 +197,17 @@ impl FlatLensCamera {
197197
//let viewPlaneHalfHeight = aspectRatio*viewPlaneHalfWidth
198198

199199
FlatLensCamera {
200-
location: location,
200+
location,
201201

202-
camz: camz,
202+
camz,
203203
camx: camx * aspect_ratio,
204-
camy: camy,
204+
camy,
205205

206206
tax: angle.tan(),
207207
tay: angle.tan(),
208208

209-
aperture: aperture,
210-
focus: focus,
209+
aperture,
210+
focus,
211211
}
212212
}
213213
}
@@ -224,7 +224,7 @@ impl Camera for FlatLensCamera {
224224
let ro = self.location + Vector3::new(point_lens[0], point_lens[1], 0.0);
225225

226226
Ray {
227-
ro: ro,
227+
ro,
228228
rd: (focal_point - ro).normalize()
229229
}
230230

src/color.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Color {
1010

1111
impl Color {
1212
pub fn new(r:f64, g:f64, b:f64) -> Color {
13-
return Color {
13+
Color {
1414
rgb: Vector3::new(r,g,b)
1515
}
1616
}
@@ -20,40 +20,40 @@ impl Color {
2020
}
2121

2222
pub fn white() -> Color {
23-
return Color::new(1f64,1f64,1f64);
23+
Color::new(1f64,1f64,1f64)
2424
}
2525
pub fn red() -> Color {
26-
return Color::new(1f64,0f64,0f64);
26+
Color::new(1f64,0f64,0f64)
2727
}
2828
pub fn blue() -> Color {
29-
return Color::new(0f64,0f64,01f64);
29+
Color::new(0f64,0f64,01f64)
3030
}
3131
pub fn green() -> Color {
32-
return Color::new(0f64,1f64,0f64);
32+
Color::new(0f64,1f64,0f64)
3333
}
3434

35-
pub fn to_u8(&self) -> (u8, u8, u8) {
36-
return ((self.rgb[0] * 255f64).min(255f64) as u8, (self.rgb[1] * 255f64).min(255f64) as u8, (self.rgb[2] * 255f64).min(255f64) as u8);
35+
pub fn as_u8(&self) -> (u8, u8, u8) {
36+
((self.rgb[0] * 255f64).min(255f64) as u8, (self.rgb[1] * 255f64).min(255f64) as u8, (self.rgb[2] * 255f64).min(255f64) as u8)
3737
}
3838

39-
pub fn to_vec(&self) -> Vector3<f64> {
40-
return self.rgb.clone();
39+
pub fn as_vec(&self) -> Vector3<f64> {
40+
self.rgb
4141
}
4242

4343
pub fn clamp(&self, val: f64) -> Color {
44-
return Color::new(self.rgb.x.min(val), self.rgb.y.min(val), self.rgb.z.min(val));
44+
Color::new(self.rgb.x.min(val), self.rgb.y.min(val), self.rgb.z.min(val))
4545
}
4646

4747
pub fn min() -> Color {
48-
return Color::new(1./255.,1./255.,1./255.);
48+
Color::new(1./255.,1./255.,1./255.)
4949
}
5050

5151
pub fn ignore_nan(&self) -> Color {
52-
return Color::new(
52+
Color::new(
5353
if self.rgb.x.is_nan() { 0. } else { self.rgb.x },
5454
if self.rgb.y.is_nan() { 0. } else { self.rgb.y },
5555
if self.rgb.z.is_nan() { 0. } else { self.rgb.z },
56-
);
56+
)
5757
}
5858

5959
/// Blend this color with another color using the given factor
@@ -65,7 +65,7 @@ impl Color {
6565
/// # Returns
6666
/// A new color that is a blend of this color and the other color
6767
pub fn blend(&self, other: &Color, factor: f64) -> Color {
68-
let clamped_factor = factor.max(0.0).min(1.0);
68+
let clamped_factor = factor.clamp(0.0, 1.0);
6969
let self_factor = 1.0 - clamped_factor;
7070

7171
Color::new(
@@ -97,7 +97,7 @@ impl Mul<Color> for Color {
9797
type Output = Color;
9898

9999
fn mul(self, _rhs: Color) -> Color {
100-
Color {rgb: (_rhs * self.to_vec()).to_vec() }
100+
Color {rgb: (_rhs * self.as_vec()).as_vec() }
101101
}
102102
}
103103

@@ -122,7 +122,7 @@ impl Add<Vector3<f64>> for Color {
122122

123123
fn add(self, _rhs: Vector3<f64>) -> Color {
124124
Color {
125-
rgb: _rhs + &self.rgb
125+
rgb: _rhs + self.rgb
126126
}
127127
}
128128
}

src/geometry.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use crate::geometry::_rand::Rng;
44
use std::f64;
55

66
pub fn rand() -> f64 {
7-
return _rand::thread_rng().gen_range(0.,1.);
7+
_rand::thread_rng().gen_range(0.,1.)
88
}
99

1010
pub fn random_point_on_unit_sphere() -> Vector3<f64>{
1111
let u = rand();
1212
let v = rand();
13-
return point_on_unit_sphere(u, v);
13+
point_on_unit_sphere(u, v)
1414
}
1515

1616
pub fn point_on_unit_sphere(u: f64, v: f64) -> Vector3<f64>{
@@ -24,21 +24,21 @@ pub fn point_on_unit_sphere(u: f64, v: f64) -> Vector3<f64>{
2424
let x = r * sin_phi * cos_theta;
2525
let y = r * sin_phi * sin_theta;
2626
let z = r * cos_phi;
27-
return Vector3::new(x, y, z);
27+
Vector3::new(x, y, z)
2828
}
2929

3030
pub fn random_point_on_disc(radius: f64) -> Vector2<f64>{
3131
let r = radius * rand().sqrt();
3232
let theta = rand() * 2.0 * f64::consts::PI;
33-
return Vector2::new(r * theta.cos(), r * theta.sin());
33+
Vector2::new(r * theta.cos(), r * theta.sin())
3434
}
3535

3636
pub fn uniform_sample_hemisphere(r1: f64, r2: f64) -> Vector3<f64>{
3737
let sin_theta = (1. - r1 * r1).sqrt();
3838
let phi = 2. * f64::consts::PI * r2;
3939
let x = sin_theta * phi.cos();
4040
let z = sin_theta * phi.sin();
41-
return Vector3::new(x, r1, z);
41+
Vector3::new(x, r1, z)
4242
}
4343

4444
// Transform into the world of vec

src/intersection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct MediumIntersection {
3333

3434
impl cmp::PartialEq for Intersection {
3535
fn eq(&self, other: &Intersection) -> bool {
36-
&self.point == &other.point
36+
self.point == other.point
3737
}
3838
}
3939

src/material/ambient.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct Ambient {
1010

1111
impl MaterialModel for Ambient {
1212
fn scatter(&self, _r: &Ray, _intersection: &Intersection, _s: &Scene) -> ScatteredRay{
13-
return ScatteredRay{ attenuate:self.albedo, ray: None };
13+
ScatteredRay{ attenuate:self.albedo, ray: None }
1414
}
1515

1616

src/material/dielectric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ pub struct Dielectric {
1313

1414
impl MaterialModel for Dielectric {
1515
fn scatter(&self, r: &Ray, intersection: &Intersection, _s: &Scene) -> ScatteredRay{
16-
return scatter_dielectric(self.refractive_index, self.attenuate, r, intersection);
16+
scatter_dielectric(self.refractive_index, self.attenuate, r, intersection)
1717
}
1818
}

src/material/diffuse_light.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub struct DiffuseLight {
1111

1212
impl MaterialModel for DiffuseLight {
1313
fn scatter(&self, _r: &Ray, _intersection: &Intersection, _s: &Scene) -> ScatteredRay{
14-
return ScatteredRay{
14+
ScatteredRay{
1515
attenuate:self.color * self.intensity,
16-
ray: None };
16+
ray: None }
1717
}
1818
}

src/material/functions.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn scatter_lambertian(albedo: Color, intersection: &Intersection) -> Scatter
3636
ro: intersection.point,
3737
rd: intersection.normal + random_point_on_unit_sphere(),
3838
};
39-
return ScatteredRay{ attenuate:albedo, ray: Some(refl) };
39+
ScatteredRay{ attenuate:albedo, ray: Some(refl) }
4040
}
4141

4242
pub fn scatter_dielectric(
@@ -46,21 +46,27 @@ pub fn scatter_dielectric(
4646
intersection: &Intersection
4747
) -> ScatteredRay {
4848

49-
let mut ni_over_nt = refractive_index; // Assumes it comes from air - TODO
50-
let cosine;
5149
let drn = r.rd.dot(&intersection.normal);
52-
let outward_normal;
53-
if drn > 0.0 {
50+
51+
let outward_normal = if drn > 0.0 {
5452
// when ray shoot through object back into vacuum,
5553
// ni_over_nt = ref_idx, surface normal has to be inverted.
56-
cosine = drn / r.rd.norm();
57-
outward_normal = -intersection.normal
54+
-intersection.normal
5855
} else {
5956
// when ray shoots into object,
60-
// ni_over_nt = 1 / ref_idx.
61-
cosine = - drn / r.rd.norm();
62-
ni_over_nt = 1.0 / refractive_index;
63-
outward_normal = intersection.normal
57+
intersection.normal
58+
};
59+
60+
let cosine = if drn > 0.0 {
61+
drn / r.rd.norm()
62+
} else {
63+
-drn / r.rd.norm()
64+
};
65+
66+
let ni_over_nt = if drn > 0.0 {
67+
refractive_index // Assumes it comes from air - TODO
68+
} else {
69+
1.0 / refractive_index
6470
};
6571

6672
match refract(r.rd, outward_normal, ni_over_nt) {
@@ -85,26 +91,27 @@ pub fn scatter_dielectric(
8591
}
8692

8793
let reflected = reflect(r.rd, intersection.normal);
88-
return ScatteredRay {
94+
ScatteredRay {
8995
attenuate: Color::white(),
9096
ray: Some(Ray {
9197
ro: intersection.point,
9298
rd: reflected
9399
})
94-
};
100+
}
95101
}
96102

97103

98104
pub fn diffuse (pigment: Color, i: &Intersection, light_vec: &Vector3<f64>, light: &Light) -> Color {
99105
let diffuse_scale = light_vec.normalize().dot(&i.normal) * light.intensity;
100106
if diffuse_scale.is_sign_positive() {
101-
return light.color * pigment * diffuse_scale;
107+
light.color * pigment * diffuse_scale
108+
} else {
109+
Color::black()
102110
}
103-
return Color::black()
104111
}
105112

106113
pub fn phong (phong: f64, r: &Ray, intersection: &Intersection, light_vec: &Vector3<f64>) -> Color {
107-
if phong < std::f64::MIN_POSITIVE {
114+
if phong < f64::MIN_POSITIVE {
108115
return Color::black();
109116
}
110117
let ln = light_vec.normalize();
@@ -116,5 +123,5 @@ pub fn phong (phong: f64, r: &Ray, intersection: &Intersection, light_vec: &Vect
116123
return Color::white() * spec_scale;
117124
}
118125

119-
return Color::black();
126+
Color::black()
120127
}

0 commit comments

Comments
 (0)