From d517daa0452db1fb1ce6f133e7bc59543cde7801 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 24 Feb 2021 12:29:38 +0100 Subject: [PATCH] :bug: Fixes problems with line paths --- common/app/common/pages/common.cljc | 2 +- common/app/common/pages/migrations.cljc | 29 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/common/app/common/pages/common.cljc b/common/app/common/pages/common.cljc index eb5a9572e..784896e3b 100644 --- a/common/app/common/pages/common.cljc +++ b/common/app/common/pages/common.cljc @@ -11,7 +11,7 @@ (:require [app.common.uuid :as uuid])) -(def file-version 5) +(def file-version 6) (def default-color "#b1b2b5") ;; $color-gray-20 (def root uuid/zero) diff --git a/common/app/common/pages/migrations.cljc b/common/app/common/pages/migrations.cljc index c2f170a01..28aa8682e 100644 --- a/common/app/common/pages/migrations.cljc +++ b/common/app/common/pages/migrations.cljc @@ -13,6 +13,7 @@ [app.common.geom.shapes :as gsh] [app.common.geom.shapes.path :as gsp] [app.common.geom.matrix :as gmt] + [app.common.math :as mth] [app.common.uuid :as uuid] [app.common.data :as d])) @@ -137,3 +138,31 @@ (update data :pages-index #(d/mapm update-page %)))) +(defn fix-line-paths + "Fixes issues with selrect/points for shapes with width/height = 0 (line-like paths)" + [_ shape] + (if (= (:type shape) :path) + (let [{:keys [width height]} (gsh/points->rect (:points shape))] + (if (or (mth/almost-zero? width) (mth/almost-zero? height)) + (let [selrect (gsh/content->selrect (:content shape)) + points (gsh/rect->points selrect) + transform (gmt/matrix) + transform-inv (gmt/matrix)] + (assoc shape + :selrect selrect + :points points + :transform transform + :transform-inverse transform-inv)) + shape)) + shape)) + + +(defmethod migrate 6 + [data] + (letfn [(update-container [_ container] + (-> container + (update :objects #(d/mapm fix-line-paths %))))] + + (-> data + (update :components #(d/mapm update-container %)) + (update :pages-index #(d/mapm update-container %)))))