+
+ let is_within_bounds t ~r ~k =
+ match t with
+ | [||] -> assert false
+ | t ->
+ r >= 0 && r < Array.length t &&
+ k >= 0 && k < Array.length t.(0)
+
+ let neighborhood t ~r ~k =
+ List.map Direction.all ~f:Direction.to_offset
+ |> List.map ~f:(fun (ro, ko) -> (r + ro), (k + ko))
+ |> List.filter ~f:(fun (r, k) -> is_within_bounds t ~r ~k)
+
+ let get_neighbors t ~r ~k =
+ List.map (neighborhood t ~r ~k) ~f:(fun (r, k) -> get t ~r ~k)