aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.lisp')
-rw-r--r--src/utils.lisp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils.lisp b/src/utils.lisp
index bcb4cb2..ed7be38 100644
--- a/src/utils.lisp
+++ b/src/utils.lisp
@@ -103,3 +103,27 @@ the path."
:width (- max-x min-x)
:height (- max-y min-y)))))
+(defmacro setf-many (places-and-value)
+ "e.g. (setf-many a b c 10) would set a b and c to 10"
+ (let ((value-form
+ (first (last places-and-value))))
+ `(setf ,@(butlast places-and-value) ,value-form)))
+
+
+(defmacro with-line
+ ((x y) (start-x start-y) (end-x end-y) &body body)
+ "Execute BODY for X and Y assigned to integer values in a line
+connecting the integer point START-X , START-Y and END-X, END-Y. "
+ (with-gensyms (sx sy ex ey distance step progress xdiff ydiff)
+ `(let* ((,sx ,start-x)
+ (,sy ,start-y)
+ (,ex ,end-x)
+ (,ey ,end-y)
+ (,xdiff (- ,ex ,sx))
+ (,ydiff (- ,ey ,sy))
+ (,distance (max (abs ,xdiff) (abs ,ydiff))))
+ (loop for ,step from 0 to ,distance
+ for ,progress = (if (zerop ,distance) 0.0 (/ ,step ,distance))
+ for ,x = (round (+ ,start-x (* ,progress ,xdiff)))
+ for ,y = (round (+ ,start-y (* ,progress ,ydiff)))
+ do (progn ,@body)))))