RectGrid.adjacentTiles

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

struct RectGrid(T)
adjacentTiles
if (
isArray2D!T
)

Parameters

coord
Type: RowCol

grid location of center tile.

diagonals
Type: Diagonals

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

Examples

1 import std.algorithm : equal;
2 auto myGrid = rectGrid([
3   [ 00, 01, 02, 03, 04 ],
4   [ 10, 11, 12, 13, 14 ],
5   [ 20, 21, 22, 23, 24 ],
6 ]);
7 
8 assert(myGrid.adjacentTiles(RowCol(0,0)).equal([01, 10]));
9 assert(myGrid.adjacentTiles(RowCol(1,1)).equal([01, 10, 12, 21]));
10 assert(myGrid.adjacentTiles(RowCol(2,2)).equal([12, 21, 23]));
11 assert(myGrid.adjacentTiles(RowCol(2,4)).equal([14, 23]));
12 
13 assert(myGrid.adjacentTiles(RowCol(0,0), Diagonals.yes)
14     .equal([01, 10, 11]));
15 assert(myGrid.adjacentTiles(RowCol(1,1), Diagonals.yes)
16     .equal([00, 01, 02, 10, 12, 20, 21, 22]));
17 assert(myGrid.adjacentTiles(RowCol(2,2), Diagonals.yes)
18     .equal([11, 12, 13, 21, 23]));
19 assert(myGrid.adjacentTiles(RowCol(2,4), Diagonals.yes)
20     .equal([13, 14, 23]));

Meta