RectGrid.maskTilesAround

Same as maskTiles, but centered.

struct RectGrid(T)
maskTilesAround
(
T
)
if (
isValidMask!T
)

Parameters

center RowCol

map coord on which to position the center of the mask. if the mask has an even side length, rounds down to compute the 'center'

mask T

a rectangular array of true/false values indicating which tiles to take. each true value takes the tile at that grid coordinate. the mask should be in row major order (indexed as maskrowcol).

Examples

More masking examples:

import std.array : empty;
import std.algorithm : equal;

auto myGrid = rectGrid([
  [ 00, 01, 02, 03, 04 ],
  [ 10, 11, 12, 13, 14 ],
  [ 20, 21, 22, 23, 24 ],
]);

uint[3][3] mask1 = [
  [ 1, 1, 1 ],
  [ 0, 0, 0 ],
    [ 0, 0, 0 ],
];
assert(myGrid.maskTilesAround(RowCol(0,0), mask1).empty);
assert(myGrid.maskTilesAround(RowCol(1,1), mask1).equal([00, 01, 02]));
assert(myGrid.maskTilesAround(RowCol(2,1), mask1).equal([10, 11, 12]));
assert(myGrid.maskTilesAround(RowCol(2,4), mask1).equal([13, 14]));

auto mask2 = [
  [ 0, 0, 1 ],
  [ 0, 0, 1 ],
  [ 1, 1, 1 ],
];
assert(myGrid.maskTilesAround(RowCol(0,0), mask2).equal([01, 10, 11]));
assert(myGrid.maskTilesAround(RowCol(1,2), mask2).equal([03, 13, 21, 22, 23]));
assert(myGrid.maskTilesAround(RowCol(2,4), mask2).empty);

auto mask3 = [
  [ 0 , 0 , 1 , 0 , 0 ],
  [ 1 , 0 , 1 , 0 , 1 ],
  [ 0 , 0 , 0 , 0 , 0 ],
];
assert(myGrid.maskTilesAround(RowCol(0,0), mask3).equal([00, 02]));
assert(myGrid.maskTilesAround(RowCol(1,2), mask3).equal([02, 10, 12, 14]));

auto mask4 = [
  [ 1 , 1 , 1 , 0 , 1 ],
];
assert(myGrid.maskTilesAround(RowCol(0,0), mask4).equal([00, 02]));
assert(myGrid.maskTilesAround(RowCol(2,2), mask4).equal([20, 21, 22, 24]));

auto mask5 = [
  [ 1 ],
  [ 1 ],
  [ 0 ],
  [ 1 ],
  [ 1 ],
];
assert(myGrid.maskTilesAround(RowCol(0,4), mask5).equal([14, 24]));
assert(myGrid.maskTilesAround(RowCol(1,1), mask5).equal([01, 21]));

Meta