Ejemplo n.º 1
0
        private float GetRestLength(Path path, float startD)
        {
            Path        tempPath    = new Path();
            PathMeasure pathMeasure = new PathMeasure(path, false);

            pathMeasure.GetSegment(startD, pathMeasure.Length, tempPath, true);

            pathMeasure.SetPath(tempPath, false);

            return(pathMeasure.Length);
        }
Ejemplo n.º 2
0
        internal static void ApplyTrimPathIfNeeded(Path path, float startValue, float endValue, float offsetValue)
        {
            LottieLog.BeginSection("applyTrimPathIfNeeded");
            PathMeasure.SetPath(path);

            var length = PathMeasure.Length;

            if (startValue == 1f && endValue == 0f)
            {
                LottieLog.EndSection("applyTrimPathIfNeeded");
                return;
            }
            if (length < 1f || Math.Abs(endValue - startValue - 1) < .01)
            {
                LottieLog.EndSection("applyTrimPathIfNeeded");
                return;
            }
            var start    = length * startValue;
            var end      = length * endValue;
            var newStart = Math.Min(start, end);
            var newEnd   = Math.Max(start, end);

            var offset = offsetValue * length;

            newStart += offset;
            newEnd   += offset;

            // If the trim path has rotated around the path, we need to shift it back.
            if (newStart >= length && newEnd >= length)
            {
                newStart = MiscUtils.FloorMod(newStart, length);
                newEnd   = MiscUtils.FloorMod(newEnd, length);
            }

            if (newStart < 0)
            {
                newStart = MiscUtils.FloorMod(newStart, length);
            }
            if (newEnd < 0)
            {
                newEnd = MiscUtils.FloorMod(newEnd, length);
            }

            // If the start and end are equals, return an empty path.
            if (newStart == newEnd)
            {
                path.Reset();
                LottieLog.EndSection("applyTrimPathIfNeeded");
                return;
            }

            if (newStart >= newEnd)
            {
                newStart -= length;
            }

            _tempPath.Reset();
            PathMeasure.GetSegment(newStart, newEnd, ref _tempPath, true);

            if (newEnd > length)
            {
                _tempPath2.Reset();
                PathMeasure.GetSegment(0, newEnd % length, ref _tempPath2, true);
                _tempPath.AddPath(_tempPath2);
            }
            else if (newStart < 0)
            {
                _tempPath2.Reset();
                PathMeasure.GetSegment(length + newStart, length, ref _tempPath2, true);
                _tempPath.AddPath(_tempPath2);
            }
            path.Set(_tempPath);
            LottieLog.EndSection("applyTrimPathIfNeeded");
        }