diff --git a/CHANGES.md b/CHANGES.md index d77a83c85..21386a2cd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,12 @@ ## 1.6.4-alpha +## 1.6.4-alpha + +### :bug: Bugs fixed + +- Fix problem with paths editing after flip [#1040](https://github.com/penpot/penpot/issues/1040) + ### :sparkles: Minor improvements - Decrease default bulk buffers on storage tasks. diff --git a/common/app/common/geom/matrix.cljc b/common/app/common/geom/matrix.cljc index 04aa8651d..b24736dff 100644 --- a/common/app/common/geom/matrix.cljc +++ b/common/app/common/geom/matrix.cljc @@ -135,7 +135,9 @@ (defmethod pp/simple-dispatch Matrix [obj] (pr obj)) (defn transform-in [pt mtx] - (-> (matrix) - (translate pt) - (multiply mtx) - (translate (gpt/negate pt)))) + (if (some? pt) + (-> (matrix) + (translate pt) + (multiply mtx) + (translate (gpt/negate pt))) + mtx)) diff --git a/common/app/common/geom/shapes/transforms.cljc b/common/app/common/geom/shapes/transforms.cljc index 5f57aaec3..e35e6536e 100644 --- a/common/app/common/geom/shapes/transforms.cljc +++ b/common/app/common/geom/shapes/transforms.cljc @@ -304,21 +304,26 @@ :else (-> shape - (merge rect-shape)))] + (merge rect-shape))) + + base-rotation (or (:rotation shape) 0) + modif-rotation (or (get-in shape [:modifiers :rotation]) 0)] + (as-> shape $ (update $ :transform #(gmt/multiply (or % (gmt/matrix)) matrix)) (update $ :transform-inverse #(gmt/multiply matrix-inverse (or % (gmt/matrix)))) (assoc $ :points (into [] points)) (assoc $ :selrect (gpr/rect->selrect rect-shape)) - (update $ :rotation #(mod (+ (or % 0) - (or (get-in $ [:modifiers :rotation]) 0)) 360))))) + (assoc $ :rotation (mod (+ base-rotation modif-rotation) 360))))) (defn set-flip [shape modifiers] (let [rx (get-in modifiers [:resize-vector :x]) ry (get-in modifiers [:resize-vector :y])] (cond-> shape - (and rx (< rx 0)) (update :flip-x not) - (and ry (< ry 0)) (update :flip-y not)))) + (and rx (< rx 0)) (-> (update :flip-x not) + (update :rotation -)) + (and ry (< ry 0)) (-> (update :flip-y not) + (update :rotation -))))) (defn apply-displacement [shape] (let [modifiers (:modifiers shape)] diff --git a/frontend/src/app/main/data/workspace/path/helpers.cljs b/frontend/src/app/main/data/workspace/path/helpers.cljs index a1185b421..cbf9d383c 100644 --- a/frontend/src/app/main/data/workspace/path/helpers.cljs +++ b/frontend/src/app/main/data/workspace/path/helpers.cljs @@ -26,12 +26,31 @@ (= event :interrupt) ;; ESC (and (ms/mouse-double-click? event)))) +(defn content-center + [content] + (-> content + gsh/content->selrect + gsh/center-selrect)) + (defn content->points+selrect "Given the content of a shape, calculate its points and selrect" [shape content] - (let [transform (:transform shape (gmt/matrix)) - transform-inverse (:transform-inverse shape (gmt/matrix)) - center (gsh/center-shape shape) + + (let [{:keys [flip-x flip-y]} shape + transform + (cond-> (:transform shape (gmt/matrix)) + flip-x (gmt/scale (gpt/point -1 1)) + flip-y (gmt/scale (gpt/point 1 -1))) + + transform-inverse + (cond-> (gmt/matrix) + flip-x (gmt/scale (gpt/point -1 1)) + flip-y (gmt/scale (gpt/point 1 -1)) + :always (gmt/multiply (:transform-inverse shape (gmt/matrix)))) + + center (or (gsh/center-shape shape) + (content-center content)) + base-content (gsh/transform-content content (gmt/transform-in center transform-inverse)) @@ -39,30 +58,22 @@ ;; Calculates the new selrect with points given the old center points (-> (gsh/content->selrect base-content) (gsh/rect->points) - (gsh/transform-points center (:transform shape (gmt/matrix)))) + (gsh/transform-points center transform)) points-center (gsh/center-points points) ;; Points is now the selrect but the center is different so we can create the selrect ;; through points selrect (-> points - (gsh/transform-points points-center (:transform-inverse shape (gmt/matrix))) + (gsh/transform-points points-center transform-inverse) (gsh/points->selrect))] [points selrect])) (defn update-selrect "Updates the selrect and points for a path" [shape] - (if (= (:rotation shape 0) 0) - (let [content (:content shape) - selrect (gsh/content->selrect content) - points (gsh/rect->points selrect)] - (assoc shape :points points :selrect selrect)) - - (let [content (:content shape) - [points selrect] (content->points+selrect shape content)] - (assoc shape :points points :selrect selrect)))) - + (let [[points selrect] (content->points+selrect shape (:content shape))] + (assoc shape :points points :selrect selrect))) (defn closest-angle [angle]