улучшен алгоритм заливки
This commit is contained in:
@@ -16,15 +16,12 @@ public sealed class FloodFillService : IFloodFillService
|
||||
return;
|
||||
|
||||
var queue = new Queue<(int X, int Y)>();
|
||||
var visited = new bool[width * height];
|
||||
|
||||
queue.Enqueue((x, y));
|
||||
visited[y * width + x] = true;
|
||||
pixels[y * width + x] = newColorIndex;
|
||||
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var (cx, cy) = queue.Dequeue();
|
||||
pixels[cy * width + cx] = newColorIndex;
|
||||
|
||||
Span<(int, int)> neighbors =
|
||||
[
|
||||
@@ -37,9 +34,9 @@ public sealed class FloodFillService : IFloodFillService
|
||||
if (nx < 0 || nx >= width || ny < 0 || ny >= height)
|
||||
continue;
|
||||
int ni = ny * width + nx;
|
||||
if (visited[ni] || pixels[ni] != targetIndex)
|
||||
if (pixels[ni] != targetIndex)
|
||||
continue;
|
||||
visited[ni] = true;
|
||||
pixels[ni] = newColorIndex;
|
||||
queue.Enqueue((nx, ny));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user