lottie/vector: refactor VPathMesure to handle offset . 92/187792/3
authorsubhransu mohanty <sub.mohanty@samsung.com>
Tue, 28 Aug 2018 06:14:24 +0000 (15:14 +0900)
committerYoungbok Shin <youngb.shin@samsung.com>
Tue, 28 Aug 2018 10:26:30 +0000 (19:26 +0900)
Change-Id: Ic84c63376c52167ee2ae88d363bf22aadf4fbca9

src/lottie/lottieitem.cpp
src/lottie/lottiemodel.h
src/vector/vpathmesure.cpp
src/vector/vpathmesure.h

index 992009b..0681437 100644 (file)
@@ -958,7 +958,9 @@ void LOTTrimItem::update()
     //@TODO take the offset and trim type into account.
     for (auto &i : mPathItems) {
         VPathMesure pm;
-        pm.setOffset(mCache.mStart, mCache.mEnd);
+        pm.setStart(mCache.mStart);
+        pm.setEnd(mCache.mEnd);
+        pm.setOffset(mCache.mOffset);
         i->updatePath(pm.trim(i->localPath()));
     }
 }
index 165a502..85e5077 100644 (file)
@@ -656,7 +656,7 @@ public:
     {visitor->visit(this);}
     float start(int frameNo) const {return mStart.value(frameNo)/100.0f;}
     float end(int frameNo) const {return mEnd.value(frameNo)/100.0f;}
-    float offset(int frameNo) const {return mOffset.value(frameNo)/100.0f;}
+    float offset(int frameNo) const {return mOffset.value(frameNo);}
     LOTTrimData::TrimType type() const {return mTrimType;}
 public:
     LOTAnimatable<float>             mStart{0};
index 5e93f8f..05c61b6 100644 (file)
@@ -4,25 +4,58 @@
 
 V_BEGIN_NAMESPACE
 
-void VPathMesure::setOffset(float sp, float ep)
+VPath oneSegment(float start, float end, const VPath & path)
 {
-    startOffset = sp;
-    endOffset = ep;
+    if (start > end) {
+        std::swap(start, end);
+    }
+    float   array[5] = {0.0f, start, end - start, 1000, 0.0f};
+    VDasher dasher(array, 5);
+    return dasher.dashed(path);
 }
 
 VPath VPathMesure::trim(const VPath &path)
 {
-    if (vCompare(startOffset, 0.0f) && (vCompare(endOffset, 1.0f))) return path;
+    if (vCompare(mStart, mEnd)) return VPath();
 
-    float len = path.length();
-    float sg = len * startOffset;
-    float eg = len * (1.0f - endOffset);
-    len = len - (sg + eg);
+    if ((vCompare(mStart, 0.0f) && (vCompare(mEnd, 1.0f))) ||
+        (vCompare(mStart, 1.0f) && (vCompare(mEnd, 0.0f)))) return path;
 
-    float   array[5] = {0.0f, sg, len, 1000, 0.0f};
-    VDasher dasher(array, 5);
+    if (vIsZero(mOffset)) {
+        float length = path.length();
+        return oneSegment(length * mStart, length * mEnd, path);
+    } else {
+        float length = path.length();
+        float offset = fmod(mOffset, length);
+        float start = length * mStart;
+        float end  = length * mEnd;
+        start += offset;
+        end +=offset;
 
-    return dasher.dashed(path);
+        if (start < 0 && end < 0) {
+            return oneSegment(length + start, length + end, path);
+        } else if (start > 0 && end > 0) {
+            if (start > length && end > length)
+                return oneSegment(start - length, end - length, path);
+            else if (start < length && end < length)
+                return oneSegment(start, end, path);
+            else {
+                float len1 = start > end ? start - length : end - length;
+                float start2 = start < end ? start : end;
+                float gap1 = start2 - len1;
+                float   array[5] = {len1, gap1, length - start2, 1000, 0.0f};
+                VDasher dasher(array, 5);
+                return dasher.dashed(path);
+            }
+        } else {
+            float len1 = start > end ? start : end;
+            float start2 = start < end ? length + start : length + end;
+            float gap1 = start2 - len1;
+            float   array[5] = {len1, gap1, length - start2, 1000, 0.0f};
+            VDasher dasher(array, 5);
+            return dasher.dashed(path);
+        }
+    }
 }
 
 V_END_NAMESPACE
index 61b1d34..8202913 100644 (file)
@@ -7,12 +7,14 @@ V_BEGIN_NAMESPACE
 
 class VPathMesure {
 public:
-    void  setOffset(float sp, float ep);
+    void  setStart(float start){mStart = start;}
+    void  setEnd(float end){mEnd = end;}
+    void  setOffset(float offset){mOffset = offset;}
     VPath trim(const VPath &path);
-
 private:
-    float startOffset{0.0f};
-    float endOffset{1.0f};
+    float mStart{0.0f};
+    float mEnd{1.0f};
+    float mOffset{0.0f};
 };
 
 V_END_NAMESPACE