RectGrid.adjacentTiles

Return all tiles adjacent to the tile at the given coord (not including the tile itself).

struct RectGrid(T)
adjacentTiles

Parameters

coord RowCol

grid location of center tile.

diagonals Diagonals

if no, include tiles to the north, south, east, and west only. if yes, also include northwest, northeast, southwest, and southeast.

Examples

import std.algorithm : equal;
auto myGrid = rectGrid([
  [ 00, 01, 02, 03, 04 ],
  [ 10, 11, 12, 13, 14 ],
  [ 20, 21, 22, 23, 24 ],
]);

assert(myGrid.adjacentTiles(RowCol(0,0)).equal([01, 10]));
assert(myGrid.adjacentTiles(RowCol(1,1)).equal([01, 10, 12, 21]));
assert(myGrid.adjacentTiles(RowCol(2,2)).equal([12, 21, 23]));
assert(myGrid.adjacentTiles(RowCol(2,4)).equal([14, 23]));

assert(myGrid.adjacentTiles(RowCol(0,0), Diagonals.yes)
    .equal([01, 10, 11]));
assert(myGrid.adjacentTiles(RowCol(1,1), Diagonals.yes)
    .equal([00, 01, 02, 10, 12, 20, 21, 22]));
assert(myGrid.adjacentTiles(RowCol(2,2), Diagonals.yes)
    .equal([11, 12, 13, 21, 23]));
assert(myGrid.adjacentTiles(RowCol(2,4), Diagonals.yes)
    .equal([13, 14, 23]));

Meta