-
Notifications
You must be signed in to change notification settings - Fork 144
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
add floodfill, floodfill_mut, neighbors, and neighbor_indices #511
base: master
Are you sure you want to change the base?
Conversation
I have implemented floodfill, floodfill_mut, as well as created the connectivity module and its utilities for working with pixels' neighbors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that connectivity is defined into it's own file. The PR lacks some regular tests but it is well documented and has doc-examples.
impl Position for Point<usize> { | ||
fn x(&self) -> u32 { self.x as u32 } | ||
fn y(&self) -> u32 { self.y as u32 } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably not a great idea to implement this trait using casts, it could cause some very hard to track down bugs. It might be a better idea to do this conversion manually where needed.
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to run cargo fmt
if old_color == fill_color || seed_point.0 >= width || seed_point.1 >= height { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy warns about an unneeded return statement
while !frontier.is_empty() { | ||
let q = frontier.pop().unwrap(); // unwrap will not panic here as we have checked that frontier is not empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could re-write this as:
while let Some(q) = frontier.pop() {
} | ||
|
||
/// Creates a clone of the input image and performs an in-place floodfill operation on | ||
/// the clone using [floodfill_mut] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think references to functions in doc-comments should also use backticks like: [`floodfill_mut()`]
This functionality is definitely nice to have. I suspect that this version will be far slower than it should be though - we're both allocating a vector and performing bounds checks for every pixel in the image. |
Added functions to yield iterators to neighboring pixel indices or references to the pixels, in-place floodfill, and floodfill.