Skip to content

Commit

Permalink
extract clockwise-vertices to poly-detect
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtized committed Nov 28, 2024
1 parent 9f08d45 commit 99ab670
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/shimmers/algorithm/polygon_detection.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@
(reduce + 0)
(* 0.5)))

(defn clockwise-vertices
"Force a clockwise ordering by sorting vertices around centroid.
This only works if the polygon is convex. This is likely an artifact of
`g/clip-with`."
[convex-polygon]
(let [centroid (g/centroid convex-polygon)]
(->> convex-polygon
g/vertices
(sort-by (fn [v] (g/heading (tm/- v centroid)))))))

(defn clockwise-polygon?
"return true if points in polygon are in a clockwise ordering."
[points]
Expand Down
14 changes: 2 additions & 12 deletions src/shimmers/sketches/window_glimpses.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[shimmers.algorithm.hand-drawn :as hand-drawn]
[shimmers.algorithm.line-clipping :as clip]
[shimmers.algorithm.lines :as lines]
[shimmers.algorithm.polygon-detection :as poly-detect]
[shimmers.common.palette :as palette]
[shimmers.common.sequence :as cs]
[shimmers.common.svg :as csvg :include-macros true]
Expand Down Expand Up @@ -340,17 +341,6 @@
:crossed-lines
(clip/hatch-rectangle bounds cross-density theta2 [(dr/random) (dr/random)])}))

(defn clockwise-vertices
"Force a clockwise ordering by sorting vertices around centroid.
This only works if the polygon is convex. This is likely an artifact of
`g/clip-with`."
[convex-polygon]
(let [centroid (g/centroid convex-polygon)]
(->> convex-polygon
g/vertices
(sort-by (fn [v] (heading-to centroid v))))))

(defn debug-chunks [arc-groups]
(for [g arc-groups]
(csvg/group {}
Expand Down Expand Up @@ -378,7 +368,7 @@

(defn arc-path [polygon {:keys [p r]} attribs show-path-points]
(let [on-arc? (fn [v] (tm/delta= (g/dist p v) r 0.0001))
vertices (clockwise-vertices polygon)
vertices (poly-detect/clockwise-vertices polygon)
arc-groups (partition-by on-arc? vertices)
commands
(mapcat
Expand Down

0 comments on commit 99ab670

Please sign in to comment.