forEachNeighbor8 method
Calls visit for each 8-connected neighbor index without allocating.
Implementation
@pragma('vm:prefer-inline')
void forEachNeighbor8(int idx, void Function(int neighborIdx) visit) {
final up = hasNeighborUp(idx);
final down = hasNeighborDown(idx);
final left = hasNeighborLeft(idx);
final right = hasNeighborRight(idx);
if (up) visit(idx - width);
if (down) visit(idx + width);
if (left) visit(idx - 1);
if (right) visit(idx + 1);
if (up && left) visit(idx - width - 1);
if (up && right) visit(idx - width + 1);
if (down && left) visit(idx + width - 1);
if (down && right) visit(idx + width + 1);
}