summaryrefslogtreecommitdiff
path: root/grapher/Models/Calculations/AccelChartData.cs
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-08-13 13:39:40 -0700
committerJacob Palecki <[email protected]>2020-08-13 13:39:40 -0700
commit6602649bd7f9a9849b25fe55a5e5e8a617f40b70 (patch)
tree01360e218547270421b7ef91a7239b2702d1297e /grapher/Models/Calculations/AccelChartData.cs
parentDot to show mouse move (diff)
downloadrawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.tar.xz
rawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.zip
All works smoothly
Diffstat (limited to 'grapher/Models/Calculations/AccelChartData.cs')
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs31
1 files changed, 26 insertions, 5 deletions
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<double, double>();
VelocityPoints = new SortedDictionary<double, double>();
GainPoints = new SortedDictionary<double, double>();
+ OrderedVelocityPointsList = new List<double>();
+ OutVelocityToPoints = new Dictionary<double, (double, double, double)>();
}
public SortedDictionary<double, double> AccelPoints { get; }
@@ -21,23 +23,42 @@ namespace grapher.Models.Calculations
public SortedDictionary<double, double> GainPoints { get; }
+ public List<double> OrderedVelocityPointsList { get; }
+
+ public Dictionary<double, (double, double, double)> 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;
+ }
}
}
}