From b72153a73875fc0081d072b90ac411c0eaef08a8 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 17 Jul 2022 07:46:21 -0500 Subject: [refactor] [rename] with-line/with-grid-line; all vars now in loop --- src/interactive/canvas.lisp | 2 +- src/utils.lisp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'src') 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)))) -- cgit v1.2.3