From 30e1391b224ae028f4476e06a07415a0285ac6c9 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 12 Aug 2020 20:39:53 -0700 Subject: Almost working --- grapher/Models/Calculations/AccelChartData.cs | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 grapher/Models/Calculations/AccelChartData.cs (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs new file mode 100644 index 0000000..243827a --- /dev/null +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -0,0 +1,31 @@ +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(); + VelocityPoints = new SortedDictionary(); + GainPoints = new SortedDictionary(); + } + + public SortedDictionary AccelPoints { get; } + + public SortedDictionary VelocityPoints { get; } + + public SortedDictionary GainPoints { get; } + + public void Clear() + { + AccelPoints.Clear(); + VelocityPoints.Clear(); + GainPoints.Clear(); + } + } +} -- cgit v1.2.3 From 93a22c08b3223b040c3a3644fc3c4ef82fc576f0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 01:52:49 -0700 Subject: Dot to show mouse move --- grapher/Models/Calculations/AccelChartData.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 243827a..a3354aa 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -27,5 +27,17 @@ namespace grapher.Models.Calculations 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); + } } } -- cgit v1.2.3 From 6602649bd7f9a9849b25fe55a5e5e8a617f40b70 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 13:39:40 -0700 Subject: All works smoothly --- grapher/Models/Calculations/AccelChartData.cs | 31 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index a3354aa..fa31f35 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -13,6 +13,8 @@ namespace grapher.Models.Calculations AccelPoints = new SortedDictionary(); VelocityPoints = new SortedDictionary(); GainPoints = new SortedDictionary(); + OrderedVelocityPointsList = new List(); + OutVelocityToPoints = new Dictionary(); } public SortedDictionary AccelPoints { get; } @@ -21,23 +23,42 @@ namespace grapher.Models.Calculations public SortedDictionary GainPoints { get; } + public List OrderedVelocityPointsList { get; } + + public Dictionary OutVelocityToPoints { get; } + public void Clear() { AccelPoints.Clear(); VelocityPoints.Clear(); GainPoints.Clear(); + OrderedVelocityPointsList.Clear(); + OutVelocityToPoints.Clear(); } public (double, double, double) FindInValuesFromOut(double outVelocityValue) { - var velIdx = ~VelocityPoints.Values.ToList().BinarySearch(outVelocityValue); - - if (velIdx < 0) + if (OutVelocityToPoints.TryGetValue(outVelocityValue, out var values)) { - velIdx = ~velIdx; + return values; } + else + { + var velIdx = OrderedVelocityPointsList.BinarySearch(outVelocityValue); + + if (velIdx < 0) + { + velIdx = ~velIdx; + } - return (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value); + velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); + + values = (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value); + + OutVelocityToPoints.Add(outVelocityValue, values); + + return values; + } } } } -- cgit v1.2.3 From 32323636b4b5390c114fc2a6d845b7621a983cdc Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 13 Aug 2020 20:56:41 -0700 Subject: Fix initial points, add poll time constant --- grapher/Models/Calculations/AccelChartData.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'grapher/Models/Calculations/AccelChartData.cs') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index fa31f35..20142a7 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -36,7 +36,7 @@ namespace grapher.Models.Calculations OutVelocityToPoints.Clear(); } - public (double, double, double) FindInValuesFromOut(double outVelocityValue) + public (double, double, double) FindPointValuesFromOut(double outVelocityValue) { if (OutVelocityToPoints.TryGetValue(outVelocityValue, out var values)) { @@ -52,11 +52,8 @@ namespace grapher.Models.Calculations } velIdx = Math.Min(velIdx, VelocityPoints.Count - 1); - values = (VelocityPoints.ElementAt(velIdx).Key, AccelPoints.ElementAt(velIdx).Value, GainPoints.ElementAt(velIdx).Value); - OutVelocityToPoints.Add(outVelocityValue, values); - return values; } } -- cgit v1.2.3