🚀 refactor get available routes
This commit is contained in:
@@ -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),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user