static Cell Cast(Cell[,] grid, int x, int y, int dX, int dY) { var shape = grid.Shape(); x += dX; y += dY; while ((x, y).WithinRect(shape)) { var c = grid[x, y]; if (c != Cell.FLOOR) { return(c); } x += dX; y += dY; } return(Cell.FLOOR); }