summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-15 10:39:45 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-15 10:39:45 +0200
commita8b2b96f3894284978691d529d555d0c554e46ce (patch)
tree702b49daf7fe882d8c24f0a3a83ced3838081f80 /Applications
parentbfaa74f0769edd54b3c1f9ff5e1b0b0ccc3d6b69 (diff)
downloadserenity-a8b2b96f3894284978691d529d555d0c554e46ce.zip
PaintBrush: Use a Queue<Point> for the flood fill.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/PaintBrush/BucketTool.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/Applications/PaintBrush/BucketTool.cpp b/Applications/PaintBrush/BucketTool.cpp
index cf226f65b6..c5aa4471d4 100644
--- a/Applications/PaintBrush/BucketTool.cpp
+++ b/Applications/PaintBrush/BucketTool.cpp
@@ -1,5 +1,6 @@
#include "BucketTool.h"
#include "PaintableWidget.h"
+#include <AK/Queue.h>
#include <AK/SinglyLinkedList.h>
#include <LibGUI/GPainter.h>
#include <SharedGraphics/GraphicsBitmap.h>
@@ -15,16 +16,10 @@ BucketTool::~BucketTool()
static void flood_fill(GraphicsBitmap& bitmap, const Point& start_position, Color target_color, Color fill_color)
{
- Vector<Point> queue;
- queue.append(start_position);
- int queue_pos = 0;
- while (queue_pos != queue.size()) {
- auto position = queue[queue_pos++];
-
- if (queue_pos > 4096) {
- queue.shift_left(4096);
- queue_pos = 0;
- }
+ Queue<Point> queue;
+ queue.enqueue(Point(start_position));
+ while (!queue.is_empty()) {
+ auto position = queue.dequeue();
if (!bitmap.rect().contains(position))
continue;
@@ -33,16 +28,16 @@ static void flood_fill(GraphicsBitmap& bitmap, const Point& start_position, Colo
bitmap.set_pixel(position, fill_color);
if (position.x() != 0)
- queue.append(position.translated(0, -1));
+ queue.enqueue(position.translated(0, -1));
if (position.x() != bitmap.width() - 1)
- queue.append(position.translated(0, 1));
+ queue.enqueue(position.translated(0, 1));
if (position.y() != 0)
- queue.append(position.translated(-1, 0));
+ queue.enqueue(position.translated(-1, 0));
if (position.y() != bitmap.height() - 1)
- queue.append(position.translated(1, 0));
+ queue.enqueue(position.translated(1, 0));
}
}