RowCol.adjacent

Return a range containing the coords adjacent to this coord.

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

Parameters

diagonal 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

import std.algorithm : equal;

assert(RowCol(1,1).north == RowCol(0,1));
assert(RowCol(1,1).south == RowCol(2,1));
assert(RowCol(1,1).east  == RowCol(1,2));
assert(RowCol(1,1).west  == RowCol(1,0));

assert(RowCol(1,1).south(5)         == RowCol(6,1));
assert(RowCol(1,1).south(2).east(5) == RowCol(3,6));

assert(RowCol(1,1).adjacent.equal([
  RowCol(0,1),
  RowCol(1,0),
  RowCol(1,2),
  RowCol(2,1)
]));

assert(RowCol(1,1).adjacent(Diagonals.yes).equal([
  RowCol(0,0),
  RowCol(0,1),
  RowCol(0,2),
  RowCol(1,0),
  RowCol(1,2),
  RowCol(2,0),
  RowCol(2,1),
  RowCol(2,2)
]));

Meta