Repository: PixiEditor/PixiEditor
File: PixiEditor/Models/Tools/Tools/FloodFill.cs (C#)

Code before:
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;

namespace PixiEditor.Models.Tools.Tools
{
    public class FloodFill : BitmapOperationTool
    {
        public override ToolType ToolType => ToolType.Bucket;

        public FloodFill()
        {
            Tooltip = "Fills area with color (G)";
        }

        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
        {
            return Only(ForestFire(layer, coordinates[0], color), layer);
        }

        private BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
        {
            List<Coordinates> changedCoords = new List<Coordinates>();

            int width = layer.Width;
            int height = layer.Height;

            var visited = new bool[width, height];

            Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);

            var stack = new Stack<Coordinates>();
            stack.Push(new Coordinates(startingCoords.X, startingCoords.Y));

            while (stack.Count > 0)
            {
                var cords = stack.Pop();
                var relativeCords = layer.GetRelativePosition(cords);

                if (cords.X < 0 || cords.X > width - 1) continue;
                if (cords.Y < 0 || cords.Y > height - 1) continue;
                if (visited[cords.X, cords.Y]) continue;
                if (layer.GetPixel(relativeCords.X, relativeCords.Y) == newColor) continue;

                if (layer.GetPixel(relativeCords.X, relativeCords.Y) == colorToReplace)
                {
                    changedCoords.Add(new Coordinates(cords.X, cords.Y));
                    visited[cords.X, cords.Y] = true;
                    stack.Push(new Coordinates(cords.X, cords.Y - 1));                    
                    stack.Push(new Coordinates(cords.X, cords.Y + 1));                    
                    stack.Push(new Coordinates(cords.X - 1, cords.Y));

Review comment (suggestion):
```suggestion
            int width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
            int height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;
```

Hey, all awesome, but it doesn't work if you don't set the height and width to `ActiveDocument` due to the nature of dynamic bitmaps. They resize to size of content, so for layer without any pixels, it will be 0x0 and nothing will fill :) 

Code after:
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using PixiEditor.ViewModels;

namespace PixiEditor.Models.Tools.Tools
{
    public class FloodFill : BitmapOperationTool
    {
        public override ToolType ToolType => ToolType.Bucket;

        public FloodFill()
        {
            Tooltip = "Fills area with color (G)";
        }

        public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
        {
            return Only(ForestFire(layer, coordinates[0], color), layer);
        }

        private BitmapPixelChanges ForestFire(Layer layer, Coordinates startingCoords, Color newColor)
        {
            List<Coordinates> changedCoords = new List<Coordinates>();

            int width = ViewModelMain.Current.BitmapManager.ActiveDocument.Width;
            int height = ViewModelMain.Current.BitmapManager.ActiveDocument.Height;

            var visited = new bool[width, height];

            Color colorToReplace = layer.GetPixelWithOffset(startingCoords.X, startingCoords.Y);

            var stack = new Stack<Coordinates>();
            stack.Push(new Coordinates(startingCoords.X, startingCoords.Y));

            while (stack.Count > 0)
            {
                var cords = stack.Pop();
                var relativeCords = layer.GetRelativePosition(cords);

                if (cords.X < 0 || cords.X > width - 1) continue;
                if (cords.Y < 0 || cords.Y > height - 1) continue;
                if (visited[cords.X, cords.Y]) continue;
                if (layer.GetPixel(relativeCords.X, relativeCords.Y) == newColor) continue;

                if (layer.GetPixel(relativeCords.X, relativeCords.Y) == colorToReplace)
                {
                    changedCoords.Add(new Coordinates(cords.X, cords.Y));
                    visited[cords.X, cords.Y] = true;
                    stack.Push(new Coordinates(cords.X, cords.Y - 1));                    
                    stack.Push(new Coordinates(cords.X, cords.Y + 1));