vector: convert radial gradient parameter from lottie space to vector space. 46/184146/3
authorsubhransu sekhar mohanty <smohantty@subhransus-MacBook-Air.local>
Sat, 14 Jul 2018 06:48:14 +0000 (15:48 +0900)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Mon, 16 Jul 2018 03:55:46 +0000 (03:55 +0000)
Change-Id: I1894dd03eb0ccd0266fa098eaaae4aa4bf1e1d57

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

index 29156e6..1a7e3b8 100644 (file)
@@ -335,8 +335,12 @@ void LOTGradient::update(std::unique_ptr<VGradient> &grad, int frameNo)
         VPointF end = mEndPoint.value(frameNo);
         grad->radial.cx = start.x();
         grad->radial.cy = start.y();
-        grad->radial.fx = end.x();
-        grad->radial.fy = end.y();
+        grad->radial.cradius = vLineLength(start.x(), start.y(), end.x(), end.y());
+
+        //TODO update focal radius and focal point
+        grad->radial.fx = grad->radial.cx;
+        grad->radial.fy = grad->radial.cy;
+        grad->radial.fradius = 0;
     }
 }
 
index b531344..fb96f30 100644 (file)
@@ -96,6 +96,21 @@ static inline bool vIsNull(float f)
     return std::abs(f) <= 0.00001f;
 }
 
+// Approximate sqrt(x*x + y*y) using the alpha max plus beta min algorithm.
+// This uses alpha = 1, beta = 3/8, which results in a maximum error of less
+// than 7% compared to the correct value.
+static inline float
+vLineLength(float x1, float y1, float x2, float y2)
+{
+   float x = x2 - x1;
+   float y = y2 - y1;
+
+   x = x < 0 ? -x : x;
+   y = y < 0 ? -y : y;
+
+   return (x > y ? x + 0.375 * y : y + 0.375 * x);
+}
+
 class vFlagHelper
 {
     int i;