summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-08-15 10:33:48 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-08-15 10:33:48 -0400
commita2b3970ddec2a88c9741efd825032cf649cc6bfd (patch)
treeea0269e7bda5edf638f7131cb6f1121e97fabdf8 /libdimension
parentb85ae851c9d8c91bc3a4c698403a24c8c09f4628 (diff)
downloaddimension-a2b3970ddec2a88c9741efd825032cf649cc6bfd.tar.xz
geometry: New dmnsn_clamp() function.
Diffstat (limited to 'libdimension')
-rw-r--r--libdimension/dimension/color.h6
-rw-r--r--libdimension/dimension/geometry.h7
-rw-r--r--libdimension/dimension/tcolor.h4
3 files changed, 12 insertions, 5 deletions
diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h
index 1b21d94..adbd396 100644
--- a/libdimension/dimension/color.h
+++ b/libdimension/dimension/color.h
@@ -158,9 +158,9 @@ dmnsn_color_illuminate(dmnsn_color light, dmnsn_color color)
DMNSN_INLINE dmnsn_color
dmnsn_color_clamp(dmnsn_color color)
{
- color.R = dmnsn_min(dmnsn_max(color.R, 0.0), 1.0);
- color.G = dmnsn_min(dmnsn_max(color.G, 0.0), 1.0);
- color.B = dmnsn_min(dmnsn_max(color.B, 0.0), 1.0);
+ color.R = dmnsn_clamp(color.R, 0.0, 1.0);
+ color.G = dmnsn_clamp(color.G, 0.0, 1.0);
+ color.B = dmnsn_clamp(color.B, 0.0, 1.0);
return color;
}
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h
index 7557680..811f591 100644
--- a/libdimension/dimension/geometry.h
+++ b/libdimension/dimension/geometry.h
@@ -120,6 +120,13 @@ dmnsn_max(double a, double b)
return a > b ? a : b;
}
+/** Clamp a value to an interval. */
+DMNSN_INLINE double
+dmnsn_clamp(double n, double min, double max)
+{
+ return dmnsn_min(dmnsn_max(n, min), max);
+}
+
/** Convert degrees to radians. */
DMNSN_INLINE double
dmnsn_radians(double degrees)
diff --git a/libdimension/dimension/tcolor.h b/libdimension/dimension/tcolor.h
index f85fcd6..8c48800 100644
--- a/libdimension/dimension/tcolor.h
+++ b/libdimension/dimension/tcolor.h
@@ -94,8 +94,8 @@ DMNSN_INLINE dmnsn_tcolor
dmnsn_tcolor_clamp(dmnsn_tcolor tcolor)
{
tcolor.c = dmnsn_color_clamp(tcolor.c);
- tcolor.T = dmnsn_min(dmnsn_max(tcolor.T, 0.0), 1.0);
- tcolor.F = dmnsn_min(dmnsn_max(tcolor.F, 0.0), 1.0);
+ tcolor.T = dmnsn_clamp(tcolor.T, 0.0, 1.0);
+ tcolor.F = dmnsn_clamp(tcolor.F, 0.0, 1.0);
return tcolor;
}