Clippy warnings

This commit is contained in:
Savanni D'Gerinel 2024-06-10 09:46:58 -04:00
parent 7be0baba53
commit bd899e3a2e
5 changed files with 19 additions and 27 deletions

View File

@ -49,5 +49,5 @@ fn main() {
let ppm = PPM::from(canvas);
let mut file = File::create("projectile.ppm").unwrap();
file.write(ppm.as_bytes()).unwrap();
let _ = file.write(ppm.as_bytes());
}

View File

@ -8,8 +8,7 @@ fn join_to_line_limit(data: impl IntoIterator<Item = String>) -> Vec<String> {
let mut lines = vec![];
let mut line = String::new();
let mut iter = data.into_iter();
while let Some(element) = iter.next() {
for element in data {
if line.is_empty() {
line = line + &element;
} else if line.len() + 1 + element.len() < 70 {

View File

@ -29,7 +29,7 @@ impl Canvas {
&self.pixels[self.addr(y, x)]
}
pub fn pixel_mut<'a>(&'a mut self, x: usize, y: usize) -> &'a mut Color {
pub fn pixel_mut(&mut self, x: usize, y: usize) -> &mut Color {
let addr = self.addr(y, x);
&mut self.pixels[addr]
}

View File

@ -1,4 +1,6 @@
use crate::types::{eq_f64, Tuple, Point, Vector};
use std::cmp::Ordering;
use crate::types::{eq_f64, Point, Tuple, Vector};
#[derive(Clone, Debug)]
pub struct Matrix {
@ -27,7 +29,7 @@ impl Matrix {
self.values[self.addr(row, column)]
}
pub fn cell_mut<'a>(&'a mut self, row: usize, column: usize) -> &'a mut f64 {
pub fn cell_mut(&mut self, row: usize, column: usize) -> &mut f64 {
let addr = self.addr(row, column);
&mut self.values[addr]
}
@ -92,19 +94,15 @@ impl Matrix {
for r in 0..self.size {
for c in 0..self.size {
let dest_r = if r < row {
r
} else if r > row {
r - 1
} else {
continue;
let dest_r = match r.cmp(&row) {
Ordering::Less => r,
Ordering::Greater => r - 1,
Ordering::Equal => continue,
};
let dest_c = if c < column {
c
} else if c > column {
c - 1
} else {
continue;
let dest_c = match c.cmp(&column) {
Ordering::Less => c,
Ordering::Greater => c - 1,
Ordering::Equal => continue,
};
*m.cell_mut(dest_r, dest_c) = self.cell(r, c);
}
@ -198,8 +196,8 @@ impl std::ops::Mul<Tuple> for Matrix {
let mut t = [0.; 4];
for row in 0..4 {
t[row] = self.cell(row, 0) * rside.0
for (row, item) in t.iter_mut().enumerate() {
*item = self.cell(row, 0) * rside.0
+ self.cell(row, 1) * rside.1
+ self.cell(row, 2) * rside.2
+ self.cell(row, 3) * rside.3;

View File

@ -44,12 +44,7 @@ impl std::ops::Sub for Tuple {
impl std::ops::Neg for Tuple {
type Output = Tuple;
fn neg(self) -> Self::Output {
return Self::Output {
0: -self.0,
1: -self.1,
2: -self.2,
3: -self.3,
};
Tuple(-self.0, -self.1, -self.2, -self.3)
}
}