mirror of https://github.com/AxioDL/zeus.git
Remove unneeded standard math functions
This commit is contained in:
parent
b1b4903cb1
commit
17a501f339
|
@ -90,7 +90,7 @@ public:
|
||||||
return dist;
|
return dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
float distanceFromPoint(const CVector3f& other) const { return sqrtF(distanceFromPointSquared(other)); }
|
float distanceFromPoint(const CVector3f& other) const { return std::sqrt(distanceFromPointSquared(other)); }
|
||||||
|
|
||||||
inline bool intersects(const CAABox& other) const
|
inline bool intersects(const CAABox& other) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -374,7 +374,7 @@ public:
|
||||||
|
|
||||||
void toHSL(float& h, float& s, float& l);
|
void toHSL(float& h, float& s, float& l);
|
||||||
|
|
||||||
CColor toGrayscale() { return {sqrtF((r * r + g * g + b * b) / 3), a}; }
|
CColor toGrayscale() { return {std::sqrt((r * r + g * g + b * b) / 3), a}; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clamps to GPU-safe RGBA values [0,1]
|
* @brief Clamps to GPU-safe RGBA values [0,1]
|
||||||
|
|
|
@ -337,7 +337,7 @@ public:
|
||||||
return x * x + y * y;
|
return x * x + y * y;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline float magnitude() const { return sqrtF(magSquared()); }
|
inline float magnitude() const { return std::sqrt(magSquared()); }
|
||||||
|
|
||||||
inline void zeroOut()
|
inline void zeroOut()
|
||||||
{
|
{
|
||||||
|
|
|
@ -306,7 +306,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline float magnitude() const { return sqrtF(magSquared()); }
|
inline float magnitude() const { return std::sqrt(magSquared()); }
|
||||||
|
|
||||||
inline bool isNotInf() const
|
inline bool isNotInf() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,26 +107,13 @@ CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const
|
||||||
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
|
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, const CVector3f& c, const CVector3f& d,
|
||||||
float t);
|
float t);
|
||||||
|
|
||||||
inline float powF(float a, float b) { return std::pow(a, b); }
|
|
||||||
inline float floorF(float val) { return std::floor(val); }
|
|
||||||
inline float ceilingF(float val)
|
|
||||||
{
|
|
||||||
float tmp = std::floor(val);
|
|
||||||
return (tmp == val ? tmp : tmp + 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since round(double) doesn't exist in some <cmath> implementations
|
// Since round(double) doesn't exist in some <cmath> implementations
|
||||||
// we'll define our own
|
// we'll define our own
|
||||||
inline double round(double val) { return (val < 0.0 ? ceilingF(val - 0.5) : floorF(val + 0.5)); }
|
inline double round(double val) { return (val < 0.0 ? std::ceil(val - 0.5) : std::ceil(val + 0.5)); }
|
||||||
inline double powD(float a, float b) { return std::exp(b * std::log(a)); }
|
inline double powD(float a, float b) { return std::exp(b * std::log(a)); }
|
||||||
|
|
||||||
double sqrtD(double val);
|
inline double invSqrtD(double val) { return 1.0 / std::sqrt(val); }
|
||||||
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
inline float invSqrtF(float val) { return float(1.0 / std::sqrt(val)); }
|
||||||
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
|
||||||
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
|
||||||
float fastArcCosF(float val);
|
|
||||||
float fastCosF(float val);
|
|
||||||
float fastSinF(float val);
|
|
||||||
int floorPowerOfTwo(int x);
|
int floorPowerOfTwo(int x);
|
||||||
int ceilingPowerOfTwo(int x);
|
int ceilingPowerOfTwo(int x);
|
||||||
|
|
||||||
|
|
128
src/Math.cpp
128
src/Math.cpp
|
@ -187,88 +187,6 @@ CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f
|
||||||
(d * t * t * t);
|
(d * t * t * t);
|
||||||
}
|
}
|
||||||
|
|
||||||
double sqrtD(double val)
|
|
||||||
{
|
|
||||||
if (val <= 0.0)
|
|
||||||
{
|
|
||||||
// Dunnno what retro is doing here,
|
|
||||||
// but this shouldn't come up anyway.
|
|
||||||
if (val != 0.0)
|
|
||||||
return 1.0 / (float)0x7FFFFFFF;
|
|
||||||
if (val == 0.0)
|
|
||||||
return 1.0 / (float)0x7F800000;
|
|
||||||
}
|
|
||||||
double q;
|
|
||||||
#if __SSE__
|
|
||||||
union {
|
|
||||||
__m128d v;
|
|
||||||
double d[2];
|
|
||||||
} qv = {val};
|
|
||||||
qv.v = _mm_sqrt_sd(qv.v, qv.v);
|
|
||||||
q = qv.d[0];
|
|
||||||
#else
|
|
||||||
// le sigh, let's use Carmack's inverse square -.-
|
|
||||||
union {
|
|
||||||
double v;
|
|
||||||
int i;
|
|
||||||
} p;
|
|
||||||
|
|
||||||
double x = val * 0.5F;
|
|
||||||
p.v = val;
|
|
||||||
p.i = 0x5fe6eb50c7b537a9 - (p.i >> 1);
|
|
||||||
p.v *= (1.5f - (x * p.v * p.v));
|
|
||||||
p.v *= (1.5f - (x * p.v * p.v));
|
|
||||||
q = p.v;
|
|
||||||
|
|
||||||
static const double half = 0.5;
|
|
||||||
static const double three = 3.0;
|
|
||||||
double sq = q * q;
|
|
||||||
q = half * q;
|
|
||||||
sq = -((val * three) - sq);
|
|
||||||
q = q * sq;
|
|
||||||
sq = q * q;
|
|
||||||
q = q * q;
|
|
||||||
sq = -((val * three) - sq);
|
|
||||||
q = q * sq;
|
|
||||||
sq = q * q;
|
|
||||||
q = half * q;
|
|
||||||
sq = -((val * three) - sq);
|
|
||||||
q = q * sq;
|
|
||||||
sq = q * q;
|
|
||||||
q = half * q;
|
|
||||||
sq = -((val * three) - sq);
|
|
||||||
sq = q * sq;
|
|
||||||
q = val * sq;
|
|
||||||
#endif
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fastArcCosF(float val)
|
|
||||||
{
|
|
||||||
/* If we're not at a low enough value,
|
|
||||||
* the approximation below won't provide any benefit,
|
|
||||||
* and we simply fall back to the standard implementation
|
|
||||||
*/
|
|
||||||
if (std::fabs(val) >= 0.925000011920929f)
|
|
||||||
return std::acos(val);
|
|
||||||
|
|
||||||
/* Fast Arc Cosine approximation using Taylor Polynomials
|
|
||||||
* while this implementation is fast, it's also not as accurate.
|
|
||||||
* This is a straight reimplementation of Retro's CFastArcCosR
|
|
||||||
* and as a result of the polynomials, it returns the inverse value,
|
|
||||||
* I'm not certain if this was intended originally, but we'll leave it
|
|
||||||
* in order to be as accurate as possible.
|
|
||||||
*/
|
|
||||||
double mag = (val * val);
|
|
||||||
double a = ((val * 1.5707964f) + -0.99822718f);
|
|
||||||
double b = (val * mag);
|
|
||||||
a = ((b * a) + -0.20586604f);
|
|
||||||
b *= mag;
|
|
||||||
a = ((b * a) + 0.1142542f);
|
|
||||||
b *= mag;
|
|
||||||
return ((b * a) + -0.2969782f);
|
|
||||||
}
|
|
||||||
|
|
||||||
int floorPowerOfTwo(int x)
|
int floorPowerOfTwo(int x)
|
||||||
{
|
{
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
|
@ -302,52 +220,6 @@ int ceilingPowerOfTwo(int x)
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float fastCosF(float val)
|
|
||||||
{
|
|
||||||
if (std::fabs(val) > M_PIF)
|
|
||||||
{
|
|
||||||
float rVal = float(uint32_t(val));
|
|
||||||
val = -((rVal * val) - 6.2831855f);
|
|
||||||
if (val <= M_PIF && val < -M_PIF)
|
|
||||||
val += 6.2831855f;
|
|
||||||
else
|
|
||||||
val -= 6.2831855f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float sq = val * val;
|
|
||||||
float b = sq * sq;
|
|
||||||
val = sq + -0.4999803f;
|
|
||||||
val = (b * val) + 0.041620344f;
|
|
||||||
b = b * sq;
|
|
||||||
val = (b * val) + -0.0013636103f;
|
|
||||||
b = b * sq;
|
|
||||||
val = (b * val) + 0.000020169435f;
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
float fastSinF(float val)
|
|
||||||
{
|
|
||||||
if (std::fabs(val) > M_PIF)
|
|
||||||
{
|
|
||||||
float rVal = float(uint32_t(val));
|
|
||||||
val = -((rVal * val) - 6.2831855f);
|
|
||||||
if (val <= M_PIF && val < -M_PIF)
|
|
||||||
val += 6.2831855f;
|
|
||||||
else
|
|
||||||
val -= 6.2831855f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float sq = val * val;
|
|
||||||
float ret = val * 0.99980587f;
|
|
||||||
val = val * sq;
|
|
||||||
ret = (val * ret) + -0.16621658f;
|
|
||||||
val = val * sq;
|
|
||||||
ret = (val * ret) + 0.0080871079f;
|
|
||||||
val = val * sq;
|
|
||||||
ret = (val * ret) + -0.00015297699f;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t)
|
float getCatmullRomSplinePoint(float a, float b, float c, float d, float t)
|
||||||
{
|
{
|
||||||
if (t <= 0.0f)
|
if (t <= 0.0f)
|
||||||
|
|
Loading…
Reference in New Issue