示例#1
0
文件: Utils.cs 项目: Ring-r/sandbox
        public static IEnumerable<bool> Segmentate(Grid grid, List<List<int>> gridVectors, int minGridCount, bool minGridClear)
        {
            Grid grid_temp = grid.Copy();

            gridVectors.Clear();

            int vectIndex = -1;
            for (int index = 0; index < grid_temp.cellsCount; ++index)
            {
                if (grid_temp[index] != 0)
                {
                    if (vectIndex < 0 || gridVectors[vectIndex].Count > 0)
                    {
                        gridVectors.Add(new List<int>());
                        vectIndex += 1;
                    }

                    List<int> gridVector = gridVectors[vectIndex];
                    foreach (var res in Border(grid_temp, index, gridVector)) ;// yield return res;

                    if (GridCount(gridVector) < minGridCount)// && !AtBorder(gridVector, grid))
                    {
                        if (minGridClear)
                        {
                            GridClear(grid, gridVector);
                        }
                        gridVector.Clear();
                    }

                    yield return true;
                }
            }
        }
示例#2
0
文件: Grid.cs 项目: Ring-r/sandbox
        public void Copy(Grid grid)
        {
            this.iCount = grid.iCount;
              this.jCount = grid.jCount;
              this.cellsCount = this.iCount * this.jCount;

              this.cells = new int[this.cellsCount];
              Array.Copy(grid.cells, this.cells, this.cellsCount);
        }
示例#3
0
 private void DrawGridVectorBorders(Graphics g, Grid grid, List<int> gridVector, Color color)
 {
     Brush brush = new SolidBrush(color);
       int count = gridVector.Count;
       for (int i = 0; i < count; ++i)
       {
     int index_i, index_j; grid.Index(gridVector[i], out index_i, out index_j);
     g.FillRectangle(brush, index_i * this.cellSize, index_j * this.cellSize, this.cellSize, this.cellSize);
       }
 }
示例#4
0
文件: Utils.cs 项目: Ring-r/sandbox
 private static bool AtBorder(List<int> gridVector, Grid grid)
 {
     bool atBorder = false;
     int count = gridVector.Count;
     for (int i = 0; i < count && !atBorder; ++i)
     {
         int index_i, index_j; grid.Index(gridVector[i], out index_i, out index_j);
         atBorder =
             index_i <= 0 || grid.iCount - 1 <= index_i ||
             index_j <= 0 || grid.jCount - 1 <= index_j;
     }
     return atBorder;
 }
示例#5
0
 public void DrawGrid(Graphics g, Grid grid)
 {
     for (int i = 0; i < grid.iCount; ++i)
       {
     for (int j = 0; j < grid.jCount; ++j)
     {
       if (grid[grid.Index(i, j)] > 0)
       {
     g.FillRectangle(this.filledBrush, i * this.cellSize, j * this.cellSize, this.cellSize, this.cellSize);
       }
     }
       }
 }
示例#6
0
        public void DrawGridVectors(Graphics g, Grid grid, List<List<int>> gridVectors)
        {
            if (gridVectors.Count == 0)
              {
            return;
              }

              Random random = new Random(0);
              for (int i = 0; i < gridVectors.Count - 1; ++i)
              {
            DrawGridVector(g, grid, gridVectors[i], ColorFrom(random, this.filledAlpha));
              }
              DrawGridVectorBorders(g, grid, gridVectors[gridVectors.Count - 1], this.borderColor);
        }
示例#7
0
文件: Utils.cs 项目: Ring-r/sandbox
        private static IEnumerable<bool> Border(Grid grid, int index, List<int> gridVector)
        {
            int iStart; int jStart; grid.Index(index, out iStart, out jStart);

            int iCurr = iStart; int iv = 0;
            int jCurr = jStart; int jv = 1;

            bool isExit = false;
            do
            {
                if (iv == 0)
                {
                    gridVector.Add(grid.Index(iCurr, jCurr));
                }

                int iNext = iCurr + iv; int jNext = jCurr + jv;
                int indexNext = grid.Index(iNext, jNext);
                bool bNext =
                    0 <= iNext && iNext < grid.iCount &&
                    0 <= jNext && jNext < grid.jCount &&
                    grid[indexNext] > 0;

                int iLeft = iNext - jv; int jLeft = jNext + iv;
                int indexLeft = grid.Index(iLeft, jLeft);
                bool bLeft =
                    0 <= iLeft && iLeft < grid.iCount &&
                    0 <= jLeft && jLeft < grid.jCount &&
                    grid[indexLeft] > 0;

                if (bLeft)
                {
                    iCurr = iLeft; jCurr = jLeft;
                    int ib = iv; iv = -jv; jv = ib;
                }
                else if (bNext)
                {
                    iCurr = iNext; jCurr = jNext;
                }
                else
                {
                    int ib = iv; iv = jv; jv = -ib;
                }
                yield return true;
            } while (!(iCurr == iStart && iv == 0 && jCurr == jStart && jv == 1));

            if (isExit)
            {
                gridVector.Clear();
            }
            else
            {
                gridVector.Sort();
                int count = gridVector.Count;
                for (int i = 0; i < count; i += 2)
                {
                    for (int j = gridVector[i]; j <= gridVector[i + 1]; ++j)
                    {
                        grid[j] = 0;
                    }
                }
            }
        }
示例#8
0
文件: Utils.cs 项目: Ring-r/sandbox
 private static int GridClear(Grid grid, List<int> gridVector)
 {
     int gridCount = 0;
     int count = gridVector.Count;
     for (int i = 0; i < count; i += 2)
     {
         for (int j = gridVector[i]; j <= gridVector[i + 1]; j++)
         {
             grid[j] = 0;
         }
     }
     return gridCount;
 }
示例#9
0
文件: Grid.cs 项目: Ring-r/sandbox
 public Grid Copy()
 {
     Grid grid = new Grid(this.iCount, this.jCount);
       Array.Copy(this.cells, grid.cells, this.cellsCount);
       return grid;
 }