lottie/vdasher: improve readability for lineTo function 47/187647/3
authorYoungbok Shin <youngb.shin@samsung.com>
Mon, 27 Aug 2018 07:18:46 +0000 (16:18 +0900)
committerYoungbok Shin <youngb.shin@samsung.com>
Mon, 27 Aug 2018 08:06:59 +0000 (17:06 +0900)
It creates two internal functions for duplicated code.
By replacing nested 'if' conditions with the functions,
it improves readability and manageability.

Change-Id: I303ba6849f776c5f02df6552f0a37acecb14a78b

src/vector/vdasher.cpp
src/vector/vdasher.h

index d5f7ba90a644b86a08956f2d2352a7ae485bb8c3..178f63a61ac1ab51b864af5ef29e1d42cc79b649 100644 (file)
@@ -106,6 +106,30 @@ void VDasher::moveTo(const VPointF &p)
     }
 }
 
+void VDasher::addLine(const VPointF &p)
+{
+   if (mIsCurrentOperationGap) return;
+
+   if (!mNewSegment) {
+        mDashedPath.moveTo(mCurPt);
+        mNewSegment = true;
+   }
+   mDashedPath.lineTo(p);
+}
+
+void VDasher::updateActiveSegment()
+{
+   if (!mIsCurrentOperationGap) {
+        mIsCurrentOperationGap = true;
+        mNewSegment = false;
+        mCurrentDashLength = mDashArray[mCurrentDashIndex].gap;
+   } else {
+        mIsCurrentOperationGap = false;
+        mCurrentDashIndex = (mCurrentDashIndex + 1) % mArraySize;
+        mCurrentDashLength = mDashArray[mCurrentDashIndex].length;
+   }
+}
+
 void VDasher::lineTo(const VPointF &p)
 {
     VLine left, right;
@@ -113,51 +137,26 @@ void VDasher::lineTo(const VPointF &p)
     float length = line.length();
     if (length < mCurrentDashLength) {
         mCurrentDashLength -= length;
-        if (!mIsCurrentOperationGap) {
-            if (!mNewSegment) {
-                mDashedPath.moveTo(mCurPt);
-                mNewSegment = true;
-            }
-            mDashedPath.lineTo(p);
-        }
+        addLine(p);
     } else {
         while (length > mCurrentDashLength) {
             length -= mCurrentDashLength;
             line.splitAtLength(mCurrentDashLength, left, right);
-            if (!mIsCurrentOperationGap) {
-                if (!mNewSegment) {
-                    mDashedPath.moveTo(left.p1());
-                    mNewSegment = true;
-                }
-                mDashedPath.lineTo(left.p2());
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].gap;
-            } else {
-                mCurrentDashIndex = (mCurrentDashIndex + 1) % mArraySize;
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].length;
-            }
-            mIsCurrentOperationGap = !mIsCurrentOperationGap;
-            if (mIsCurrentOperationGap)
-                mNewSegment = false;
+
+            addLine(left.p2());
+            updateActiveSegment();
+
             line = right;
             mCurPt = line.p1();
         }
+
         // remainder
         mCurrentDashLength -= length;
-        if (!mIsCurrentOperationGap) {
-            mDashedPath.moveTo(line.p1());
-            mDashedPath.lineTo(line.p2());
-        }
+        addLine(line.p2());
+
         if (mCurrentDashLength < 1.0) {
             // move to next dash
-            if (!mIsCurrentOperationGap) {
-                mIsCurrentOperationGap = true;
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].gap;
-                mNewSegment = false;
-            } else {
-                mIsCurrentOperationGap = false;
-                mCurrentDashIndex = (mCurrentDashIndex + 1) % mArraySize;
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].length;
-            }
+            updateActiveSegment();
         }
     }
     mCurPt = p;
index c50bfb535c9db47564966636ca82422053b06f8f..cc341991b799ad0931bd91d1f583c30909fc76e4 100644 (file)
@@ -14,6 +14,8 @@ private:
     void lineTo(const VPointF &p);
     void cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e);
     void close();
+    void addLine(const VPointF &p);
+    void updateActiveSegment();
 
 private:
     struct Dash {