From 543704f0f54cbb1de78754ad8a323c482ab6829c Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 14 Dec 2024 12:29:29 -0800 Subject: Loop style nits --- src/utils.lisp | 70 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/utils.lisp') diff --git a/src/utils.lisp b/src/utils.lisp index f6af42c..910f962 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -46,11 +46,11 @@ and B intersects the linesegment between C and D, NIL otherwise." (defun paths-intersect-p (path1 path2) "Paths are lists of vectors, each of which represents a 2d point." (declare (optimize (speed 3) (safety 0) )) - (loop for ((ax ay) (bx by) . more1) on path1 - while bx - thereis (loop for ((cx cy) (dx dy) . more2) on path2 - while dx - thereis (segments-intersect-p ax ay bx by cx cy dx dy)))) + (loop :for ((ax ay) (bx by) . more1) :on path1 + :while bx + :thereis (loop :for ((cx cy) (dx dy) . more2) :on path2 + :while dx + :thereis (segments-intersect-p ax ay bx by cx cy dx dy)))) (defun closed-path-p (path) (equalp (first path) @@ -66,12 +66,12 @@ and B intersects the linesegment between C and D, NIL otherwise." (list (- (getf bounds :left) (getf bounds :width)) (- (getf bounds :bottom) (getf bounds :height))))) (loop - with (cx cy) = corner - for ((ax ay) (bx by) . more) on path - while bx - when (segments-intersect-p ax ay bx by px py cx cy) - count 1 into intersection-count - finally + :with (cx cy) := corner + :for ((ax ay) (bx by) . more) :on path + :while bx + :when (segments-intersect-p ax ay bx by px py cx cy) + :count 1 :into intersection-count + :finally (return (oddp intersection-count))))) ;; (defun path-encloses-path-p (path-a path-b) @@ -92,20 +92,20 @@ bounds and width and height as a plist of the form This is the smallest UNROTATED RECTANGLE that contains the points in the path." (loop - with max-x = nil - and max-y = nil - and min-x = nil - and min-y = nil - for (x y) in path - when (or (null max-x) (< max-x x)) - do (setf max-x x) - when (or (null min-x) (< x min-x)) - do (setf min-x x) - when (or (null max-y) (< max-y y)) - do (setf max-y y) - when (or (null min-y) (< y min-y)) - do (setf min-y y) - finally + :with max-x := nil + :and max-y := nil + :and min-x := nil + :and min-y := nil + :for (x y) :in path + :when (or (null max-x) (< max-x x)) + :do (setf max-x x) + :when (or (null min-x) (< x min-x)) + :do (setf min-x x) + :when (or (null max-y) (< max-y y)) + :do (setf max-y y) + :when (or (null min-y) (< y min-y)) + :do (setf min-y y) + :finally (return (list :top max-y :left min-x :right max-x :bottom min-y :width (- max-x min-x) :height (- max-y min-y))))) @@ -148,17 +148,17 @@ the path." (let* ((n (1- (length points))) (bin-coeffs - (loop for i from 0 to n collect (binomial-coefficient n i)))) + (loop :for i :from 0 :to n :collect (binomial-coefficient n i)))) (lambda (a) - (loop for (x y) in points - for i from 0 - for bin-coeff in bin-coeffs - for coeff = (* bin-coeff - (expt (- 1 a) (- n i)) - (expt a i)) - sum (* coeff x) into bx - sum (* coeff y) into by - finally (return (list bx by)))))) + (loop :for (x y) :in points + :for i :from 0 + :for bin-coeff :in bin-coeffs + :for coeff := (* bin-coeff + (expt (- 1 a) (- n i)) + (expt a i)) + :sum (* coeff x) :into bx + :sum (* coeff y) :into by + :finally (return (list bx by)))))) (defun clamp (lo val hi) "Returns VAL if (< LO VAL HI), otherwise returns LO or HI depending -- cgit v1.2.3