From 2833d3126ff1c12864ab758e4d735a04cdd0e7e7 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 11 Oct 2021 10:50:18 +0200 Subject: [PATCH] :bug: Fix bug with transformation operations --- CHANGES.md | 1 + .../app/main/data/workspace/transforms.cljs | 67 ++++++++++--------- .../main/ui/workspace/viewport/selection.cljs | 9 ++- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4d18f210c..1ad8cea69 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -36,6 +36,7 @@ - Add stroke width in selection calculation [Taiga #2146](https://tree.taiga.io/project/penpot/issue/2146) - Fix shift+wheel to horizontal scrolling in MacOS [#1217](https://github.com/penpot/penpot/issues/1217) - Fix path stroke is not working properly with high thickness [Taiga #2154](https://tree.taiga.io/project/penpot/issue/2154) +- Fix bug with transformation operations [Taiga #2155](https://tree.taiga.io/project/penpot/issue/2155) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index b6f660ea4..8180690bf 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -70,23 +70,19 @@ (defn- fix-init-point "Fix the initial point so the resizes are accurate" [initial handler shape] - (let [{:keys [x y width height]} (:selrect shape) - {:keys [rotation]} shape - rotation (or rotation 0)] - (if (= rotation 0) - (cond-> initial - (contains? #{:left :top-left :bottom-left} handler) - (assoc :x x) + (let [{:keys [x y width height]} (:selrect shape)] + (cond-> initial + (contains? #{:left :top-left :bottom-left} handler) + (assoc :x x) - (contains? #{:right :top-right :bottom-right} handler) - (assoc :x (+ x width)) + (contains? #{:right :top-right :bottom-right} handler) + (assoc :x (+ x width)) - (contains? #{:top :top-right :top-left} handler) - (assoc :y y) + (contains? #{:top :top-right :top-left} handler) + (assoc :y y) - (contains? #{:bottom :bottom-right :bottom-left} handler) - (assoc :y (+ y height))) - initial))) + (contains? #{:bottom :bottom-right :bottom-left} handler) + (assoc :y (+ y height))))) (defn finish-transform [] (ptk/reify ::finish-transform @@ -285,10 +281,19 @@ (letfn [(resize [shape initial layout [point lock? center? point-snap]] (let [{:keys [width height]} (:selrect shape) {:keys [rotation]} shape + + shape-center (gsh/center-shape shape) + shape-transform (:transform shape (gmt/matrix)) + shape-transform-inverse (:transform-inverse shape (gmt/matrix)) + rotation (or rotation 0) + initial (gsh/transform-point-center initial shape-center shape-transform-inverse) initial (fix-init-point initial handler shape) + point (gsh/transform-point-center (if (= rotation 0) point-snap point) + shape-center shape-transform-inverse) + shapev (-> (gpt/point width height)) scale-text (:scale-text layout) @@ -300,8 +305,7 @@ handler-mult (let [[x y] (handler-multipliers handler)] (gpt/point x y)) ;; Difference between the origin point in the coordinate system of the rotation - deltav (-> (gpt/to-vec initial (if (= rotation 0) point-snap point)) - (gpt/transform (gmt/rotate-matrix (- rotation))) + deltav (-> (gpt/to-vec initial point) (gpt/multiply handler-mult)) ;; Resize vector @@ -317,26 +321,25 @@ scalev) ;; Resize origin point given the selected handler - origin (handler-resize-origin (:selrect shape) handler) + handler-origin (handler-resize-origin (:selrect shape) handler) - shape-center (gsh/center-shape shape) - shape-transform (:transform shape (gmt/matrix)) - shape-transform-inverse (:transform-inverse shape (gmt/matrix)) ;; If we want resize from center, displace the shape ;; so it is still centered after resize. - displacement (when center? - (-> shape-center - (gpt/subtract origin) - (gpt/multiply scalev) - (gpt/add origin) - (gpt/subtract shape-center) - (gpt/multiply (gpt/point -1 -1)) - (gpt/transform shape-transform))) + displacement + (when center? + (-> shape-center + (gpt/subtract handler-origin) + (gpt/multiply scalev) + (gpt/add handler-origin) + (gpt/subtract shape-center) + (gpt/multiply (gpt/point -1 -1)) + (gpt/transform shape-transform))) - origin (cond-> (gsh/transform-point-center origin shape-center shape-transform) - (some? displacement) - (gpt/add displacement)) + resize-origin + (cond-> (gsh/transform-point-center handler-origin shape-center shape-transform) + (some? displacement) + (gpt/add displacement)) displacement (when (some? displacement) (gmt/translate-matrix displacement))] @@ -344,7 +347,7 @@ (rx/of (set-modifiers ids {:displacement displacement :resize-vector scalev - :resize-origin origin + :resize-origin resize-origin :resize-transform shape-transform :resize-scale-text scale-text :resize-transform-inverse shape-transform-inverse})))) diff --git a/frontend/src/app/main/ui/workspace/viewport/selection.cljs b/frontend/src/app/main/ui/workspace/viewport/selection.cljs index b8282b5d8..9dc30ad5d 100644 --- a/frontend/src/app/main/ui/workspace/viewport/selection.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/selection.cljs @@ -229,7 +229,12 @@ current-transform (mf/deref refs/current-transform) selrect (:selrect shape) - transform (geom/transform-matrix shape {:no-flip true})] + transform (geom/transform-matrix shape {:no-flip true}) + + rotation (-> (gpt/point 1 0) + (gpt/transform (:transform shape)) + (gpt/angle) + (mod 360))] (when (not (#{:move :rotate} current-transform)) [:g.controls {:pointer-events (if disable-handlers "none" "visible")} @@ -249,7 +254,7 @@ :on-rotate on-rotate :on-resize (partial on-resize position) :transform transform - :rotation (:rotation shape) + :rotation rotation :color color :overflow-text overflow-text} props (map->obj (merge common-props props))]