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 },
            });
        }
Example #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 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);
 }
        public void Draw(Raster Grid, int XPointCenter, int YPointCenter)
        {
            CenterPointInGrid = new int[] { XPointCenter, YPointCenter };
            //DrawBorders
            for (int j = 0; j < BorderSize_pixels; j++)
            {
                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];

                    Drawing.DrawLine(x1, y1, x2, y2, Grid, ID);
                }
            }
            //infil
            if (Infill)
            {
                Drawing.FloodFill(ID, CenterPointInGrid[0], CenterPointInGrid[1], Const.EMPTY, Grid.getGrid(), false);
            }
        }
Example #5
0
 public void FindClosestTest(Raster grid)
 {
     foreach (var v in grid.getGridObjectList())
     {
         int[][] searchResult = v.FindClosestNeighbourt(grid);
         if (searchResult.Length > 0)
         {
             if (searchResult[0][0] == 0)
             {
                 Console.WriteLine("Search Failed");
             }
             else
             {
                 for (int i = 0; i < searchResult.Length; i++)
                 {
                     Console.WriteLine("Object with ID : {0} has closest neighbourt {1} on coordinates X:{2}, Y:{3}", v.getID(), searchResult[i][0], searchResult[i][1], searchResult[i][2]);
                     int[] centerPoint = new int[] { 0, 0 };
                     for (int l = 0; l < grid.getGridObjectList().Count; l++)
                     {
                         if (grid.getGridObjectList().ElementAt(l).getID() == searchResult[i][0])
                         {
                             centerPoint = grid.getGridObjectList().ElementAt(l).getCenterPoint();
                         }
                     }
                     Console.WriteLine("CenterCoordinate : X:{0}, Y:{1}", v.getCenterPoint()[0], v.getCenterPoint()[1]);
                     if (v.getCenterPoint()[0] != 0 && v.getCenterPoint()[1] != 0 && centerPoint[0] != 0 && centerPoint[1] != 0)
                     {
                         Drawing.DrawLine(v.getCenterPoint()[0], v.getCenterPoint()[1], centerPoint[0], centerPoint[1], grid.getGrid(), Const.CENTERCONECTION);
                     }
                 }
             }
         }
     }
 }