forked from ddrilling/asb_cloud_front
Добавлен метод получения расстояния между координатами с типом сравнения
This commit is contained in:
parent
8cbfb3d903
commit
e22927530d
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user