mirror of
https://github.com/penpot/penpot.git
synced 2025-06-04 03:32:36 +02:00
Add the ability to invert matrix.
This commit is contained in:
parent
0dff98801c
commit
d9a5c06106
1 changed files with 18 additions and 0 deletions
|
@ -123,3 +123,21 @@
|
||||||
(+ ty1 (* tx2 c1) (* ty2 d1)))))
|
(+ ty1 (* tx2 c1) (* ty2 d1)))))
|
||||||
([m om & others]
|
([m om & others]
|
||||||
(reduce append (append m om) others)))
|
(reduce append (append m om) others)))
|
||||||
|
|
||||||
|
(defn ^boolean invertible?
|
||||||
|
[{:keys [a b c d tx ty] :as m}]
|
||||||
|
(let [det (- (* a d) (* c b))]
|
||||||
|
(and (not (mth/nan? det))
|
||||||
|
(mth/finite? tx)
|
||||||
|
(mth/finite? ty))))
|
||||||
|
|
||||||
|
(defn invert
|
||||||
|
[{:keys [a b c d tx ty] :as m}]
|
||||||
|
(when (invertible? m)
|
||||||
|
(let [det (- (* a d) (* c b))]
|
||||||
|
(Matrix. (/ d det)
|
||||||
|
(/ (- b) det)
|
||||||
|
(/ (- c) det)
|
||||||
|
(/ a det)
|
||||||
|
(/ (- (* c ty) (* d tx)) det)
|
||||||
|
(/ (- (* b tx) (* a ty)) det)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue