You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
675 B
TypeScript
25 lines
675 B
TypeScript
type Direction = "N" | "E" | "S" | "W" | "NW" | "NE" | "SW" | "SE";
|
|
export function toGetClosestPoint(
|
|
x1: number,
|
|
y1: number,
|
|
x2: number,
|
|
y2: number,
|
|
sx: number,
|
|
sy: number,
|
|
) {
|
|
let direction: Direction = "" as Direction;
|
|
|
|
if (sx >= x1 && sx <= x2 && sy >= y2) direction = "N";
|
|
if (sx >= x2 && sy <= y2 && sy >= y1) direction = "E";
|
|
if (sx >= x1 && sx <= x2 && sy <= y1) direction = "S";
|
|
if (sx <= x1 && sy <= y2 && sy >= y1) direction = "W";
|
|
|
|
if (sx <= x1 && sy >= y2) direction = "NW";
|
|
if (sx >= x2 && sy >= y2) direction = "NE";
|
|
|
|
if (sx <= x1 && sy <= y1) direction = "SW";
|
|
if (sx >= x2 && sy <= y1) direction = "SE";
|
|
|
|
return direction;
|
|
}
|