Function RowCol.adjacent

Return a range containing the coords adjacent to this coord.

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

Prototype

auto std.range.chain!(std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult,std.range.OnlyResult!(dtiled.coords.RowCol,1L).OnlyResult) adjacent(
  std.typecons.Flag!("Diagonals") diagonal = cast(Flag)false
) @property;

Parameters

NameDescription
diagonal if no, include coords to the north, south, east, and west only. if yes, additionaly include northwest, northeast, southwest, and southeast. Get a string representation of the coordinate, useful for debugging

Example

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)
]));

Authors

Copyright

License