mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 23:28:24 +02:00
🐛 Fixes problems with transforms
This commit is contained in:
parent
b1c786077b
commit
55b71a111b
6 changed files with 68 additions and 65 deletions
|
@ -157,7 +157,8 @@
|
|||
rotation of each shape. Mainly used for multiple selection."
|
||||
[shapes]
|
||||
(->> shapes
|
||||
(map :selrect)
|
||||
(gtr/transform-shape)
|
||||
(map (comp gpr/points->selrect :points))
|
||||
(gpr/join-selrects)))
|
||||
|
||||
(defn translate-to-frame
|
||||
|
@ -288,15 +289,9 @@
|
|||
(defn center-rect [rect] (gco/center-rect rect))
|
||||
|
||||
(defn rect->selrect [rect] (gpr/rect->selrect rect))
|
||||
|
||||
#_(def shape->rect-shape gpr/shape->rect-shape)
|
||||
#_(def fix-invalid-rect-values gtr/fix-invalid-rect-values)
|
||||
#_(def rect->rect-shape gpr/rect->rect-shape)
|
||||
(defn rect->points [rect] (gpr/rect->points rect))
|
||||
(defn points->selrect [points] (gpr/points->selrect points))
|
||||
|
||||
#_(def transform-shape-point gtr/transform-shape-point)
|
||||
#_(def update-path-selrect gtr/update-path-selrect)
|
||||
#_(def transform gtr/transform)
|
||||
(defn transform-shape [shape] (gtr/transform-shape shape))
|
||||
(defn transform-matrix [shape] (gtr/transform-matrix shape))
|
||||
(defn transform-point-center [point center transform] (gtr/transform-point-center point center transform))
|
||||
|
|
|
@ -108,6 +108,8 @@
|
|||
resize-transform-inverse (:resize-transform-inverse modifiers (gmt/matrix))
|
||||
rt-modif (or (:rotation modifiers) 0)
|
||||
|
||||
center (gpt/transform center ds-modifier)
|
||||
|
||||
transform (-> (gmt/matrix)
|
||||
|
||||
;; Applies the current resize transformation
|
||||
|
@ -120,7 +122,6 @@
|
|||
;; Applies the stacked transformations
|
||||
(gmt/translate center)
|
||||
(gmt/multiply (gmt/rotate-matrix rt-modif))
|
||||
#_(gmt/multiply current-transform)
|
||||
(gmt/translate (gpt/negate center))
|
||||
|
||||
;; Displacement
|
||||
|
@ -186,7 +187,7 @@
|
|||
stretch-matrix (gmt/multiply stretch-matrix (gmt/skew-matrix skew-angle 0))
|
||||
|
||||
h1 (calculate-height points-temp)
|
||||
h2 (calculate-height (transform-points points-temp center stretch-matrix))
|
||||
h2 (calculate-height (transform-points points-rec center stretch-matrix))
|
||||
h3 (/ h1 h2)
|
||||
h3 (if (mth/nan? h3) 1 h3)
|
||||
|
||||
|
@ -200,15 +201,10 @@
|
|||
|
||||
stretch-matrix (gmt/multiply (gmt/rotate-matrix rotation-angle) stretch-matrix)
|
||||
|
||||
stretch-matrix (-> (gmt/matrix)
|
||||
(gmt/rotate rotation-angle)
|
||||
(gmt/skew skew-angle 0)
|
||||
(gmt/scale (gpt/point 1 h3)))
|
||||
|
||||
|
||||
;; This is the inverse to be able to remove the transformation
|
||||
stretch-matrix-inverse (-> (gmt/matrix)
|
||||
(gmt/scale (gpt/point 1 h3))
|
||||
(gmt/scale (gpt/point 1 (/ 1 h3)))
|
||||
(gmt/skew (- skew-angle) 0)
|
||||
(gmt/rotate (- rotation-angle)))]
|
||||
[stretch-matrix stretch-matrix-inverse]))
|
||||
|
@ -217,17 +213,15 @@
|
|||
(defn apply-transform-path
|
||||
[shape transform]
|
||||
(let [content (gpa/transform-content (:content shape) transform)
|
||||
points (gpa/content->points content)
|
||||
selrect (gpa/content->selrect content)
|
||||
points (gpr/rect->points selrect)
|
||||
rotation (mod (+ (:rotation shape 0)
|
||||
(or (get-in shape [:modifiers :rotation]) 0))
|
||||
360)
|
||||
selrect (gpa/content->selrect content)]
|
||||
360)]
|
||||
(assoc shape
|
||||
:content content
|
||||
:points points
|
||||
:selrect selrect
|
||||
;;:rotation rotation
|
||||
)))
|
||||
:selrect selrect)))
|
||||
|
||||
(defn apply-transform-curve
|
||||
[shape transform]
|
||||
|
@ -255,22 +249,19 @@
|
|||
(:height points-temp-dim))
|
||||
rect-points (gpr/rect->points rect-shape)
|
||||
|
||||
[matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points (:flip-x shape) (:flip-y shape))
|
||||
;;[matrix matrix-inverse] [(gmt/matrix) (gmt/matrix)]
|
||||
|
||||
new-shape (as-> shape $
|
||||
(merge $ rect-shape)
|
||||
(update $ :x #(mth/precision % 0))
|
||||
(update $ :y #(mth/precision % 0))
|
||||
(update $ :width #(mth/precision % 0))
|
||||
(update $ :height #(mth/precision % 0))
|
||||
(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)))]
|
||||
new-shape))
|
||||
[matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points (:flip-x shape) (:flip-y shape))]
|
||||
(as-> shape $
|
||||
(merge $ rect-shape)
|
||||
(update $ :x #(mth/precision % 0))
|
||||
(update $ :y #(mth/precision % 0))
|
||||
(update $ :width #(mth/precision % 0))
|
||||
(update $ :height #(mth/precision % 0))
|
||||
(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)))))
|
||||
|
||||
(defn apply-transform [shape transform]
|
||||
(let [apply-transform-fn
|
||||
|
@ -281,9 +272,11 @@
|
|||
(apply-transform-fn shape transform)))
|
||||
|
||||
(defn set-flip [shape modifiers]
|
||||
(cond-> shape
|
||||
(< (get-in modifiers [:resize-vector :x]) 0) (update :flip-x not)
|
||||
(< (get-in modifiers [:resize-vector :y]) 0) (update :flip-y not)))
|
||||
(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))))
|
||||
|
||||
(defn transform-shape [shape]
|
||||
(let [center (gco/center-shape shape)]
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
(defn finite?
|
||||
[v]
|
||||
#?(:cljs (and (not (nil? v)) (js/isFinite v))
|
||||
:clj (Double/isFinite v)))
|
||||
:clj (and (not (nil? v)) (Double/isFinite v))))
|
||||
|
||||
(defn abs
|
||||
[v]
|
||||
|
|
|
@ -798,10 +798,10 @@
|
|||
|
||||
;; Rotate the group shape change the data and rotate back again
|
||||
(-> group
|
||||
(assoc-in [:modifiers :rotation] (- (:rotation group 0)))
|
||||
(geom/transform-shape)
|
||||
(assoc :selrect selrect)
|
||||
(assoc :points (geom/rect->points selrect))
|
||||
(merge (select-keys selrect [:x :y :width :height]))
|
||||
(assoc-in [:modifiers :rotation] (:rotation group))
|
||||
(assoc-in [:modifiers :rotation] (:rotation group 0))
|
||||
(geom/transform-shape))))]
|
||||
|
||||
(d/update-in-when data [:pages-index page-id :objects] reg-objects)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue