From f4be3aa9de02588cbf787180555a02a2e9a114ce Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 8 Mar 2022 19:18:26 +0100 Subject: [PATCH] :sparkles: Improvements over selrect generation --- common/src/app/common/geom/shapes.cljc | 40 ----------- common/src/app/common/geom/shapes/bool.cljc | 20 +++--- common/src/app/common/geom/shapes/path.cljc | 33 ++++----- .../app/common/geom/shapes/transforms.cljc | 67 +++++++++---------- common/src/app/common/pages.cljc | 3 +- common/src/app/common/pages/common.cljc | 1 + common/src/app/common/pages/init.cljc | 38 +++++++++++ common/src/app/common/pages/migrations.cljc | 2 +- frontend/src/app/main/data/workspace.cljs | 4 +- .../src/app/main/data/workspace/common.cljs | 2 +- .../app/main/data/workspace/drawing/box.cljs | 6 +- .../main/data/workspace/drawing/common.cljs | 3 +- .../src/app/main/data/workspace/groups.cljs | 2 +- .../main/data/workspace/path/selection.cljs | 11 +-- .../app/main/data/workspace/svg_upload.cljs | 7 +- .../app/main/data/workspace/transforms.cljs | 35 +++++----- frontend/src/app/main/snap.cljs | 16 ++--- .../main/ui/workspace/viewport/selection.cljs | 27 ++++---- .../ui/workspace/viewport/snap_points.cljs | 30 +++++---- 19 files changed, 176 insertions(+), 171 deletions(-) diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index 5c15d0691..b866d9cd8 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -17,39 +17,6 @@ [app.common.geom.shapes.transforms :as gtr] [app.common.math :as mth])) -;; --- Setup (Initialize) -;; FIXME: Is this the correct place for these functions? - -(defn- setup-rect - "A specialized function for setup rect-like shapes." - [shape {:keys [x y width height]}] - (let [rect {:x x :y y :width width :height height} - points (gpr/rect->points rect) - selrect (gpr/points->selrect points)] - (assoc shape - :x x - :y y - :width width - :height height - :points points - :selrect selrect))) - -(defn- setup-image - [{:keys [metadata] :as shape} props] - (-> (setup-rect shape props) - (assoc - :proportion (/ (:width metadata) - (:height metadata)) - :proportion-lock true))) - -(defn setup - "A function that initializes the first coordinates for - the shape. Used mainly for draw operations." - [shape props] - (case (:type shape) - :image (setup-image shape props) - (setup-rect shape props))) - ;; --- Outer Rect (defn selection-rect @@ -121,13 +88,6 @@ (defn distance-shapes [shape other] (distance-selrect (:selrect shape) (:selrect other))) -(defn setup-selrect [shape] - (let [selrect (gpr/rect->selrect shape) - points (gpr/rect->points shape)] - (-> shape - (assoc :selrect selrect - :points points)))) - (defn shape-stroke-margin [shape stroke-width] (if (= (:type shape) :path) diff --git a/common/src/app/common/geom/shapes/bool.cljc b/common/src/app/common/geom/shapes/bool.cljc index 4d5bdb401..c4646838c 100644 --- a/common/src/app/common/geom/shapes/bool.cljc +++ b/common/src/app/common/geom/shapes/bool.cljc @@ -30,15 +30,13 @@ "Calculates the selrect+points for the boolean shape" [shape children objects] - (let [content (calc-bool-content shape objects) - [points selrect] - (if (empty? content) - (let [selrect (gtr/selection-rect children) - points (gpr/rect->points selrect)] - [points selrect]) - (gsp/content->points+selrect shape content))] - (-> shape - (assoc :selrect selrect) - (assoc :points points) - (assoc :bool-content content)))) + (let [bool-content (calc-bool-content shape objects) + shape (assoc shape :bool-content bool-content) + [points selrect] (gsp/content->points+selrect shape bool-content)] + + (if (and (some? selrect) (d/not-empty? points)) + (-> shape + (assoc :selrect selrect) + (assoc :points points)) + (gtr/update-group-selrect shape children)))) diff --git a/common/src/app/common/geom/shapes/path.cljc b/common/src/app/common/geom/shapes/path.cljc index fc8a725f4..fe9d0fd21 100644 --- a/common/src/app/common/geom/shapes/path.cljc +++ b/common/src/app/common/geom/shapes/path.cljc @@ -333,11 +333,8 @@ (command->point command :c2)]] (->> (curve-extremities curve) (mapv #(curve-values curve %))))) - []) - selrect (gpr/points->selrect points)] - (-> selrect - (update :width #(if (mth/almost-zero? %) 1 %)) - (update :height #(if (mth/almost-zero? %) 1 %)))))) + [])] + (gpr/points->selrect points)))) (defn content->selrect [content] (let [calc-extremities @@ -371,20 +368,26 @@ set-tr (fn [params px py] - (-> params - (update px + dx) - (update py + dy))) + (cond-> params + (d/num? dx) + (update px + dx) + + (d/num? dy) + (update py + dy))) transform-params - (fn [{:keys [x c1x c2x] :as params}] + (fn [{:keys [x y c1x c1y c2x c2y] :as params}] (cond-> params - (some? x) (set-tr :x :y) - (some? c1x) (set-tr :c1x :c1y) - (some? c2x) (set-tr :c2x :c2y)))] + (d/num? x y) (set-tr :x :y) + (d/num? c1x c1y) (set-tr :c1x :c1y) + (d/num? c2x c2y) (set-tr :c2x :c2y))) - (into [] - (map #(update % :params transform-params)) - content))) + update-command + (fn [command] + (update command :params transform-params))] + + (->> content + (into [] (map update-command))))) (defn transform-content [content transform] diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 2dbf96ec2..e20fa49bb 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -21,38 +21,38 @@ ;; --- Relative Movement -(defn- move-selrect [selrect pt] - (when (and (some? selrect) (some? pt)) - (let [dx (.-x pt) - dy (.-y pt) - {:keys [x y x1 y1 x2 y2 width height]} selrect] - {:x (if (some? x) (+ dx x) x) - :y (if (some? y) (+ dy y) y) - :x1 (if (some? x1) (+ dx x1) x1) - :y1 (if (some? y1) (+ dy y1) y1) - :x2 (if (some? x2) (+ dx x2) x2) - :y2 (if (some? y2) (+ dy y2) y2) - :width width - :height height}))) +(defn- move-selrect [{:keys [x y x1 y1 x2 y2 width height] :as selrect} {dx :x dy :y :as pt}] + (if (and (some? selrect) (some? pt) (d/num? dx dy)) + {:x (if (d/num? x) (+ dx x) x) + :y (if (d/num? y) (+ dy y) y) + :x1 (if (d/num? x1) (+ dx x1) x1) + :y1 (if (d/num? y1) (+ dy y1) y1) + :x2 (if (d/num? x2) (+ dx x2) x2) + :y2 (if (d/num? y2) (+ dy y2) y2) + :width width + :height height} + selrect)) (defn- move-points [points move-vec] - (->> points - (mapv #(gpt/add % move-vec)))) + (cond->> points + (d/num? (:x move-vec) (:y move-vec)) + (mapv #(gpt/add % move-vec)))) (defn move-position-data [position-data dx dy] - (->> position-data - (mapv #(-> % - (update :x + dx) - (update :y + dy))))) + (cond->> position-data + (d/num? dx dy) + (mapv #(-> % + (update :x + dx) + (update :y + dy))))) (defn move "Move the shape relatively to its current position applying the provided delta." [{:keys [type] :as shape} {dx :x dy :y}] - (let [dx (d/check-num dx) - dy (d/check-num dy) + (let [dx (d/check-num dx 0) + dy (d/check-num dy 0) move-vec (gpt/point dx dy)] (-> shape @@ -138,9 +138,12 @@ (defn transform-matrix "Returns a transformation matrix without changing the shape properties. The result should be used in a `transform` attribute in svg" - ([shape] (transform-matrix shape nil)) - ([shape params] (transform-matrix shape params (or (gco/center-shape shape) - (gpt/point 0 0)))) + ([shape] + (transform-matrix shape nil)) + + ([shape params] + (transform-matrix shape params (or (gco/center-shape shape) (gpt/point 0 0)))) + ([{:keys [flip-x flip-y] :as shape} {:keys [no-flip]} shape-center] (-> (gmt/matrix) (gmt/translate shape-center) @@ -276,10 +279,6 @@ [(gpr/points->selrect points) nil nil] (adjust-rotated-transform shape points)) - ;;selrect (cond-> selrect - ;; round-coords? gpr/round-selrect) - - ;; Redondear los points? base-rotation (or (:rotation shape) 0) modif-rotation (or (get-in shape [:modifiers :rotation]) 0) rotation (mod (+ base-rotation modif-rotation) 360)] @@ -296,8 +295,10 @@ (assoc :transform-inverse transform-inverse))) (cond-> (not transform) (dissoc :transform :transform-inverse)) - (assoc :selrect selrect) - (assoc :points points) + (cond-> (some? selrect) + (assoc :selrect selrect)) + (cond-> (d/not-empty? points) + (assoc :points points)) (assoc :rotation rotation)))) (defn- update-group-viewbox @@ -568,11 +569,7 @@ displacement (when (some? displacement) - (gmt/multiply resize-transform-inverse displacement) - #_(-> (gpt/point 0 0) - (gpt/transform displacement) - (gpt/transform resize-transform-inverse) - (gmt/translate-matrix))) + (gmt/multiply resize-transform-inverse displacement)) resize-origin (when (some? resize-origin) diff --git a/common/src/app/common/pages.cljc b/common/src/app/common/pages.cljc index 496c7ccb7..0e6a91a94 100644 --- a/common/src/app/common/pages.cljc +++ b/common/src/app/common/pages.cljc @@ -42,4 +42,5 @@ (dm/export init/make-minimal-shape) (dm/export init/make-minimal-group) (dm/export init/empty-file-data) - +(dm/export init/setup-shape) +(dm/export init/setup-rect-selrect) diff --git a/common/src/app/common/pages/common.cljc b/common/src/app/common/pages/common.cljc index 1988f2137..1a586beb5 100644 --- a/common/src/app/common/pages/common.cljc +++ b/common/src/app/common/pages/common.cljc @@ -104,6 +104,7 @@ :group #{:proportion-lock :width :height :x :y + :rotation :selrect :constraints-h diff --git a/common/src/app/common/pages/init.cljc b/common/src/app/common/pages/init.cljc index 8107c17cb..97e499711 100644 --- a/common/src/app/common/pages/init.cljc +++ b/common/src/app/common/pages/init.cljc @@ -9,6 +9,7 @@ [app.common.colors :as clr] [app.common.data :as d] [app.common.exceptions :as ex] + [app.common.geom.shapes :as gsh] [app.common.pages.common :refer [file-version default-color]] [app.common.uuid :as uuid])) @@ -146,3 +147,40 @@ (assoc :id file-id) (update :pages conj page-id) (update :pages-index assoc page-id pd))))) + +(defn setup-rect-selrect + "Initializes the selrect and points for a shape" + [shape] + (let [selrect (gsh/rect->selrect shape) + points (gsh/rect->points shape)] + (-> shape + (assoc :selrect selrect + :points points)))) + +(defn- setup-rect + "A specialized function for setup rect-like shapes." + [shape {:keys [x y width height]}] + (-> shape + (assoc :x x :y y :width width :height height) + (setup-rect-selrect))) + +(defn- setup-image + [{:keys [metadata] :as shape} props] + (-> (setup-rect shape props) + (assoc + :proportion (/ (:width metadata) + (:height metadata)) + :proportion-lock true))) + +(defn setup-shape + "A function that initializes the first coordinates for + the shape. Used mainly for draw operations." + ([props] + (setup-shape {:type :rect} props)) + + ([shape props] + (case (:type shape) + :image (setup-image shape props) + (setup-rect shape props)))) + + diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index 4a3ebc581..844475a08 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -84,7 +84,7 @@ (fix-empty-points [shape] (let [shape (cond-> shape - (empty? (:selrect shape)) (gsh/setup-selrect))] + (empty? (:selrect shape)) (cp/setup-rect-selrect))] (cond-> shape (empty? (:points shape)) (assoc :points (gsh/rect->points (:selrect shape)))))) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 33d681cca..0300d3bf0 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1574,7 +1574,7 @@ page-id (:current-page-id state) frame-id (-> (wsh/lookup-page-objects state page-id) (cph/frame-id-by-position @ms/mouse-position)) - shape (gsh/setup-selrect + shape (cp/setup-rect-selrect {:id id :type :text :name "Text" @@ -1667,7 +1667,7 @@ shape (-> (cp/make-minimal-shape :frame) (merge {:x (:x srect) :y (:y srect) :width (:width srect) :height (:height srect)}) (assoc :frame-id frame-id) - (gsh/setup-selrect))] + (cp/setup-rect-selrect))] (rx/of (dwu/start-undo-transaction) (dwc/add-shape shape) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index d610d4d84..55fc8adf7 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -480,7 +480,7 @@ (merge data) (merge {:x x :y y}) (assoc :frame-id frame-id) - (gsh/setup-selrect))] + (cp/setup-rect-selrect))] (rx/of (add-shape shape)))))) (defn image-uploaded diff --git a/frontend/src/app/main/data/workspace/drawing/box.cljs b/frontend/src/app/main/data/workspace/drawing/box.cljs index f2dd60954..6b81787d9 100644 --- a/frontend/src/app/main/data/workspace/drawing/box.cljs +++ b/frontend/src/app/main/data/workspace/drawing/box.cljs @@ -9,6 +9,7 @@ [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.math :as mth] + [app.common.pages :as cp] [app.common.pages.helpers :as cph] [app.common.uuid :as uuid] [app.main.data.workspace.drawing.common :as common] @@ -70,7 +71,10 @@ shape (-> state (get-in [:workspace-drawing :object]) - (gsh/setup {:x (:x initial) :y (:y initial) :width 0.01 :height 0.01}) + (cp/setup-shape {:x (:x initial) + :y (:y initial) + :width 0.01 + :height 0.01}) (assoc :frame-id fid) (assoc :initialized? true) (assoc :click-draw? true))] diff --git a/frontend/src/app/main/data/workspace/drawing/common.cljs b/frontend/src/app/main/data/workspace/drawing/common.cljs index d43c54f96..6dc28ac72 100644 --- a/frontend/src/app/main/data/workspace/drawing/common.cljs +++ b/frontend/src/app/main/data/workspace/drawing/common.cljs @@ -6,6 +6,7 @@ (ns app.main.data.workspace.drawing.common (:require + [app.common.pages :as cp] [app.common.geom.matrix :as gmt] [app.common.geom.shapes :as gsh] [app.common.math :as mth] @@ -49,7 +50,7 @@ (assoc :height 17 :width 4 :grow-type :auto-width) click-draw? - (gsh/setup-selrect) + (cp/setup-rect-selrect) :always (-> (gsh/transform-shape) diff --git a/frontend/src/app/main/data/workspace/groups.cljs b/frontend/src/app/main/data/workspace/groups.cljs index 422299e62..f09384d06 100644 --- a/frontend/src/app/main/data/workspace/groups.cljs +++ b/frontend/src/app/main/data/workspace/groups.cljs @@ -76,7 +76,7 @@ selrect (gsh/selection-rect shapes) group (-> (cp/make-minimal-group frame-id selrect gname) - (gsh/setup selrect) + (cp/setup-shape selrect) (assoc :shapes (mapv :id shapes) :parent-id parent-id :frame-id frame-id diff --git a/frontend/src/app/main/data/workspace/path/selection.cljs b/frontend/src/app/main/data/workspace/path/selection.cljs index 3fed3f365..df6366a6d 100644 --- a/frontend/src/app/main/data/workspace/path/selection.cljs +++ b/frontend/src/app/main/data/workspace/path/selection.cljs @@ -103,20 +103,21 @@ (defn handle-area-selection [shift?] - (letfn [(valid-rect? [{width :width height :height}] - (or (> width 10) (> height 10)))] + (letfn [(valid-rect? [zoom {width :width height :height}] + (or (> width (/ 10 zoom)) (> height (/ 10 zoom))))] (ptk/reify ::handle-area-selection ptk/WatchEvent - (watch [_ _ stream] - (let [stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event))) + (watch [_ state stream] + (let [zoom (get-in state [:workspace-local :zoom] 1) + stop? (fn [event] (or (dwc/interrupt? event) (ms/mouse-up? event))) stoper (->> stream (rx/filter stop?)) from-p @ms/mouse-position] (rx/concat (->> ms/mouse-position (rx/take-until stoper) (rx/map #(gsh/points->rect [from-p %])) - (rx/filter valid-rect?) + (rx/filter (partial valid-rect? zoom)) (rx/map update-area-selection)) (rx/of (select-node-area shift?) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 7bfc12c85..282a87920 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -12,6 +12,7 @@ [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.common.pages.changes-builder :as pcb] + [app.common.pages :as cp] [app.common.pages.helpers :as cph] [app.common.spec :refer [max-safe-int min-safe-int]] [app.common.uuid :as uuid] @@ -165,7 +166,7 @@ (assoc :svg-attrs attrs) (assoc :svg-viewbox (-> (select-keys svg-data [:width :height]) (assoc :x offset-x :y offset-y))) - (gsh/setup-selrect)))) + (cp/setup-rect-selrect)))) (defn create-svg-root [frame-id svg-data] (let [{:keys [name x y width height offset-x offset-y]} svg-data] @@ -177,7 +178,7 @@ :height height :x (+ x offset-x) :y (+ y offset-y)} - (gsh/setup-selrect) + (cp/setup-rect-selrect) (assoc :svg-attrs (-> (:attrs svg-data) (dissoc :viewBox :xmlns) (d/without-keys usvg/inheritable-props)))))) @@ -197,7 +198,7 @@ (assoc :svg-attrs (d/without-keys attrs usvg/inheritable-props)) (assoc :svg-viewbox (-> (select-keys svg-data [:width :height]) (assoc :x offset-x :y offset-y))) - (gsh/setup-selrect)))) + (cp/setup-rect-selrect)))) (defn create-path-shape [name frame-id svg-data {:keys [attrs] :as data}] (when (and (contains? attrs :d) (seq (:d attrs))) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index f3baade05..6a15acdc3 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -442,26 +442,29 @@ group (gsh/selection-rect shapes) group-center (gsh/center-selrect group) initial-angle (gpt/angle @ms/mouse-position group-center) - calculate-angle (fn [pos ctrl? shift?] - (let [angle (- (gpt/angle pos group-center) initial-angle) - angle (if (neg? angle) (+ 360 angle) angle) - angle (if (= angle 360) - 0 - angle) - angle (if ctrl? - (* (mth/floor (/ angle 45)) 45) - angle) - angle (if shift? - (* (mth/floor (/ angle 15)) 15) - angle)] - angle))] + + calculate-angle + (fn [pos ctrl? shift?] + (let [angle (- (gpt/angle pos group-center) initial-angle) + angle (if (neg? angle) (+ 360 angle) angle) + angle (if (= angle 360) + 0 + angle) + angle (if ctrl? + (* (mth/floor (/ angle 45)) 45) + angle) + angle (if shift? + (* (mth/floor (/ angle 15)) 15) + angle)] + angle))] (rx/concat (->> ms/mouse-position (rx/with-latest vector ms/mouse-position-ctrl) (rx/with-latest vector ms/mouse-position-shift) - (rx/map (fn [[[pos ctrl?] shift?]] - (let [delta-angle (calculate-angle pos ctrl? shift?)] - (set-rotation-modifiers delta-angle shapes group-center)))) + (rx/map + (fn [[[pos ctrl?] shift?]] + (let [delta-angle (calculate-angle pos ctrl? shift?)] + (set-rotation-modifiers delta-angle shapes group-center)))) (rx/take-until stoper)) (rx/of (apply-modifiers (map :id shapes)) (finish-transform))))))) diff --git a/frontend/src/app/main/snap.cljs b/frontend/src/app/main/snap.cljs index d7d67078c..8e97d2513 100644 --- a/frontend/src/app/main/snap.cljs +++ b/frontend/src/app/main/snap.cljs @@ -256,16 +256,14 @@ filter-shapes (into #{} (map :id shapes)) remove-snap? (make-remove-snap layout filter-shapes objects focus) - shape (if (> (count shapes) 1) - (->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect})) - (->> shapes (first))) + snap-points + (->> shapes + (gsh/selection-rect) + (sp/selrect-snap-points) + ;; Move the points in the translation vector + (map #(gpt/add % movev)))] - shapes-points (->> shape - (sp/shape-snap-points) - ;; Move the points in the translation vector - (map #(gpt/add % movev)))] - - (->> (rx/merge (closest-snap page-id frame-id shapes-points remove-snap? zoom) + (->> (rx/merge (closest-snap page-id frame-id snap-points remove-snap? zoom) (when (contains? layout :dynamic-alignment) (closest-distance-snap page-id shapes objects zoom movev))) (rx/reduce combine-snaps-points) diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index 62abcd9ec..814bf4983 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -9,7 +9,8 @@ (:require [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] - [app.common.geom.shapes :as geom] + [app.common.geom.shapes :as gsh] + [app.common.pages :as cp] [app.main.data.workspace :as dw] [app.main.refs :as refs] [app.main.store :as st] @@ -33,7 +34,8 @@ (def min-selrect-side 10) (def small-selrect-side 30) -(mf/defc selection-rect [{:keys [transform rect zoom color on-move-selected on-context-menu]}] +(mf/defc selection-rect + [{:keys [transform rect zoom color on-move-selected on-context-menu]}] (when rect (let [{:keys [x y width height]} rect] [:rect.main.viewport-selrect @@ -117,10 +119,7 @@ (when show-resize-point? {:type :resize-point :position :bottom-left - :props {:cx x :cy (+ y height) :align align}}) - - - ] + :props {:cx x :cy (+ y height) :align align}})] (filterv (comp not nil?))))) @@ -185,8 +184,7 @@ :style {:fill (if (debug? :resize-handler) "red" "none") :stroke (if (debug? :resize-handler) "red" "none") :stroke-width 0 - :cursor cursor}}] - )])) + :cursor cursor}}])])) (mf/defc resize-side-handler "The side handler is always rendered horizontally and then rotated" @@ -265,7 +263,7 @@ current-transform (mf/deref refs/current-transform) selrect (:selrect shape) - transform (geom/transform-matrix shape {:no-flip true}) + transform (gsh/transform-matrix shape {:no-flip true}) rotation (-> (gpt/point 1 0) (gpt/transform (:transform shape)) @@ -298,7 +296,7 @@ (let [{:keys [x y width height]} shape] [:g.controls [:rect.main {:x x :y y - :transform (geom/transform-matrix shape) + :transform (gsh/transform-matrix shape) :width width :height height :pointer-events "visible" @@ -312,10 +310,9 @@ (let [shape (mf/use-memo (mf/deps shapes) #(->> shapes - (map geom/transform-shape) - (geom/selection-rect) - (geom/setup {:type :rect}))) - + (map gsh/transform-shape) + (gsh/selection-rect) + (cp/setup-shape))) on-resize (fn [current-position _initial-position event] (when (dom/left-mouse? event) @@ -356,7 +353,7 @@ (mf/defc single-handlers [{:keys [shape zoom color disable-handlers] :as props}] (let [shape-id (:id shape) - shape (geom/transform-shape shape) + shape (gsh/transform-shape shape) on-resize (fn [current-position _initial-position event] diff --git a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs index a89825675..0771cbee0 100644 --- a/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/snap_points.cljs @@ -51,23 +51,25 @@ (defn get-snap [coord {:keys [shapes page-id remove-snap? zoom modifiers]}] - (let [shape (if (> (count shapes) 1) - (->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect})) - (->> shapes (first))) - - shape (if modifiers - (-> shape (merge (get modifiers (:id shape))) gsh/transform-shape) - shape) + (let [shapes-sr + (->> shapes + ;; Merge modifiers into shapes + (map #(merge % (get modifiers (:id %)))) + ;; Create the bounding rectangle for the shapes + (gsh/selection-rect)) frame-id (snap/snap-frame-id shapes)] - (->> (rx/of shape) - (rx/flat-map (fn [shape] - (->> (sp/shape-snap-points shape) - (map #(vector frame-id %))))) - (rx/flat-map (fn [[frame-id point]] - (->> (snap/get-snap-points page-id frame-id remove-snap? zoom point coord) - (rx/map #(vector point % coord))))) + (->> (rx/of shapes-sr) + (rx/flat-map + (fn [selrect] + (->> (sp/selrect-snap-points selrect) + (map #(vector frame-id %))))) + + (rx/flat-map + (fn [[frame-id point]] + (->> (snap/get-snap-points page-id frame-id remove-snap? zoom point coord) + (rx/map #(vector point % coord))))) (rx/reduce conj [])))) (defn- flip