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; // }