Skip to content

Commit 05b921b

Browse files
committed
Clippy lint
1 parent 00e9d83 commit 05b921b

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Context {
2424
height: 0,
2525
frame_buffer: vec![],
2626
z_buffer: vec![],
27-
image: image
27+
image
2828
}
2929
}
3030
pub fn clear(&mut self) {

src/geometry.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub trait ToSimpleMesh {
6565
}
6666

6767
pub trait ToSimpleMeshWithMaterial {
68-
fn to_simple_mesh_with_materials(&self, materials: &Vec<Material>) -> SimpleMesh;
68+
fn to_simple_mesh_with_materials(&self, materials: &[Material]) -> SimpleMesh;
6969
}
7070

7171
pub struct SimpleMesh {
@@ -74,7 +74,7 @@ pub struct SimpleMesh {
7474
}
7575

7676
impl ToSimpleMeshWithMaterial for Mesh {
77-
fn to_simple_mesh_with_materials(&self, materials: &Vec<Material>) -> SimpleMesh {
77+
fn to_simple_mesh_with_materials(&self, materials: &[Material]) -> SimpleMesh {
7878
let mut bounding_box = AABB {
7979
// This is the general bounding box for the mesh
8080
min: Vector4::new(0.0, 0.0, 0.0, 1.0),
@@ -101,8 +101,8 @@ impl ToSimpleMeshWithMaterial for Mesh {
101101
tri.v3.y = self.positions[(self.indices[x * 3 + 2] * 3 + 1) as usize];
102102
tri.v3.z = self.positions[(self.indices[x * 3 + 2] * 3 + 2) as usize];
103103

104-
if materials.len() > 0 {
105-
let material = &materials[*&self.material_id.unwrap()];
104+
if materials.is_empty() {
105+
let material = &materials[self.material_id.unwrap()];
106106
tri.color = (
107107
(material.diffuse[0] * 255.0) as u8,
108108
(material.diffuse[1] * 255.0) as u8,
@@ -127,7 +127,7 @@ impl ToSimpleMeshWithMaterial for Mesh {
127127

128128
impl ToSimpleMesh for Mesh {
129129
fn to_simple_mesh(&self) -> SimpleMesh {
130-
self.to_simple_mesh_with_materials(&vec![])
130+
self.to_simple_mesh_with_materials(&[])
131131
}
132132
}
133133

@@ -151,11 +151,12 @@ impl ToSimpleMesh for stl_io::IndexedMesh {
151151
};
152152
self.faces.len()
153153
];
154-
for i in 0..self.faces.len() {
155-
triangles[i].v1 = stlv2v4(self.vertices[self.faces[i].vertices[0]]);
156-
triangles[i].v2 = stlv2v4(self.vertices[self.faces[i].vertices[1]]);
157-
triangles[i].v3 = stlv2v4(self.vertices[self.faces[i].vertices[2]]);
158-
let aabb = triangles[i].to_aabb();
154+
#[allow(clippy::needless_range_loop)] // We need an index number, to get the triangle's index too
155+
for t_index in 0..self.faces.len() {
156+
triangles[t_index].v1 = stlv2v4(self.vertices[self.faces[t_index].vertices[0]]);
157+
triangles[t_index].v2 = stlv2v4(self.vertices[self.faces[t_index].vertices[1]]);
158+
triangles[t_index].v3 = stlv2v4(self.vertices[self.faces[t_index].vertices[2]]);
159+
let aabb = triangles[t_index].to_aabb();
159160
bounding_box.min.x = aabb.min.x.min(bounding_box.min.x);
160161
bounding_box.min.y = aabb.min.y.min(bounding_box.min.y);
161162
bounding_box.min.z = aabb.min.z.min(bounding_box.min.z);

src/inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn match_turntable(matches: &ArgMatches) -> Result<(f32, f32, f32, f32), Box
136136
} else {
137137
turntable.3 = 1.0; // No speed defined -> 1.0 rad/s
138138
}
139-
turntable.1 += 3.14159; // All models for some reason are backwards, this fixes that
139+
turntable.1 += std::f32::consts::PI; // All models for some reason are backwards, this fixes that
140140
Ok(turntable)
141141
}
142142

@@ -148,7 +148,7 @@ pub fn match_no_color_mode(matches: &ArgMatches) -> bool {
148148
matches.is_present("no color")
149149
}
150150

151-
pub fn match_dimensions<'a>(context: &mut Context, matches: &ArgMatches) -> Result<(), Box<Error>> {
151+
pub fn match_dimensions(context: &mut Context, matches: &ArgMatches) -> Result<(), Box<Error>> {
152152
if let Some(x) = matches.value_of("width") {
153153
context.width = x.parse()?;
154154
if let Some(y) = matches.value_of("height") {

src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,18 @@ fn main() -> Result<(), Box<Error>> {
5151

5252
if webify {
5353
println!("let frames = [");
54-
turntable.3 = (2.0 * 3.14159) * (1.0 / webify_todo_frames as f32);
54+
turntable.3 = (2.0 * f32::consts::PI) * (1.0 / webify_todo_frames as f32);
5555
}
5656
let mut last_time; // Used in the variable time step
5757
loop {
5858
last_time = Instant::now();
5959
if !context.image {
6060
if let Some(b) = stdin.next() {
61-
match b {
62-
InputEvent::Keyboard(event) => match event {
63-
KeyEvent::Char('q') => {
64-
cursor.show()?;
65-
break;
66-
},
67-
_ => {}
68-
},
69-
_ => {}
61+
if let InputEvent::Keyboard(event) = b {
62+
if let KeyEvent::Char('q') = event {
63+
cursor.show()?;
64+
break;
65+
}
7066
}
7167
}
7268
}

0 commit comments

Comments
 (0)