예제 #1
0
        public int[][] FindClosestNeighbourt(Raster Grid)
        {
            bool neighbourtFound = false;
            int  j = 0;

            while (!neighbourtFound)
            {
                int     DiameterShift = (int)(Math.Round(Diameter / 2, MidpointRounding.AwayFromZero)) + j;
                int[][] extremePoints =
                {
                    Drawing.GetAngledPoint(CenterPointInGrid[0], CenterPointInGrid[1], (45 + Angle) % 360, DiameterShift),       //UperRightCorner
                    Drawing.GetAngledPoint(CenterPointInGrid[0], CenterPointInGrid[1], (45 + 90 + Angle) % 360, DiameterShift),  //UperLeftCorner
                    Drawing.GetAngledPoint(CenterPointInGrid[0], CenterPointInGrid[1], (45 + 180 + Angle) % 360, DiameterShift), //LowerLeftCorner
                    Drawing.GetAngledPoint(CenterPointInGrid[0], CenterPointInGrid[1], (45 + 270 + Angle) % 360, DiameterShift)  //LowerRightCorner
                };

                int[][] sides =
                {
                    new int[] { 0, 1 },
                    new int[] { 1, 2 },
                    new int[] { 2, 3 },
                    new int[] { 3, 0 },
                };

                for (int i = 0; i < sides.Length; i++)
                {
                    int x1 = extremePoints[sides[i][0]][0];
                    int y1 = extremePoints[sides[i][0]][1];
                    int x2 = extremePoints[sides[i][1]][0];
                    int y2 = extremePoints[sides[i][1]][1];

                    int[][] searchResult = Drawing.DrawSearchLine(x1, y1, x2, y2, Grid.getGrid(), ID);
                    if (searchResult.Length > 0)
                    {
                        neighbourtFound = true;
                        return(searchResult);
                    }
                    else if ((j > Grid.GetWidth() && j > Grid.GetHeight()))
                    {
                        neighbourtFound = true;
                        return(new int[][]
                        {
                            new int[] { 0, 0, 0 },
                        });
                    }
                }
                j++;
            }
            return(new int[][]
            {
                new int[] { 0, 0, 0 },
            });
        }
예제 #2
0
        public void SearchLineTest(Raster grid)
        {
            int Height = grid.GetHeight();
            int Width  = grid.GetWidth();

            byte[][] returnGrid = new byte[Height][];
            for (int i = 0; i < Height; i++)
            {
                returnGrid[i] = new byte[Width];
            }
            for (int i = 0; i < Height; i++)
            {
                int[][] searchResult = Drawing.DrawSearchLine(0, i, Width - 1, i, grid.getGrid(), 1);
                for (int j = 0; j < searchResult.Length; j++)
                {
                    returnGrid[searchResult[j][2]][searchResult[j][1]] = 1;
                }
            }

            ImageBuffer buffer = new ImageBuffer(Width, Height);

            for (int i = 0; i < Height; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    if (returnGrid[i][j] == 0)
                    {
                        buffer.PlotPixel(j, i, 255, 255, 255);
                    }
                    else if (returnGrid[i][j] == 1)
                    {
                        buffer.PlotPixel(j, i, 0, 0, 0);
                    }
                    else
                    {
                        buffer.PlotPixel(j, i, 255, 0, 0);
                    }
                }
            }
            buffer.saveColor();
        }
        public void FillGrid(Raster Grid, GridObjectTemplate objectTemplate, int NumberOfObject)
        {
            int RemainCount = NumberOfObject;
            //Random random = Grid.getRandom();
            int        Width         = Grid.GetWidth();
            int        Height        = Grid.GetHeight();
            GridObject objectToPLace = objectTemplate.GenerateGridObject();

            while (RemainCount != 0)
            {
                int Xcoordinate = random.Next(1, Width);
                int Ycoordinate = random.Next(1, Height);
                if (objectToPLace.CanBePlaced(Grid, Xcoordinate, Ycoordinate))
                {
                    objectToPLace.Draw(Grid, Xcoordinate, Ycoordinate);
                    objectToPLace = objectTemplate.GenerateGridObject(random);
                    RemainCount--;
                    Grid.addGridObject(objectToPLace);
                }
            }
        }
예제 #4
0
 public bool CanBePlaced(Raster RasterGrid, int Xcenter, int Ycenter)
 {
     int[][] temporaryGrid = new int[2 * SideLength][];
     for (int i = 0; i < temporaryGrid.Length; i++)
     {
         temporaryGrid[i] = new int[2 * SideLength];
     }
     DrawRaster(temporaryGrid, SideLength, SideLength);
     for (int i = 0; i < temporaryGrid.Length; i++)
     {
         for (int j = 0; j < temporaryGrid[0].Length; j++)
         {
             if (Ycenter + (i - SideLength) >= RasterGrid.GetHeight() || Xcenter + (j - SideLength) >= RasterGrid.GetHeight() || Ycenter + (i - SideLength) < 0 || Xcenter + (j - SideLength) < 0)
             {
                 return(false);
             }
             if (RasterGrid.getGrid()[Ycenter + (i - SideLength)][Xcenter + (j - SideLength)] != Const.EMPTY && temporaryGrid[i][j] == ID)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #5
0
        public static void DrawLine(int x0, int y0, int x1, int y1, Raster Grid, int ID)
        {
            int dx, dy;
            int stepX, stepY;

            dx = (x1 - x0);
            dy = (y1 - y0);

            if (dy < 0)
            {
                dy    = -dy;
                stepY = -1;
            }
            else
            {
                stepY = 1;
            }
            if (dx < 0)
            {
                dx    = -dx;
                stepX = -1;
            }
            else
            {
                stepX = 1;
            }

            //Im not totaly sure WHY ??????
            dx <<= 1;
            dy <<= 1;

            //Check if point is inside of the raster and plot first pixel
            if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
            {
                Grid.SetTileID(ID, x0, y0);
            }
            if (dx > dy)
            {
                int fraction = dy - (dx >> 1);
                while (x0 != x1)
                {
                    x0 += stepX;
                    if (fraction >= 0)
                    {
                        y0       += stepY;
                        fraction -= dx;
                    }
                    fraction += dy;
                    if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
                    {
                        Grid.SetTileID(ID, x0, y0);
                    }
                }
            }
            else
            {
                int fraction = dx - (dy >> 1);
                while (y0 != y1)
                {
                    if (fraction >= 0)
                    {
                        x0       += stepX;
                        fraction -= dy;
                    }
                    fraction += dx;
                    y0       += stepY;
                    if ((0 <= x0) && (x0 < Grid.GetWidth()) && (0 <= y0) && (y0 < Grid.GetHeight()))
                    {
                        Grid.SetTileID(ID, x0, y0);
                    }
                }
            }
        }