Skip to content

Commit

Permalink
Simple polygons always returns polygon objects
Browse files Browse the repository at this point in the history
convert back to pts if necessary
  • Loading branch information
dgtized committed Nov 28, 2024
1 parent 99ab670 commit 8572f2d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/shimmers/algorithm/polygon_detection.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)]
Expand Down Expand Up @@ -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]))
2 changes: 1 addition & 1 deletion src/shimmers/sketches/intertwined.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/shimmers/sketches/network_effects.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions src/shimmers/sketches/spaces_divided.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8572f2d

Please sign in to comment.