diff --git a/common/app/common/geom/shapes.cljc b/common/app/common/geom/shapes.cljc index b45b7beed..cfe531402 100644 --- a/common/app/common/geom/shapes.cljc +++ b/common/app/common/geom/shapes.cljc @@ -156,8 +156,9 @@ "Returns a rect that contains all the shapes and is aware of the rotation of each shape. Mainly used for multiple selection." [shapes] - (let [points (->> shapes (mapcat :points))] - (gpr/points->selrect points))) + (->> shapes + (map :selrect) + (gpr/join-selrects))) (defn translate-to-frame [shape {:keys [x y] :as frame}] diff --git a/common/app/common/geom/shapes/rect.cljc b/common/app/common/geom/shapes/rect.cljc index 89da516a6..47f6543dc 100644 --- a/common/app/common/geom/shapes/rect.cljc +++ b/common/app/common/geom/shapes/rect.cljc @@ -44,6 +44,20 @@ (defn rect->selrect [rect] (-> rect rect->points points->selrect)) +(defn join-selrects [selrects] + (let [minx (transduce (map :x1) min ##Inf selrects) + miny (transduce (map :y1) min ##Inf selrects) + maxx (transduce (map :x2) max ##-Inf selrects) + maxy (transduce (map :y2) max ##-Inf selrects)] + {:x minx + :y miny + :x1 minx + :y1 miny + :x2 maxx + :y2 maxy + :width (- maxx minx) + :height (- maxy miny)})) + ;; --- SHAPE -> RECT #_( (defn- rect->rect-shape diff --git a/common/app/common/geom/shapes/transforms.cljc b/common/app/common/geom/shapes/transforms.cljc index cd819cca5..1b79e9b02 100644 --- a/common/app/common/geom/shapes/transforms.cljc +++ b/common/app/common/geom/shapes/transforms.cljc @@ -285,14 +285,14 @@ (< (get-in modifiers [:resize-vector :y]) 0) (update :flip-y not))) (defn transform-shape [shape] - (if (:modifiers shape) - (let [center (gco/center-shape shape) - transform (modifiers->transform (:transform shape (gmt/matrix)) center (:modifiers shape))] - (-> shape - (set-flip (:modifiers shape)) - (apply-transform transform) - (dissoc :modifiers))) - shape)) + (let [center (gco/center-shape shape)] + (if (and (:modifiers shape) center) + (let [transform (modifiers->transform (:transform shape (gmt/matrix)) center (:modifiers shape))] + (-> shape + (set-flip (:modifiers shape)) + (apply-transform transform) + (dissoc :modifiers))) + shape))) #_(defn transform-shape "Transform the shape properties given the modifiers" diff --git a/frontend/src/app/main/snap.cljs b/frontend/src/app/main/snap.cljs index 463da699b..e20db5f63 100644 --- a/frontend/src/app/main/snap.cljs +++ b/frontend/src/app/main/snap.cljs @@ -195,7 +195,7 @@ (or (filter-shapes id) (not (contains? layout :dynamic-alignment))))) shape (if (> (count shapes) 1) - (->> shapes (map gsh/transform-shape) gsh/selection-rect) + (->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect})) (->> shapes (first))) shapes-points (->> shape diff --git a/frontend/src/app/main/ui/workspace/shapes/path.cljs b/frontend/src/app/main/ui/workspace/shapes/path.cljs index b844ffbdb..d1f761ab5 100644 --- a/frontend/src/app/main/ui/workspace/shapes/path.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/path.cljs @@ -81,7 +81,7 @@ (mf/defc path-editor [{:keys [shape zoom]}] - (let [points (:points shape) + (let [points (gsp/content->points (:content shape)) drag-handler (:drag-handler shape) prev-handler (:prev-handler shape) last-command (last (:content shape)) diff --git a/frontend/src/app/main/ui/workspace/snap_points.cljs b/frontend/src/app/main/ui/workspace/snap_points.cljs index 480d1d57c..1a24da932 100644 --- a/frontend/src/app/main/ui/workspace/snap_points.cljs +++ b/frontend/src/app/main/ui/workspace/snap_points.cljs @@ -58,7 +58,7 @@ (defn get-snap [coord {:keys [shapes page-id filter-shapes local]}] (let [shape (if (> (count shapes) 1) - (->> shapes (map gsh/transform-shape) gsh/selection-rect) + (->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect})) (->> shapes (first))) shape (if (:modifiers local) diff --git a/frontend/src/app/util/geom/snap_points.cljs b/frontend/src/app/util/geom/snap_points.cljs index ee3a5f695..d6ad0bdaa 100644 --- a/frontend/src/app/util/geom/snap_points.cljs +++ b/frontend/src/app/util/geom/snap_points.cljs @@ -14,22 +14,25 @@ [app.common.geom.shapes :as gsh] [app.common.geom.point :as gpt])) -(defn- frame-snap-points [{:keys [x y width height] :as frame}] - (into #{(gpt/point x y) - (gpt/point (+ x (/ width 2)) y) - (gpt/point (+ x width) y) +(defn- selrect-snap-points [{:keys [x y width height]}] + #{(gpt/point x y) + (gpt/point (+ x width) y) + (gpt/point (+ x width) (+ y height)) + (gpt/point x (+ y height))}) + +(defn- frame-snap-points [{:keys [x y width height] :as selrect}] + (into (selrect-snap-points selrect) + #{(gpt/point (+ x (/ width 2)) y) (gpt/point (+ x width) (+ y (/ height 2))) - (gpt/point (+ x width) (+ y height)) (gpt/point (+ x (/ width 2)) (+ y height)) - (gpt/point x (+ y height)) (gpt/point x (+ y (/ height 2)))})) (defn shape-snap-points [shape] - (let [shape (gsh/transform-shape shape) - shape-center (gsh/center-shape shape)] - (if (= :frame (:type shape)) - (-> shape - :selrect - (frame-snap-points)) - (into #{shape-center} (:points shape))))) + (let [shape (gsh/transform-shape shape)] + + (case (:type shape) + :frame (-> shape :selrect frame-snap-points) + (:path :curve) (-> shape :selrect selrect-snap-points) + (into #{(gsh/center-shape shape)} (:points shape))) + ))