Skip to content

Commit ecdf83a

Browse files
committed
refactor to-fixed
1 parent 7e6fd2e commit ecdf83a

File tree

18 files changed

+74
-45
lines changed

18 files changed

+74
-45
lines changed

.clj-kondo/config.edn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
:aliased-namespace-symbol {:level :warning}
66
:condition-always-true {:level :warning}
77
:docstring-leading-trailing-whitespace {:level :warning}
8-
:equals-float {:level :warning}
98
:def-fn {:level :warning}
109
:reduce-without-init {:level :warning}
1110
:keyword-binding {:level :warning}

src/renderer/app/views.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,20 @@
3333
[renderer.toolbar.status :as toolbar.status]
3434
[renderer.toolbar.tools :as toolbar.tools]
3535
[renderer.tree.views :as tree.views]
36+
[renderer.utils.length :as utils.length]
3637
[renderer.views :as views]
3738
[renderer.window.views :as window.views]))
3839

3940
(defn coll->str
4041
[coll]
41-
(str "[" (string/join " " (map #(.toFixed % 2) coll)) "]"))
42+
(str "[" (string/join " " (map utils.length/to-fixed coll)) "]"))
4243

4344
(defn map->str
4445
[m]
4546
(interpose ", " (map (fn [[k v]]
4647
^{:key k}
4748
[:span (str (name k) ": " (if (number? v)
48-
(.toFixed v 3)
49+
(utils.length/to-fixed v)
4950
(coll->str v)))]) m)))
5051

5152
(defn debug-rows

src/renderer/element/impl/custom/brush.cljs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@
8282
b (nth points 1)
8383
c (nth points 2)
8484
d (str
85-
"M" (.toFixed (first a) 2) "," (.toFixed (second a) 2)
86-
" Q" (.toFixed (first b) 2) "," (.toFixed (second b) 2)
87-
" " (.toFixed (matrix.stats/mean [(first b) (first c)]) 2) ","
88-
(.toFixed (matrix.stats/mean [(second b) (second c)]) 2) " T")]
85+
"M" (utils.length/to-fixed (first a)) "," (utils.length/to-fixed (second a))
86+
" Q" (utils.length/to-fixed (first b)) "," (utils.length/to-fixed (second b))
87+
" " (utils.length/to-fixed (matrix.stats/mean [(first b) (first c)])) ","
88+
(utils.length/to-fixed (matrix.stats/mean [(second b) (second c)])) " T")]
8989
(reduce-kv
9090
(fn [result index]
9191
(if (or (= len (inc index)) (< index 2))
9292
result
9393
(let [a (nth points index)
9494
b (nth points (inc index))]
9595
(str result
96-
(.toFixed (matrix.stats/mean [(first a) (first b)]) 2)
96+
(utils.length/to-fixed (matrix.stats/mean [(first a) (first b)]))
9797
","
98-
(.toFixed (matrix.stats/mean [(second a) (second b)]) 2)
98+
(utils.length/to-fixed (matrix.stats/mean [(second a) (second b)]))
9999
" ")))) d points)))))
100100

101101
(def partition-to-px

src/renderer/element/impl/shape/circle.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
r (/ (first (utils.bounds/->dimensions bbox)) 2)]
7878
[:g
7979
[utils.svg/line [cx cy] [(+ cx r) cy]]
80-
[utils.svg/label (str (.toFixed r 3)) [(+ cx (/ r 2)) cy]]
80+
[utils.svg/label (str (utils.length/to-fixed r)) [(+ cx (/ r 2)) cy]]
8181
[utils.svg/times [cx cy]]
8282
[tool.views/square-handle {:x (+ cx r)
8383
:y cy

src/renderer/element/impl/shape/ellipse.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
[:g ::edit-handles
8585
[utils.svg/times [cx cy]]
8686
[utils.svg/line [cx cy] [(+ cx rx) cy]]
87-
[utils.svg/label (str (.toFixed rx 3)) [(+ cx (/ rx 2)) cy]]
87+
[utils.svg/label (str (utils.length/to-fixed rx)) [(+ cx (/ rx 2)) cy]]
8888
[utils.svg/line [cx cy] [cx (- cy ry)]]
89-
[utils.svg/label (str (.toFixed ry 3)) [cx (- cy (/ ry 2))]]
89+
[utils.svg/label (str (utils.length/to-fixed ry)) [cx (- cy (/ ry 2))]]
9090
(map (fn [handle]
9191
^{:key (:id handle)}
9292
[tool.views/square-handle

src/renderer/element/impl/shape/line.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
[:title {:key (str id "-title")} (name id)]]
7373
(when is-active
7474
[utils.svg/label
75-
(string/join " " [(.toFixed x 3) (.toFixed y 3)])
75+
(string/join " " [(utils.length/to-fixed x) (utils.length/to-fixed y)])
7676
[(- x margin) (+ y margin)]
7777
"end"])]))
7878
[{:x x1

src/renderer/element/impl/shape/polyshape.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
:element (:id el)}]
8484
(when is-active
8585
[utils.svg/label
86-
(string/join " " [(.toFixed x 3) (.toFixed y 3)])
86+
(->> [(utils.length/to-fixed x) (utils.length/to-fixed y)]
87+
(string/join " "))
8788
[(- x margin) (+ y margin)]
8889
"end"])]))
8990
(utils.attribute/points->vec (-> el :attrs :points)))]))

src/renderer/tool/impl/base/transform.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
[renderer.tool.views :as tool.views]
2222
[renderer.utils.bounds :as utils.bounds :refer [BBox]]
2323
[renderer.utils.element :as utils.element]
24+
[renderer.utils.length :as utils.length]
2425
[renderer.utils.math :refer [Vec2]]
2526
[renderer.utils.svg :as utils.svg]))
2627

@@ -421,7 +422,7 @@
421422
x (+ min-x (/ (- max-x min-x) 2))
422423
y (+ y2 (/ (+ (/ theme.db/handle-size 2) 15) zoom))
423424
[w h] (utils.bounds/->dimensions bbox)
424-
text (str (.toFixed w 3) " x " (.toFixed h 3))]
425+
text (str (utils.length/to-fixed w) " x " (utils.length/to-fixed h))]
425426
[utils.svg/label text [x y]]))
426427

427428
(m/=> area-label [:-> number? BBox any?])
@@ -432,7 +433,7 @@
432433
[min-x min-y max-x] bbox
433434
x (+ min-x (/ (- max-x min-x) 2))
434435
y (+ min-y (/ (- -15 (/ theme.db/handle-size 2)) zoom))
435-
text (str (.toFixed area 3) " px²")]
436+
text (str (utils.length/to-fixed area) " px²")]
436437
[utils.svg/label text [x y]])))
437438

438439
(defmethod tool.hierarchy/render :transform

src/renderer/tool/impl/element/circle.cljs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[renderer.element.handlers :as element.handlers]
77
[renderer.history.handlers :as history.handlers]
88
[renderer.tool.handlers :as tool.handlers]
9-
[renderer.tool.hierarchy :as tool.hierarchy]))
9+
[renderer.tool.hierarchy :as tool.hierarchy]
10+
[renderer.utils.length :as utils.length]))
1011

1112
(derive :circle ::tool.hierarchy/element)
1213

@@ -35,7 +36,7 @@
3536
[db _e]
3637
(let [offset (or (:nearest-neighbor-offset db) (:adjusted-pointer-offset db))
3738
position (or (:point (:nearest-neighbor db)) (:adjusted-pointer-pos db))
38-
radius (.toFixed (matrix/distance position offset) 3)
39+
radius (utils.length/to-fixed (matrix/distance position offset))
3940
id (:id (first (element.handlers/selected db)))]
4041
(element.handlers/update-el db id #(assoc-in % [:attrs :r] (str radius)))))
4142

src/renderer/tool/impl/element/ellipse.cljs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
[renderer.element.handlers :as element.handlers]
66
[renderer.history.handlers :as history.handlers]
77
[renderer.tool.handlers :as tool.handlers]
8-
[renderer.tool.hierarchy :as tool.hierarchy]))
8+
[renderer.tool.hierarchy :as tool.hierarchy]
9+
[renderer.utils.length :as utils.length]))
910

1011
(derive :ellipse ::tool.hierarchy/element)
1112

@@ -23,8 +24,8 @@
2324
(let [[offset-x offset-y] (or (:nearest-neighbor-offset db)
2425
(:adjusted-pointer-offset db))
2526
[x y] (or (:point (:nearest-neighbor db)) (:adjusted-pointer-pos db))
26-
rx (.toFixed (abs (- x offset-x)) 3)
27-
ry (.toFixed (abs (- y offset-y)) 3)]
27+
rx (utils.length/to-fixed (abs (- x offset-x)))
28+
ry (utils.length/to-fixed (abs (- y offset-y)))]
2829
{:rx (cond-> rx lock-ratio (min ry))
2930
:ry (cond-> ry lock-ratio (min rx))}))
3031

0 commit comments

Comments
 (0)