From 5c771a708f0f5265858b9a4f19705478d76dc18a Mon Sep 17 00:00:00 2001 From: subhransu sekhar mohanty Date: Sat, 14 Jul 2018 15:48:14 +0900 Subject: [PATCH] vector: convert radial gradient parameter from lottie space to vector space. Change-Id: I1894dd03eb0ccd0266fa098eaaae4aa4bf1e1d57 --- src/lottie/lottiemodel.cpp | 8 ++++++-- src/vector/vglobal.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/lottie/lottiemodel.cpp b/src/lottie/lottiemodel.cpp index 29156e6..1a7e3b8 100644 --- a/src/lottie/lottiemodel.cpp +++ b/src/lottie/lottiemodel.cpp @@ -335,8 +335,12 @@ void LOTGradient::update(std::unique_ptr &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; } } diff --git a/src/vector/vglobal.h b/src/vector/vglobal.h index b531344..fb96f30 100644 --- a/src/vector/vglobal.h +++ b/src/vector/vglobal.h @@ -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; -- 2.7.4