aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-17 07:46:21 -0500
committerColin Okay <colin@cicadas.surf>2022-07-17 07:46:21 -0500
commitb72153a73875fc0081d072b90ac411c0eaef08a8 (patch)
tree11feee3e28e665b7661151d191c2126428157429 /src
parent35fad29cec4ccaa338e03f9b0879757a9c4c860e (diff)
[refactor] [rename] with-line/with-grid-line; all vars now in loop
Diffstat (limited to 'src')
-rw-r--r--src/interactive/canvas.lisp2
-rw-r--r--src/utils.lisp28
2 files changed, 15 insertions, 15 deletions
diff --git a/src/interactive/canvas.lisp b/src/interactive/canvas.lisp
index 256348e..e8bdc39 100644
--- a/src/interactive/canvas.lisp
+++ b/src/interactive/canvas.lisp
@@ -89,7 +89,7 @@
e.g., drawing a line in a particular color."
(let ((pxs (gensym)))
`(let ((,pxs ,pixels))
- (with-line (,x ,y) (,start-x ,start-y) (,end-x ,end-y)
+ (with-grid-line (,x ,y) (,start-x ,start-y) (,end-x ,end-y)
(with-pixel (,r ,g ,b ,a) (pixel ,pxs ,x ,y) ,@body)))))
diff --git a/src/utils.lisp b/src/utils.lisp
index 9e1e46b..4037b7a 100644
--- a/src/utils.lisp
+++ b/src/utils.lisp
@@ -116,22 +116,22 @@ the path."
(setf ,@clauses))))
-(defmacro with-line
+(defmacro with-grid-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)))))
-
+ `(loop
+ with ,sx = ,start-x
+ with ,sy = ,start-y
+ with ,ex = ,end-x
+ with ,ey = ,end-y
+ with ,xdiff = (- ,ex ,sx)
+ with ,ydiff = (- ,ey, sy)
+ with ,distance = (max (abs ,xdiff) (abs ,ydiff))
+ 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))))