mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
⚡ Add efficiency changes on make-curve-point helper
This commit is contained in:
parent
4ce654511b
commit
f302c724c4
1 changed files with 28 additions and 24 deletions
|
@ -86,13 +86,18 @@
|
||||||
handler-points (map #(upc/handler->point content (first %) (second %)) handlers)]
|
handler-points (map #(upc/handler->point content (first %) (second %)) handlers)]
|
||||||
(some #(not= point %) handler-points)))
|
(some #(not= point %) handler-points)))
|
||||||
|
|
||||||
|
(def ^:private xf:mapcat-points
|
||||||
|
(comp
|
||||||
|
(mapcat #(vector (:next-p %) (:prev-p %)))
|
||||||
|
(remove nil?)))
|
||||||
|
|
||||||
(defn make-curve-point
|
(defn make-curve-point
|
||||||
"Changes the content to make the point a 'curve'. The handlers will be positioned
|
"Changes the content to make the point a 'curve'. The handlers will be positioned
|
||||||
in the same vector that results from the previous->next points but with fixed length."
|
in the same vector that results from the previous->next points but with fixed length."
|
||||||
[content point]
|
[content point]
|
||||||
|
|
||||||
(let [indices (upc/point-indices content point)
|
(let [indices (upc/point-indices content point)
|
||||||
vectors (->> indices (mapv (fn [index]
|
vectors (map (fn [index]
|
||||||
(let [cmd (nth content index)
|
(let [cmd (nth content index)
|
||||||
prev-i (dec index)
|
prev-i (dec index)
|
||||||
prev (when (not (= :move-to (:command cmd)))
|
prev (when (not (= :move-to (:command cmd)))
|
||||||
|
@ -102,20 +107,19 @@
|
||||||
|
|
||||||
next (when (not (= :move-to (:command next)))
|
next (when (not (= :move-to (:command next)))
|
||||||
next)]
|
next)]
|
||||||
(hash-map :index index
|
{:index index
|
||||||
:prev-i (when (some? prev) prev-i)
|
:prev-i (when (some? prev) prev-i)
|
||||||
:prev-c prev
|
:prev-c prev
|
||||||
:prev-p (upc/command->point prev)
|
:prev-p (upc/command->point prev)
|
||||||
:next-i (when (some? next) next-i)
|
:next-i (when (some? next) next-i)
|
||||||
:next-c next
|
:next-c next
|
||||||
:next-p (upc/command->point next)
|
:next-p (upc/command->point next)
|
||||||
:command cmd)))))
|
:command cmd}))
|
||||||
|
indices)
|
||||||
|
|
||||||
points (->> vectors (mapcat #(vector (:next-p %) (:prev-p %))) (remove nil?) (into #{}))]
|
points (into #{} xf:mapcat-points vectors)]
|
||||||
|
|
||||||
(cond
|
(if (= (count points) 2)
|
||||||
(= (count points) 2)
|
|
||||||
;;
|
|
||||||
(let [v1 (gpt/to-vec (first points) point)
|
(let [v1 (gpt/to-vec (first points) point)
|
||||||
v2 (gpt/to-vec (first points) (second points))
|
v2 (gpt/to-vec (first points) (second points))
|
||||||
vp (gpt/project v1 v2)
|
vp (gpt/project v1 v2)
|
||||||
|
@ -148,9 +152,9 @@
|
||||||
|
|
||||||
(and (= :curve-to (:command next-cmd)) (some? next-p))
|
(and (= :curve-to (:command next-cmd)) (some? next-p))
|
||||||
(update next-i upc/update-handler :c1 next-h))))]
|
(update next-i upc/update-handler :c1 next-h))))]
|
||||||
(->> vectors (reduce add-curve content)))
|
|
||||||
|
|
||||||
:else
|
(reduce add-curve content vectors))
|
||||||
|
|
||||||
(let [add-curve
|
(let [add-curve
|
||||||
(fn [content {:keys [index command prev-p next-c next-i]}]
|
(fn [content {:keys [index command prev-p next-c next-i]}]
|
||||||
(cond-> content
|
(cond-> content
|
||||||
|
@ -165,7 +169,7 @@
|
||||||
|
|
||||||
(= :curve-to (:command next-c))
|
(= :curve-to (:command next-c))
|
||||||
(update next-i #(line->curve point %))))]
|
(update next-i #(line->curve point %))))]
|
||||||
(->> vectors (reduce add-curve content))))))
|
(reduce add-curve content vectors)))))
|
||||||
|
|
||||||
(defn get-segments
|
(defn get-segments
|
||||||
"Given a content and a set of points return all the segments in the path
|
"Given a content and a set of points return all the segments in the path
|
||||||
|
|
Loading…
Add table
Reference in a new issue