mirror of
https://github.com/penpot/penpot.git
synced 2025-08-04 00:08:34 +02:00
🎉 Improved reusability of drawing functions
This commit is contained in:
parent
05366eac6f
commit
275f6e3dc2
6 changed files with 154 additions and 77 deletions
|
@ -26,6 +26,14 @@
|
|||
[v]
|
||||
(instance? Point v))
|
||||
|
||||
(defn ^boolean point-like?
|
||||
[{:keys [x y] :as v}]
|
||||
(and (map? v)
|
||||
(not (nil? x))
|
||||
(not (nil? y))
|
||||
(number? x)
|
||||
(number? y)))
|
||||
|
||||
(defn point
|
||||
"Create a Point instance."
|
||||
([] (Point. 0 0))
|
||||
|
@ -37,6 +45,9 @@
|
|||
(number? v)
|
||||
(Point. v v)
|
||||
|
||||
(point-like? v)
|
||||
(Point. (:x v) (:y v))
|
||||
|
||||
:else
|
||||
(throw (ex-info "Invalid arguments" {:v v}))))
|
||||
([x y]
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
segments)
|
||||
|
||||
(defn content->points [content]
|
||||
(mapv #(gpt/point (-> % :params :x) (-> % :params :y)) content))
|
||||
(->> content
|
||||
(map #(when (-> % :params :x) (gpt/point (-> % :params :x) (-> % :params :y))))
|
||||
(remove nil?)
|
||||
(into [])))
|
||||
|
||||
;; https://medium.com/@Acegikmo/the-ever-so-lovely-b%C3%A9zier-curve-eb27514da3bf
|
||||
;; https://en.wikipedia.org/wiki/Bernstein_polynomial
|
||||
|
@ -105,6 +108,7 @@
|
|||
(let [calc-extremities
|
||||
(fn [command prev]
|
||||
(case (:command command)
|
||||
:close-path []
|
||||
:move-to [(command->point command)]
|
||||
|
||||
;; If it's a line we add the beginning point and endpoint
|
||||
|
|
|
@ -226,7 +226,8 @@
|
|||
:content content
|
||||
:points points
|
||||
:selrect selrect
|
||||
:rotation rotation)))
|
||||
;;:rotation rotation
|
||||
)))
|
||||
|
||||
(defn apply-transform-curve
|
||||
[shape transform]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue