From 4c5e847b1153e17d3f462b2bdc356af36c60c079 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 5 Apr 2016 17:57:16 +0300 Subject: [PATCH] Add point-transform and multiply functions. --- src/uxbox/util/geom/point.cljs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/uxbox/util/geom/point.cljs b/src/uxbox/util/geom/point.cljs index af450f6e61..ff82a05db9 100644 --- a/src/uxbox/util/geom/point.cljs +++ b/src/uxbox/util/geom/point.cljs @@ -76,10 +76,19 @@ (Point. (- (:x p) (:x other)) (- (:y p) (:y other))))) + +(defn multiply + "Returns the subtraction of the supplied value to both + coordinates of the point as a new point." + [p other] + {:pre [(point? p)]} + (let [other (-point other)] + (Point. (* (:x p) (:x other)) + (* (:y p) (:y other))))) + (defn distance "Calculate the distance between two points." [p other] - {:pre [(point? p)]} (let [other (-point other) dx (- (:x p) (:x other)) dy (- (:y p) (:y other))] @@ -135,3 +144,13 @@ (if (>= x 0) (if (>= y 0) 1 4) (if (>= y 0) 2 3))) + +(defn transform-point + [pt mx] + (let [other (-point other)] + (Point. (+ (* (:x pt) (:a mx)) + (* (:y pt) (:c mx)) + (:tx mx)) + (+ (* (:x pt) (:b mx)) + (* (:y pt) (:d mx)) + (:ty mx)))))