mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 08:18:26 +02:00
✨ Snap for beziers
This commit is contained in:
parent
d8ab3473bf
commit
05366eac6f
7 changed files with 44 additions and 26 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue