Adds method to-fixed to math

Changes matrix/toString to use `to-fixed`
This commit is contained in:
Aitor 2023-01-12 11:06:55 +01:00 committed by Alonso Torres
parent 57a569a07a
commit 1b7ea6ed53
2 changed files with 13 additions and 17 deletions

View file

@ -27,23 +27,13 @@
^double f] ^double f]
Object Object
(toString [_] (toString [_]
#?(:clj (dm/fmt "matrix(%, %, %, %, %, %)"
(dm/fmt "matrix(%, %, %, %, %, %)" (mth/to-fixed a precision)
(mth/precision a precision) (mth/to-fixed b precision)
(mth/precision b precision) (mth/to-fixed c precision)
(mth/precision c precision) (mth/to-fixed d precision)
(mth/precision d precision) (mth/to-fixed e precision)
(mth/precision e precision) (mth/to-fixed f precision))))
(mth/precision f precision))
:cljs
(dm/fmt "matrix(%, %, %, %, %, %)"
(.toFixed a precision)
(.toFixed b precision)
(.toFixed c precision)
(.toFixed d precision)
(.toFixed e precision)
(.toFixed f precision)))))
(defn matrix? (defn matrix?
"Return true if `v` is Matrix instance." "Return true if `v` is Matrix instance."

View file

@ -127,6 +127,12 @@
(let [d (pow 10 n)] (let [d (pow 10 n)]
(/ (round (* v d)) d)))) (/ (round (* v d)) d))))
(defn to-fixed
"Returns a string representing the given number, using fixed precision."
[v n]
#?(:cljs (.toFixed ^js v n)
:clj (str (precision v n))))
(defn radians (defn radians
"Converts degrees to radians." "Converts degrees to radians."
[degrees] [degrees]