Добавлен метод получения расстояния между координатами с типом сравнения

This commit is contained in:
goodmice 2022-07-11 12:45:37 +05:00
parent 8cbfb3d903
commit e22927530d

View File

@ -8,3 +8,12 @@ export const makePointsOptimizator = <DataType extends Record<string, unknown>>(
return [points[0], ...out, points[points.length - 1]]
}
export type TouchType = 'all' | 'x' | 'y'
export const getDistance = (x1: number, y1: number, x2: number, y2: number, type: TouchType = 'all') => {
if (type === 'x') return Math.abs(x1 - x2)
if (type === 'y') return Math.abs(y1 - y2)
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2))
}