diff --git a/src/binary_descriptors/brief.rs b/src/binary_descriptors/brief.rs index 1ebf52ce..4283ce3f 100644 --- a/src/binary_descriptors/brief.rs +++ b/src/binary_descriptors/brief.rs @@ -71,8 +71,8 @@ fn local_pixel_average(integral_image: &Image>, x: u32, y: u32, radius if radius == 0 { return 0; } - let y_min = if y < radius { 0 } else { y - radius }; - let x_min = if x < radius { 0 } else { x - radius }; + let y_min = y.saturating_sub(radius); + let x_min = x.saturating_sub(radius); let y_max = u32::min(y + radius + 1, integral_image.height() - 1); let x_max = u32::min(x + radius + 1, integral_image.width() - 1); diff --git a/src/corners.rs b/src/corners.rs index 80422823..51f17be9 100644 --- a/src/corners.rs +++ b/src/corners.rs @@ -119,8 +119,8 @@ fn intensity_centroid(image: &GrayImage, x: u32, y: u32, radius: u32) -> f32 { let mut x_centroid: i32 = 0; let (width, height) = image.dimensions(); - let x_min = if x < radius { 0 } else { x - radius }; - let y_min = if y < radius { 0 } else { y - radius }; + let x_min = x.saturating_sub(radius); + let y_min = y.saturating_sub(radius); let y_max = u32::min(y + radius + 1, height); let x_max = u32::min(x + radius + 1, width); diff --git a/src/distance_transform.rs b/src/distance_transform.rs index 1226ff40..f6f588bd 100644 --- a/src/distance_transform.rs +++ b/src/distance_transform.rs @@ -286,7 +286,7 @@ struct Row<'a> { row: u32, } -impl<'a> Sink for Row<'a> { +impl Sink for Row<'_> { fn put(&mut self, idx: usize, value: f64) { unsafe { self.image @@ -303,7 +303,7 @@ struct ColumnMut<'a> { column: u32, } -impl<'a> Sink for ColumnMut<'a> { +impl Sink for ColumnMut<'_> { fn put(&mut self, idx: usize, value: f64) { unsafe { self.image @@ -338,7 +338,7 @@ struct Column<'a> { column: u32, } -impl<'a> Source for Column<'a> { +impl Source for Column<'_> { fn get(&self, idx: usize) -> f64 { let pixel = unsafe { self.image.unsafe_get_pixel(self.column, idx as u32)[0] as f64 }; if pixel > 0f64 { diff --git a/src/drawing/fill.rs b/src/drawing/fill.rs index f7cb458f..74c05aba 100644 --- a/src/drawing/fill.rs +++ b/src/drawing/fill.rs @@ -17,21 +17,20 @@ pub fn flood_fill_mut

(image: &mut Image

, x: u32, y: u32, fill_with: P) where P: Pixel + PartialEq, { - let target = image.get_pixel(x, y).clone(); + let target = *image.get_pixel(x, y); let mut stack = Vec::new(); - stack.push((x as i32, x as i32, y as i32, 1 as i32)); - stack.push((x as i32, x as i32, y as i32 - 1, -1 as i32)); + stack.push((x as i32, x as i32, y as i32, 1_i32)); + stack.push((x as i32, x as i32, y as i32 - 1, -1_i32)); - while !stack.is_empty() { - let (x1, x2, y, dy) = stack.pop().unwrap(); + while let Some((x1, x2, y, dy)) = stack.pop() { let mut x1 = x1; let mut x = x1; if inside(image, x, y, target) { while inside(image, x - 1, y, target) { image.put_pixel(x as u32 - 1, y as u32, fill_with); - x = x - 1; + x -= 1; } if x < x1 { stack.push((x, x1 - 1, y - dy, -dy)) @@ -40,7 +39,7 @@ where while x1 <= x2 { while inside(image, x1, y, target) { image.put_pixel(x1 as u32, y as u32, fill_with); - x1 = x1 + 1; + x1 += 1; } if x1 > x { stack.push((x, x1 - 1, y + dy, dy)) @@ -48,9 +47,9 @@ where if x1 - 1 > x2 { stack.push((x2 + 1, x1 - 1, y - dy, -dy)) } - x1 = x1 + 1; + x1 += 1; while x1 < x2 && !inside(image, x1, y, target) { - x1 = x1 + 1 + x1 += 1 } x = x1 } diff --git a/src/drawing/line.rs b/src/drawing/line.rs index 628315d4..2e8f962f 100644 --- a/src/drawing/line.rs +++ b/src/drawing/line.rs @@ -91,7 +91,7 @@ pub struct BresenhamLinePixelIter<'a, P: Pixel> { image: &'a Image

, } -impl<'a, P: Pixel> BresenhamLinePixelIter<'a, P> { +impl BresenhamLinePixelIter<'_, P> { /// Creates a [`BresenhamLinePixelIter`] which will iterate over /// the image pixels with coordinates between `start` and `end`. pub fn new( @@ -125,7 +125,7 @@ pub struct BresenhamLinePixelIterMut<'a, P: Pixel> { image: &'a mut Image

, } -impl<'a, P: Pixel> BresenhamLinePixelIterMut<'a, P> { +impl BresenhamLinePixelIterMut<'_, P> { /// Creates a [`BresenhamLinePixelIterMut`] which will iterate over /// the image pixels with coordinates between `start` and `end`. pub fn new( @@ -302,7 +302,7 @@ where blend: B, } -impl<'a, I, T, B> Plotter<'a, I, T, B> +impl Plotter<'_, I, T, B> where I: GenericImage, diff --git a/src/geometric_transformations.rs b/src/geometric_transformations.rs index a6394b52..87ef25ea 100644 --- a/src/geometric_transformations.rs +++ b/src/geometric_transformations.rs @@ -243,7 +243,7 @@ impl Mul for Projection { } } -impl<'a, 'b> Mul<&'b Projection> for &'a Projection { +impl Mul<&Projection> for &Projection { type Output = Projection; fn mul(self, rhs: &Projection) -> Projection { @@ -264,7 +264,7 @@ impl Mul<(f32, f32)> for Projection { } } -impl<'a, 'b> Mul<&'b (f32, f32)> for &'a Projection { +impl Mul<&(f32, f32)> for &Projection { type Output = (f32, f32); fn mul(self, rhs: &(f32, f32)) -> (f32, f32) { diff --git a/src/suppress.rs b/src/suppress.rs index 4b97a2fe..b7af9d63 100644 --- a/src/suppress.rs +++ b/src/suppress.rs @@ -46,12 +46,12 @@ where } } - let x0 = if radius >= best_x { 0 } else { best_x - radius }; + let x0 = best_x.saturating_sub(radius); let x1 = x; let x2 = cmp::min(width, x + radius + 1); let x3 = cmp::min(width, best_x + radius + 1); - let y0 = if radius >= best_y { 0 } else { best_y - radius }; + let y0 = best_y.saturating_sub(radius); let y1 = y; let y2 = cmp::min(height, y + radius + 1); let y3 = cmp::min(height, best_y + radius + 1); @@ -131,7 +131,7 @@ where let cs = t.score(); let mut is_max = true; - let row_lower = if radius > cy { 0 } else { cy - radius }; + let row_lower = cy.saturating_sub(radius); let row_upper = if cy + radius + 1 > height { height } else { diff --git a/src/template_matching.rs b/src/template_matching.rs index c7974e42..e51a2fb6 100644 --- a/src/template_matching.rs +++ b/src/template_matching.rs @@ -432,7 +432,7 @@ impl<'a> ImageTemplate<'a> { } } } -impl<'a> OutputDims for ImageTemplate<'a> { +impl OutputDims for ImageTemplate<'_> { fn output_dims(&self) -> (u32, u32) { let width = self.image.width() - self.template.width() + 1; let height = self.image.height() - self.template.height() + 1; @@ -470,7 +470,7 @@ impl<'a> ImageTemplateMask<'a> { } } } -impl<'a> OutputDims for ImageTemplateMask<'a> { +impl OutputDims for ImageTemplateMask<'_> { fn output_dims(&self) -> (u32, u32) { self.inner.output_dims() } diff --git a/tests/regression.rs b/tests/regression.rs index 68a969d5..f171fc79 100644 --- a/tests/regression.rs +++ b/tests/regression.rs @@ -752,7 +752,7 @@ fn test_draw_filled_ellipse() { #[test] fn test_draw_flood_filled_shape() { - use imageproc::drawing::{draw_hollow_ellipse_mut, flood_fill, flood_fill_mut}; + use imageproc::drawing::{draw_hollow_ellipse_mut, flood_fill_mut}; let red = Rgb([255, 0, 0]); let green = Rgb([0, 255, 0]);