Computes 4- or 8-direction neighbour pairs (from, to) for every input cell and filters out neighbours that fall off the raster top/bottom or wrap across left/right edges. Returns a 2-column integer matrix with column names "from" and "to". Equivalent to adj(..., pairs = TRUE) but without the data.table allocation/coercion overhead.

adjPairsMatrix(cells, numCol, numCell, directions, state = NULL)

Arguments

cells

integer vector of source cell indices (1-based)

numCol

integer; number of raster columns

numCell

integer; total number of raster cells

directions

integer; either 4 or 8

state

Optional integer vector of length numCell giving the state of every cell, where 0 means "not yet spread to". When supplied, neighbours whose state is non-zero are dropped, in the same pass that builds the pairs, so the caller does not have to build and subset a bigger matrix.

Value

A 2-column integer matrix with columns named from and to.