-
Notifications
You must be signed in to change notification settings - Fork 149
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
New feature: Flood-fill #684
Conversation
tests/regression.rs
Outdated
#[test] | ||
fn test_draw_flood_filled_shape() { | ||
use imageproc::drawing::{draw_hollow_ellipse_mut, flood_fill}; | ||
|
||
let red = Rgb([255, 0, 0]); | ||
let green = Rgb([0, 255, 0]); | ||
let blue = Rgb([0, 0, 255]); | ||
let mut image = RgbImage::from_pixel(200, 200, Rgb([255, 255, 255])); | ||
|
||
draw_hollow_ellipse_mut(&mut image, (100, 100), 50, 50, red); | ||
draw_hollow_ellipse_mut(&mut image, (50, 100), 40, 90, blue); | ||
draw_hollow_ellipse_mut(&mut image, (100, 150), 80, 30, green); | ||
draw_hollow_ellipse_mut(&mut image, (150, 150), 100, 60, blue); | ||
|
||
flood_fill(&mut image, 120, 120, red); | ||
|
||
compare_to_truth_image(&image, "flood_filled_shape.png"); | ||
} | ||
|
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.
Awesome test!
src/drawing/fill.rs
Outdated
filled_image | ||
} | ||
|
||
#[doc=generate_mut_doc_comment!("draw_line_segment")] |
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 need to update this to the same name as the non-mut method
tests/regression.rs
Outdated
flood_fill(&mut image, 120, 120, red); | ||
let filled_image = flood_fill(&image, 120, 120, red); | ||
compare_to_truth_image(&filled_image, "flood_filled_shape.png"); | ||
|
||
flood_fill_mut(&mut image, 120, 120, red); |
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.
Not really any need to test both variants since they are the same method underneath.
Apart from the two new nits, I'm happy for this PR to be merged. |
All done. Thanks. |
for |
CI should pass now. |
Actually I think |
Thanks! |
Similar to bucket tool in MS-PAINT.
I've just taken the algorithm from here:
https://en.wikipedia.org/wiki/Flood_fill#Span_filling
I'm fairly new to rust and didn't know how to do generic Pixel equality without first converting to rgba pixel, perhaps someone knows how to do this better?:
imageproc/src/drawing/fill.rs
Line 61 in d2a187c