File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
contents/graham_scan/code/elisp Expand file tree Collapse file tree 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."
1313 (nth (- (length lst) (1+ n)) lst))
1414
1515(defun is-ccw (a b c )
16+ " Determines if a turn between three points is counterclockwise."
1617 (>= (* (- (nth 1 c) (nth 1 a)) (- (nth 0 b) (nth 0 a)))
1718 (* (- (nth 1 b) (nth 1 a)) (- (nth 0 c) (nth 0 a)))))
1819
1920(defun polar-angle (ref point )
21+ " Returns the polar angle from a point relative to a reference point"
2022 (atan (- (nth 1 point) (nth 1 ref)) (- (nth 0 point) (nth 0 ref))))
2123
22- (require 'dash )
23-
2424(defun graham-scan (initial-gift )
25+ " Finds the convex hull of a distribution of points with a Graham scan."
2526 (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.
2728 (min-sorted-gift (sort gift (lambda (p1 p2 ) (< (nth 1 p1) (nth 1 p2)))))
2829 (start (car min-sorted-gift))
2930 (trimmed-gift (cdr min-sorted-gift))
@@ -32,7 +33,7 @@ Adapted from dash.el."
3233 (hull (list start (car points) (cadr points))))
3334 (dolist (point (cddr points))
3435 (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)))))
3637 (setq hull (snoc hull point)))
3738 hull))
3839
You can’t perform that action at this time.
0 commit comments