public CellEnumerator(LeapGrid grid) { this.grid = grid; this.idx = -1; this.cellWidth = grid.rect.radii.x * 2f / grid.numCols; this.cellHeight = grid.rect.radii.y * 2f / grid.numRows; _useSubGrid = false; _col0 = 0; _col1 = 0; _lastIndex = grid.numCells - 1; }
/// <summary> Initializes a CellEnumerator that enumerates cells within /// the rectangular subgrid defined by cell indices at two opposite /// corners of the subgrid. </summary> public CellEnumerator(LeapGrid grid, int subGridBegin, int subGridEnd) : this(grid) { int idx0 = subGridBegin, idx1 = subGridEnd; int row0 = grid.getRow(idx0), row1 = grid.getRow(idx1); if (row0 > row1) { Utils.Swap(ref row0, ref row1); } int col0 = grid.getCol(idx0), col1 = grid.getCol(idx1); if (col0 > col1) { Utils.Swap(ref col0, ref col1); } _col0 = col0; _col1 = col1; _lastIndex = Mathf.Max(subGridBegin, subGridEnd); idx = grid.getIndex(row0, col0) - 1; _useSubGrid = true; }