23 lines
595 B
TypeScript
23 lines
595 B
TypeScript
/**
|
|
* Calculates the Euclidean distance between two coordinate points.
|
|
* Coordinates are [x, y] pairs (map units).
|
|
*/
|
|
export function calculateDistance(
|
|
coord1: [number, number],
|
|
coord2: [number, number],
|
|
): number {
|
|
const [x1, y1] = coord1;
|
|
const [x2, y2] = coord2;
|
|
return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2);
|
|
}
|
|
|
|
/**
|
|
* Checks if two coordinates are within a given proximity threshold.
|
|
*/
|
|
export function isWithinProximity(
|
|
coord1: [number, number],
|
|
coord2: [number, number],
|
|
threshold: number,
|
|
): boolean {
|
|
return calculateDistance(coord1, coord2) <= threshold;
|
|
}
|