void AddNextFillLine(LineFill line, int xMin, int xMax, int y, bool isNext, bool downwards, int height, Stack <LineFill> lines, System.Func <int, int, bool> shouldDrawTestCallback, System.Action <int, int> drawCallback) { var inRange = false; var rangeXMin = xMin; int x; // needs use outside of the loop for (x = xMin; x <= xMax; ++x) { // skip testing if testing previous line within previous range var empty = (isNext || (x <line.XMin || x> line.XMax)) && y < height && shouldDrawTestCallback(x, y); if (!inRange && empty) { rangeXMin = x; inRange = true; } else if (inRange && !empty) { lines.Push(new LineFill { XMin = rangeXMin, XMax = x - 1, Y = y, Direction = downwards ? FillDirection.Down : FillDirection.Up, ShouldPaintLeft = xMin == rangeXMin, ShouldPaintRight = false, }); inRange = false; } if (inRange) { drawCallback(x, y); } // skip if (!isNext && x == line.XMin) { x = line.XMax; } } if (inRange) { lines.Push(new LineFill { XMin = rangeXMin, XMax = x - 1, Y = y, Direction = downwards ? FillDirection.Down : FillDirection.Up, ShouldPaintLeft = rangeXMin == xMin, ShouldPaintRight = true, }); } }
void AddNextFillLine(LineFill line, int xMin, int xMax, int y, bool isNext, bool downwards, int height, Stack<LineFill> lines, System.Func<int, int, bool> shouldDrawTestCallback, System.Action<int, int> drawCallback) { var inRange = false; var rangeXMin = xMin; int x; // needs use outside of the loop for(x = xMin; x <= xMax; ++x) { // skip testing if testing previous line within previous range var empty = (isNext || (x < line.XMin || x > line.XMax)) && y < height && shouldDrawTestCallback(x, y); if(!inRange && empty) { rangeXMin = x; inRange = true; } else if(inRange && !empty) { lines.Push(new LineFill { XMin = rangeXMin, XMax = x - 1, Y = y, Direction = downwards ? FillDirection.Down : FillDirection.Up, ShouldPaintLeft = xMin == rangeXMin, ShouldPaintRight = false, }); inRange = false; } if(inRange) { drawCallback(x, y); } // skip if(!isNext && x == line.XMin) { x = line.XMax; } } if(inRange) { lines.Push(new LineFill { XMin = rangeXMin, XMax = x - 1, Y = y, Direction = downwards ? FillDirection.Down : FillDirection.Up, ShouldPaintLeft = rangeXMin == xMin, ShouldPaintRight = true, }); } }