random constexpr

This commit is contained in:
Silent 2017-03-20 23:06:29 +01:00
parent 82115849b1
commit d40fff0b05
2 changed files with 13 additions and 13 deletions

View file

@ -17,27 +17,27 @@ public:
inline CRGBA() {} inline CRGBA() {}
inline CRGBA(const CRGBA& in) inline constexpr CRGBA(const CRGBA& in)
: r(in.r), g(in.g), b(in.b), a(in.a) : r(in.r), g(in.g), b(in.b), a(in.a)
{} {}
inline CRGBA(const CRGBA& in, uint8_t alpha) inline constexpr CRGBA(const CRGBA& in, uint8_t alpha)
: r(in.r), g(in.g), b(in.b), a(alpha) : r(in.r), g(in.g), b(in.b), a(alpha)
{} {}
inline CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255) inline constexpr CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
: r(red), g(green), b(blue), a(alpha) : r(red), g(green), b(blue), a(alpha)
{} {}
friend CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal) friend constexpr CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal)
{ double InvBlendVal = 1.0 - BlendVal; { double InvBlendVal = 1.0 - BlendVal;
return CRGBA( To.r * BlendVal + From.r * InvBlendVal, return CRGBA( To.r * BlendVal + From.r * InvBlendVal,
To.g * BlendVal + From.g * InvBlendVal, To.g * BlendVal + From.g * InvBlendVal,
To.b * BlendVal + From.b * InvBlendVal, To.b * BlendVal + From.b * InvBlendVal,
To.a * BlendVal + From.a * InvBlendVal); } To.a * BlendVal + From.a * InvBlendVal); }
friend CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal) friend constexpr CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal)
{ double InvBlendVal = 1.0 - BlendVal; { double InvBlendVal = 1.0 - BlendVal;
return CRGBA( sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal), return CRGBA( sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal),
sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal), sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal),
@ -55,7 +55,7 @@ public:
float x2, y2; float x2, y2;
inline CRect() {} inline CRect() {}
inline CRect(float a, float b, float c, float d) inline constexpr CRect(float a, float b, float c, float d)
: x1(a), y1(b), x2(c), y2(d) : x1(a), y1(b), x2(c), y2(d)
{} {}
}; };

View file

@ -12,11 +12,11 @@ public:
CVector() CVector()
{} {}
CVector(float fX, float fY, float fZ=0.0f) constexpr CVector(float fX, float fY, float fZ=0.0f)
: x(fX), y(fY), z(fZ) : x(fX), y(fY), z(fZ)
{} {}
CVector(const RwV3d& rwVec) constexpr CVector(const RwV3d& rwVec)
: x(rwVec.x), y(rwVec.y), z(rwVec.z) : x(rwVec.x), y(rwVec.y), z(rwVec.z)
{} {}
@ -33,9 +33,9 @@ public:
{ x -= vec.x; y -= vec.y; z -= vec.z; { x -= vec.x; y -= vec.y; z -= vec.z;
return *this; } return *this; }
inline float Magnitude() inline float Magnitude() const
{ return sqrt(x * x + y * y + z * z); } { return sqrt(x * x + y * y + z * z); }
inline float MagnitudeSqr() inline constexpr float MagnitudeSqr() const
{ return x * x + y * y + z * z; } { return x * x + y * y + z * z; }
inline CVector& Normalize() inline CVector& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; } { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; }
@ -69,7 +69,7 @@ public:
CVector2D() CVector2D()
{} {}
CVector2D(float fX, float fY) constexpr CVector2D(float fX, float fY)
: x(fX), y(fY) : x(fX), y(fY)
{} {}
@ -80,9 +80,9 @@ public:
{ x -= vec.x; y -= vec.y; { x -= vec.x; y -= vec.y;
return *this; } return *this; }
inline float Magnitude() inline float Magnitude() const
{ return sqrt(x * x + y * y); } { return sqrt(x * x + y * y); }
inline float MagnitudeSqr() inline constexpr float MagnitudeSqr() const
{ return x * x + y * y; } { return x * x + y * y; }
inline CVector2D& Normalize() inline CVector2D& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; } { float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; }