Ejemplo n.º 1
0
        public static void Test_FloodFill_01()
        {
            int[][] field = new int[][]
            {
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                new int[] { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 },
                new int[] { 1, 1, 1, 1, 0, 0, 0, 1, 1, 1 },
                new int[] { 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 },
                new int[] { 1, 1, 0, 0, 0, 1, 1, 1, 1, 1 },
                new int[] { 1, 0, 1, 1, 0, 0, 1, 1, 1, 1 },
                new int[] { 1, 1, 0, 1, 0, 0, 0, 0, 1, 1 },
                new int[] { 1, 1, 0, 1, 1, 1, 1, 0, 0, 1 },
                new int[] { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1 },
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            };

            int pixelsWith0 = 0;

            Math2D.FloodFill_4Neighbour(
                5,
                5,
                (x, y) => field[y][x] == 0, (x, y) => ++ pixelsWith0,
                0, 0, 10, 10
                );

            Assert.AreEqual(19, pixelsWith0);
        }