mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 06:31:38 +02:00
Add absolute move abstraction.
This commit is contained in:
parent
00cc51c6d3
commit
bbca48a7a2
1 changed files with 37 additions and 2 deletions
|
@ -42,6 +42,10 @@
|
||||||
dispatch-by-type
|
dispatch-by-type
|
||||||
:hierarchy #'+hierarchy+)
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
|
(defmulti -move'
|
||||||
|
dispatch-by-type
|
||||||
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
(defmulti -resize
|
(defmulti -resize
|
||||||
dispatch-by-type
|
dispatch-by-type
|
||||||
:hierarchy #'+hierarchy+)
|
:hierarchy #'+hierarchy+)
|
||||||
|
@ -128,23 +132,54 @@
|
||||||
;; Move
|
;; Move
|
||||||
|
|
||||||
(defmethod -move ::rect
|
(defmethod -move ::rect
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape [dx dy]]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x (+ (:x shape) dx)
|
:x (+ (:x shape) dx)
|
||||||
:y (+ (:y shape) dy)))
|
:y (+ (:y shape) dy)))
|
||||||
|
|
||||||
(defmethod -move :builtin/line
|
(defmethod -move :builtin/line
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape [dx dy]]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x1 (+ (:x1 shape) dx)
|
:x1 (+ (:x1 shape) dx)
|
||||||
:y1 (+ (:y1 shape) dy)
|
:y1 (+ (:y1 shape) dy)
|
||||||
:x2 (+ (:x2 shape) dx)
|
:x2 (+ (:x2 shape) dx)
|
||||||
:y2 (+ (:y2 shape) dy)))
|
:y2 (+ (:y2 shape) dy)))
|
||||||
|
|
||||||
|
(defmethod -move :builtin/circle
|
||||||
|
[shape [dx dy]]
|
||||||
|
(assoc shape
|
||||||
|
:cx (+ (:cx shape) dx)
|
||||||
|
:cy (+ (:cy shape) dy)))
|
||||||
|
|
||||||
(defmethod -move :default
|
(defmethod -move :default
|
||||||
[shape _]
|
[shape _]
|
||||||
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
|
(defmethod -move' ::rect
|
||||||
|
[shape [x y]]
|
||||||
|
(let [dx (if x (- (:x shape) x) 0)
|
||||||
|
dy (if y (- (:y shape) y) 0)]
|
||||||
|
(-move shape [dx dy])))
|
||||||
|
|
||||||
|
(defmethod -move' :builtin/line
|
||||||
|
[shape [x y]]
|
||||||
|
(let [dx (if x (- (:x1 shape) x) 0)
|
||||||
|
dy (if y (- (:y1 shape) y) 0)]
|
||||||
|
(-move shape [dx dy])))
|
||||||
|
|
||||||
|
(defmethod -move' :builtin/circle
|
||||||
|
[shape [x y]]
|
||||||
|
(let [{:keys [cx cy rx ry]} shape
|
||||||
|
x1 (- cx rx)
|
||||||
|
y1 (- cy ry)
|
||||||
|
dx (if x (- (:x1 shape) x) 0)
|
||||||
|
dy (if y (- (:y1 shape) y) 0)]
|
||||||
|
(-move shape [dx dy])))
|
||||||
|
|
||||||
|
(defmethod -move' :default
|
||||||
|
[shape _]
|
||||||
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
(defmethod -rotate ::shape
|
(defmethod -rotate ::shape
|
||||||
[shape rotation]
|
[shape rotation]
|
||||||
(assoc shape :rotation rotation))
|
(assoc shape :rotation rotation))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue