B:BD[
3.698] → [
3.698:789]
pub fn Grid(comptime T: type, comptime GRID_ROWS: usize, comptime GRID_COLS: usize) type {
pub const D2Neighbour = enum {
horizontal,
vertical,
HV,
diagonal,
all,
};
const horizontal = [_][2]isize{ .{ 0, -1 }, .{ 0, 1 } };
const vertical = [_][2]isize{ .{ -1, 0 }, .{ 1, 0 } };
const HV = horizontal ++ vertical;
const diagonal = [_][2]isize{ .{ -1, -1 }, .{ -1, 1 }, .{ 1, -1 }, .{ 1, 1 } };
const all = HV ++ diagonal;
pub fn Grid(comptime T: type, comptime GRID_ROWS: usize, comptime GRID_COLS: usize, dir: anytype) type {
const dir_slice: [][]isize = blk: {
var dir_array = switch (@typeInfo(@TypeOf(dir))) {
.EnumLiteral, .Enum => switch (std.enums.nameCast(D2Neighbour, dir)) {
.horizontal => horizontal,
.vertical => vertical,
.HV => HV,
.diagonal => diagonal,
.all => all,
},
else => dir,
};
var ret: [dir_array.len][]isize = undefined;
for (dir_array) |*sub_array_ptr, idx| ret[idx] = sub_array_ptr;
break :blk ret[0..];
};