From 48615ca5b205c66b9312ae05e77759a9123c6b97 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 15 Jul 2022 14:33:08 +0200 Subject: [PATCH] :bug: Round coordinates in viewport and paths --- common/src/app/common/geom/matrix.cljc | 10 +++- frontend/src/app/main/render.cljs | 6 +-- .../app/main/ui/workspace/viewport/utils.cljs | 9 ++-- frontend/src/app/util/path/format.cljs | 47 ++++++++++++++++--- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/geom/matrix.cljc b/common/src/app/common/geom/matrix.cljc index b0b2009975..f891532a12 100644 --- a/common/src/app/common/geom/matrix.cljc +++ b/common/src/app/common/geom/matrix.cljc @@ -14,6 +14,8 @@ [app.common.spec :as us] [clojure.spec.alpha :as s])) +(def precision 3) + ;; --- Matrix Impl (defrecord Matrix [^double a @@ -24,7 +26,13 @@ ^double f] Object (toString [_] - (str "matrix(" a "," b "," c "," d "," e "," f ")"))) + (str "matrix(" + (mth/precision a precision) "," + (mth/precision b precision) "," + (mth/precision c precision) "," + (mth/precision d precision) "," + (mth/precision e precision) "," + (mth/precision f precision) ")"))) (defn matrix? "Return true if `v` is Matrix instance." diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index 2914629274..240a442018 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -354,7 +354,7 @@ (assoc :fills [])) - bounds (gsb/get-object-bounds objects object) + {:keys [width height] :as bounds} (gsb/get-object-bounds objects object) vbox (format-viewbox bounds) fonts (ff/shape->fonts object objects) @@ -366,8 +366,8 @@ [:& (mf/provider embed/context) {:value render-embed?} [:svg {:id (dm/str "screenshot-" object-id) :view-box vbox - :width (:width bounds) - :height (:height bounds) + :width (ust/format-precision width viewbox-decimal-precision) + :height (ust/format-precision height viewbox-decimal-precision) :version "1.1" :xmlns "http://www.w3.org/2000/svg" :xmlnsXlink "http://www.w3.org/1999/xlink" diff --git a/frontend/src/app/main/ui/workspace/viewport/utils.cljs b/frontend/src/app/main/ui/workspace/viewport/utils.cljs index 7f29d47766..e657b72678 100644 --- a/frontend/src/app/main/ui/workspace/viewport/utils.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/utils.cljs @@ -10,13 +10,14 @@ [app.common.data.macros :as dm] [app.common.geom.point :as gpt] [app.main.ui.cursors :as cur] + [app.main.ui.formats :refer [format-number]] [app.util.dom :as dom])) (defn format-viewbox [vbox] - (dm/str (:x vbox 0) " " - (:y vbox 0) " " - (:width vbox 0) " " - (:height vbox 0))) + (dm/str (format-number(:x vbox 0)) " " + (format-number (:y vbox 0)) " " + (format-number (:width vbox 0)) " " + (format-number (:height vbox 0)))) (defn translate-point-to-viewport [viewport zoom pt] (let [vbox (.. ^js viewport -viewBox -baseVal) diff --git a/frontend/src/app/util/path/format.cljs b/frontend/src/app/util/path/format.cljs index 30c2745470..6cd541c53d 100644 --- a/frontend/src/app/util/path/format.cljs +++ b/frontend/src/app/util/path/format.cljs @@ -6,25 +6,58 @@ (ns app.util.path.format (:require + [app.common.math :as mth] [app.common.path.commands :as upc] [app.common.path.subpaths :refer [pt=]] [app.util.array :as arr])) +(def path-precision 3) + (defn- join-params ([a] - (js* "\"\"+~{}" a)) + (js* "\"\"+~{}" + (mth/precision a path-precision))) ([a b] - (js* "\"\"+~{}+\",\"+~{}" a b)) + (js* "\"\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision))) ([a b c] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}" a b c)) + (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision) + (mth/precision c path-precision))) ([a b c d] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d)) + (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision) + (mth/precision c path-precision) + (mth/precision d path-precision) + )) ([a b c d e] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e)) + (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision) + (mth/precision c path-precision) + (mth/precision d path-precision) + (mth/precision e path-precision))) ([a b c d e f] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e f)) + (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision) + (mth/precision c path-precision) + (mth/precision d path-precision) + (mth/precision e path-precision) + (mth/precision f path-precision) + )) ([a b c d e f g] - (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" a b c d e f g))) + (js* "\"\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}+\",\"+~{}" + (mth/precision a path-precision) + (mth/precision b path-precision) + (mth/precision c path-precision) + (mth/precision d path-precision) + (mth/precision e path-precision) + (mth/precision f path-precision) + (mth/precision g path-precision)))) (defn- translate-params [command {:keys [x y] :as params}]