public:
LottieColor() = default;
LottieColor(float red, float green , float blue):r(red), g(green),b(blue){}
- VColor toColor(float a=1){ return VColor((255 * r), (255 * g), (255 * b), (255 * a));}
+ VColor toColor(float a=1){ return VColor(uchar(255 * r),
+ uchar(255 * g),
+ uchar(255 * b),
+ uchar(255 * a));}
friend inline LottieColor operator+(const LottieColor &c1, const LottieColor &c2);
friend inline LottieColor operator-(const LottieColor &c1, const LottieColor &c2);
public:
inline void VBezier::coefficients(float t, float &a, float &b, float &c,
float &d)
{
- float m_t = 1. - t;
+ float m_t = 1.0f - t;
b = m_t * m_t;
c = t * t;
d = c * t;
a = b * m_t;
- b *= 3. * t;
- c *= 3. * m_t;
+ b *= 3.0f * t;
+ c *= 3.0f * m_t;
}
inline VPointF VBezier::pointAt(float t) const
// numerically more stable:
float x, y;
- float m_t = 1. - t;
+ float m_t = 1.0f - t;
{
float a = x1 * m_t + x2 * t;
float b = x2 * m_t + x3 * t;
inline void VBezier::split(VBezier *firstHalf, VBezier *secondHalf) const
{
- float c = (x2 + x3) * .5;
- firstHalf->x2 = (x1 + x2) * .5;
- secondHalf->x3 = (x3 + x4) * .5;
+ float c = (x2 + x3) * .5f;
+ firstHalf->x2 = (x1 + x2) * .5f;
+ secondHalf->x3 = (x3 + x4) * .5f;
firstHalf->x1 = x1;
secondHalf->x4 = x4;
- firstHalf->x3 = (firstHalf->x2 + c) * .5;
- secondHalf->x2 = (secondHalf->x3 + c) * .5;
- firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2) * .5;
+ firstHalf->x3 = (firstHalf->x2 + c) * .5f;
+ secondHalf->x2 = (secondHalf->x3 + c) * .5f;
+ firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2) * .5f;
c = (y2 + y3) / 2;
- firstHalf->y2 = (y1 + y2) * .5;
- secondHalf->y3 = (y3 + y4) * .5;
+ firstHalf->y2 = (y1 + y2) * .5f;
+ secondHalf->y3 = (y3 + y4) * .5f;
firstHalf->y1 = y1;
secondHalf->y4 = y4;
- firstHalf->y3 = (firstHalf->y2 + c) * .5;
- secondHalf->y2 = (secondHalf->y3 + c) * .5;
- firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2) * .5;
+ firstHalf->y3 = (firstHalf->y2 + c) * .5f;
+ secondHalf->y2 = (secondHalf->y3 + c) * .5f;
+ firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2) * .5f;
}
V_END_NAMESPACE
#include <type_traits>
#include <utility>
-typedef uint32_t uint;
-typedef uint16_t ushort;
-typedef uint8_t uchar;
+using uint = uint32_t;
+using ushort = uint16_t;
+using uchar = uint8_t;
#if !defined(V_NAMESPACE)
#include <atomic>
class RefCount {
public:
- inline RefCount(int i) : atomic(i) {}
+ explicit RefCount(int i) : atomic(i) {}
inline bool ref()
{
int count = atomic.load();
int i;
public:
- constexpr inline vFlagHelper(int ai) noexcept : i(ai) {}
+ explicit constexpr inline vFlagHelper(int ai) noexcept : i(ai) {}
constexpr inline operator int() const noexcept { return i; }
- constexpr inline vFlagHelper(uint ai) noexcept : i(int(ai)) {}
- constexpr inline vFlagHelper(short ai) noexcept : i(int(ai)) {}
- constexpr inline vFlagHelper(ushort ai) noexcept : i(int(uint(ai))) {}
+ explicit constexpr inline vFlagHelper(uint ai) noexcept : i(int(ai)) {}
+ explicit constexpr inline vFlagHelper(short ai) noexcept : i(int(ai)) {}
+ explicit constexpr inline vFlagHelper(ushort ai) noexcept : i(int(uint(ai))) {}
constexpr inline operator uint() const noexcept { return uint(i); }
};
static_assert((std::is_enum<Enum>::value),
"vFlag is only usable on enumeration types.");
- typedef typename std::conditional<
+ using Int = typename std::conditional<
std::is_unsigned<typename std::underlying_type<Enum>::type>::value,
- unsigned int, signed int>::type Int;
+ unsigned int, signed int>::type;
- typedef Enum enum_type;
+ using enum_type = Enum;
// compiler-generated copy/move ctor/assignment operators are fine!
- constexpr inline vFlag(Enum f) noexcept : i(Int(f)) {}
- constexpr inline vFlag() noexcept : i(0) {}
- constexpr inline vFlag(vFlagHelper f) noexcept : i(f) {}
+ vFlag() = default;
+ constexpr vFlag(Enum f) noexcept : i(Int(f)) {}
+ explicit constexpr vFlag(vFlagHelper f) noexcept : i(f) {}
inline vFlag &operator&=(int mask) noexcept
{
return on ? (*this |= f) : (*this &= ~f);
}
- Int i;
+ Int i{0};
};
class VColor {
public:
- inline VColor() noexcept { a = r = g = b = 0; }
- inline VColor(int red, int green, int blue, int alpha = 255) noexcept
- {
- r = red;
- g = green;
- b = blue;
- a = alpha;
- }
+ VColor() = default;
+ explicit VColor(uchar red, uchar green, uchar blue, uchar alpha = 255) noexcept
+ :a(alpha), r(red), g(green), b(blue){}
inline int red() const noexcept { return r; }
inline int green() const noexcept { return g; }
inline int blue() const noexcept { return b; }
uint premulARGB(float opacity) const
{
- int alpha = a * opacity;
+ int alpha = int(a * opacity);
int pr = (r * alpha) / 255;
int pg = (g * alpha) / 255;
int pb = (b * alpha) / 255;
}
public:
- uchar a;
- uchar r;
- uchar g;
- uchar b;
+ uchar a{0};
+ uchar r{0};
+ uchar g{0};
+ uchar b{0};
};
enum class FillRule: unsigned char { EvenOdd, Winding };
float BinarySubdivide(float aX, float aA, float aB) const;
- static float A(float aA1, float aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
+ static float A(float aA1, float aA2) { return 1.0f - 3.0f * aA2 + 3.0f * aA1; }
- static float B(float aA1, float aA2) { return 3.0 * aA2 - 6.0 * aA1; }
+ static float B(float aA1, float aA2) { return 3.0f * aA2 - 6.0f * aA1; }
- static float C(float aA1) { return 3.0 * aA1; }
+ static float C(float aA1) { return 3.0f * aA1; }
float mX1;
float mY1;
inline friend VDebug & operator<<(VDebug &os, const VPointF &o);
friend inline VPointF operator-(const VPointF &p1, const VPointF &p2);
- friend inline const VPointF operator*(const VPointF &, float val);
- friend inline const VPointF operator*(float val, const VPointF &);
- friend inline const VPointF operator/(const VPointF &, float val);
- friend inline const VPointF operator/(float val, const VPointF &);
+ friend inline const VPointF operator*(const VPointF &, float);
+ friend inline const VPointF operator*(float, const VPointF &);
+ friend inline const VPointF operator/(const VPointF &, float);
+ friend inline const VPointF operator/(float, const VPointF &);
private:
float mx{0};
inline bool VRect::contains(const VRect &r, bool proper) const
{
- if (!proper) {
- if ((x1 <= r.x1) && (x2 >= r.x2) && (y1 <= r.y1) && (y2 >= r.y2))
- return true;
- return false;
- } else {
- if ((x1 < r.x1) && (x2 > r.x2) && (y1 < r.y1) && (y2 > r.y2))
- return true;
- return false;
- }
+ return proper ?
+ ((x1 < r.x1) && (x2 > r.x2) && (y1 < r.y1) && (y2 > r.y2)) :
+ ((x1 <= r.x1) && (x2 >= r.x2) && (y1 <= r.y1) && (y2 >= r.y2));
}
class VRectF {
public:
VRectF() = default;
VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
- explicit VRectF(const VRect &r):x1(r.left()),y1(r.top()),
- x2(r.right()),y2(r.bottom()){}
+ explicit VRectF(const VRect &r):x1(float(r.left())),y1(float(r.top())),
+ x2(float(r.right())),y2(float(r.bottom())){}
V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
V_CONSTEXPR float left() const {return x1;}
float y2{0};
};
-inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
- x2(r.right()),y2(r.bottom()){}
+inline VRect::VRect(const VRectF &r):x1(int(r.left())),y1(int(r.top())),
+ x2(int(r.right())),y2(int(r.bottom())){}
V_END_NAMESPACE
#endif // VRECT_H