0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-08 16:18:11 -05:00

🐛 Avoid datatype problem calculating proportions

This commit is contained in:
Andrés Moya 2024-04-05 10:04:27 +02:00 committed by Andrey Antukh
parent b2020c8a66
commit c2737f2378
3 changed files with 10 additions and 10 deletions

View file

@ -1255,7 +1255,7 @@
:frame-id frame-id
:parent-id frame-id})
(assoc
:proportion (/ width height)
:proportion (float (/ width height))
:proportion-lock true))
img-shape (cts/setup-shape

View file

@ -13,27 +13,27 @@
(defn assign-proportions
[shape]
(let [{:keys [width height]} (:selrect shape)]
(assoc shape :proportion (/ width height))))
;; --- Setup Proportions
(assoc shape :proportion (float (/ width height))))) ; Note: we need to convert explicitly to float.
; In Clojure (not clojurescript) when we divide
;; --- Setup Proportions ; two integers it does not create a float, but
; a clojure.lang.Ratio object.
(defn setup-proportions-image
[{:keys [metadata] :as shape}]
(let [{:keys [width height]} metadata]
(assoc shape
:proportion (/ width height)
:proportion (float (/ width height))
:proportion-lock true)))
(defn setup-proportions-size
[{{:keys [width height]} :selrect :as shape}]
(assoc shape
:proportion (/ width height)
:proportion (float (/ width height))
:proportion-lock true))
(defn setup-proportions-const
[shape]
(assoc shape
:proportion 1
:proportion 1.0
:proportion-lock false))
(defn setup-proportions

View file

@ -483,8 +483,8 @@
(defn- setup-image
[{:keys [metadata] :as shape}]
(-> shape
(assoc :proportion (/ (:width metadata)
(:height metadata)))
(assoc :proportion (float (/ (:width metadata)
(:height metadata))))
(assoc :proportion-lock true)))
(defn setup-shape