Minor changes suggested by clippy

This commit is contained in:
Matthew Gordon 2025-03-28 22:12:58 -03:00
parent 8c458d073e
commit 80b2d87d22
9 changed files with 18 additions and 14 deletions

View File

@ -82,6 +82,7 @@ impl Spectrum {
Spectrum { Spectrum {
shortest_wavelength: rgb_reference_spectrum::SHORTEST_WAVELENGTH, shortest_wavelength: rgb_reference_spectrum::SHORTEST_WAVELENGTH,
longest_wavelength: rgb_reference_spectrum::LONGEST_WAVELENGTH, longest_wavelength: rgb_reference_spectrum::LONGEST_WAVELENGTH,
#[allow(clippy::collapsible_else_if)]
samples: if colour.red() <= colour.green() && colour.red() <= colour.blue() { samples: if colour.red() <= colour.green() && colour.red() <= colour.blue() {
if colour.green() <= colour.blue() { if colour.green() <= colour.blue() {
izip![ izip![
@ -178,6 +179,7 @@ impl Spectrum {
mod rgb_reference_spectrum { mod rgb_reference_spectrum {
pub const SHORTEST_WAVELENGTH: f64 = 380.0; pub const SHORTEST_WAVELENGTH: f64 = 380.0;
pub const LONGEST_WAVELENGTH: f64 = 720.0; pub const LONGEST_WAVELENGTH: f64 = 720.0;
#[allow(clippy::excessive_precision)]
pub mod reflection { pub mod reflection {
pub const WHITE: [f64; 32] = [ pub const WHITE: [f64; 32] = [
1.0618958571272863e+00, 1.0618958571272863e+00,

View File

@ -109,21 +109,21 @@ pub trait NormalizedAsByte {
impl NormalizedAsByte for f32 { impl NormalizedAsByte for f32 {
fn normalized_to_byte(self) -> u8 { fn normalized_to_byte(self) -> u8 {
(self * (std::u8::MAX as f32)) as u8 (self * (u8::MAX as f32)) as u8
} }
fn byte_to_normalized(byte: u8) -> f32 { fn byte_to_normalized(byte: u8) -> f32 {
(byte as f32) / (std::u8::MAX as f32) (byte as f32) / (u8::MAX as f32)
} }
} }
impl NormalizedAsByte for f64 { impl NormalizedAsByte for f64 {
fn normalized_to_byte(self) -> u8 { fn normalized_to_byte(self) -> u8 {
(self * (std::u8::MAX as f64)) as u8 (self * (u8::MAX as f64)) as u8
} }
fn byte_to_normalized(byte: u8) -> f64 { fn byte_to_normalized(byte: u8) -> f64 {
(byte as f64) / (std::u8::MAX as f64) (byte as f64) / (u8::MAX as f64)
} }
} }

View File

@ -79,7 +79,7 @@ fn update_texture(image: &ImageRgbU8, texture: &mut Texture) {
.update( .update(
Rect::new(0, 0, image.get_width() as u32, image.get_height() as u32), Rect::new(0, 0, image.get_width() as u32, image.get_height() as u32),
image.get_pixel_data(), image.get_pixel_data(),
(image.get_width() * ImageRgbU8::num_channels()) as usize, image.get_width() * ImageRgbU8::num_channels(),
) )
.expect("Couldn't update texture."); .expect("Couldn't update texture.");
} }

View File

@ -8,6 +8,7 @@ pub struct Mat4<T:Float> {
} }
impl<T:Float> Mat4<T> { impl<T:Float> Mat4<T> {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
m00: T, m00: T,
m01: T, m01: T,

View File

@ -47,7 +47,7 @@ mod wavefront_obj {
) -> Vec<Triangle> { ) -> Vec<Triangle> {
if let Some(v0_index) = polygon.iter().next() { if let Some(v0_index) = polygon.iter().next() {
let (v0_vertex, v0_normal) = let (v0_vertex, v0_normal) =
get_vertex_and_normal(v0_index, &vertex_positions, normal_positions); get_vertex_and_normal(v0_index, vertex_positions, normal_positions);
polygon polygon
.iter() .iter()
.skip(1) .skip(1)

View File

@ -82,17 +82,17 @@ impl HasBoundingBox for Plane {
if v.x() == 0.0 { if v.x() == 0.0 {
0.0 0.0
} else { } else {
std::f64::INFINITY f64::INFINITY
}, },
if v.y() == 0.0 { if v.y() == 0.0 {
0.0 0.0
} else { } else {
std::f64::INFINITY f64::INFINITY
}, },
if v.z() == 0.0 { if v.z() == 0.0 {
0.0 0.0
} else { } else {
std::f64::INFINITY f64::INFINITY
}, },
) )
}; };

View File

@ -106,6 +106,7 @@ impl HasBoundingBox for Triangle {
impl Primitive for Triangle {} impl Primitive for Triangle {}
fn indices_with_index_of_largest_element_last(v: &Vec3<f64>) -> [usize; 3] { fn indices_with_index_of_largest_element_last(v: &Vec3<f64>) -> [usize; 3] {
#[allow(clippy::collapsible_else_if)]
if v.x() > v.y() { if v.x() > v.y() {
if v.z() > v.x() { if v.z() > v.x() {
[0, 1, 2] [0, 1, 2]

View File

@ -15,15 +15,15 @@ impl Interval {
pub fn empty() -> Self { pub fn empty() -> Self {
Interval { Interval {
min: std::f64::INFINITY, min: f64::INFINITY,
max: std::f64::NEG_INFINITY, max: f64::NEG_INFINITY,
} }
} }
pub fn infinite() -> Self { pub fn infinite() -> Self {
Interval { Interval {
min: std::f64::NEG_INFINITY, min: f64::NEG_INFINITY,
max: std::f64::INFINITY, max: f64::INFINITY,
} }
} }

View File

@ -27,7 +27,7 @@ pub struct TileIterator {
impl TileIterator { impl TileIterator {
pub fn new(total_width: usize, total_height: usize, tile_size: usize) -> TileIterator { pub fn new(total_width: usize, total_height: usize, tile_size: usize) -> TileIterator {
// If tile_size*2 is greater than usize::max_value(), increment would overflow // If tile_size*2 is greater than usize::max_value(), increment would overflow
assert!(tile_size > 0 && tile_size * 2 < usize::max_value()); assert!(tile_size > 0 && tile_size * 2 < usize::MAX);
TileIterator { TileIterator {
tile_size, tile_size,
total_width, total_width,