From 462f37e601cabe4ce3b513ea3519944a25a964e0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 20 Dec 2016 17:04:18 +0100 Subject: [PATCH] Improve point transformation helpers. --- frontend/src/uxbox/util/geom/point.cljs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/uxbox/util/geom/point.cljs b/frontend/src/uxbox/util/geom/point.cljs index f5258bbf71..b2c05325ec 100644 --- a/frontend/src/uxbox/util/geom/point.cljs +++ b/frontend/src/uxbox/util/geom/point.cljs @@ -94,6 +94,12 @@ (Point. (/ (:x p) (:x other)) (/ (:y p) (:y other))))) +(defn negate + [p] + {:pre [(point? p)]} + (let [{:keys [x y]} (-point p)] + (Point. (- x) (- y)))) + (defn distance "Calculate the distance between two points." [p other] @@ -161,7 +167,7 @@ (defn transform "Transform a point applying a matrix transfomation." - [{:keys [x y] :as p} {:keys [a b c d tx ty] :as m}] - (Point. (+ (* x a) (* y c) tx) - (+ (* x b) (* y d) ty))) - + [pt {:keys [a b c d tx ty] :as m}] + (let [{:keys [x y]} (point pt)] + (Point. (+ (* x a) (* y c) tx) + (+ (* x b) (* y d) ty))))