From bf3ef3a95649c565f14278aa7fe6dc5269505825 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 2 Dec 2013 20:26:58 -0500 Subject: Add clamp procedure. * 2d/math.scm (clamp): New procedure. --- 2d/math.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to '2d/math.scm') diff --git a/2d/math.scm b/2d/math.scm index af46fff..767e7f6 100644 --- a/2d/math.scm +++ b/2d/math.scm @@ -28,7 +28,8 @@ sin-degrees cos-degrees tan-degrees - atan-degrees)) + atan-degrees + clamp)) ;; Dave was editing this module on Pi Approximation Day. ;; @@ -80,3 +81,10 @@ (define (atan-degrees y x) "Compute the arctangent in degrees of the coordinates Y and X." (radians->degrees (atan y x))) + +(define (clamp min max x) + "Restrict X to the range defined by MIN and MAX. Assumes that MIN is +actually less than MAX." + (cond ((< x min) min) + ((> x max) max) + (else x))) -- cgit v1.2.3