Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix new clippy lints #691

Merged
merged 5 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/binary_descriptors/brief.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ fn local_pixel_average(integral_image: &Image<Luma<u32>>, 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);

Expand Down
4 changes: 2 additions & 2 deletions src/corners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions src/distance_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 8 additions & 9 deletions src/drawing/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ pub fn flood_fill_mut<P>(image: &mut Image<P>, 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))
Expand All @@ -40,17 +39,17 @@ 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))
}
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
}
Expand Down
6 changes: 3 additions & 3 deletions src/drawing/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct BresenhamLinePixelIter<'a, P: Pixel> {
image: &'a Image<P>,
}

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

impl<'a, P: Pixel> BresenhamLinePixelIterMut<'a, P> {
impl<P: Pixel> BresenhamLinePixelIterMut<'_, P> {
/// Creates a [`BresenhamLinePixelIterMut`] which will iterate over
/// the image pixels with coordinates between `start` and `end`.
pub fn new(
Expand Down Expand Up @@ -302,7 +302,7 @@ where
blend: B,
}

impl<'a, I, T, B> Plotter<'a, I, T, B>
impl<I, T, B> Plotter<'_, I, T, B>
where
I: GenericImage,

Expand Down
4 changes: 2 additions & 2 deletions src/geometric_transformations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Mul<Projection> 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 {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/suppress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/template_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Loading