public static IEnumerable <Vector2D> Positions <T>(this IPersistentGrid <T> grid) { foreach (var x in Enumerable.Range(0, grid.Width)) { foreach (var y in Enumerable.Range(0, grid.Height)) { yield return(new Vector2D(x, y)); } } }
public static Vector2D FindPosition <T>(this IPersistentGrid <T> grid, Func <T, bool> predicate) { foreach (var position in grid.Positions()) { if (predicate(grid[position])) { return(position); } } return(null); }
public static IPersistentGrid <T> Update <T>(this IPersistentGrid <T> grid, Vector2D position, Func <T, T> updater) { return(grid.Set(position, updater(grid[position]))); }
public static IPersistentGrid <U> Map <T, U>(this IPersistentGrid <T> grid, Func <T, U> mapper) { return(new PersistentGrid <U>(grid.Width, grid.Height, p => mapper(grid[p]))); }
public static bool IsValidPosition <T>(this IPersistentGrid <T> grid, Vector2D position) { return(0 <= position.X && position.X < grid.Width && 0 <= position.Y && position.Y < grid.Height); }