]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/cml/util.h
cml version bump to 1.0.1
[chaz/yoink] / src / Moof / cml / util.h
index 0fcca0099ec7fcaab94d5eaf83abc4e410d0525f..8517c343cfc197ddbb07f6725161d809444b243f 100644 (file)
@@ -17,6 +17,13 @@ Boost Software License, v1.0 (see cml/LICENSE for details).
 #include <cstdlib>     // For std::rand.
 #include <cml/constants.h>
 
+#if defined(_MSC_VER)
+#pragma push_macro("min")
+#pragma push_macro("max")
+#undef min
+#undef max
+#endif
+
 namespace cml {
 
 /** Sign of input value as double. */
@@ -34,7 +41,7 @@ T clamp(T value, T min, T max) {
 /** Test input value for inclusion in [min, max]. */
 template < typename T >
 bool in_range(T value, T min, T max) {
-    return value >= min && value <= max;
+    return !(value < min) && !(value > max);
 }
 
 /** Map input value from [min1, max1] to [min2, max2]. */
@@ -63,12 +70,18 @@ T sqrt_safe(T value) {
 }
 
 
-/** For convenient squaring of expressions. */
+/** Square a value. */
 template < typename T >
 T sqr(T value) {
     return value * value;
 }
 
+/** Cube a value. */
+template < typename T >
+T cub(T value) {
+    return value * value * value;
+}
+
 /** Inverse square root. */
 template < typename T >
 T inv_sqrt(T value) {
@@ -247,6 +260,30 @@ T length(T x, T y, T z) {
     return std::sqrt(length_squared(x,y,z));
 }
 
+/** Index of maximum of 2 values. */
+template < typename T >
+size_t index_of_max(T a, T b) {
+    return a > b ? 0 : 1;
+}
+
+/** Index of maximum of 2 values by magnitude. */
+template < typename T >
+size_t index_of_max_abs(T a, T b) {
+    return index_of_max(std::fabs(a),std::fabs(b));
+}
+
+/** Index of minimum of 2 values. */
+template < typename T >
+size_t index_of_min(T a, T b) {
+    return a < b ? 0 : 1;
+}
+
+/** Index of minimum of 2 values by magnitude. */
+template < typename T >
+size_t index_of_min_abs(T a, T b) {
+    return index_of_min(std::fabs(a),std::fabs(b));
+}
+
 /** Index of maximum of 3 values. */
 template < typename T >
 size_t index_of_max(T a, T b, T c) {
@@ -320,6 +357,11 @@ T fov_to_zoom(T fov) {
 
 } // namespace cml
 
+#if defined(_MSC_VER)
+#pragma pop_macro("min")
+#pragma pop_macro("max")
+#endif
+
 #endif
 
 // -------------------------------------------------------------------------
This page took 0.017376 seconds and 4 git commands to generate.