RowCol.adjacent

Return a range containing the coords adjacent to this coord.

The returned coords are ordered from north to south, west to east.

struct RowCol
@property
adjacent

Parameters

diagonal
Type: Diagonals

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

Examples

convenient access of nearby coordinates

1 import std.algorithm : equal;
2 
3 assert(RowCol(1,1).north == RowCol(0,1));
4 assert(RowCol(1,1).south == RowCol(2,1));
5 assert(RowCol(1,1).east  == RowCol(1,2));
6 assert(RowCol(1,1).west  == RowCol(1,0));
7 
8 assert(RowCol(1,1).south(5)         == RowCol(6,1));
9 assert(RowCol(1,1).south(2).east(5) == RowCol(3,6));
10 
11 assert(RowCol(1,1).adjacent.equal([
12   RowCol(0,1),
13   RowCol(1,0),
14   RowCol(1,2),
15   RowCol(2,1)
16 ]));
17 
18 assert(RowCol(1,1).adjacent(Diagonals.yes).equal([
19   RowCol(0,0),
20   RowCol(0,1),
21   RowCol(0,2),
22   RowCol(1,0),
23   RowCol(1,2),
24   RowCol(2,0),
25   RowCol(2,1),
26   RowCol(2,2)
27 ]));

Meta