azchohfi / LottieUWP

UWP port of Lottie(https://github.com/airbnb/lottie-android)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please improve BezLength logic

minudf opened this issue · comments

Hello.
I need to improve performance while playing JSON.
I think below logic takes long time while Draw.
(There is TODO comment also)

Path.cs
internal static double BezLength(float c0X, float c0Y, float c1X, float c1Y, float c2X, float c2Y, float c3X, float c3Y)
{
const double steps = 1000d; // TODO: improve

            var length = 0d;
            float prevPtX = 0;
            float prevPtY = 0;

            for (var i = 0d; i < steps; i++)
            {
                var pt = GetPointAtT(c0X, c0Y, c1X, c1Y, c2X, c2Y, c3X, c3Y, i / steps);

                if (i > 0)
                {
                    var x = pt.X - prevPtX;
                    var y = pt.Y - prevPtY;
                    length = length + Math.Sqrt(x * x + y * y);
                }

                prevPtX = pt.X;
                prevPtY = pt.Y;
            }
            return length;
        }

Please check it.
Thank you.

@minudf Have you tried the newest version? There was a great improvement on the rendering performance.