summaryrefslogtreecommitdiff
path: root/2d/math.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@member.fsf.org>2013-12-02 20:26:58 -0500
committerDavid Thompson <dthompson@member.fsf.org>2013-12-02 20:26:58 -0500
commitbf3ef3a95649c565f14278aa7fe6dc5269505825 (patch)
tree95cf2b9509a12d01a9e5c0da25289eef3cdc16ab /2d/math.scm
parentbb3b1daffce323d8aa17eb2c078698faaaab7835 (diff)
Add clamp procedure.
* 2d/math.scm (clamp): New procedure.
Diffstat (limited to '2d/math.scm')
-rw-r--r--2d/math.scm10
1 files changed, 9 insertions, 1 deletions
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)))