@@ -14,7 +14,7 @@ namespace Algorithms.Other;
14
14
/// </summary>
15
15
public static class FloodFill
16
16
{
17
- private static readonly List < ( int xOffset , int yOffset ) > Neighbors = new ( ) { ( - 1 , - 1 ) , ( - 1 , 0 ) , ( - 1 , 1 ) , ( 0 , - 1 ) , ( 0 , 1 ) , ( 1 , - 1 ) , ( 1 , 0 ) , ( 1 , 1 ) } ;
17
+ private static readonly List < ( int XOffset , int YOffset ) > Neighbors = new ( ) { ( - 1 , - 1 ) , ( - 1 , 0 ) , ( - 1 , 1 ) , ( 0 , - 1 ) , ( 0 , 1 ) , ( 1 , - 1 ) , ( 1 , 0 ) , ( 1 , 1 ) } ;
18
18
19
19
/// <summary>
20
20
/// Implements the flood fill algorithm through a breadth-first approach using a queue.
@@ -23,14 +23,14 @@ public static class FloodFill
23
23
/// <param name="location">The start location on the bitmap.</param>
24
24
/// <param name="targetColor">The old color to be replaced.</param>
25
25
/// <param name="replacementColor">The new color to replace the old one.</param>
26
- public static void BreadthFirstSearch ( SKBitmap bitmap , ( int x , int y ) location , SKColor targetColor , SKColor replacementColor )
26
+ public static void BreadthFirstSearch ( SKBitmap bitmap , ( int X , int Y ) location , SKColor targetColor , SKColor replacementColor )
27
27
{
28
- if ( location . x < 0 || location . x >= bitmap . Width || location . y < 0 || location . y >= bitmap . Height )
28
+ if ( location . X < 0 || location . X >= bitmap . Width || location . Y < 0 || location . Y >= bitmap . Height )
29
29
{
30
30
throw new ArgumentOutOfRangeException ( nameof ( location ) , $ "{ nameof ( location ) } should point to a pixel within the bitmap") ;
31
31
}
32
32
33
- var queue = new List < ( int x , int y ) > ( ) ;
33
+ var queue = new List < ( int X , int Y ) > ( ) ;
34
34
queue . Add ( location ) ;
35
35
36
36
while ( queue . Count > 0 )
@@ -46,29 +46,29 @@ public static void BreadthFirstSearch(SKBitmap bitmap, (int x, int y) location,
46
46
/// <param name="location">The start location on the bitmap.</param>
47
47
/// <param name="targetColor">The old color to be replaced.</param>
48
48
/// <param name="replacementColor">The new color to replace the old one.</param>
49
- public static void DepthFirstSearch ( SKBitmap bitmap , ( int x , int y ) location , SKColor targetColor , SKColor replacementColor )
49
+ public static void DepthFirstSearch ( SKBitmap bitmap , ( int X , int Y ) location , SKColor targetColor , SKColor replacementColor )
50
50
{
51
- if ( location . x < 0 || location . x >= bitmap . Width || location . y < 0 || location . y >= bitmap . Height )
51
+ if ( location . X < 0 || location . X >= bitmap . Width || location . Y < 0 || location . Y >= bitmap . Height )
52
52
{
53
53
throw new ArgumentOutOfRangeException ( nameof ( location ) , $ "{ nameof ( location ) } should point to a pixel within the bitmap") ;
54
54
}
55
55
56
56
DepthFirstFill ( bitmap , location , targetColor , replacementColor ) ;
57
57
}
58
58
59
- private static void BreadthFirstFill ( SKBitmap bitmap , ( int x , int y ) location , SKColor targetColor , SKColor replacementColor , List < ( int x , int y ) > queue )
59
+ private static void BreadthFirstFill ( SKBitmap bitmap , ( int X , int Y ) location , SKColor targetColor , SKColor replacementColor , List < ( int X , int Y ) > queue )
60
60
{
61
- ( int x , int y ) currentLocation = queue [ 0 ] ;
61
+ ( int X , int Y ) currentLocation = queue [ 0 ] ;
62
62
queue . RemoveAt ( 0 ) ;
63
63
64
- if ( bitmap . GetPixel ( currentLocation . x , currentLocation . y ) == targetColor )
64
+ if ( bitmap . GetPixel ( currentLocation . X , currentLocation . Y ) == targetColor )
65
65
{
66
- bitmap . SetPixel ( currentLocation . x , currentLocation . y , replacementColor ) ;
66
+ bitmap . SetPixel ( currentLocation . X , currentLocation . Y , replacementColor ) ;
67
67
68
68
for ( int i = 0 ; i < Neighbors . Count ; i ++ )
69
69
{
70
- int x = currentLocation . x + Neighbors [ i ] . xOffset ;
71
- int y = currentLocation . y + Neighbors [ i ] . yOffset ;
70
+ int x = currentLocation . X + Neighbors [ i ] . XOffset ;
71
+ int y = currentLocation . Y + Neighbors [ i ] . YOffset ;
72
72
if ( x >= 0 && x < bitmap . Width && y >= 0 && y < bitmap . Height )
73
73
{
74
74
queue . Add ( ( x , y ) ) ;
@@ -77,16 +77,16 @@ private static void BreadthFirstFill(SKBitmap bitmap, (int x, int y) location, S
77
77
}
78
78
}
79
79
80
- private static void DepthFirstFill ( SKBitmap bitmap , ( int x , int y ) location , SKColor targetColor , SKColor replacementColor )
80
+ private static void DepthFirstFill ( SKBitmap bitmap , ( int X , int Y ) location , SKColor targetColor , SKColor replacementColor )
81
81
{
82
- if ( bitmap . GetPixel ( location . x , location . y ) == targetColor )
82
+ if ( bitmap . GetPixel ( location . X , location . Y ) == targetColor )
83
83
{
84
- bitmap . SetPixel ( location . x , location . y , replacementColor ) ;
84
+ bitmap . SetPixel ( location . X , location . Y , replacementColor ) ;
85
85
86
86
for ( int i = 0 ; i < Neighbors . Count ; i ++ )
87
87
{
88
- int x = location . x + Neighbors [ i ] . xOffset ;
89
- int y = location . y + Neighbors [ i ] . yOffset ;
88
+ int x = location . X + Neighbors [ i ] . XOffset ;
89
+ int y = location . Y + Neighbors [ i ] . YOffset ;
90
90
if ( x >= 0 && x < bitmap . Width && y >= 0 && y < bitmap . Height )
91
91
{
92
92
DepthFirstFill ( bitmap , ( x , y ) , targetColor , replacementColor ) ;
0 commit comments