mirror of
https://github.com/penpot/penpot.git
synced 2025-03-11 07:11:32 -05:00
Add matrix library abstraction.
This commit is contained in:
parent
ee3ed22e2c
commit
4c84fd46da
1 changed files with 40 additions and 0 deletions
40
src/uxbox/matrix.cljs
Normal file
40
src/uxbox/matrix.cljs
Normal file
|
@ -0,0 +1,40 @@
|
|||
(ns uxbox.matrix
|
||||
"A lightweight abstraction over Matrix library
|
||||
of the Google Closure Library."
|
||||
(:import goog.math.Matrix
|
||||
goog.math.Size))
|
||||
|
||||
(extend-type Matrix
|
||||
cljs.core/ICounted
|
||||
(-count [v]
|
||||
(let [^Size size (.getSize v)]
|
||||
(* (.-width size)
|
||||
(.-height size))))
|
||||
|
||||
cljs.core/IDeref
|
||||
(-deref [v]
|
||||
(js->clj (.toArray v)))
|
||||
|
||||
IPrintWithWriter
|
||||
(-pr-writer [v writer _]
|
||||
(->> (str "#goog.math.Matrix " (js->clj (.toArray v)))
|
||||
(cljs.core/-write writer))))
|
||||
|
||||
(defn matrix
|
||||
"Create a matrix instance from coll.
|
||||
The size is determined by the number
|
||||
of elements of the collection."
|
||||
[coll]
|
||||
{:pre [(coll? coll)
|
||||
(coll? (first coll))
|
||||
(= (count coll)
|
||||
(count (first coll)))]}
|
||||
(Matrix. (clj->js coll)))
|
||||
|
||||
(defn multiply
|
||||
([n] n)
|
||||
([n m]
|
||||
(.multiply n m))
|
||||
([n m & more]
|
||||
(reduce multiply (.multiply n m) more)))
|
||||
|
Loading…
Add table
Reference in a new issue