From 36f1690120abbb1d38781569cfdb3b8157c3c1a5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 30 Jan 2016 20:18:51 +0200 Subject: [PATCH] Add distance function to math ns. --- src/uxbox/util/math.cljs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/uxbox/util/math.cljs b/src/uxbox/util/math.cljs index ecea5997d..fc34cdc1b 100644 --- a/src/uxbox/util/math.cljs +++ b/src/uxbox/util/math.cljs @@ -67,3 +67,11 @@ "Converts radians to degrees." [^number radiants] (math/toDegrees radiants)) + +(defn distance + "Calculate the distance between two points." + [[x1 y1] [x2 y2]] + (let [dx (- x1 x2) + dy (- y1 y2)] + (-> (sqrt (+ (pow dx 2) (pow dy 2))) + (precision 2))))