I’m getting these errors when using Urho3D’s math functions because there exist no overloads of Clamp() (or any of the other math functions) that use double.
I took a look at MathDefs.h and I feel like there are two big improvements that can be made.
1) Use templates
This:
inline float Clamp(float value, float min, float max)
{
if (value < min)
return min;
else if (value > max)
return max;
else
return value;
}
should be this:
template <class T>
inline T Clamp(T value, T min, T max)
{
if (value < min)
return min;
else if (value > max)
return max;
return value;
}
2) We should be using std::numeric_limits instead of trying to define our own epsilon, our own infinity etc.
This:
would be much better as:
template <class T>
bool Equals(T lhs, T rhs) { return lhs + std::numeric_limits<T>::epsilon >= rhs && lhs - std::numeric_limits<T>::epsilon <= rhs; }
that way these defines can be eliminated:
[code]static const int M_MIN_INT = 0x80000000;
static const int M_MAX_INT = 0x7fffffff;
static const unsigned M_MIN_UNSIGNED = 0x00000000;
static const unsigned M_MAX_UNSIGNED = 0xffffffff;
static const float M_EPSILON = 0.000001f;
static const float M_LARGE_EPSILON = 0.00005f;
static const float M_LARGE_VALUE = 100000000.0f;
static const float M_INFINITY = (float)HUGE_VAL;[/code]
Can I apply these changes and make a PR, or are there objections?