🐛 Fix problem with mix between open/closed and line/curves

This commit is contained in:
alonso.torres 2021-10-11 11:54:50 +02:00
parent 2833d3126f
commit d2d506dbf0

View file

@ -126,8 +126,8 @@
(let [tangent (curve-tangent curve t)] (let [tangent (curve-tangent curve t)]
(cond (cond
(> (:y tangent) 0) 1 (> (:y tangent) 0) -1
(< (:y tangent) 0) -1 (< (:y tangent) 0) 1
:else 0))) :else 0)))
(defn curve-split (defn curve-split
@ -822,30 +822,27 @@
(let [selrect (content->selrect content) (let [selrect (content->selrect content)
ray-line [point (gpt/point (inc (:x point)) (:y point))] ray-line [point (gpt/point (inc (:x point)) (:y point))]
closed-subpaths closed-content
(->> content (into []
(sp/close-subpaths) (comp (filter sp/is-closed?)
(sp/get-subpaths) (mapcat :data))
(filterv sp/is-closed?)) (->> content
(sp/close-subpaths)
(sp/get-subpaths)))
cast-ray cast-ray
(fn [cmd] (fn [cmd]
(case (:command cmd) (case (:command cmd)
:line-to (ray-line-intersect point (command->line cmd)) :line-to (ray-line-intersect point (command->line cmd))
:curve-to (ray-curve-intersect ray-line (command->bezier cmd)) :curve-to (ray-curve-intersect ray-line (command->bezier cmd))
#_:else [])) #_:else []))]
is-point-in-subpath?
(fn [subpath]
(and (gpr/contains-point? (content->selrect (:data subpath)) point)
(->> (:data subpath)
(mapcat cast-ray)
(map second)
(reduce +)
(not= 0))))]
(and (gpr/contains-point? selrect point) (and (gpr/contains-point? selrect point)
(some is-point-in-subpath? closed-subpaths)))) (->> closed-content
(mapcat cast-ray)
(map second)
(reduce +)
(not= 0)))))
(defn split-line-to (defn split-line-to
"Given a point and a line-to command will create a two new line-to commands "Given a point and a line-to command will create a two new line-to commands