🎉 Improved reusability of drawing functions

This commit is contained in:
alonso.torres 2020-11-13 16:23:36 +01:00
parent 05366eac6f
commit 275f6e3dc2
6 changed files with 154 additions and 77 deletions

View file

@ -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]

View file

@ -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

View file

@ -226,7 +226,8 @@
:content content
:points points
:selrect selrect
:rotation rotation)))
;;:rotation rotation
)))
(defn apply-transform-curve
[shape transform]