blob: 6f19367da3e4e85f9360b75f5bac2542843f822e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
export enum Direction {
UP = "UP",
DOWN = "DOWN",
LEFT = "LEFT",
RIGHT = "RIGHT",
NONE = "NONE",
}
export const angleToDirection = (angle: number): Direction => {
if (angle >= -Math.PI / 4 && angle < Math.PI / 4) {
return Direction.RIGHT;
} else if (angle >= Math.PI / 4 && angle < (3 * Math.PI) / 4) {
return Direction.DOWN;
} else if (angle >= (3 * Math.PI) / 4 || angle < -(3 * Math.PI) / 4) {
return Direction.LEFT;
} else {
return Direction.UP;
}
};
|