azchohfi / LottieUWP

UWP port of Lottie(https://github.com/airbnb/lottie-android)
Apache License 2.0
274 stars 45 forks source link

Please improve BezLength logic #39

Open minudf opened 6 years ago

minudf commented 6 years ago

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.

azchohfi commented 6 years ago

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