mirror of
https://github.com/penpot/penpot.git
synced 2025-06-05 08:21:39 +02:00
✨ Add exclusion boolean operation
This commit is contained in:
parent
0b4b2d3814
commit
df60ee06a1
8 changed files with 142 additions and 55 deletions
|
@ -6,70 +6,38 @@
|
|||
|
||||
(ns app.main.ui.shapes.bool
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.main.ui.hooks :refer [use-equal-memo]]
|
||||
[app.util.object :as obj]
|
||||
[app.util.path.bool :as pb]
|
||||
[app.util.path.geom :as upg]
|
||||
[app.util.path.shapes-to-path :as stp]
|
||||
[clojure.set :as set]
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
(mf/defc path-points
|
||||
[{:keys [points color]}]
|
||||
|
||||
[:*
|
||||
(for [[idx {:keys [x y]}] (d/enumerate points)]
|
||||
[:circle {:key (str "circle-" idx)
|
||||
:cx x
|
||||
:cy y
|
||||
:r 5
|
||||
:style {:fill color
|
||||
;;:fillOpacity 0.5
|
||||
}}])])
|
||||
|
||||
(defn bool-shape
|
||||
[shape-wrapper]
|
||||
(mf/fnc bool-shape
|
||||
{::mf/wrap-props false}
|
||||
[props]
|
||||
(let [frame (obj/get props "frame")
|
||||
childs (obj/get props "childs")
|
||||
shape-1 (stp/convert-to-path (nth childs 0))
|
||||
shape-2 (stp/convert-to-path (nth childs 1))
|
||||
shape (obj/get props "shape")
|
||||
childs (obj/get props "childs")]
|
||||
|
||||
content-1 (-> shape-1 gsh/transform-shape (gsh/translate-to-frame frame) :content)
|
||||
content-2 (-> shape-2 gsh/transform-shape (gsh/translate-to-frame frame) :content)
|
||||
|
||||
(when (> (count childs) 1)
|
||||
(let [shape-1 (stp/convert-to-path (nth childs 0))
|
||||
shape-2 (stp/convert-to-path (nth childs 1))
|
||||
|
||||
[content-1' content-2'] (pb/content-intersect-split content-1 content-2)
|
||||
|
||||
points-1 (->> (upg/content->points content-1')
|
||||
(map #(hash-map :x (mth/round (:x %))
|
||||
:y (mth/round (:y %))))
|
||||
(into #{}))
|
||||
|
||||
points-2 (->> (upg/content->points content-2')
|
||||
(map #(hash-map :x (mth/round (:x %))
|
||||
:y (mth/round (:y %))))
|
||||
(into #{}))
|
||||
content-1 (use-equal-memo (-> shape-1 :content gsh/transform-shape))
|
||||
content-2 (use-equal-memo (-> shape-2 :content gsh/transform-shape))
|
||||
|
||||
points-3 (set/intersection points-1 points-2)]
|
||||
content
|
||||
(mf/use-memo
|
||||
(mf/deps content-1 content-2)
|
||||
#(pb/content-bool (:bool-type shape) content-1 content-2))]
|
||||
|
||||
[:*
|
||||
[:& shape-wrapper {:shape (-> shape-1 #_(assoc :content content-1'))
|
||||
:frame frame}]
|
||||
|
||||
[:& shape-wrapper {:shape (-> shape-2 #_(assoc :content content-2'))
|
||||
:frame frame}]
|
||||
|
||||
[:& path-points {:points points-1 :color "#FF0000"}]
|
||||
[:& path-points {:points points-2 :color "#0000FF"}]
|
||||
[:& path-points {:points points-3 :color "#FF00FF"}]
|
||||
|
||||
|
||||
])))
|
||||
[:& shape-wrapper {:shape (-> shape
|
||||
(assoc :type :path)
|
||||
(assoc :content content))
|
||||
:frame frame}])))))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue