perf: added tAtLength(len, totalLength) api to Bezier.
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Fri, 7 Aug 2020 02:08:09 +0000 (11:08 +0900)
committerJongmin Lee <jm105.lee@samsung.com>
Sun, 9 Aug 2020 21:37:12 +0000 (06:37 +0900)
When length of the bezier is known , then pass it to tAtLength function
to avoid doing expensive length() operation again.

src/lottie/lottiemodel.h
src/vector/vbezier.cpp
src/vector/vbezier.h

index 5a886b7..6f96089 100644 (file)
@@ -185,7 +185,7 @@ struct Value<VPointF> {
             VBezier b =
                 VBezier::fromPoints(mStartValue, mOutTangent,
                                     mInTangent, mEndValue);
-            return b.pointAt(b.tAtLength(t * mBezierLength));
+            return b.pointAt(b.tAtLength(t * mBezierLength, mBezierLength));
         }
         return lerp(mStartValue, mEndValue, t);
     }
@@ -196,7 +196,7 @@ struct Value<VPointF> {
             VBezier b =
                 VBezier::fromPoints(mStartValue, mOutTangent,
                                     mInTangent, mEndValue);
-            return b.angleAt(b.tAtLength(t * mBezierLength));
+            return b.angleAt(b.tAtLength(t * mBezierLength, mBezierLength));
         }
         return 0;
     }
index 079a5f0..08498c3 100644 (file)
@@ -79,12 +79,11 @@ VBezier VBezier::onInterval(float t0, float t1) const
     return result;
 }
 
-float VBezier::tAtLength(float l) const
+float VBezier::tAtLength(float l, float totalLength) const
 {
-    float       len = length();
     float       t = 1.0;
     const float error = 0.01f;
-    if (l > len || vCompare(l, len)) return t;
+    if (l > totalLength || vCompare(l, totalLength)) return t;
 
     t *= 0.5;
 
index 9339af4..18b7c59 100644 (file)
@@ -39,7 +39,8 @@ public:
                               const VPointF &cp2, const VPointF &end);
     inline void    parameterSplitLeft(float t, VBezier *left);
     inline void    split(VBezier *firstHalf, VBezier *secondHalf) const;
-    float          tAtLength(float len) const;
+    float          tAtLength(float len) const { return tAtLength(len , length());}
+    float          tAtLength(float len, float totalLength) const;
     void           splitAtLength(float len, VBezier *left, VBezier *right);
     VPointF        pt1() const { return {x1, y1}; }
     VPointF        pt2() const { return {x2, y2}; }