Skip to content

Commit

Permalink
Clippy suggestions. Fixed non-op in inpaint::find_starting_point, add…
Browse files Browse the repository at this point in the history
…ed test
  • Loading branch information
kmgill committed Apr 9, 2023
1 parent 5ad7627 commit 78d3a27
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
40 changes: 18 additions & 22 deletions src/inpaint.rs
Expand Up @@ -2,14 +2,16 @@

use crate::{enums, error, image::Image, imagebuffer::ImageBuffer, stats};

use itertools::iproduct;

#[cfg(rayon)]
use rayon::prelude::*;

#[derive(Debug, Clone)]
struct Point {
x: usize,
y: usize,
score: u32,
pub struct Point {
pub x: usize,
pub y: usize,
pub score: u32,
}

struct RgbVec {
Expand Down Expand Up @@ -78,30 +80,24 @@ fn get_num_good_neighbors(mask: &ImageBuffer, x: i32, y: i32) -> u32 {
}

#[cfg(rayon)]
fn find_starting_point(mask: &ImageBuffer) -> Option<Point> {
pub fn find_starting_point(mask: &ImageBuffer) -> Option<Point> {
let height_iter = (0..mask.height.clone()).into_par_iter();

height_iter.for_each(|y| {
(0..mask.width).for_each(|x| {
if mask.get(x, y) > 0.0 {
Some(Point { x, y, score: 0 });
} else {
}
});
});
for (y, x) in iproduct!(height_iter, (0..mask.width)) {
if mask.get(x, y) > 0.0 {
return Some(Point { x, y, score: 0 });
}
}
None
}

#[cfg(not(rayon))]
fn find_starting_point(mask: &ImageBuffer) -> Option<Point> {
(0..mask.height).for_each(|y| {
(0..mask.width).for_each(|x| {
if mask.get(x, y) > 0.0 {
Some(Point { x, y, score: 0 });
} else {
}
});
});
pub fn find_starting_point(mask: &ImageBuffer) -> Option<Point> {
for (y, x) in iproduct!((0..mask.height), (0..mask.width)) {
if mask.get(x, y) > 0.0 {
return Some(Point { x, y, score: 0 });
}
}
None
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Expand Up @@ -86,7 +86,7 @@ pub fn replace_image_extension(input_file: &str, append: &str) -> String {
pub fn vec_to_str(v: &[f64]) -> String {
let mut b = Builder::default();

v.into_iter().for_each(|item| {
v.iter().for_each(|item| {
b.append(format!("{},", item));
});

Expand Down
17 changes: 17 additions & 0 deletions tests/inpaint.rs
@@ -0,0 +1,17 @@
use sciimg::{imagebuffer::ImageBuffer, inpaint};

const INPAINT_TEST_IMAGE: &str = "tests/testdata/MSL_MAHLI_INPAINT_Sol2904_V1.png";

#[test]
fn test_find_starting_point() {
let inpaint_mask = ImageBuffer::from_file(&String::from(INPAINT_TEST_IMAGE)).unwrap();

let start_point = inpaint::find_starting_point(&inpaint_mask);

assert!(start_point.is_some());

let start = start_point.unwrap();
assert_eq!(1581, start.x);
assert_eq!(15, start.y);
assert_eq!(0, start.score);
}
Binary file added tests/testdata/MSL_MAHLI_INPAINT_Sol2904_V1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 78d3a27

Please sign in to comment.