mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 15:01:39 +02:00
Improve point transformation helpers.
This commit is contained in:
parent
aed1b8cd26
commit
462f37e601
1 changed files with 10 additions and 4 deletions
|
@ -94,6 +94,12 @@
|
||||||
(Point. (/ (:x p) (:x other))
|
(Point. (/ (:x p) (:x other))
|
||||||
(/ (:y p) (:y other)))))
|
(/ (:y p) (:y other)))))
|
||||||
|
|
||||||
|
(defn negate
|
||||||
|
[p]
|
||||||
|
{:pre [(point? p)]}
|
||||||
|
(let [{:keys [x y]} (-point p)]
|
||||||
|
(Point. (- x) (- y))))
|
||||||
|
|
||||||
(defn distance
|
(defn distance
|
||||||
"Calculate the distance between two points."
|
"Calculate the distance between two points."
|
||||||
[p other]
|
[p other]
|
||||||
|
@ -161,7 +167,7 @@
|
||||||
|
|
||||||
(defn transform
|
(defn transform
|
||||||
"Transform a point applying a matrix transfomation."
|
"Transform a point applying a matrix transfomation."
|
||||||
[{:keys [x y] :as p} {:keys [a b c d tx ty] :as m}]
|
[pt {:keys [a b c d tx ty] :as m}]
|
||||||
|
(let [{:keys [x y]} (point pt)]
|
||||||
(Point. (+ (* x a) (* y c) tx)
|
(Point. (+ (* x a) (* y c) tx)
|
||||||
(+ (* x b) (* y d) ty)))
|
(+ (* x b) (* y d) ty))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue