0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Improve point transformation helpers.

This commit is contained in:
Andrey Antukh 2016-12-20 17:04:18 +01:00
parent aed1b8cd26
commit 462f37e601
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -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))))