code refactorig.
authorHermet Park <hermetpark@gmail.com>
Thu, 11 Jul 2019 02:23:23 +0000 (11:23 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Thu, 18 Jul 2019 11:04:28 +0000 (20:04 +0900)
To avoid implicit double type data,
Tell compiler to treat numbers as float explicitly.

src/lottie/lottieitem.cpp
src/vector/vbezier.cpp
src/vector/vbezier.h
src/vector/vbitmap.cpp
src/vector/vdrawhelper.cpp
src/vector/vinterpolator.cpp
src/vector/vline.h
src/vector/vmatrix.cpp
src/vector/vpath.cpp

index d6b063a..bec7dd1 100644 (file)
@@ -132,8 +132,8 @@ bool LOTCompItem::update(int frameNo)
     float sx = float(viewPort.width()) / viewBox.width();
     float sy = float(viewPort.height()) / viewBox.height();
     float scale = fmin(sx, sy);
-    float tx = (viewPort.width() - viewBox.width() * scale) * 0.5;
-    float ty = (viewPort.height() - viewBox.height() * scale) * 0.5;
+    float tx = (viewPort.width() - viewBox.width() * scale) * 0.5f;
+    float ty = (viewPort.height() - viewBox.height() * scale) * 0.5f;
 
     VMatrix m;
     m.translate(tx, ty).scale(scale, scale);
@@ -231,7 +231,7 @@ void LOTLayerItem::buildLayerNode()
         mLayerCNode->mClipPath.elmCount = 0;
         mLayerCNode->name = name().c_str();
     }
-    if (complexContent()) mLayerCNode->mAlpha = combinedAlpha() * 255;
+    if (complexContent()) mLayerCNode->mAlpha = combinedAlpha() * 255.f;
     mLayerCNode->mVisible = visible();
     // update matte
     if (hasMatte()) {
@@ -267,7 +267,7 @@ void LOTLayerItem::buildLayerNode()
             cNode->mPath.ptCount = pts.size();
             cNode->mPath.elmPtr = elmPtr;
             cNode->mPath.elmCount = elm.size();
-            cNode->mAlpha = mask.mCombinedAlpha * 255;
+            cNode->mAlpha = mask.mCombinedAlpha * 255.0f;
             switch (mask.maskMode()) {
             case LOTMaskData::Mode::Add:
                 cNode->mMode = MaskAdd;
@@ -584,7 +584,7 @@ void LOTCompLayerItem::render(VPainter *painter, const VRle &inheritMask,
             srcPainter.begin(&srcBitmap);
             renderHelper(&srcPainter, inheritMask, matteRle);
             srcPainter.end();
-            painter->drawBitmap(VPoint(), srcBitmap, combinedAlpha() * 255);
+            painter->drawBitmap(VPoint(), srcBitmap, combinedAlpha() * 255.0f);
         } else {
             renderHelper(painter, inheritMask, matteRle);
         }
@@ -1383,14 +1383,14 @@ void LOTStrokeItem::updateContent(int frameNo)
 
 static float getScale(const VMatrix &matrix)
 {
-    constexpr float SQRT_2 = 1.41421;
+    constexpr float SQRT_2 = 1.41421f;
     VPointF         p1(0, 0);
     VPointF         p2(SQRT_2, SQRT_2);
     p1 = matrix.map(p1);
     p2 = matrix.map(p2);
     VPointF final = p2 - p1;
 
-    return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0;
+    return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0f;
 }
 
 void LOTStrokeItem::updateRenderNode()
@@ -1408,7 +1408,7 @@ void LOTStrokeItem::updateRenderNode()
         for (int i = 0; i < mDashArraySize; i++) mDashArray[i] *= scale;
 
         /* AE draw the dash even if dash value is 0 */
-        if (vCompare(mDashArray[0], 0.0f)) mDashArray[0] = 0.1;
+        if (vCompare(mDashArray[0], 0.0f)) mDashArray[0] = 0.1f;
 
         mDrawable.setDashInfo(mDashArray, mDashArraySize);
     }
index c5d7a17..e699157 100644 (file)
@@ -79,7 +79,7 @@ float VBezier::tAtLength(float l) const
 {
     float       len = length();
     float       t = 1.0;
-    const float error = 0.01;
+    const float error = 0.01f;
     if (l > len || vCompare(l, len)) return t;
 
     t *= 0.5;
@@ -93,10 +93,10 @@ float VBezier::tAtLength(float l) const
         if (fabs(lLen - l) < error) break;
 
         if (lLen < l) {
-            t += (lastBigger - t) * 0.5;
+            t += (lastBigger - t) * 0.5f;
         } else {
             lastBigger = t;
-            t -= t * 0.5;
+            t -= t * 0.5f;
         }
     }
     return t;
@@ -116,7 +116,7 @@ VPointF VBezier::derivative(float t) const
     // p'(t) = 3 * (-(1-2t+t^2) * p0 + (1 - 4 * t + 3 * t^2) * p1 + (2 * t - 3 *
     // t^2) * p2 + t^2 * p3)
 
-    float m_t = 1. - t;
+    float m_t = 1.0f - t;
 
     float d = t * t;
     float a = -m_t * m_t;
index ea85374..c90b884 100644 (file)
@@ -110,23 +110,23 @@ inline void VBezier::parameterSplitLeft(float t, VBezier *left)
 
 inline void VBezier::split(VBezier *firstHalf, VBezier *secondHalf) const
 {
-    float c = (x2 + x3) * .5f;
-    firstHalf->x2 = (x1 + x2) * .5f;
-    secondHalf->x3 = (x3 + x4) * .5f;
+    float c = (x2 + x3) * 0.5f;
+    firstHalf->x2 = (x1 + x2) * 0.5f;
+    secondHalf->x3 = (x3 + x4) * 0.5f;
     firstHalf->x1 = x1;
     secondHalf->x4 = x4;
-    firstHalf->x3 = (firstHalf->x2 + c) * .5f;
-    secondHalf->x2 = (secondHalf->x3 + c) * .5f;
-    firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2) * .5f;
+    firstHalf->x3 = (firstHalf->x2 + c) * 0.5f;
+    secondHalf->x2 = (secondHalf->x3 + c) * 0.5f;
+    firstHalf->x4 = secondHalf->x1 = (firstHalf->x3 + secondHalf->x2) * 0.5f;
 
     c = (y2 + y3) / 2;
-    firstHalf->y2 = (y1 + y2) * .5f;
-    secondHalf->y3 = (y3 + y4) * .5f;
+    firstHalf->y2 = (y1 + y2) * 0.5f;
+    secondHalf->y3 = (y3 + y4) * 0.5f;
     firstHalf->y1 = y1;
     secondHalf->y4 = y4;
-    firstHalf->y3 = (firstHalf->y2 + c) * .5f;
-    secondHalf->y2 = (secondHalf->y3 + c) * .5f;
-    firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2) * .5f;
+    firstHalf->y3 = (firstHalf->y2 + c) * 0.5f;
+    secondHalf->y2 = (secondHalf->y3 + c) * 0.5f;
+    firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2) * 0.5f;
 }
 
 V_END_NAMESPACE
index 20963a6..b2f676c 100644 (file)
@@ -125,7 +125,7 @@ struct VBitmap::Impl {
                     green = (green * 255) / alpha;
                     blue = (blue * 255) / alpha;
                 }
-                int luminosity = (0.299 * red + 0.587 * green + 0.114 * blue);
+                int luminosity = (0.299f * red + 0.587f * green + 0.114f * blue);
                 *pixel = luminosity << 24;
                 pixel++;
             }
index a22ce34..bc6b689 100644 (file)
@@ -150,8 +150,8 @@ bool VGradientCache::generateGradientColorTable(const VGradientStops &stops,
     curr = start;
     if (!curr->second.isOpaque()) alpha = true;
     curColor = curr->second.premulARGB(opacity);
-    incr = 1.0 / (float)size;
-    fpos = 1.5 * incr;
+    incr = 1.0f / (float)size;
+    fpos = 1.5f * incr;
 
     colorTable[pos++] = curColor;
 
index 94f454a..86fbf7a 100644 (file)
@@ -45,7 +45,7 @@ V_BEGIN_NAMESPACE
 #define SUBDIVISION_MAX_ITERATIONS 10
 
 const float VInterpolator::kSampleStepSize =
-    1.0 / float(VInterpolator::kSplineTableSize - 1);
+    1.0f / float(VInterpolator::kSplineTableSize - 1);
 
 void VInterpolator::init(float aX1, float aY1, float aX2, float aY2)
 {
@@ -72,7 +72,7 @@ void VInterpolator::CalcSampleValues()
 
 float VInterpolator::GetSlope(float aT, float aA1, float aA2)
 {
-    return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
+    return 3.0f * A(aA1, aA2) * aT * aT + 2.0f * B(aA1, aA2) * aT + C(aA1);
 }
 
 float VInterpolator::value(float aX) const
@@ -137,7 +137,7 @@ float VInterpolator::BinarySubdivide(float aX, float aA, float aB) const
     int   i = 0;
 
     do {
-        currentT = aA + (aB - aA) / 2.0;
+        currentT = aA + (aB - aA) / 2.0f;
         currentX = CalcBezier(currentT, mX1, mX2) - aX;
 
         if (currentX > 0.0) {
index 869d198..d3167c1 100644 (file)
@@ -70,7 +70,7 @@ inline float VLine::length(float x1, float y1, float x2, float y2)
     x = x < 0 ? -x : x;
     y = y < 0 ? -y : y;
 
-    return (x > y ? x + 0.375 * y : y + 0.375 * x);
+    return (x > y ? x + 0.375f * y : y + 0.375f * x);
 }
 
 inline void VLine::splitAtLength(float lengthAt, VLine &left, VLine &right) const
index f69d15a..0baecf5 100644 (file)
@@ -510,8 +510,8 @@ VMatrix VMatrix::inverted(bool *invertible) const
         inv = !vIsZero(m11);
         inv &= !vIsZero(m22);
         if (inv) {
-            invert.m11 = 1. / m11;
-            invert.m22 = 1. / m22;
+            invert.m11 = 1.0f / m11;
+            invert.m22 = 1.0f / m22;
             invert.mtx = -mtx * invert.m11;
             invert.mty = -mty * invert.m22;
         }
@@ -553,7 +553,7 @@ bool VMatrix::fuzzyCompare(const VMatrix &o) const
            vCompare(mtx, o.mtx) && vCompare(mty, o.mty);
 }
 
-#define V_NEAR_CLIP 0.000001
+#define V_NEAR_CLIP 0.000001f
 #ifdef MAP
 #undef MAP
 #endif
@@ -687,7 +687,7 @@ VPointF VMatrix::map(const VPointF &p) const
         x = m11 * fx + m21 * fy + mtx;
         y = m12 * fx + m22 * fy + mty;
         if (t == MatrixType::Project) {
-            float w = 1. / (m13 * fx + m23 * fy + m33);
+            float w = 1.0f / (m13 * fx + m23 * fy + m33);
             x *= w;
             y *= w;
         }
index 220b05e..475e144 100644 (file)
@@ -524,7 +524,7 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
     float              partialPointAmount = points - floorf(points);
     bool               longSegment = false;
     size_t             numPoints = size_t(ceilf(points) * 2);
-    float              angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
+    float              angleDir = ((dir == VPath::Direction::CW) ? 1.0f : -1.0f);
     bool               hasRoundness = false;
 
     innerRoundness /= 100.0f;
@@ -625,7 +625,7 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
     float              y;
     float              anglePerPoint = 2.0f * K_PI / floorf(points);
     size_t             numPoints = size_t(floorf(points));
-    float              angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
+    float              angleDir = ((dir == VPath::Direction::CW) ? 1.0f : -1.0f);
     bool               hasRoundness = false;
 
     roundness /= 100.0f;