From f6b182a3b56d1ab412fab19d2f1664008b027f47 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 30 Jan 2024 18:02:25 +0100 Subject: [PATCH] :bug: Fix problem calculating selrect for certain paths --- common/src/app/common/geom/shapes/path.cljc | 44 +++++++++++---------- frontend/src/app/main/data/workspace.cljs | 23 +++++------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index 84f0b5241..14571d65a 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -340,29 +340,31 @@ (grc/points->rect points)))) (defn content->selrect [content] - (let [calc-extremities - (fn [command prev] - (case (:command command) - :move-to [(command->point command)] + (let [extremities + (loop [points #{} + from-p nil + move-p nil + content (seq content)] + (if content + (let [command (first content) + to-p (command->point command) - ;; If it's a line we add the beginning point and endpoint - :line-to [(command->point prev) - (command->point command)] + [from-p move-p command-pts] + (case (:command command) + :move-to [to-p to-p [to-p]] + :close-path [move-p move-p [move-p]] + :line-to [to-p move-p [from-p to-p]] + :curve-to [to-p move-p + (let [c1 (command->point command :c1) + c2 (command->point command :c2) + curve [from-p to-p c1 c2]] + (into [from-p to-p] + (->> (curve-extremities curve) + (map #(curve-values curve %)))))] + [to-p move-p []])] - ;; We return the bezier extremities - :curve-to (into [(command->point prev) - (command->point command)] - (let [curve [(command->point prev) - (command->point command) - (command->point command :c1) - (command->point command :c2)]] - (->> (curve-extremities curve) - (map #(curve-values curve %))))) - [])) - - extremities (mapcat calc-extremities - content - (concat [nil] content))] + (recur (apply conj points command-pts) from-p move-p (next content))) + points))] (grc/points->rect extremities))) (defn move-content [content move-vec] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 5418a24e7..46d847794 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1013,20 +1013,21 @@ (d/ordered-set)))] (rx/of (dws/select-shapes shapes-to-select))) - (let [{:keys [id type shapes]} (get objects (first selected))] - (case type - :text - (rx/of (dwe/start-edition-mode id)) + (when (d/not-empty? selected) + (let [{:keys [id type shapes]} (get objects (first selected))] + (case type + :text + (rx/of (dwe/start-edition-mode id)) - (:group :bool :frame) - (let [shapes-ids (into (d/ordered-set) shapes)] - (rx/of (dws/select-shapes shapes-ids))) + (:group :bool :frame) + (let [shapes-ids (into (d/ordered-set) shapes)] + (rx/of (dws/select-shapes shapes-ids))) - :svg-raw - nil + :svg-raw + nil - (rx/of (dwe/start-edition-mode id) - (dwdp/start-path-edit id))))))))) + (rx/of (dwe/start-edition-mode id) + (dwdp/start-path-edit id)))))))))) (defn select-parent-layer []