00001 #ifndef VRS_UTILS_H
00002 #define VRS_UTILS_H
00003
00004 #include <vrs/vector.h>
00005 #include <vrs/color.h>
00006 #include <vrs/matrix.h>
00007 #include <string>
00008
00009 namespace VRS {
00010 class VRS_CORE_API Utils
00011 {
00012
00013 public:
00014
00017 static double round(double value, unsigned int dp = 0);
00018
00019 static inline double modulus(double x, double y) {
00020 return (x - y * floor(x / y));
00021 }
00022
00023 static inline float modulus(float x, float y) {
00024 return (x - y * floorf(x / y));
00025 }
00026
00028 static double random(double lower, double upper);
00029 static float random(float lower, float upper);
00030 static int random(int lower, int upper);
00031 static bool random();
00032
00033 template<typename T>
00034 static inline T clamp(const T& minimum, const T& value, const T& maximum)
00035 {
00036 return std::max<T>(minimum, std::min<T>(value, maximum));
00037 }
00038
00041 template<typename T>
00042 static inline T lerp(double t, const T &a, const T &b) { return a + t * (b - a); }
00043
00046 template <typename T>
00047 static inline T smoothStep(double x, T a, T b, double left = 0.0f, double right = 1.0f)
00048 {
00049 if (x <= left) return a;
00050 if (x >= right) return b;
00051 x = (x - left) / (right - left);
00052 return VRS::Utils::lerp(x * x * (3 - 2 * x), a, b);
00053 }
00054
00055
00057 static bool isPow2(VRS::UINT64 value);
00058
00059
00061 static unsigned int powerOf10ui(unsigned int i);
00062
00063
00065 static VRS::UINT64 roundToPow2(VRS::UINT64 value);
00066
00068 static VRS::UINT64 log2(VRS::UINT64 value);
00069
00070 };
00071
00072 }
00073
00074 #endif // VRS_UTILS_H