Skip to content

Commit d0026c7

Browse files
committed
Remove dependence on dash.el, add more docstrings
1 parent da0c8a9 commit d0026c7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

contents/graham_scan/code/elisp/graham-scan.el

+5-4
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)