RectGrid.maskTilesAround

Same as maskTiles, but centered.

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

Parameters

center
Type: 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
Type: 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:

1 import std.array : empty;
2 import std.algorithm : equal;
3 
4 auto myGrid = rectGrid([
5   [ 00, 01, 02, 03, 04 ],
6   [ 10, 11, 12, 13, 14 ],
7   [ 20, 21, 22, 23, 24 ],
8 ]);
9 
10 uint[3][3] mask1 = [
11   [ 1, 1, 1 ],
12   [ 0, 0, 0 ],
13     [ 0, 0, 0 ],
14 ];
15 assert(myGrid.maskTilesAround(RowCol(0,0), mask1).empty);
16 assert(myGrid.maskTilesAround(RowCol(1,1), mask1).equal([00, 01, 02]));
17 assert(myGrid.maskTilesAround(RowCol(2,1), mask1).equal([10, 11, 12]));
18 assert(myGrid.maskTilesAround(RowCol(2,4), mask1).equal([13, 14]));
19 
20 auto mask2 = [
21   [ 0, 0, 1 ],
22   [ 0, 0, 1 ],
23   [ 1, 1, 1 ],
24 ];
25 assert(myGrid.maskTilesAround(RowCol(0,0), mask2).equal([01, 10, 11]));
26 assert(myGrid.maskTilesAround(RowCol(1,2), mask2).equal([03, 13, 21, 22, 23]));
27 assert(myGrid.maskTilesAround(RowCol(2,4), mask2).empty);
28 
29 auto mask3 = [
30   [ 0 , 0 , 1 , 0 , 0 ],
31   [ 1 , 0 , 1 , 0 , 1 ],
32   [ 0 , 0 , 0 , 0 , 0 ],
33 ];
34 assert(myGrid.maskTilesAround(RowCol(0,0), mask3).equal([00, 02]));
35 assert(myGrid.maskTilesAround(RowCol(1,2), mask3).equal([02, 10, 12, 14]));
36 
37 auto mask4 = [
38   [ 1 , 1 , 1 , 0 , 1 ],
39 ];
40 assert(myGrid.maskTilesAround(RowCol(0,0), mask4).equal([00, 02]));
41 assert(myGrid.maskTilesAround(RowCol(2,2), mask4).equal([20, 21, 22, 24]));
42 
43 auto mask5 = [
44   [ 1 ],
45   [ 1 ],
46   [ 0 ],
47   [ 1 ],
48   [ 1 ],
49 ];
50 assert(myGrid.maskTilesAround(RowCol(0,4), mask5).equal([14, 24]));
51 assert(myGrid.maskTilesAround(RowCol(1,1), mask5).equal([01, 21]));

Meta