🐛 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 :frame-id frame-id
:parent-id frame-id}) :parent-id frame-id})
(assoc (assoc
:proportion (/ width height) :proportion (float (/ width height))
:proportion-lock true)) :proportion-lock true))
img-shape (cts/setup-shape img-shape (cts/setup-shape

View file

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

View file

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