Skip to content

Commit 97a72dd

Browse files
committed
enhance precision
1 parent ec7c4f7 commit 97a72dd

File tree

8 files changed

+26
-19
lines changed

8 files changed

+26
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
r (/ (first (utils.bounds/->dimensions bbox)) 2)]
8181
[:g
8282
[utils.svg/line [cx cy] [(+ cx r) cy]]
83-
[utils.svg/label (str (utils.length/->fixed r)) [(+ cx (/ r 2)) cy]]
83+
[utils.svg/label (str (utils.length/->fixed r 2 false)) [(+ cx (/ r 2)) cy]]
8484
[utils.svg/times [cx cy]]
8585
[tool.views/square-handle {:x (+ cx r)
8686
:y cy

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
[]
2020
{:icon "ellipse"
2121
:label (t [::name "Ellipse"])
22-
:description (t [::description
22+
:description (t [::description
2323
"The <ellipse> element is an SVG basic shape, used to create
2424
ellipses based on a center coordinate, and both their x and
2525
y radius."])
@@ -87,9 +87,9 @@
8787
[:g ::edit-handles
8888
[utils.svg/times [cx cy]]
8989
[utils.svg/line [cx cy] [(+ cx rx) cy]]
90-
[utils.svg/label (str (utils.length/->fixed rx)) [(+ cx (/ rx 2)) cy]]
90+
[utils.svg/label (str (utils.length/->fixed rx 2 false)) [(+ cx (/ rx 2)) cy]]
9191
[utils.svg/line [cx cy] [cx (- cy ry)]]
92-
[utils.svg/label (str (utils.length/->fixed ry)) [cx (- cy (/ ry 2))]]
92+
[utils.svg/label (str (utils.length/->fixed ry 2 false)) [cx (- cy (/ ry 2))]]
9393
(map (fn [handle]
9494
^{:key (:id handle)}
9595
[tool.views/square-handle

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[renderer.utils.bounds :as utils.bounds]
1313
[renderer.utils.element :as utils.element]
1414
[renderer.utils.i18n :refer [t]]
15-
[renderer.utils.length :as utils.length]
15+
[renderer.utils.length :as utils.length]
1616
[renderer.utils.svg :as utils.svg]))
1717

1818
(derive :line ::element.hierarchy/shape)
@@ -21,8 +21,8 @@
2121
[]
2222
{:icon "line"
2323
:label (t [::name "Line"])
24-
:description (t [::description
25-
"The <line> element is an SVG basic shape
24+
:description (t [::description
25+
"The <line> element is an SVG basic shape
2626
used to create a line connecting two points."])
2727
:attrs [:stroke
2828
:stroke-width
@@ -75,7 +75,8 @@
7575
[:title {:key (str id "-title")} (name id)]]
7676
(when is-active
7777
[utils.svg/label
78-
(string/join " " [(utils.length/->fixed x) (utils.length/->fixed y)])
78+
(string/join " " [(utils.length/->fixed x 2 false)
79+
(utils.length/->fixed y 2 false)])
7980
[(- x margin) (+ y margin)]
8081
"end"])]))
8182
[{:x x1

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
(when is-active
8585
[utils.svg/label
8686
(->> [x y]
87-
(mapv utils.length/->fixed)
87+
(mapv #(utils.length/->fixed % 2 false))
8888
(string/join " "))
8989
[(- x margin) (+ y margin)]
9090
"end"])]))

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@
425425
x (+ min-x (/ (- max-x min-x) 2))
426426
y (+ y2 (/ (+ (/ theme.db/handle-size 2) 15) zoom))
427427
[w h] (utils.bounds/->dimensions bbox)
428-
text (str (utils.length/->fixed w) " x " (utils.length/->fixed h))]
428+
text (str (utils.length/->fixed w 2 false)
429+
" x "
430+
(utils.length/->fixed h 2 false))]
429431
[utils.svg/label text [x y]]))
430432

431433
(m/=> area-label [:-> number? BBox any?])
@@ -436,7 +438,7 @@
436438
[min-x min-y max-x] bbox
437439
x (+ min-x (/ (- max-x min-x) 2))
438440
y (+ min-y (/ (- -15 (/ theme.db/handle-size 2)) zoom))
439-
text (str (utils.length/->fixed area) " px²")]
441+
text (str (utils.length/->fixed area 2 false) " px²")]
440442
[utils.svg/label text [x y]])))
441443

442444
(defmethod tool.hierarchy/render :transform

src/renderer/tool/impl/misc/measure.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
[utils.svg/line [x1 y1] [(+ x1 (/ 30 zoom)) y1]]
7171

7272
[utils.svg/label
73-
(str (utils.length/->fixed straight-angle) "°")
73+
(str (utils.length/->fixed straight-angle 2 false) "°")
7474
[(+ x1 (/ 40 zoom)) y1]
7575
"start"]
7676

7777
[utils.svg/label
78-
(-> hypotenuse js/parseFloat utils.length/->fixed str)
78+
(-> hypotenuse js/parseFloat (utils.length/->fixed 2 false) str)
7979
[(/ (+ x1 x2) 2) (/ (+ y1 y2) 2)]]])))
8080

8181
(defmethod tool.hierarchy/snapping-points :measure

src/renderer/toolbar/status.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
:style {:min-width "100px"}
2626
:dir "ltr"}
2727
[:div.flex.justify-between
28-
[:span.mr-1 "X:"] [:span (utils.length/->fixed x)]]
28+
[:span.mr-1 "X:"] [:span (utils.length/->fixed x 2 false)]]
2929
[:div.flex.justify-between
30-
[:span.mr-1 "Y:"] [:span (utils.length/->fixed y)]]]))
30+
[:span.mr-1 "Y:"] [:span (utils.length/->fixed y 2 false)]]]))
3131

3232
(defn zoom-options []
3333
[{:label (t [::zoom-set-50 "Set to 50%"])
@@ -115,7 +115,7 @@
115115

116116
(defn zoom-input
117117
[zoom]
118-
(let [value (utils.length/->fixed (* 100 zoom) (zoom-decimal-points zoom))]
118+
(let [value (utils.length/->fixed (* 100 zoom) (zoom-decimal-points zoom) false)]
119119
[:input.form-element.overlay.text-right.font-mono.p-1
120120
{:key zoom
121121
:aria-label "Zoom"

src/renderer/utils/length.cljs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@
6565

6666
(m/=> ->fixed [:function
6767
[:-> number? number?]
68-
[:-> number? integer? number?]])
68+
[:-> number? integer? number?]
69+
[:-> number? integer? boolean? number?]])
6970
(defn ->fixed
7071
([v]
7172
(->fixed v 3))
7273
([v precision]
73-
(-> (.toFixed v precision)
74-
(js/parseFloat))))
74+
(->fixed v precision true))
75+
([v precision remove-trailing-zeros]
76+
(cond-> (.toFixed v precision)
77+
remove-trailing-zeros
78+
(js/parseFloat))))
7579

7680
(m/=> transform [:-> [:or string? number? nil?] ifn? [:* any?] string?])
7781
(defn transform

0 commit comments

Comments
 (0)