aboutsummaryrefslogtreecommitdiff
path: root/guile/starlet
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-04-23 16:08:24 +0200
committerThomas White <taw@physics.org>2022-04-23 16:35:04 +0200
commit77aab1e1fc6433edc1254ae16964cdf0f8bc9a5a (patch)
tree5506b7641ac8b5b2c78d35321e693cabf3fb41ac /guile/starlet
parent65e32128b1ebd6c6b4072e9588de8ef5db17f04a (diff)
Add scale-and-clamp-to-range
Diffstat (limited to 'guile/starlet')
-rw-r--r--guile/starlet/fixture.scm14
1 files changed, 14 insertions, 0 deletions
diff --git a/guile/starlet/fixture.scm b/guile/starlet/fixture.scm
index 9f58f25..ee0d5b8 100644
--- a/guile/starlet/fixture.scm
+++ b/guile/starlet/fixture.scm
@@ -42,6 +42,7 @@
intensity?
scale-to-range
+ scale-and-clamp-to-range
round-dmx
percent->dmxval8
percent->dmxval16))
@@ -202,3 +203,16 @@
(/ (- val (car orig-range))
(range orig-range)))))
+
+(define (clamp-to-range val val1 val2)
+ (let ((minval (min val1 val2))
+ (maxval (max val1 val2)))
+ (max minval
+ (min val maxval))))
+
+;; Like scale-to-range, but result is clamped within dest-range
+(define (scale-and-clamp-to-range val orig-range dest-range)
+ (clamp-to-range
+ (scale-to-range val orig-range dest-range)
+ (car dest-range)
+ (cadr dest-range)))