Add the ability to provide initial value on path -walk

This commit is contained in:
Andrey Antukh 2025-04-08 22:02:37 +02:00
parent 33bcbd89f1
commit 44e8eacb8d
2 changed files with 7 additions and 6 deletions

View File

@ -33,7 +33,7 @@
(defprotocol ITransformable (defprotocol ITransformable
(-transform [_ m] "apply a transform") (-transform [_ m] "apply a transform")
(-walk [_ f])) (-walk [_ f initial]))
(defn- transform! (defn- transform!
"Apply a transformation to a segment located under specified offset" "Apply a transformation to a segment located under specified offset"
@ -260,9 +260,9 @@
(recur (inc index))))) (recur (inc index)))))
(PathData. size buffer nil))) (PathData. size buffer nil)))
(-walk [_ f] (-walk [_ f initial]
(loop [index 0 (loop [index 0
result (transient [])] result (transient initial)]
(if (< index size) (if (< index size)
(let [offset (* index SEGMENT-BYTE-SIZE) (let [offset (* index SEGMENT-BYTE-SIZE)
type (.getShort ^ByteBuffer buffer offset) type (.getShort ^ByteBuffer buffer offset)
@ -367,11 +367,11 @@
(recur (inc index))))) (recur (inc index)))))
(PathData. size buffer dview (weak-map/create) nil))) (PathData. size buffer dview (weak-map/create) nil)))
(-walk [_ f] (-walk [_ f initial]
(let [farray (js/Float32Array. buffer) (let [farray (js/Float32Array. buffer)
iarray (js/Int32Array. buffer)] iarray (js/Int32Array. buffer)]
(loop [index 0 (loop [index 0
result (transient [])] result (transient initial)]
(if (< index size) (if (< index size)
(let [offset (* index SEGMENT-BYTE-SIZE) (let [offset (* index SEGMENT-BYTE-SIZE)
type (.getInt16 dview offset) type (.getInt16 dview offset)

View File

@ -174,7 +174,8 @@
(impl/-walk content (impl/-walk content
(fn [type _ _ _ _ x y] (fn [type _ _ _ _ x y]
(when (not= type :close-path) (when (not= type :close-path)
(gpt/point x y)))))) (gpt/point x y)))
[])))
(defn segments->content (defn segments->content
([segments] ([segments]