diff --git a/src/utils/functions/chart.ts b/src/utils/functions/chart.ts index e178a73..607e3cd 100644 --- a/src/utils/functions/chart.ts +++ b/src/utils/functions/chart.ts @@ -8,3 +8,12 @@ export const makePointsOptimizator = >( 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)) +}