I am using Matrex in the context of AoC for the second year now, and it is not the first time I am confronted with the need to get the neighbours of a given position in the matrix.
That is, given a valid position {x,y}, calculating the list of [{x-1, y-1}, {x-1, y}, {x-1, y+1}, {x, y-1}, {x, y+1}, {x+1, y-1}, {x+1, y}, {x+1, y+1}] (or a subset of this, including only valid points inside the bounds of the matrix, of course).
Would a PR implementing Matrex.neighbours/3 as
@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer())
something that this project would be interested in? If so, I offer to implement such PR.
An alternative would be Matrex.neighbours/4,
@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer(), boolean())
with an optional argument (default true) to consider the diagonals (or not).
I am using Matrex in the context of AoC for the second year now, and it is not the first time I am confronted with the need to get the neighbours of a given position in the matrix.
That is, given a valid position
{x,y}, calculating the list of [{x-1, y-1}, {x-1, y}, {x-1, y+1}, {x, y-1}, {x, y+1}, {x+1, y-1}, {x+1, y}, {x+1, y+1}] (or a subset of this, including only valid points inside the bounds of the matrix, of course).Would a PR implementing
Matrex.neighbours/3as@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer())something that this project would be interested in? If so, I offer to implement such PR.
An alternative would be
Matrex.neighbours/4,@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer(), boolean())with an optional argument (default true) to consider the diagonals (or not).