<commit_before>﻿using System.Diagnostics;
using Mapsui.Geometries;
using Mapsui.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Timers;

namespace Mapsui.Layers
{
    public enum EasingFunction
    {
        CubicEaseOut,
        Linear
    }

    public class AnimatedFeatures
    {
        private Timer _animation;
        private List<AnimatedItem> _cache = new List<AnimatedItem>();
        private long _startTimeAnimation;
        public double Threshold { get; set; }

        public AnimatedFeatures()
        {
            MillisecondsBetweenUpdates = 16;
            AnimationDuration = 1000;
            IdField = "ID";
            Function = EasingFunction.CubicEaseOut;
            Threshold = 20000;
        }

        public string IdField { get; set; }
        public int MillisecondsBetweenUpdates { get; set; }
        public int AnimationDuration { get; set; }
        public EasingFunction Function { get; set; }

        public event EventHandler AnimatedPositionChanged;
        
        public void AddFeatures(IEnumerable<IFeature> features)
        {
            var previousCache = _cache;
            _cache = ConvertToAnimatedItems(features.ToList(), previousCache, IdField);
            _startTimeAnimation = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            if (_animation != null) StopAnimation();
            _animation = new Timer(AnimationCallback, this, 0, MillisecondsBetweenUpdates);
            _first = true;
        }

        public IEnumerable<IFeature> GetFeatures()
        {
            LogAllFeatures(_cache);

            var progress = CalculateProgress(_startTimeAnimation, AnimationDuration, Function);
            if (!Completed(progress)) InterpolateAnimatedPosition(_cache, progress, Threshold);
            else if (_animation != null) StopAnimation();
            return _cache.Select(f => f.Feature);
        }

        private void StopAnimation()
        {
            _animation.Stop();
            _animation.Dispose();
            _animation = null;
        }

        private static bool Completed(double progress)
        {<commit_msg>AnimatedFeatures: Renamed Threshold to DistanceThreahold.Default now Double.Value<commit_after>﻿using System.Diagnostics;
using Mapsui.Geometries;
using Mapsui.Providers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Timers;

namespace Mapsui.Layers
{
    public enum EasingFunction
    {
        CubicEaseOut,
        Linear
    }

    public class AnimatedFeatures
    {
        private Timer _animation;
        private List<AnimatedItem> _cache = new List<AnimatedItem>();
        private long _startTimeAnimation;

        /// <summary>
        /// When the distane between the current and the previous position is larger
        /// than the DistanceThreshold it will not be animated. 
        /// The default is Double.MaxValue
        /// </summary>
        public double DistanceThreshold { get; set; }

        public AnimatedFeatures()
        {
            MillisecondsBetweenUpdates = 16;
            AnimationDuration = 1000;
            IdField = "ID";
            Function = EasingFunction.CubicEaseOut;
            DistanceThreshold = Double.MaxValue;
        }

        public string IdField { get; set; }
        public int MillisecondsBetweenUpdates { get; set; }
        public int AnimationDuration { get; set; }
        public EasingFunction Function { get; set; }

        public event EventHandler AnimatedPositionChanged;
        
        public void AddFeatures(IEnumerable<IFeature> features)
        {
            var previousCache = _cache;
            _cache = ConvertToAnimatedItems(features.ToList(), previousCache, IdField);
            _startTimeAnimation = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            if (_animation != null) StopAnimation();
            _animation = new Timer(AnimationCallback, this, 0, MillisecondsBetweenUpdates);
            _first = true;
        }

        public IEnumerable<IFeature> GetFeatures()
        {
            LogAllFeatures(_cache);

            var progress = CalculateProgress(_startTimeAnimation, AnimationDuration, Function);
            if (!Completed(progress)) InterpolateAnimatedPosition(_cache, progress, DistanceThreshold);
            else if (_animation != null) StopAnimation();
            return _cache.Select(f => f.Feature);
        }

        private void StopAnimation()
        {
            _animation.Stop();
            _animation.Dispose();
            _animation = null;
        }

        private static bool Completed(double progress)
        {
{'fraction_non_alphanumeric': 0.0775588048315321, 'fraction_numerical': 0.004026276753549481, 'mean_word_length': 2.3076384022424667, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491284', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1155, 'n_words': 308}