mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
✨ Snap for beziers
This commit is contained in:
parent
d8ab3473bf
commit
05366eac6f
7 changed files with 44 additions and 26 deletions
|
@ -156,8 +156,9 @@
|
|||
"Returns a rect that contains all the shapes and is aware of the
|
||||
rotation of each shape. Mainly used for multiple selection."
|
||||
[shapes]
|
||||
(let [points (->> shapes (mapcat :points))]
|
||||
(gpr/points->selrect points)))
|
||||
(->> shapes
|
||||
(map :selrect)
|
||||
(gpr/join-selrects)))
|
||||
|
||||
(defn translate-to-frame
|
||||
[shape {:keys [x y] :as frame}]
|
||||
|
|
|
@ -44,6 +44,20 @@
|
|||
(defn rect->selrect [rect]
|
||||
(-> rect rect->points points->selrect))
|
||||
|
||||
(defn join-selrects [selrects]
|
||||
(let [minx (transduce (map :x1) min ##Inf selrects)
|
||||
miny (transduce (map :y1) min ##Inf selrects)
|
||||
maxx (transduce (map :x2) max ##-Inf selrects)
|
||||
maxy (transduce (map :y2) max ##-Inf selrects)]
|
||||
{:x minx
|
||||
:y miny
|
||||
:x1 minx
|
||||
:y1 miny
|
||||
:x2 maxx
|
||||
:y2 maxy
|
||||
:width (- maxx minx)
|
||||
:height (- maxy miny)}))
|
||||
|
||||
;; --- SHAPE -> RECT
|
||||
#_(
|
||||
(defn- rect->rect-shape
|
||||
|
|
|
@ -285,14 +285,14 @@
|
|||
(< (get-in modifiers [:resize-vector :y]) 0) (update :flip-y not)))
|
||||
|
||||
(defn transform-shape [shape]
|
||||
(if (:modifiers shape)
|
||||
(let [center (gco/center-shape shape)
|
||||
transform (modifiers->transform (:transform shape (gmt/matrix)) center (:modifiers shape))]
|
||||
(-> shape
|
||||
(set-flip (:modifiers shape))
|
||||
(apply-transform transform)
|
||||
(dissoc :modifiers)))
|
||||
shape))
|
||||
(let [center (gco/center-shape shape)]
|
||||
(if (and (:modifiers shape) center)
|
||||
(let [transform (modifiers->transform (:transform shape (gmt/matrix)) center (:modifiers shape))]
|
||||
(-> shape
|
||||
(set-flip (:modifiers shape))
|
||||
(apply-transform transform)
|
||||
(dissoc :modifiers)))
|
||||
shape)))
|
||||
|
||||
#_(defn transform-shape
|
||||
"Transform the shape properties given the modifiers"
|
||||
|
|
|
@ -195,7 +195,7 @@
|
|||
(or (filter-shapes id)
|
||||
(not (contains? layout :dynamic-alignment)))))
|
||||
shape (if (> (count shapes) 1)
|
||||
(->> shapes (map gsh/transform-shape) gsh/selection-rect)
|
||||
(->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect}))
|
||||
(->> shapes (first)))
|
||||
|
||||
shapes-points (->> shape
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
(mf/defc path-editor
|
||||
[{:keys [shape zoom]}]
|
||||
|
||||
(let [points (:points shape)
|
||||
(let [points (gsp/content->points (:content shape))
|
||||
drag-handler (:drag-handler shape)
|
||||
prev-handler (:prev-handler shape)
|
||||
last-command (last (:content shape))
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
(defn get-snap
|
||||
[coord {:keys [shapes page-id filter-shapes local]}]
|
||||
(let [shape (if (> (count shapes) 1)
|
||||
(->> shapes (map gsh/transform-shape) gsh/selection-rect)
|
||||
(->> shapes (map gsh/transform-shape) gsh/selection-rect (gsh/setup {:type :rect}))
|
||||
(->> shapes (first)))
|
||||
|
||||
shape (if (:modifiers local)
|
||||
|
|
|
@ -14,22 +14,25 @@
|
|||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.point :as gpt]))
|
||||
|
||||
(defn- frame-snap-points [{:keys [x y width height] :as frame}]
|
||||
(into #{(gpt/point x y)
|
||||
(gpt/point (+ x (/ width 2)) y)
|
||||
(gpt/point (+ x width) y)
|
||||
(defn- selrect-snap-points [{:keys [x y width height]}]
|
||||
#{(gpt/point x y)
|
||||
(gpt/point (+ x width) y)
|
||||
(gpt/point (+ x width) (+ y height))
|
||||
(gpt/point x (+ y height))})
|
||||
|
||||
(defn- frame-snap-points [{:keys [x y width height] :as selrect}]
|
||||
(into (selrect-snap-points selrect)
|
||||
#{(gpt/point (+ x (/ width 2)) y)
|
||||
(gpt/point (+ x width) (+ y (/ height 2)))
|
||||
(gpt/point (+ x width) (+ y height))
|
||||
(gpt/point (+ x (/ width 2)) (+ y height))
|
||||
(gpt/point x (+ y height))
|
||||
(gpt/point x (+ y (/ height 2)))}))
|
||||
|
||||
(defn shape-snap-points
|
||||
[shape]
|
||||
(let [shape (gsh/transform-shape shape)
|
||||
shape-center (gsh/center-shape shape)]
|
||||
(if (= :frame (:type shape))
|
||||
(-> shape
|
||||
:selrect
|
||||
(frame-snap-points))
|
||||
(into #{shape-center} (:points shape)))))
|
||||
(let [shape (gsh/transform-shape shape)]
|
||||
|
||||
(case (:type shape)
|
||||
:frame (-> shape :selrect frame-snap-points)
|
||||
(:path :curve) (-> shape :selrect selrect-snap-points)
|
||||
(into #{(gsh/center-shape shape)} (:points shape)))
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue