diff options
| author | Jacob Palecki <[email protected]> | 2020-08-13 13:39:40 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-08-13 13:39:40 -0700 |
| commit | 6602649bd7f9a9849b25fe55a5e5e8a617f40b70 (patch) | |
| tree | 01360e218547270421b7ef91a7239b2702d1297e /grapher/Models/Calculations | |
| parent | Dot to show mouse move (diff) | |
| download | rawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.tar.xz rawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.zip | |
All works smoothly
Diffstat (limited to 'grapher/Models/Calculations')
| -rw-r--r-- | grapher/Models/Calculations/AccelCalculator.cs | 2 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelChartData.cs | 31 | ||||
| -rw-r--r-- | grapher/Models/Calculations/AccelData.cs | 63 |
3 files changed, 65 insertions, 31 deletions
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs index d61a59b..e194854 100644 --- a/grapher/Models/Calculations/AccelCalculator.cs +++ b/grapher/Models/Calculations/AccelCalculator.cs @@ -66,6 +66,8 @@ namespace grapher.Models.Calculations lastInputMagnitude = magnitudeDatum.magnitude; lastOutputMagnitude = outMagnitude; } + + data.OrderedVelocityPointsList.AddRange(data.VelocityPoints.Values.ToList()); } public static ReadOnlyCollection<MagnitudeData> GetMagnitudes() 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; + } } } } diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index a8f3307..6fb4767 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Charts; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,11 +11,18 @@ namespace grapher.Models.Calculations public class AccelData { - public AccelData() + public AccelData( + EstimatedPoints combined, + EstimatedPoints x, + EstimatedPoints y) { Combined = new AccelChartData(); X = new AccelChartData(); Y = new AccelChartData(); + + Estimated = combined; + EstimatedX = x; + EstimatedY = y; } public AccelChartData Combined { get; } @@ -23,6 +31,12 @@ namespace grapher.Models.Calculations public AccelChartData Y { get; } + private EstimatedPoints Estimated { get; } + + private EstimatedPoints EstimatedX { get; } + + private EstimatedPoints EstimatedY { get; } + public void Clear() { Combined.Clear(); @@ -30,34 +44,31 @@ namespace grapher.Models.Calculations Y.Clear(); } - public void CalculateDots(int x, int y, ref EstimatedPoints estimation) + public void CalculateDots(int x, int y) { var magnitude = AccelCalculator.Magnitude(x, y); - estimation.CombinedVelocity.Y = magnitude; - estimation.XVelocity.Y = Math.Abs(x); - estimation.YVelocity.Y = Math.Abs(y); - (var inCombVel, var combSens, var combGain) = Combined.FindInValuesFromOut(magnitude); - estimation.CombinedVelocity.X = inCombVel; - estimation.CombinedSensitivity.X = inCombVel; - estimation.CombinedGain.X = inCombVel; - estimation.CombinedSensitivity.Y = combSens; - estimation.CombinedGain.Y = combGain; - - (var inXVel, var xSens, var xGain) = X.FindInValuesFromOut(estimation.XVelocity.Y); - estimation.XVelocity.X = inXVel; - estimation.XSensitivity.X = inXVel; - estimation.XGain.X = inXVel; - estimation.XSensitivity.Y = xSens; - estimation.XGain.Y = xGain; - - (var inYVel, var ySens, var yGain) = Y.FindInValuesFromOut(estimation.YVelocity.Y); - estimation.YVelocity.X = inYVel; - estimation.YSensitivity.X = inYVel; - estimation.YGain.X = inYVel; - estimation.YSensitivity.Y = ySens; - estimation.YGain.Y = yGain; + Estimated.Velocity.Set(inCombVel, magnitude); + Estimated.Sensitivity.Set(inCombVel, combSens); + Estimated.Gain.Set(inCombVel, combGain); } + + public void CalculateDotsXY(int x, int y) + { + var magnitudeX = Math.Abs(x); + var magnitudeY = Math.Abs(y); + + (var inXVel, var xSens, var xGain) = X.FindInValuesFromOut(magnitudeX); + EstimatedX.Velocity.Set(inXVel, magnitudeX); + EstimatedX.Sensitivity.Set(inXVel, xSens); + EstimatedX.Gain.Set(inXVel, xGain); + + (var inYVel, var ySens, var yGain) = Y.FindInValuesFromOut(magnitudeY); + EstimatedY.Velocity.Set(inYVel, magnitudeY); + EstimatedY.Sensitivity.Set(inYVel, ySens); + EstimatedY.Gain.Set(inYVel, yGain); + } + } } |