File tree 1 file changed +5
-4
lines changed
contents/graham_scan/code/elisp
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -13,17 +13,18 @@ Adapted from dash.el."
13
13
(nth (- (length lst) (1+ n)) lst))
14
14
15
15
(defun is-ccw (a b c )
16
+ " Determines if a turn between three points is counterclockwise."
16
17
(>= (* (- (nth 1 c) (nth 1 a)) (- (nth 0 b) (nth 0 a)))
17
18
(* (- (nth 1 b) (nth 1 a)) (- (nth 0 c) (nth 0 a)))))
18
19
19
20
(defun polar-angle (ref point )
21
+ " Returns the polar angle from a point relative to a reference point"
20
22
(atan (- (nth 1 point) (nth 1 ref)) (- (nth 0 point) (nth 0 ref))))
21
23
22
- (require 'dash )
23
-
24
24
(defun graham-scan (initial-gift )
25
+ " Finds the convex hull of a distribution of points with a Graham scan."
25
26
(let* ((gift (cl-remove-duplicates initial-gift))
26
- ; ; this is /only/ to get the starting point
27
+ ; ; This is /only/ to get the starting point.
27
28
(min-sorted-gift (sort gift (lambda (p1 p2 ) (< (nth 1 p1) (nth 1 p2)))))
28
29
(start (car min-sorted-gift))
29
30
(trimmed-gift (cdr min-sorted-gift))
@@ -32,7 +33,7 @@ Adapted from dash.el."
32
33
(hull (list start (car points) (cadr points))))
33
34
(dolist (point (cddr points))
34
35
(while (not (is-ccw (nthrev 1 hull) (nthrev 0 hull) point))
35
- (setq hull (-remove-at ( 1- ( length hull)) hull )))
36
+ (setq hull (reverse ( cdr ( reverse hull)))))
36
37
(setq hull (snoc hull point)))
37
38
hull))
38
39
You can’t perform that action at this time.
0 commit comments