From 1cc43738eeaee1c1a53c102cdec2722c78805f93 Mon Sep 17 00:00:00 2001 From: rearman Date: Mon, 13 Apr 2026 16:00:20 -0400 Subject: [PATCH] Replace cond with if in average-of-points Don't use a cond with only two paths --- math.lisp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/math.lisp b/math.lisp index 70099e8..405669d 100644 --- a/math.lisp +++ b/math.lisp @@ -23,21 +23,16 @@ (defun average-of-points (points) "Calculate an average of 2d or 3d points, given as a list of lists. If a 2d point is given, it is converted to 3d with z=0." - (cond ((numberp (first points)) - points) - (t (let ((numpoints (length points))) - (mapcar #'/ - (list (apply #'+ (mapcar #'first points)) - (apply #'+ (mapcar #'second points)) - (apply #'+ - (mapcar #'(lambda (x) - (if (null (third x)) - 0 - (third x))) - points))) - (list numpoints - numpoints - numpoints)))))) + (if (numberp (first points)) + points + (let ((numpoints (length points))) + (mapcar #'/ + (list (apply #'+ (mapcar #'first points)) + (apply #'+ (mapcar #'second points)) + (apply #'+ + (mapcar #'(lambda (x) (if (null (third x)) 0 (third x))) + points))) + (list numpoints numpoints numpoints))))) (defun dot-product-points (apoint bpoint) "Return the dot-product of 3d vectors a and b. -- 2.39.5