-
Notifications
You must be signed in to change notification settings - Fork 20.4k
Feature iterative flood fill #6584
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
Open
CrodiYa
wants to merge
8
commits into
TheAlgorithms:master
from
CrodiYa:feature-iterative-flood-fill
Open
Feature iterative flood fill #6584
CrodiYa
wants to merge
8
commits into
TheAlgorithms:master
from
CrodiYa:feature-iterative-flood-fill
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- nested class Point: helper class, represents point in 2D field (x,y) - shouldSkipPixel method: helper method to validate point - floodFill method: iterative version of floodFill, uses Queue to add and poll Points and change it color if allowed
-same tests as for normal floodFill and test for a big image
Codecov Report
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.53%. Comparing base (f8f315e
) to head (5c52b36
).
Additional details and impacted files
@@ Coverage Diff @@ ## master #6584 +/- ## ============================================ + Coverage 75.31% 75.53% +0.22% - Complexity 5659 5703 +44 ============================================ Files 693 695 +2 Lines 19552 19595 +43 Branches 3786 3795 +9 ============================================ + Hits 14725 14801 +76 + Misses 4252 4217 -35 - Partials 575 577 +2
☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@CrodiYa
CrodiYa
requested review from
DenizAltunkapan,
yanglbme and
alxkm
as code owners
October 2, 2025 08:14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BFS Flood Fill algorithm
Project already has Flood Fill
This project already has a Flood Fill algorithm, but it is DFS.
For any big "image" DFS version won`t work because of stack overflow.
The BFS version, on the other hand, handles large "images" without any problems.
My first "big" project on Java was simple pixel paint app and that was my first time encountering StackOverflowException and I was very confused: it took me some time to figure out the problem and solution.
So, it would be useful to have this example of this algorithm here.
A similar version of this algorithm can be found here: https://www.geeksforgeeks.org/dsa/flood-fill-algorithm/
Main difference - this version looks for diagonals too
Technical details
This version uses queue and helper class
Point
to traverse.While queue is not empty, the "pixel" is painted and "pixels" around it are added to queue (if coordinates are in boundaries and colour is not the same).
Directions for new "pixels" stored in arrays
dx
anddy
. First four - horizontal and vertical, second four - diagonals.It is achievable to store coordinates (x, y) in long, using bit mask, but it`s too much and possibly can lead to collision.
Tests were copied from original FloodFill and one test was added to demonstrate that BFS handles "big images".
To be honest, I am not entirely sure in what package to add this, so "others" was picked.
clang-format -i --style=file path/to/your/file.java