0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 17:00:36 -05:00

🐛 Fixed open shapes boolean operations

This commit is contained in:
alonso.torres 2021-10-06 14:32:25 +02:00
parent efd2ad8f8b
commit 6918216b86
2 changed files with 31 additions and 13 deletions

View file

@ -12,7 +12,8 @@
[app.common.geom.shapes.common :as gsc]
[app.common.geom.shapes.rect :as gpr]
[app.common.math :as mth]
[app.common.path.commands :as upc]))
[app.common.path.commands :as upc]
[app.common.path.subpaths :as sp]))
(def ^:const curve-curve-precision 0.1)
(def ^:const curve-range-precision 2)
@ -818,19 +819,33 @@
(defn is-point-in-content?
[point content]
(let [selrect (content->selrect content)
ray-line [point (gpt/point (inc (:x point)) (:y point))]
(letfn [(cast-ray [cmd]
(let [ray-line [point (gpt/point (inc (:x point)) (:y point))]]
(case (:command cmd)
:line-to (ray-line-intersect point (command->line cmd))
:curve-to (ray-curve-intersect ray-line (command->bezier cmd))
#_:else [])))]
closed-subpaths
(->> content
(sp/close-subpaths)
(sp/get-subpaths)
(filterv sp/is-closed?))
(->> content
(mapcat cast-ray)
(map second)
(reduce +)
(not= 0))))
cast-ray
(fn [cmd]
(case (:command cmd)
:line-to (ray-line-intersect point (command->line cmd))
:curve-to (ray-curve-intersect ray-line (command->bezier cmd))
#_: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)
(some is-point-in-subpath? closed-subpaths))))
(defn split-line-to
"Given a point and a line-to command will create a two new line-to commands

View file

@ -116,6 +116,9 @@
(->> subpaths
(reduce merge-with-candidate [candidate []]))))
(defn is-closed? [subpath]
(pt= (:from subpath) (:to subpath)))
(defn close-subpaths
"Searches a path for posible supaths that can create closed loops and merge them"
[content]
@ -127,7 +130,7 @@
(if (some? current)
(let [[new-current new-subpaths]
(if (pt= (:from current) (:to current))
(if (is-closed? current)
[current subpaths]
(merge-paths current subpaths))]