diff --git a/CHANGES.md b/CHANGES.md index 569d5dde3..5ef076825 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -83,6 +83,7 @@ - Fix position of text cursor is a bit too high in Invitations section [Taiga #5511](https://tree.taiga.io/project/penpot/issue/5511) - Fix undo when updating several texts [Taiga #5197](https://tree.taiga.io/project/penpot/issue/5197) - Fix assets right click button for multiple selection [Taiga #5545](https://tree.taiga.io/project/penpot/issue/5545) +- Fix problem with precision in resizes [Taiga #5623](https://tree.taiga.io/project/penpot/issue/5623) ### :arrow_up: Deps updates diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index fabefe36b..9c2e99dcb 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -136,6 +136,7 @@ (dm/export gco/center-rect) (dm/export gco/center-points) (dm/export gco/transform-points) +(dm/export gco/shape->points) (dm/export gpr/make-rect) (dm/export gpr/make-selrect) diff --git a/common/src/app/common/geom/shapes/common.cljc b/common/src/app/common/geom/shapes/common.cljc index a0fcdb4b5..bb4d57356 100644 --- a/common/src/app/common/geom/shapes/common.cljc +++ b/common/src/app/common/geom/shapes/common.cljc @@ -84,3 +84,15 @@ (or (mth/nan? (:x p)) (mth/nan? (:y p)))) points))) + +(defn shape->points + [{:keys [transform points]}] + (if (gmt/unit? transform) + ;; Fix problem with precision could skew the shape + ;; when there are no transforms the points are the selrect shape + (let [p0 (nth points 0) ;; left top + p2 (nth points 2) ;; right bottom + p1 (gpt/point (:x p2) (:y p0)) + p3 (gpt/point (:x p0) (:y p2))] + [p0 p1 p2 p3]) + points)) diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index 14ffa6ddf..fb033a49b 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -463,7 +463,7 @@ (cond-> modif-tree snap-pixel? (gpp/adjust-pixel-precision objects snap-precision snap-ignore-axis)) - bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points])) + bounds (d/lazy-map (keys objects) #(gco/shape->points (get objects %))) bounds (cond-> bounds (some? old-modif-tree) (transform-bounds objects old-modif-tree)) diff --git a/common/src/app/common/geom/shapes/pixel_precision.cljc b/common/src/app/common/geom/shapes/pixel_precision.cljc index 9994b0978..340246501 100644 --- a/common/src/app/common/geom/shapes/pixel_precision.cljc +++ b/common/src/app/common/geom/shapes/pixel_precision.cljc @@ -58,7 +58,7 @@ (defn set-pixel-precision "Adjust modifiers so they adjust to the pixel grid" [modifiers shape precision ignore-axis] - (let [points (-> shape :points (gco/transform-points (ctm/modifiers->transform modifiers))) + (let [points (-> shape gco/shape->points (gco/transform-points (ctm/modifiers->transform modifiers))) has-resize? (not (ctm/only-move? modifiers)) [modifiers points] diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index 1c7bc9b8e..90bddd81e 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -317,7 +317,7 @@ its properties. We adjust de x,y,width,height and create a custom transform" [shape transform-mtx] - (let [points' (:points shape) + (let [points' (gco/shape->points shape) points (gco/transform-points points' transform-mtx) shape (-> shape (adjust-shape-flips points)) bool? (= (:type shape) :bool)