🐛 Fix bug with transformation operations

This commit is contained in:
alonso.torres 2021-10-11 10:50:18 +02:00
parent 950367b055
commit 2833d3126f
3 changed files with 43 additions and 34 deletions

View file

@ -36,6 +36,7 @@
- Add stroke width in selection calculation [Taiga #2146](https://tree.taiga.io/project/penpot/issue/2146) - 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 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 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 ### :arrow_up: Deps updates

View file

@ -70,23 +70,19 @@
(defn- fix-init-point (defn- fix-init-point
"Fix the initial point so the resizes are accurate" "Fix the initial point so the resizes are accurate"
[initial handler shape] [initial handler shape]
(let [{:keys [x y width height]} (:selrect shape) (let [{:keys [x y width height]} (:selrect shape)]
{:keys [rotation]} shape (cond-> initial
rotation (or rotation 0)] (contains? #{:left :top-left :bottom-left} handler)
(if (= rotation 0) (assoc :x x)
(cond-> initial
(contains? #{:left :top-left :bottom-left} handler)
(assoc :x x)
(contains? #{:right :top-right :bottom-right} handler) (contains? #{:right :top-right :bottom-right} handler)
(assoc :x (+ x width)) (assoc :x (+ x width))
(contains? #{:top :top-right :top-left} handler) (contains? #{:top :top-right :top-left} handler)
(assoc :y y) (assoc :y y)
(contains? #{:bottom :bottom-right :bottom-left} handler) (contains? #{:bottom :bottom-right :bottom-left} handler)
(assoc :y (+ y height))) (assoc :y (+ y height)))))
initial)))
(defn finish-transform [] (defn finish-transform []
(ptk/reify ::finish-transform (ptk/reify ::finish-transform
@ -285,10 +281,19 @@
(letfn [(resize [shape initial layout [point lock? center? point-snap]] (letfn [(resize [shape initial layout [point lock? center? point-snap]]
(let [{:keys [width height]} (:selrect shape) (let [{:keys [width height]} (:selrect shape)
{:keys [rotation]} 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) rotation (or rotation 0)
initial (gsh/transform-point-center initial shape-center shape-transform-inverse)
initial (fix-init-point initial handler shape) 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)) shapev (-> (gpt/point width height))
scale-text (:scale-text layout) scale-text (:scale-text layout)
@ -300,8 +305,7 @@
handler-mult (let [[x y] (handler-multipliers handler)] (gpt/point x y)) handler-mult (let [[x y] (handler-multipliers handler)] (gpt/point x y))
;; Difference between the origin point in the coordinate system of the rotation ;; Difference between the origin point in the coordinate system of the rotation
deltav (-> (gpt/to-vec initial (if (= rotation 0) point-snap point)) deltav (-> (gpt/to-vec initial point)
(gpt/transform (gmt/rotate-matrix (- rotation)))
(gpt/multiply handler-mult)) (gpt/multiply handler-mult))
;; Resize vector ;; Resize vector
@ -317,26 +321,25 @@
scalev) scalev)
;; Resize origin point given the selected handler ;; 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 ;; If we want resize from center, displace the shape
;; so it is still centered after resize. ;; so it is still centered after resize.
displacement (when center? displacement
(-> shape-center (when center?
(gpt/subtract origin) (-> shape-center
(gpt/multiply scalev) (gpt/subtract handler-origin)
(gpt/add origin) (gpt/multiply scalev)
(gpt/subtract shape-center) (gpt/add handler-origin)
(gpt/multiply (gpt/point -1 -1)) (gpt/subtract shape-center)
(gpt/transform shape-transform))) (gpt/multiply (gpt/point -1 -1))
(gpt/transform shape-transform)))
origin (cond-> (gsh/transform-point-center origin shape-center shape-transform) resize-origin
(some? displacement) (cond-> (gsh/transform-point-center handler-origin shape-center shape-transform)
(gpt/add displacement)) (some? displacement)
(gpt/add displacement))
displacement (when (some? displacement) displacement (when (some? displacement)
(gmt/translate-matrix displacement))] (gmt/translate-matrix displacement))]
@ -344,7 +347,7 @@
(rx/of (set-modifiers ids (rx/of (set-modifiers ids
{:displacement displacement {:displacement displacement
:resize-vector scalev :resize-vector scalev
:resize-origin origin :resize-origin resize-origin
:resize-transform shape-transform :resize-transform shape-transform
:resize-scale-text scale-text :resize-scale-text scale-text
:resize-transform-inverse shape-transform-inverse})))) :resize-transform-inverse shape-transform-inverse}))))

View file

@ -229,7 +229,12 @@
current-transform (mf/deref refs/current-transform) current-transform (mf/deref refs/current-transform)
selrect (:selrect shape) 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)) (when (not (#{:move :rotate} current-transform))
[:g.controls {:pointer-events (if disable-handlers "none" "visible")} [:g.controls {:pointer-events (if disable-handlers "none" "visible")}
@ -249,7 +254,7 @@
:on-rotate on-rotate :on-rotate on-rotate
:on-resize (partial on-resize position) :on-resize (partial on-resize position)
:transform transform :transform transform
:rotation (:rotation shape) :rotation rotation
:color color :color color
:overflow-text overflow-text} :overflow-text overflow-text}
props (map->obj (merge common-props props))] props (map->obj (merge common-props props))]