/// <summary>Gets the tile based on its row and column.</summary> public T this[int col, int row] { get { var c = GridType.IsSpheric() ? col.Mod(Cols) : col; var r = GridType.IsSpheric() ? row.Mod(Rows) : row; return(c >= 0 && c < Cols && r >= 0 && r < Rows ? Tiles[Index(c, r)] : null); } }
/// <summary>Initializes a rows * cols sized raster.</summary> protected virtual void Initialize(int cols, int rows) { var neighbors = new SimpleList <Vector>(8); if (GridType.HasFlag(GridType.Horizontal)) { neighbors.Add(Vector.W); neighbors.Add(Vector.E); } if (GridType.HasFlag(GridType.Veritical)) { neighbors.Add(Vector.N); neighbors.Add(Vector.S); } if (GridType.HasFlag(GridType.Diagonal)) { neighbors.Add(Vector.NE); neighbors.Add(Vector.NW); neighbors.Add(Vector.SE); neighbors.Add(Vector.SW); } foreach (var point in Points.Grid(cols, rows)) { var n = GridType.IsSpheric() ? neighbors.Count : neighbors.Select(v => point + v).Count(p => OnGrid(p)); var index = Index(point.X, point.Y); Tiles[index] = Create(index, point.X, point.Y, n); } foreach (var tile in Tiles) { foreach (var position in neighbors.Select(v => tile.Position + v)) { var neighbor = this[position]; if (neighbor is ITile) { tile.Neighbors.Add(neighbor); } } } }