lottie: refactor trim object handling
[platform/core/uifw/lottie-player.git] / src / vector / vpathmesure.cpp
1 #include "vpathmesure.h"
2 #include "vbezier.h"
3 #include "vdasher.h"
4 #include <limits>
5
6 V_BEGIN_NAMESPACE
7
8 /*
9  * start and end value must be normalized to [0 - 1]
10  * Path mesure trims the path from [start --> end]
11  * if start > end it treates as a loop and trims as two segment
12  *  [0-->end] and [start --> 1]
13  */
14 VPath VPathMesure::trim(const VPath &path)
15 {
16     if (vCompare(mStart, mEnd)) return VPath();
17
18     if ((vCompare(mStart, 0.0f) && (vCompare(mEnd, 1.0f))) ||
19         (vCompare(mStart, 1.0f) && (vCompare(mEnd, 0.0f)))) return path;
20
21     float length = path.length();
22
23     if (mStart < mEnd) {
24         float   array[4] = {0.0f, length * mStart, //1st segment
25                             (mEnd - mStart) * length, std::numeric_limits<float>::max(), //2nd segment
26                            };
27         VDasher dasher(array, 4);
28         return dasher.dashed(path);
29     } else {
30         float   array[4] = {length * mEnd, (mStart - mEnd) * length, //1st segment
31                             (1 - mStart) * length, std::numeric_limits<float>::max(), //2nd segment
32                            };
33         VDasher dasher(array, 4);
34         return dasher.dashed(path);
35     }
36 }
37
38 V_END_NAMESPACE