From e22927530d8d1587c2cce498ee0ca47bb16cc720 Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 11 Jul 2022 12:45:37 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=80=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B5=D0=B6=D0=B4?= =?UTF-8?q?=D1=83=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20=D1=81=20=D1=82=D0=B8=D0=BF=D0=BE=D0=BC=20?= =?UTF-8?q?=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/functions/chart.ts | 9 +++++++++ 1 file changed, 9 insertions(+) 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)) +}