mirror of
https://github.com/penpot/penpot.git
synced 2026-09-14 07:59:36 +00:00
🐛 Fix problem with boolean edges (#6218)
This commit is contained in:
parent
5937ed57ce
commit
137e8d042f
@ -10,6 +10,7 @@
|
|||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.rect :as grc]
|
[app.common.geom.rect :as grc]
|
||||||
[app.common.geom.shapes.path :as gsp]
|
[app.common.geom.shapes.path :as gsp]
|
||||||
|
[app.common.math :as mth]
|
||||||
[app.common.svg.path.command :as upc]
|
[app.common.svg.path.command :as upc]
|
||||||
[app.common.svg.path.subpath :as ups]))
|
[app.common.svg.path.subpath :as ups]))
|
||||||
|
|
||||||
@ -233,6 +234,45 @@
|
|||||||
(gsp/command->point current)
|
(gsp/command->point current)
|
||||||
(conj result (dissoc current :prev)))))))
|
(conj result (dissoc current :prev)))))))
|
||||||
|
|
||||||
|
(defn remove-duplicated-segments
|
||||||
|
"Remove from the content segments"
|
||||||
|
[content]
|
||||||
|
(letfn [;; This is a comparator for float points with a precission
|
||||||
|
;; used to remove already existing segments
|
||||||
|
(comparator [[fx1 fy1 tx1 ty1 :as v1] [fx2 fy2 tx2 ty2 :as v2]]
|
||||||
|
(if (and (mth/close? tx1 tx2)
|
||||||
|
(mth/close? ty1 ty2)
|
||||||
|
(mth/close? fx1 fx2)
|
||||||
|
(mth/close? fy1 fy2))
|
||||||
|
0 ;; equal
|
||||||
|
(compare v1 v2)))]
|
||||||
|
|
||||||
|
(loop [current (first content)
|
||||||
|
content (rest content)
|
||||||
|
segments (sorted-set-by comparator)
|
||||||
|
result []]
|
||||||
|
|
||||||
|
(if (nil? current)
|
||||||
|
result
|
||||||
|
|
||||||
|
(let [fx (-> current :prev :x)
|
||||||
|
fy (-> current :prev :y)
|
||||||
|
tx (-> current :params :x)
|
||||||
|
ty (-> current :params :y)
|
||||||
|
|
||||||
|
result
|
||||||
|
(cond-> result
|
||||||
|
(and (not (contains? segments [fx fy tx ty]))
|
||||||
|
(not (contains? segments [tx ty fx fy])))
|
||||||
|
(conj current))
|
||||||
|
|
||||||
|
segments (conj segments [fx fy tx ty])]
|
||||||
|
|
||||||
|
(recur (first content)
|
||||||
|
(rest content)
|
||||||
|
segments
|
||||||
|
result))))))
|
||||||
|
|
||||||
(defn create-union [content-a content-a-split content-b content-b-split sr-a sr-b]
|
(defn create-union [content-a content-a-split content-b content-b-split sr-a sr-b]
|
||||||
;; Pick all segments in content-a that are not inside content-b
|
;; Pick all segments in content-a that are not inside content-b
|
||||||
;; Pick all segments in content-b that are not inside content-a
|
;; Pick all segments in content-b that are not inside content-a
|
||||||
@ -319,8 +359,10 @@
|
|||||||
:intersection (create-intersection content-a content-a-split content-b content-b-split sr-a sr-b)
|
:intersection (create-intersection content-a content-a-split content-b content-b-split sr-a sr-b)
|
||||||
:exclude (create-exclusion content-a-split content-b-split))]
|
:exclude (create-exclusion content-a-split content-b-split))]
|
||||||
|
|
||||||
(->> (fix-move-to content)
|
(-> content
|
||||||
(ups/close-subpaths))))
|
remove-duplicated-segments
|
||||||
|
fix-move-to
|
||||||
|
ups/close-subpaths)))
|
||||||
|
|
||||||
(defn content-bool
|
(defn content-bool
|
||||||
[bool-type contents]
|
[bool-type contents]
|
||||||
@ -331,4 +373,3 @@
|
|||||||
(reduce (partial content-bool-pair bool-type))
|
(reduce (partial content-bool-pair bool-type))
|
||||||
(into []))
|
(into []))
|
||||||
[]))
|
[]))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user