From 8572f2da615b6e8a8bc944cddeeda2efd28725f8 Mon Sep 17 00:00:00 2001 From: Charles Comstock Date: Thu, 28 Nov 2024 13:46:26 -0600 Subject: [PATCH] Simple polygons always returns polygon objects convert back to pts if necessary --- src/shimmers/algorithm/polygon_detection.cljc | 7 +++---- src/shimmers/sketches/intertwined.cljs | 2 +- src/shimmers/sketches/network_effects.cljs | 3 ++- src/shimmers/sketches/spaces_divided.cljs | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/shimmers/algorithm/polygon_detection.cljc b/src/shimmers/algorithm/polygon_detection.cljc index 5c07845d9..2433a6db1 100644 --- a/src/shimmers/algorithm/polygon_detection.cljc +++ b/src/shimmers/algorithm/polygon_detection.cljc @@ -212,7 +212,7 @@ ;; TODO: inline cycle-clockwise-from-edge and keep track of a single list of ;; seen edges (defn simple-polygons - "`graph` is a digraph of points, returns a set of cycles, where cycles are a list of points. + "`graph` is a digraph of points, returns a set of polygons from each point cycles. They should be simple cycles without any internal edges/chords." [graph] @@ -225,7 +225,7 @@ (if (or (empty? pending) (zero? limit)) (do (when (and (zero? limit) (> (count polygons) 2)) (println "halted after " (count polygons) " polygons")) - polygons) + (map gp/polygon2 polygons)) (let [edge (first pending) [p q] edge cycle (cycle-clockwise-from-edge g p q)] @@ -413,6 +413,5 @@ (for [[p q] (partition 2 1 (concat [a] isecs [b]))] [p q (g/dist p q)])))))) (lg/weighted-graph)) - simple-polygons - (map gp/polygon2)) + simple-polygons) [polygon])) diff --git a/src/shimmers/sketches/intertwined.cljs b/src/shimmers/sketches/intertwined.cljs index a9d5cdd81..528a3e80a 100644 --- a/src/shimmers/sketches/intertwined.cljs +++ b/src/shimmers/sketches/intertwined.cljs @@ -228,7 +228,7 @@ :polygon polygon)) :polygons - (let [polygons (mapv gp/polygon2 (poly-detect/simple-polygons graph))] + (let [polygons (poly-detect/simple-polygons graph)] (q/stroke 0 0.5) (q/stroke-weight 0.5) (swap! defo assoc :polygons polygons) diff --git a/src/shimmers/sketches/network_effects.cljs b/src/shimmers/sketches/network_effects.cljs index e70fe6638..68f644f18 100644 --- a/src/shimmers/sketches/network_effects.cljs +++ b/src/shimmers/sketches/network_effects.cljs @@ -99,7 +99,8 @@ polygons (->> conns (mapv :points) poly-detect/edges->graph - poly-detect/simple-polygons)] + poly-detect/simple-polygons + (map g/vertices))] (assoc state :nodes nodes' :quadtree (build-tree bounds nodes') diff --git a/src/shimmers/sketches/spaces_divided.cljs b/src/shimmers/sketches/spaces_divided.cljs index 2abd81170..23381cd11 100644 --- a/src/shimmers/sketches/spaces_divided.cljs +++ b/src/shimmers/sketches/spaces_divided.cljs @@ -66,8 +66,7 @@ (defn calculate-polygons [edges] (->> edges poly-detect/edges->graph - poly-detect/simple-polygons - (mapv gp/polygon2))) + poly-detect/simple-polygons)) (defn inset-shapes [polygons] (->> (for [poly polygons