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

add floodfill, floodfill_mut, neighbors, and neighbor_indices #511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mcaveniathor
Copy link

Added functions to yield iterators to neighboring pixel indices or references to the pixels, in-place floodfill, and floodfill.

@mcaveniathor
Copy link
Author

I have implemented floodfill, floodfill_mut, as well as created the connectivity module and its utilities for working with pixels' neighbors.

Copy link
Contributor

@ripytide ripytide left a 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.

Comment on lines +77 to +80
impl Position for Point<usize> {
fn x(&self) -> u32 { self.x as u32 }
fn y(&self) -> u32 { self.y as u32 }
}
Copy link
Contributor

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.

Comment on lines +319 to +336


















Copy link
Contributor

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

Comment on lines +283 to +285
if old_color == fill_color || seed_point.0 >= width || seed_point.1 >= height {
return;
}
Copy link
Contributor

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

Comment on lines +291 to +292
while !frontier.is_empty() {
let q = frontier.pop().unwrap(); // unwrap will not panic here as we have checked that frontier is not empty
Copy link
Contributor

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]
Copy link
Contributor

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()`]

@theotherphil
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants