span

Enumerate all row/col pairs spanning the rectangle bounded by the corners start and end.

The order of enumeration is determined as follows: Enumerate all columns in a row before moving to the next row. If start.row >= end.row, enumerate rows in increasing order, otherwise enumerate in decreasing. If start.col >= end.col, enumerate cols in increasing order, otherwise enumerate in decreasing.

  1. auto span(RowCol start, RowCol end)
    span
    (
    string bound = "[)"
    )
  2. auto span(RowCol start, coord_t endRow, coord_t endCol)

Parameters

bound

Determines whether each bound is "[" (inclusive) or ")" (exclusive). The default of "[)" includes start but excludes end.

Examples

1 import std.algorithm : equal;
2 
3 assert(RowCol(0,0).span(RowCol(2,3)).equal([
4   RowCol(0,0), RowCol(0,1), RowCol(0,2),
5   RowCol(1,0), RowCol(1,1), RowCol(1,2)]));
6 
7 assert(RowCol(2,2).span(RowCol(0,0)).equal([
8   RowCol(2,2), RowCol(2,1),
9   RowCol(1,2), RowCol(1,1)]));
10 
11 assert(RowCol(2,2).span(RowCol(1,3)).equal([RowCol(2,2)]));
12 
13 assert(RowCol(2,2).span(RowCol(3,1)).equal([RowCol(2,2)]));
14 
15 // as the upper bound of span is exclusive, both of these are empty (span over 0 columns):
16 assert(RowCol(2,2).span(RowCol(2,2)).empty);
17 assert(RowCol(2,2).span(RowCol(5,2)).empty);

You can control whether the bounds are inclusive or exclusive

1 import std.algorithm : equal;
2 assert(RowCol(2,2).span!"[]"(RowCol(2,2)).equal([ RowCol(2,2) ]));
3 
4 assert(RowCol(2,2).span!"[]"(RowCol(2,5)).equal(
5       [ RowCol(2,2), RowCol(2,3), RowCol(2,4), RowCol(2,5) ]));
6 
7 assert(RowCol(5,2).span!"[]"(RowCol(2,2)).equal(
8       [ RowCol(5,2), RowCol(4,2), RowCol(3,2), RowCol(2,2) ]));
9 
10 assert(RowCol(2,2).span!"[]"(RowCol(0,0)).equal([
11       RowCol(2,2), RowCol(2,1), RowCol(2,0),
12       RowCol(1,2), RowCol(1,1), RowCol(1,0),
13       RowCol(0,2), RowCol(0,1), RowCol(0,0)]));
14 
15 assert(RowCol(2,2).span!"(]"(RowCol(3,3)).equal([ RowCol(3,3) ]));
16 
17 assert(RowCol(2,2).span!"()"(RowCol(3,3)).empty);

See Also

std.random.uniform. start = RowCol pair to start enumeration from, inclusive end = RowCol pair to end enumeration at, exclusive

Meta