matrex icon indicating copy to clipboard operation
matrex copied to clipboard

Retrieve neighbours

Open lauramcastro opened this issue 3 years ago • 1 comments

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).

lauramcastro avatar Dec 09 '21 11:12 lauramcastro

This would be very much appreciated! I'm currently using matrex for the same purpose. Sadly it seems that this excellent library does not get a lot of love in general any more.

MLNW avatar Dec 08 '22 06:12 MLNW