vector: clean up single, double-decision comparison 54/184354/5
authorHermet Park <hermetpark@gmail.com>
Tue, 17 Jul 2018 10:23:22 +0000 (19:23 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Tue, 17 Jul 2018 10:41:52 +0000 (10:41 +0000)
Change-Id: I9ed37192c9c1236103aeeb7f239bbae2dabe6368

src/lottie/lottieitem.cpp
src/vector/vbezier.cpp
src/vector/vdasher.cpp
src/vector/vdrawhelper.cpp
src/vector/vglobal.h
src/vector/vmatrix.cpp
src/vector/vpath.cpp
src/vector/vpoint.h

index 7274405..c4129ca 100644 (file)
@@ -703,7 +703,7 @@ void LOTContentGroupItem::update(int frameNo, const VMatrix &parentMatrix, float
       m = mData->mTransform->matrix(frameNo) * parentMatrix;
       alpha *= mData->mTransform->opacity(frameNo);
 
-      if (!floatCmp(alpha, parentAlpha)) {
+      if (!vCompare(alpha, parentAlpha)) {
          newFlag |= DirtyFlagBit::Alpha;
       }
    }
index 34e5093..c3874f4 100644 (file)
@@ -48,7 +48,7 @@ VBezier::length()const
 
    chord = lineLength(x1, y1, x4, y4);
 
-   if (!floatCmp(len, chord)) {
+   if (!vCompare(len, chord)) {
       split(&left, &right); /* split in two */
       length =
                left.length() + /* try left side */
@@ -80,7 +80,7 @@ float VBezier::tAtLength(float l) const
     float len = length();
     float t   = 1.0;
     const float error = 0.01;
-    if (l > len || floatCmp(l, len))
+    if (l > len || vCompare(l, len))
         return t;
 
     t *= 0.5;
index 8c9f738..f3d7f88 100644 (file)
@@ -70,7 +70,7 @@ void VDasher::moveTo(const VPointF &p)
     mStartPt = p;
     mCurPt = p;
 
-    if (!floatCmp(mDashOffset, 0.0)) {
+    if (!vCompare(mDashOffset, 0.0f)) {
         float totalLength = 0.0;
         for (int i = 0; i < mArraySize ; i++) {
             totalLength = mDashArray[i].length + mDashArray[i].gap;
index a2c8932..d43198a 100644 (file)
@@ -209,7 +209,7 @@ getRadialGradientValues(RadialGradientValues *v, const VSpanData *data)
     v->a = v->dr * v->dr - v->dx*v->dx - v->dy*v->dy;
     v->inv2a = 1 / (2 * v->a);
 
-    v->extended = !vIsNull(gradient.radial.fradius) || v->a <= 0;
+    v->extended = !vIsZero(gradient.radial.fradius) || v->a <= 0;
 }
 
 static inline int
@@ -360,7 +360,7 @@ static void fetch(uint32_t *buffer, uint32_t *end,
 void fetch_radial_gradient(uint32_t *buffer, const Operator *op, const VSpanData *data, int y, int x, int length)
 {
     // avoid division by zero
-    if (vIsNull(op->radial.a)) {
+    if (vIsZero(op->radial.a)) {
         memfill32(buffer, 0, length);
         return;
     }
index aa9e617..8984600 100644 (file)
@@ -79,35 +79,29 @@ V_CONSTEXPR inline const T &vMin(const T &a, const T &b) { return (a < b) ? a :
 template <typename T>
 V_CONSTEXPR inline const T &vMax(const T &a, const T &b) { return (a < b) ? b : a; }
 
-static inline bool vCompare(double p1, double p2)
-{
-    return (std::abs(p1 - p2) * 1000000000000. <= vMin(std::abs(p1), std::abs(p2)));
-}
 
-static inline bool vCompare(float p1, float p2)
-{
-    return (std::abs(p1 - p2) * 100000.f <= vMin(std::abs(p1), std::abs(p2)));
-}
 
-static inline bool floatCmp(float p1, float p2)
+static const double EPSILON_DOUBLE = 0.000000000001f;
+static const float EPSILON_FLOAT = 0.000001f;
+
+static inline bool vCompare(double p1, double p2)
 {
-    return (std::abs(p1 - p2) * 100000.f <= fminf(std::abs(p1), std::abs(p2)));
+    return (std::abs(p1 - p2) < EPSILON_DOUBLE);
 }
 
-static inline bool floatNull(float f)
+static inline bool vCompare(float p1, float p2)
 {
-    return std::abs(f) <= 0.00001f;
+    return (std::abs(p1 - p2) < EPSILON_FLOAT);
 }
 
-
-static inline bool vIsNull(double d)
+static inline bool vIsZero(float f)
 {
-    return std::abs(d) <= 0.000000000001;
+    return (std::abs(f) <= EPSILON_FLOAT);
 }
 
-static inline bool vIsNull(float f)
+static inline bool vIsZero(double f)
 {
-    return std::abs(f) <= 0.00001f;
+    return (std::abs(f) <= EPSILON_DOUBLE);
 }
 
 // Approximate sqrt(x*x + y*y) using the alpha max plus beta min algorithm.
index ad5192d..2a72700 100644 (file)
@@ -43,7 +43,7 @@ bool VMatrix::isIdentity() const
 
 bool VMatrix::isInvertible() const
 {
-    return !vIsNull(determinant());
+    return !vIsZero(determinant());
 }
 
 bool VMatrix::isScaling() const
@@ -178,27 +178,27 @@ VMatrix::MatrixType VMatrix::type() const
 
     switch (static_cast<MatrixType>(d->dirty)) {
     case MatrixType::Project:
-        if (!vIsNull(d->m13) || !vIsNull(d->m23) || !vIsNull(d->m33 - 1)) {
+        if (!vIsZero(d->m13) || !vIsZero(d->m23) || !vIsZero(d->m33 - 1)) {
              d->type = MatrixType::Project;
              break;
         }
     case MatrixType::Shear:
     case MatrixType::Rotate:
-        if (!vIsNull(d->m12) || !vIsNull(d->m21)) {
+        if (!vIsZero(d->m12) || !vIsZero(d->m21)) {
             const float dot = d->m11 * d->m12 + d->m21 * d->m22;
-            if (vIsNull(dot))
+            if (vIsZero(dot))
                 d->type = MatrixType::Rotate;
             else
                 d->type = MatrixType::Shear;
             break;
         }
     case MatrixType::Scale:
-        if (!vIsNull(d->m11 - 1) || !vIsNull(d->m22 - 1)) {
+        if (!vIsZero(d->m11 - 1) || !vIsZero(d->m22 - 1)) {
             d->type = MatrixType::Scale;
             break;
         }
     case MatrixType::Translate:
-        if (!vIsNull(d->mtx) || !vIsNull(d->mty)) {
+        if (!vIsZero(d->mtx) || !vIsZero(d->mty)) {
             d->type = MatrixType::Translate;
             break;
         }
@@ -566,8 +566,8 @@ VMatrix VMatrix::inverted(bool *invertible) const
         invert.d->mty = -d->mty;
         break;
     case MatrixType::Scale:
-        inv = !vIsNull(d->m11);
-        inv &= !vIsNull(d->m22);
+        inv = !vIsZero(d->m11);
+        inv &= !vIsZero(d->m22);
         if (inv) {
             invert.d->m11 = 1. / d->m11;
             invert.d->m22 = 1. / d->m22;
@@ -578,7 +578,7 @@ VMatrix VMatrix::inverted(bool *invertible) const
     default:
         // general case
         float det = determinant();
-        inv = !vIsNull(det);
+        inv = !vIsZero(det);
         if (inv)
             invert = (adjoint() /= det);
         //TODO Test above line
index 4df2918..ba352ee 100644 (file)
@@ -280,8 +280,8 @@ tForArcAngle(float angle)
 {
    float radians, cos_angle, sin_angle, tc, ts, t;
 
-   if (floatCmp(angle,0.f)) return 0;
-   if (floatCmp(angle, 90.0)) return 1;
+   if (vCompare(angle,0.f)) return 0;
+   if (vCompare(angle, 90.0f)) return 1;
 
    radians = (angle/180) * M_PI;
 
@@ -389,13 +389,13 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength,
     }
 
     // avoid empty start segment
-    if (floatNull(startT - float(1))) {
+    if (vIsZero(startT - float(1))) {
         startT = 0;
         startSegment += delta;
     }
 
     // avoid empty end segment
-    if (floatNull(endT)) {
+    if (vIsZero(endT)) {
         endT = 1;
         endSegment -= delta;
     }
@@ -403,8 +403,8 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength,
     startT = tForArcAngle(startT * 90);
     endT = tForArcAngle(endT * 90);
 
-    const bool splitAtStart = !floatNull(startT);
-    const bool splitAtEnd = !floatNull(endT - float(1));
+    const bool splitAtStart = !vIsZero(startT);
+    const bool splitAtEnd = !vIsZero(endT - float(1));
 
     const int end = endSegment + delta;
 
@@ -429,7 +429,7 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength,
             b = VBezier::fromPoints(points[j], points[j + 1], points[j + 2], points[j + 3]);
 
         // empty arc?
-        if (startSegment == endSegment && floatCmp(startT, endT))
+        if (startSegment == endSegment && vCompare(startT, endT))
             return startPoint;
 
         if (i == startSegment) {
@@ -546,7 +546,7 @@ void VPath::addRect(const VRectF &rect, VPath::Direction dir)
 
 void VPath::addRoundRect(const VRectF &rect, float rx, float ry, VPath::Direction dir)
 {
-    if (floatCmp(rx, 0.f) || floatCmp(ry, 0.f)) {
+    if (vCompare(rx, 0.f) || vCompare(ry, 0.f)) {
         addRect(rect, dir);
         return;
     }
index 9206856..3d47514 100644 (file)
@@ -37,7 +37,7 @@ private:
 
 inline const bool fuzzyCompare(const VPointF & p1, const VPointF & p2)
 {
-    return (floatCmp(p1.mx , p2.mx) && floatCmp(p1.my , p2.my));
+    return (vCompare(p1.mx , p2.mx) && vCompare(p1.my , p2.my));
 }