Determines whether each bound is "[" (inclusive) or ")" (exclusive). The default of "[)" includes start but excludes end.
import std.algorithm : equal; assert(RowCol(0,0).span(RowCol(2,3)).equal([ RowCol(0,0), RowCol(0,1), RowCol(0,2), RowCol(1,0), RowCol(1,1), RowCol(1,2)])); assert(RowCol(2,2).span(RowCol(0,0)).equal([ RowCol(2,2), RowCol(2,1), RowCol(1,2), RowCol(1,1)])); assert(RowCol(2,2).span(RowCol(1,3)).equal([RowCol(2,2)])); assert(RowCol(2,2).span(RowCol(3,1)).equal([RowCol(2,2)])); // as the upper bound of span is exclusive, both of these are empty (span over 0 columns): assert(RowCol(2,2).span(RowCol(2,2)).empty); assert(RowCol(2,2).span(RowCol(5,2)).empty);
You can control whether the bounds are inclusive or exclusive
import std.algorithm : equal; assert(RowCol(2,2).span!"[]"(RowCol(2,2)).equal([ RowCol(2,2) ])); assert(RowCol(2,2).span!"[]"(RowCol(2,5)).equal( [ RowCol(2,2), RowCol(2,3), RowCol(2,4), RowCol(2,5) ])); assert(RowCol(5,2).span!"[]"(RowCol(2,2)).equal( [ RowCol(5,2), RowCol(4,2), RowCol(3,2), RowCol(2,2) ])); assert(RowCol(2,2).span!"[]"(RowCol(0,0)).equal([ RowCol(2,2), RowCol(2,1), RowCol(2,0), RowCol(1,2), RowCol(1,1), RowCol(1,0), RowCol(0,2), RowCol(0,1), RowCol(0,0)])); assert(RowCol(2,2).span!"(]"(RowCol(3,3)).equal([ RowCol(3,3) ])); assert(RowCol(2,2).span!"()"(RowCol(3,3)).empty);
std.random.uniform. start = RowCol pair to start enumeration from, inclusive end = RowCol pair to end enumeration at, exclusive
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.