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 | |
| parent | Dot to show mouse move (diff) | |
| download | rawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.tar.xz rawaccel-6602649bd7f9a9849b25fe55a5e5e8a617f40b70.zip | |
All works smoothly
Diffstat (limited to 'grapher/Models')
| -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 | ||||
| -rw-r--r-- | grapher/Models/Charts/AccelCharts.cs | 70 | ||||
| -rw-r--r-- | grapher/Models/Charts/ChartXY.cs | 41 | ||||
| -rw-r--r-- | grapher/Models/Charts/EstimatedPoints.cs | 25 | ||||
| -rw-r--r-- | grapher/Models/Mouse/PointData.cs | 46 |
7 files changed, 193 insertions, 85 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); + } + } } diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index e593bb9..42377c4 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -1,4 +1,5 @@ using grapher.Models.Calculations; +using grapher.Models.Charts; using System; using System.Collections.Generic; using System.Drawing; @@ -13,27 +14,6 @@ namespace grapher { public class AccelCharts { - public struct ChartPoint - { - public double X; - public double Y; - } - - public struct EstimatedPoints - { - public ChartPoint CombinedVelocity; - public ChartPoint CombinedSensitivity; - public ChartPoint CombinedGain; - - public ChartPoint XVelocity; - public ChartPoint XSensitivity; - public ChartPoint XGain; - - public ChartPoint YVelocity; - public ChartPoint YSensitivity; - public ChartPoint YGain; - } - public const int ChartSeparationVertical = 10; /// <summary> Needed to show full contents in form. Unsure why. </summary> @@ -47,28 +27,21 @@ namespace grapher ToolStripMenuItem enableVelocityAndGain, ICollection<CheckBox> checkBoxesXY) { + Estimated = new EstimatedPoints(); + EstimatedX = new EstimatedPoints(); + EstimatedY = new EstimatedPoints(); + AccelData = new AccelData(Estimated, EstimatedX, EstimatedY); + ContaingForm = form; SensitivityChart = sensitivityChart; VelocityChart = velocityChart; GainChart = gainChart; EnableVelocityAndGain = enableVelocityAndGain; CheckBoxesXY = checkBoxesXY; - AccelData = new AccelData(); - - Estimated = new EstimatedPoints - { - CombinedVelocity = new ChartPoint { X = 0, Y = 0 }, - CombinedSensitivity = new ChartPoint { X = 0, Y = 0 }, - CombinedGain = new ChartPoint { X = 0, Y = 0 }, - - XVelocity = new ChartPoint { X = 0, Y = 0 }, - XSensitivity = new ChartPoint { X = 0, Y = 0 }, - XGain = new ChartPoint { X = 0, Y = 0 }, - YVelocity = new ChartPoint { X = 0, Y = 0 }, - YSensitivity = new ChartPoint { X = 0, Y = 0 }, - YGain = new ChartPoint { X = 0, Y = 0 }, - }; + SensitivityChart.SetPointBinds(Estimated.Sensitivity, EstimatedX.Sensitivity, EstimatedY.Sensitivity); + VelocityChart.SetPointBinds(Estimated.Velocity, EstimatedX.Velocity, EstimatedY.Velocity); + GainChart.SetPointBinds(Estimated.Gain, EstimatedX.Gain, EstimatedY.Gain); SensitivityChart.SetTop(0); VelocityChart.SetHeight(SensitivityChart.Height); @@ -99,7 +72,11 @@ namespace grapher public AccelData AccelData { get; } - private EstimatedPoints Estimated; + private EstimatedPoints Estimated { get; } + + private EstimatedPoints EstimatedX { get; } + + private EstimatedPoints EstimatedY { get; } private ICollection<CheckBox> CheckBoxesXY { get; } @@ -109,10 +86,21 @@ namespace grapher public void MakeDots(int x, int y) { - AccelData.CalculateDots(x, y, ref Estimated); - SensitivityChart.DrawPoints(Estimated.CombinedSensitivity, Estimated.XSensitivity, Estimated.YSensitivity); - VelocityChart.DrawPoints(Estimated.CombinedVelocity, Estimated.XVelocity, Estimated.YVelocity); - GainChart.DrawPoints(Estimated.CombinedGain, Estimated.XGain, Estimated.YGain); + if (Combined) + { + AccelData.CalculateDots(x, y); + } + else + { + AccelData.CalculateDotsXY(x, y); + } + } + + public void DrawPoints() + { + SensitivityChart.DrawPoints(); + VelocityChart.DrawPoints(); + GainChart.DrawPoints(); } public void Bind() diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 2c0ce2c..c0c8713 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,4 +1,6 @@ -using System; +using grapher.Models.Charts; +using grapher.Models.Mouse; +using System; using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -80,6 +82,12 @@ namespace grapher public bool Combined { get; private set; } + private PointData CombinedPointData { get; set; } + + private PointData XPointData { get; set; } + + private PointData YPointData { get; set; } + #endregion Properties #region Methods @@ -109,26 +117,33 @@ namespace grapher chart.Series[1].Points.AddXY(0, 0); } - public static void DrawPoint(Chart chart, ChartPoint point) + public static void DrawPoint(Chart chart, PointData point) { - chart.Series[1].Points[0].XValue = point.X; - chart.Series[1].Points[0].YValues[0] = point.Y; + if (chart.Visible) + { + (var x, var y) = point.Get(); + chart.Series[1].Points.DataBindXY(x, y); + chart.Update(); + } } - public void DrawPoints(ChartPoint CombinedPoint, ChartPoint XPoint, ChartPoint YPoint) + public void SetPointBinds(PointData combined, PointData x, PointData y) { - if (Combined) + CombinedPointData = combined; + XPointData = x; + YPointData = y; + } + + public void DrawPoints() + { + if(Combined) { - DrawPoint(ChartX, CombinedPoint); + DrawPoint(ChartX, CombinedPointData); } else { - DrawPoint(ChartX, XPoint); - } - - if (ChartY.Visible) - { - DrawPoint(ChartY, YPoint); + DrawPoint(ChartX, XPointData); + DrawPoint(ChartY, YPointData); } } diff --git a/grapher/Models/Charts/EstimatedPoints.cs b/grapher/Models/Charts/EstimatedPoints.cs new file mode 100644 index 0000000..fa0718b --- /dev/null +++ b/grapher/Models/Charts/EstimatedPoints.cs @@ -0,0 +1,25 @@ +using grapher.Models.Mouse; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Charts +{ + public class EstimatedPoints + { + public EstimatedPoints() + { + Sensitivity = new PointData(); + Velocity = new PointData(); + Gain = new PointData(); + } + + public PointData Sensitivity { get; } + + public PointData Velocity { get; } + + public PointData Gain { get; } + } +} diff --git a/grapher/Models/Mouse/PointData.cs b/grapher/Models/Mouse/PointData.cs new file mode 100644 index 0000000..d0273d5 --- /dev/null +++ b/grapher/Models/Mouse/PointData.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace grapher.Models.Mouse +{ + public class PointData + { + public PointData() + { + Lock = new Object(); + X = new double[] { 0 }; + Y = new double[] { 0 }; + } + + public Object Lock { get; } + + private double[] X { get; set; } + private double[] Y { get; set; } + + public void Set(double x, double y) + { + lock(Lock) + { + X[0] = x; + Y[0] = y; + } + } + + public (double[], double[]) Get() + { + double[] xRet; + double[] yRet; + + lock(Lock) + { + xRet = X; + yRet = Y; + } + + return (xRet, yRet); + } + } +} |