Math/Algorithm: Clean code

Former-commit-id: 5133320f4cf04e78d3cf7d66dbbe6f87f44b4bdc
This commit is contained in:
Lynix 2015-06-13 17:34:06 +02:00
parent b1081c63e5
commit 009d860d6c
1 changed files with 13 additions and 20 deletions

View File

@ -10,9 +10,6 @@
#include <type_traits>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
#define F2(a) static_cast<T2>(a)
namespace
{
// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
@ -131,7 +128,7 @@ T NzCountBits(T value)
template<typename T>
constexpr T NzDegreeToRadian(T degrees)
{
return degrees * F(M_PI/180.0);
return degrees * T(M_PI/180.0);
}
template<typename T>
@ -276,7 +273,7 @@ template<typename T, typename T2>
T NzLerp(T from, T to, T2 interpolation)
{
#ifdef NAZARA_DEBUG
if (interpolation < F2(0.0) || interpolation > F2(1.0))
if (interpolation < T2(0.0) || interpolation > T2(1.0))
NazaraWarning("Interpolation should be in range [0..1] (Got " + NzString::Number(interpolation) + ')');
#endif
@ -317,14 +314,14 @@ template<typename T>
T NzNormalizeAngle(T angle)
{
#if NAZARA_MATH_ANGLE_RADIAN
const T limit = F(M_PI);
const T limit = T(M_PI);
#else
const T limit = F(180.0);
const T limit = T(180.0);
#endif
const T twoLimit = limit*F(2.0);
const T twoLimit = limit * T(2);
angle = std::fmod(angle + limit, twoLimit);
if (angle < F(0.0))
if (angle < T(0))
angle += twoLimit;
return angle - limit;
@ -339,9 +336,8 @@ bool NzNumberEquals(T a, T b)
template<typename T>
bool NzNumberEquals(T a, T b, T maxDifference)
{
T diff = a - b;
if (diff < F(0.0))
diff = -diff;
std::pair<const T&, const T&> minmax = std::minmax(a, b);
T diff = minmax.second - minmax.first;
return diff <= maxDifference;
}
@ -389,7 +385,7 @@ inline NzString NzNumberToString(long long number, nzUInt8 radix)
template<typename T>
T NzRadianToDegree(T radians)
{
return radians * F(180.0/M_PI);
return radians * T(180.0/M_PI);
}
inline long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok)
@ -461,7 +457,4 @@ constexpr T NzToRadians(T angle)
#endif
}
#undef F2
#undef F
#include <Nazara/Core/DebugOff.hpp>