lottie/vdasher: improve readability for cubicTo function 52/187652/2
authorYoungbok Shin <youngb.shin@samsung.com>
Mon, 27 Aug 2018 08:48:35 +0000 (17:48 +0900)
committerYoungbok Shin <youngb.shin@samsung.com>
Mon, 27 Aug 2018 08:51:13 +0000 (17:51 +0900)
Change-Id: I86422527c33c323d0469a4a6b58089997b55b004

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

index 178f63a..d91bc6d 100644 (file)
@@ -162,6 +162,17 @@ void VDasher::lineTo(const VPointF &p)
     mCurPt = p;
 }
 
+void VDasher::addCubic(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
+{
+    if (mIsCurrentOperationGap) return;
+
+    if (!mNewSegment) {
+        mDashedPath.moveTo(mCurPt);
+        mNewSegment = true;
+    }
+    mDashedPath.cubicTo(cp1, cp2, e);
+}
+
 void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
 {
     VBezier left, right;
@@ -170,54 +181,26 @@ void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
     bezLen = b.length();
     if (bezLen < mCurrentDashLength) {
         mCurrentDashLength -= bezLen;
-        if (!mIsCurrentOperationGap) {
-            if (!mNewSegment) {
-                mDashedPath.moveTo(mCurPt);
-                mNewSegment = true;
-            }
-            mDashedPath.cubicTo(cp1, cp2, e);
-        }
+        addCubic(cp1, cp2, e);
     } else {
         while (bezLen > mCurrentDashLength) {
             bezLen -= mCurrentDashLength;
             b.splitAtLength(mCurrentDashLength, &left, &right);
-            if (!mIsCurrentOperationGap) {
-                if (!mNewSegment) {
-                    mDashedPath.moveTo(left.pt1());
-                    mNewSegment = true;
-                }
-                mDashedPath.cubicTo(left.pt2(), left.pt3(), left.pt4());
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].gap;
-            } else {
-                mCurrentDashIndex = (mCurrentDashIndex + 1) % mArraySize;
-                mCurrentDashLength = mDashArray[mCurrentDashIndex].length;
-            }
-            mIsCurrentOperationGap = !mIsCurrentOperationGap;
-            if (mIsCurrentOperationGap)
-                mNewSegment = false;
+
+            addCubic(left.pt2(), left.pt3(), left.pt4());
+            updateActiveSegment();
+
             b = right;
             mCurPt = b.pt1();
         }
+
         // remainder
         mCurrentDashLength -= bezLen;
-        if (!mIsCurrentOperationGap) {
-            if (!mNewSegment) {
-                mDashedPath.moveTo(b.pt1());
-                mNewSegment = true;
-            }
-            mDashedPath.cubicTo(b.pt2(), b.pt3(), b.pt4());
-        }
+        addCubic(b.pt2(), b.pt3(), b.pt4());
+
         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 = e;
index cc34199..7d247de 100644 (file)
@@ -15,6 +15,7 @@ private:
     void cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e);
     void close();
     void addLine(const VPointF &p);
+    void addCubic(const VPointF &cp1, const VPointF &cp2, const VPointF &e);
     void updateActiveSegment();
 
 private: