mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -05:00
Add polymorphic impl for -outer-rect calculation.
This commit is contained in:
parent
42d818138a
commit
59af707143
1 changed files with 35 additions and 0 deletions
|
@ -46,6 +46,10 @@
|
|||
dispatch-by-type
|
||||
:hierarchy #'+hierarchy+)
|
||||
|
||||
(defmulti -outer-rect
|
||||
dispatch-by-type
|
||||
:hierarchy #'+hierarchy+)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Implementation
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
@ -66,6 +70,37 @@
|
|||
[shape rotation]
|
||||
(assoc shape :rotation rotation))
|
||||
|
||||
(declare container-rect)
|
||||
(declare resolve-position)
|
||||
|
||||
(defmethod -outer-rect ::shape
|
||||
[{:keys [group] :as shape}]
|
||||
(as-> shape $
|
||||
(resolve-position $)
|
||||
(container-rect $)))
|
||||
|
||||
(defmethod -outer-rect :builtin/group
|
||||
[{:keys [id group rotation view-box] :as shape}]
|
||||
(let [shapes (->> (:items shape)
|
||||
(map #(get-in @st/state [:shapes-by-id %]))
|
||||
(map -outer-rect))
|
||||
|
||||
crect (-> shape
|
||||
(resolve-position)
|
||||
(container-rect))
|
||||
|
||||
shapes (into [crect] shapes)
|
||||
|
||||
x (apply min (map :x shapes))
|
||||
y (apply min (map :y shapes))
|
||||
x' (apply max (map (fn [{:keys [x width]}] (+ x width)) shapes))
|
||||
y' (apply max (map (fn [{:keys [y height]}] (+ y height)) shapes))
|
||||
width (- x' x)
|
||||
height (- y' y)]
|
||||
(as-> shape $
|
||||
(merge $ {:width width :height height :x x :y y})
|
||||
(container-rect $))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Helpers
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
Loading…
Reference in a new issue