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.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
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;
|
|
}
|
|
// export function toGetClosestPoint(
|
|
// x1: number,
|
|
// y1: number,
|
|
// x2: number,
|
|
// y2: number,
|
|
// sx: number,
|
|
// sy: number,
|
|
// ) {
|
|
// let direction: Direction = "" as Direction;
|
|
|
|
// if (sy > y2) direction += "N"
|
|
// if (sy < y1) direction += "S";
|
|
// if (sx < x1) direction += "W"
|
|
// if (sx > x2) direction += "E"
|
|
|
|
// return direction;
|
|
// }
|