summaryrefslogtreecommitdiff
path: root/grapher/Models/Calculations/AccelChartData.cs
blob: a3354aa16203bbafb6c7fc56bc5c9dfd350b095b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace grapher.Models.Calculations
{
    public class AccelChartData
    {
        public AccelChartData()
        {
            AccelPoints = new SortedDictionary<double, double>();
            VelocityPoints = new SortedDictionary<double, double>();
            GainPoints = new SortedDictionary<double, double>();
        }

        public SortedDictionary<double, double> AccelPoints { get; }

        public SortedDictionary<double, double> VelocityPoints { get; }

        public SortedDictionary<double, double> GainPoints { get; }

        public void Clear()
        {
            AccelPoints.Clear();
            VelocityPoints.Clear();
            GainPoints.Clear();
        }

        public (double, double, double) FindInValuesFromOut(double outVelocityValue)
        {
            var velIdx = ~VelocityPoints.Values.ToList().BinarySearch(outVelocityValue);

            if (velIdx < 0)
            {
                velIdx = ~velIdx;
            }

            return (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value);
        }
    }
}