X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2Fcml%2Futil.h;h=8517c343cfc197ddbb07f6725161d809444b243f;hp=0fcca0099ec7fcaab94d5eaf83abc4e410d0525f;hb=50c1239917f5e443b8ec91773c85ceb3db7da67b;hpb=1dd005530930657fd6216edc1dfcfa4c270a81c9 diff --git a/src/Moof/cml/util.h b/src/Moof/cml/util.h index 0fcca00..8517c34 100644 --- a/src/Moof/cml/util.h +++ b/src/Moof/cml/util.h @@ -17,6 +17,13 @@ Boost Software License, v1.0 (see cml/LICENSE for details). #include // For std::rand. #include +#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 // -------------------------------------------------------------------------