@2d-game-grid/square
Version:
A simple square grid made for games
15 lines (14 loc) • 510 B
JavaScript
import { euclideanDistance } from './euclideanDistance.js';
import { manhattanDistance } from './manhattanDistance.js';
/**
* @param start The start coordinate
* @param end The end coordinate
* @param algorithm The algorithm that should be used for the distance calculation
* @returns The distance between the given coordinates
*/
export function getDistance(start, end, algorithm) {
return {
EUCLIDEAN: euclideanDistance,
MANHATTAN: manhattanDistance,
}[algorithm](start, end);
}