🚀 refactor get available routes

This commit is contained in:
platane
2020-09-29 10:34:12 +02:00
committed by Platane
parent 2499529b1d
commit 8d8956229c
15 changed files with 190 additions and 454 deletions

View File

@@ -3,7 +3,7 @@ export type Color = number;
export type Grid = {
width: number;
height: number;
data: (Color | null)[];
data: Uint8Array;
};
export const getIndex = (grid: Grid, x: number, y: number) =>
@@ -18,7 +18,11 @@ export const isInsideLarge = (grid: Grid, m: number, x: number, y: number) =>
export const getColor = (grid: Grid, x: number, y: number) =>
grid.data[getIndex(grid, x, y)];
export const copyGrid = (grid: Grid) => ({ ...grid, data: grid.data.slice() });
export const copyGrid = ({ width, height, data }: Grid) => ({
width,
height,
data: Uint8Array.from(data),
});
export const setColor = (
grid: Grid,
@@ -26,11 +30,11 @@ export const setColor = (
y: number,
color: Color | null
) => {
grid.data[getIndex(grid, x, y)] = color;
grid.data[getIndex(grid, x, y)] = color || 0;
};
export const createEmptyGrid = (width: number, height: number) => ({
width,
height,
data: Array.from({ length: width * height }, () => null),
data: new Uint8Array(width * height),
});