From 7d14daf1d5fce4d09471a3abe2aca49cf7680816 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Wed, 2 Dec 2020 05:25:19 -0500 Subject: embed version info into assemblies check app versions against lib, lib against driver add an 'about' dialog which displays version details, accessible from menu refactor error handling + add check for negative offset --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Serialized/SettingsManager.cs | 29 ---------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index c08313b..f9291c1 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -153,7 +153,7 @@ namespace grapher } else { - throw new Exception($"Bad arguments: \n {SettingsManager.ErrorStringFrom(errors)}"); + throw new Exception($"Bad arguments:\n\n{errors}"); } } diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index f13ba81..f5bb1f1 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -47,35 +47,6 @@ namespace grapher.Models.Serialized #endregion Properties #region Methods - - public static string ErrorStringFrom(SettingsErrors errors) - { - StringBuilder builder = new StringBuilder(); - bool yPresent = errors.y?.Count > 0; - - if (yPresent) - { - builder.AppendLine("\nx:"); - } - - foreach (var error in errors.x) - { - builder.AppendLine(error); - } - - if (yPresent) - { - builder.AppendLine("\ny:"); - - foreach (var error in errors.y) - { - builder.AppendLine(error); - } - } - - return builder.ToString(); - } - public SettingsErrors TryUpdateActiveSettings(DriverSettings settings) { var errors = TryUpdateAccel(settings); -- cgit v1.2.3 From 5657d5a54c0a8e980c9b0cac39e2d16e452f302e Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 3 Dec 2020 20:00:31 -0500 Subject: add directional multipliers adds multipliers for movement in negative directions (up & left by default, can be flipped by rot or sens) avoid division by user input in mousewatcher --- grapher/Models/AccelGUI.cs | 3 +- grapher/Models/AccelGUIFactory.cs | 3 +- grapher/Models/Calculations/AccelData.cs | 14 +++---- grapher/Models/Charts/AccelCharts.cs | 4 +- grapher/Models/Charts/ChartState/ChartState.cs | 2 +- grapher/Models/Charts/ChartState/CombinedState.cs | 4 +- .../Models/Charts/ChartState/XYOneGraphState.cs | 4 +- .../Models/Charts/ChartState/XYTwoGraphState.cs | 4 +- grapher/Models/Mouse/MouseWatcher.cs | 46 ++++++++++++++-------- grapher/Models/Serialized/RawAccelSettings.cs | 2 + grapher/Models/Serialized/SettingsManager.cs | 4 +- 11 files changed, 54 insertions(+), 36 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index f9291c1..e1cf462 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -140,7 +140,8 @@ namespace grapher combineMagnitudes = ApplyOptions.IsWhole, modes = ApplyOptions.GetModes(), args = newArgs, - minimumTime = driverSettings.minimumTime + minimumTime = driverSettings.minimumTime, + negativeMultipliers = driverSettings.negativeMultipliers }; ButtonDelay(WriteButton); diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index 3dc2a74..d789593 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -2,6 +2,7 @@ using grapher.Models.Mouse; using grapher.Models.Options; using grapher.Models.Serialized; +using System; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; @@ -331,7 +332,7 @@ namespace grapher.Models showLastMouseMoveMenuItem, showVelocityGainToolStripMenuItem); - var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, accelCalculator.PollRate); + var mouseWatcher = new MouseWatcher(form, mouseLabel, accelCharts, settings); return new AccelGUI( form, diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 67d4f3f..778c5a2 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -56,9 +56,9 @@ namespace grapher.Models.Calculations OutVelocityToPoints.Clear(); } - public void CalculateDots(int x, int y, double timeInMs) + public void CalculateDots(double x, double y, double timeInMsRecip) { - var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); + var outVelocity = AccelCalculator.Magnitude(x, y) * timeInMsRecip; (var inCombVel, var combSens, var combGain) = Combined.FindPointValuesFromOut(outVelocity); Estimated.Velocity.Set(inCombVel, outVelocity); @@ -66,10 +66,10 @@ namespace grapher.Models.Calculations Estimated.Gain.Set(inCombVel, combGain); } - public void CalculateDotsXY(int x, int y, double timeInMs) + public void CalculateDotsXY(double x, double y, double timeInMsRecip) { - var outX = Math.Abs(x) / timeInMs; - var outY = Math.Abs(y) / timeInMs; + var outX = Math.Abs(x) * timeInMsRecip; + var outY = Math.Abs(y) * timeInMsRecip; (var inXVelocity, var xSensitivity, var xGain) = X.FindPointValuesFromOut(outX); EstimatedX.Velocity.Set(inXVelocity, outX); @@ -82,10 +82,10 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } - public void CalculateDotsCombinedDiffSens(int x, int y, double timeInMs, DriverSettings settings) + public void CalculateDotsCombinedDiffSens(double x, double y, double timeInMsRecip, DriverSettings settings) { (var xStripped, var yStripped) = AccelCalculator.StripSens(x, y, settings.sensitivity.x, settings.sensitivity.y); - var outVelocity = AccelCalculator.Velocity(xStripped, yStripped, timeInMs); + var outVelocity = AccelCalculator.Magnitude(xStripped, yStripped) * timeInMsRecip; if (OutVelocityToPoints.TryGetValue(outVelocity, out var points)) { diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 6247811..188db10 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -99,9 +99,9 @@ namespace grapher #region Methods - public void MakeDots(int x, int y, double timeInMs) + public void MakeDots(double x, double y, double timeInMsRecip) { - ChartState.MakeDots(x, y, timeInMs); + ChartState.MakeDots(x, y, timeInMsRecip); } public void DrawLastMovement() diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index 270e212..c1b8e9b 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -40,7 +40,7 @@ namespace grapher.Models.Charts.ChartState internal bool TwoDotsPerGraph { get; set; } - public abstract void MakeDots(int x, int y, double timeInMs); + public abstract void MakeDots(double x, double y, double timeInMsRecip); public abstract void Bind(); diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index aab8a38..9fcdc11 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -30,9 +30,9 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMsRecip) { - Data.CalculateDots(x, y, timeInMs); + Data.CalculateDots(x, y, timeInMsRecip); } public override void Bind() diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 92c799f..95c4b20 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -28,9 +28,9 @@ namespace grapher.Models.Charts.ChartState GainChart.SetCombined(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMsRecip) { - Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); + Data.CalculateDotsCombinedDiffSens(x, y, timeInMsRecip, Settings); } public override void Bind() diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index d107f87..075cc0f 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -33,9 +33,9 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(int x, int y, double timeInMs) + public override void MakeDots(double x, double y, double timeInMsRecip) { - Data.CalculateDotsXY(x, y, timeInMs); + Data.CalculateDotsXY(x, y, timeInMsRecip); } public override void Bind() diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 6209445..66e72bb 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -1,4 +1,5 @@ -using System; +using grapher.Models.Serialized; +using System; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -677,12 +678,12 @@ namespace grapher.Models.Mouse #region Constructors - public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts, Field pollRate) + public MouseWatcher(Form containingForm, Label display, AccelCharts accelCharts, SettingsManager setMngr) { ContainingForm = containingForm; Display = display; AccelCharts = accelCharts; - PollRateField = pollRate; + SettingsManager = setMngr; MouseData = new MouseData(); RAWINPUTDEVICE device = new RAWINPUTDEVICE(); @@ -694,7 +695,7 @@ namespace grapher.Models.Mouse RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1]; devices[0] = device; RegisterRawInputDevices(devices, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE))); - PollTime = 1; + PollTimeRecip = 1; PollRate = 1000; } @@ -708,24 +709,18 @@ namespace grapher.Models.Mouse private AccelCharts AccelCharts { get; } - private Field PollRateField { get; set; } + private SettingsManager SettingsManager { get; } private MouseData MouseData { get; } private double PollRate { get; set; } - private double PollTime { get; set; } + private double PollTimeRecip { get; set; } #endregion Properties #region Methods - public void OnMouseMove(int x, int y, double timeInMs) - { - MouseData.Set(x,y); - AccelCharts.MakeDots(x, y, timeInMs); - } - public void UpdateLastMove() { MouseData.Get(out var x, out var y); @@ -740,15 +735,34 @@ namespace grapher.Models.Mouse outSize = GetRawInputData((IntPtr)message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); - if (PollRateField.Data != PollRate) + if (SettingsManager.PollRateField.Data != PollRate) { - PollRate = PollRateField.Data; - PollTime = 1000 / PollRate; + PollRate = SettingsManager.PollRateField.Data; + PollTimeRecip = Math.Abs(SettingsManager.PollRateField.Data) / 1000; } if (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0) { - OnMouseMove(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY, PollTime); + double x = rawInput.Data.Mouse.LastX; + double y = rawInput.Data.Mouse.LastY; + + // strip negative multipliers, charts calculated from positive input + + Vec2 negMults = SettingsManager.RawAccelSettings + .AccelerationSettings.negativeMultipliers; + + if (negMults.x > 0 && x < 0) + { + x /= negMults.x; + } + + if (negMults.y > 0 && y < 0) + { + y /= negMults.y; + } + + MouseData.Set(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY); + AccelCharts.MakeDots(x, y, PollTimeRecip); } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index af87a65..67953ac 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -127,6 +127,8 @@ namespace grapher.Models.Serialized return accelSettings.sensitivity.x == 1 && accelSettings.sensitivity.y == 1 && + accelSettings.negativeMultipliers.x <= 0 && + accelSettings.negativeMultipliers.y <= 0 && accelSettings.rotation == 0 && accelSettings.modes.x == AccelMode.noaccel && wholeOrNoY; diff --git a/grapher/Models/Serialized/SettingsManager.cs b/grapher/Models/Serialized/SettingsManager.cs index f5bb1f1..41ebcb5 100644 --- a/grapher/Models/Serialized/SettingsManager.cs +++ b/grapher/Models/Serialized/SettingsManager.cs @@ -34,9 +34,9 @@ namespace grapher.Models.Serialized public RawAccelSettings RawAccelSettings { get; private set; } - private Field DpiField { get; set; } + public Field DpiField { get; private set; } - private Field PollRateField { get; set; } + public Field PollRateField { get; private set; } private ToolStripMenuItem AutoWriteMenuItem { get; set; } -- cgit v1.2.3 From c5c3c2a8a841d664a422380ab31497b3f741f07f Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 3 Dec 2020 20:01:49 -0500 Subject: filter out abs move raw input --- grapher/Models/Calculations/AccelChartData.cs | 3 +++ grapher/Models/Mouse/MouseWatcher.cs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 60d4c89..48374c1 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; namespace grapher.Models.Calculations @@ -80,6 +81,8 @@ namespace grapher.Models.Calculations public int GetVelocityIndex(double outVelocityValue) { + Debug.Assert(outVelocityValue >= 0); + var log = Math.Log10(outVelocityValue); if (log < -2) { diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 66e72bb..68b56e5 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -741,7 +741,9 @@ namespace grapher.Models.Mouse PollTimeRecip = Math.Abs(SettingsManager.PollRateField.Data) / 1000; } - if (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0) + bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); + + if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) { double x = rawInput.Data.Mouse.LastX; double y = rawInput.Data.Mouse.LastY; -- cgit v1.2.3 From 95755e723bab4942dffe5e45c9f8007ce0e008c7 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 3 Dec 2020 20:03:47 -0500 Subject: fix chart range not updating on disable --- grapher/Models/Charts/ChartXY.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 98ba059..953065e 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,5 +1,6 @@ using grapher.Models.Mouse; using System.Collections; +using System.Diagnostics; using System.Windows.Forms.DataVisualization.Charting; namespace grapher @@ -29,6 +30,8 @@ namespace grapher #endregion Constructors + private const double VerticalMargin = 0.1; + #region Properties public Chart ChartX { get; } @@ -221,26 +224,20 @@ namespace grapher public void SetMinMax(double min, double max) { - if (min < max) - { - ChartX.ChartAreas[0].AxisY.Minimum = min * 0.95; - ChartX.ChartAreas[0].AxisY.Maximum = max * 1.05; - } + Debug.Assert(min <= max); + ChartX.ChartAreas[0].AxisY.Minimum = min * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = max * (1 + VerticalMargin); } public void SetMinMaxXY(double minX, double maxX, double minY, double maxY) { - if (minX < maxX) - { - ChartX.ChartAreas[0].AxisY.Minimum = minX * 0.95; - ChartX.ChartAreas[0].AxisY.Maximum = maxX * 1.05; - } + Debug.Assert(minX <= maxY); + ChartX.ChartAreas[0].AxisY.Minimum = minX * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = maxX * (1 + VerticalMargin); - if (minY < maxY) - { - ChartY.ChartAreas[0].AxisY.Minimum = minY * 0.95; - ChartY.ChartAreas[0].AxisY.Maximum = maxY * 1.05; - } + Debug.Assert(minX <= maxY); + ChartX.ChartAreas[0].AxisY.Minimum = minY * (1 - VerticalMargin); + ChartX.ChartAreas[0].AxisY.Maximum = maxY * (1 + VerticalMargin); } public void SetCombined() -- cgit v1.2.3 From c221eb3d62ccbd7f2a5203abd3e0eae8e9bf31e8 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 3 Dec 2020 22:42:29 -0500 Subject: add changes from review rename some vars prefer exceptions over assert refactor poll rate field usage in MouseWatcher --- grapher/Models/AccelGUI.cs | 2 +- grapher/Models/Calculations/AccelChartData.cs | 6 ++++-- grapher/Models/Charts/ChartXY.cs | 16 ++++++++++---- grapher/Models/Mouse/MouseWatcher.cs | 31 +++++++++++---------------- grapher/Models/Serialized/RawAccelSettings.cs | 4 ++-- 5 files changed, 31 insertions(+), 28 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUI.cs b/grapher/Models/AccelGUI.cs index e1cf462..c6a2dcc 100644 --- a/grapher/Models/AccelGUI.cs +++ b/grapher/Models/AccelGUI.cs @@ -141,7 +141,7 @@ namespace grapher modes = ApplyOptions.GetModes(), args = newArgs, minimumTime = driverSettings.minimumTime, - negativeMultipliers = driverSettings.negativeMultipliers + directionalMultipliers = driverSettings.directionalMultipliers }; ButtonDelay(WriteButton); diff --git a/grapher/Models/Calculations/AccelChartData.cs b/grapher/Models/Calculations/AccelChartData.cs index 48374c1..71ee927 100644 --- a/grapher/Models/Calculations/AccelChartData.cs +++ b/grapher/Models/Calculations/AccelChartData.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; namespace grapher.Models.Calculations @@ -81,7 +80,10 @@ namespace grapher.Models.Calculations public int GetVelocityIndex(double outVelocityValue) { - Debug.Assert(outVelocityValue >= 0); + if (outVelocityValue < 0) + { + throw new ArgumentException($"invalid velocity: {outVelocityValue}"); + } var log = Math.Log10(outVelocityValue); if (log < -2) diff --git a/grapher/Models/Charts/ChartXY.cs b/grapher/Models/Charts/ChartXY.cs index 953065e..553ab3e 100644 --- a/grapher/Models/Charts/ChartXY.cs +++ b/grapher/Models/Charts/ChartXY.cs @@ -1,6 +1,6 @@ using grapher.Models.Mouse; +using System; using System.Collections; -using System.Diagnostics; using System.Windows.Forms.DataVisualization.Charting; namespace grapher @@ -222,20 +222,28 @@ namespace grapher ChartX.Series[2].IsVisibleInLegend = true; } + private void VerifyRange(double min, double max) + { + if (min > max) + { + throw new ArgumentException($"invalid chart range: ({min}, {max})"); + } + } + public void SetMinMax(double min, double max) { - Debug.Assert(min <= max); + VerifyRange(min, max); ChartX.ChartAreas[0].AxisY.Minimum = min * (1 - VerticalMargin); ChartX.ChartAreas[0].AxisY.Maximum = max * (1 + VerticalMargin); } public void SetMinMaxXY(double minX, double maxX, double minY, double maxY) { - Debug.Assert(minX <= maxY); + VerifyRange(minX, maxX); ChartX.ChartAreas[0].AxisY.Minimum = minX * (1 - VerticalMargin); ChartX.ChartAreas[0].AxisY.Maximum = maxX * (1 + VerticalMargin); - Debug.Assert(minX <= maxY); + VerifyRange(minY, maxY); ChartX.ChartAreas[0].AxisY.Minimum = minY * (1 - VerticalMargin); ChartX.ChartAreas[0].AxisY.Maximum = maxY * (1 + VerticalMargin); } diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index 68b56e5..ae48a76 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -695,8 +695,6 @@ namespace grapher.Models.Mouse RAWINPUTDEVICE[] devices = new RAWINPUTDEVICE[1]; devices[0] = device; RegisterRawInputDevices(devices, 1, Marshal.SizeOf(typeof(RAWINPUTDEVICE))); - PollTimeRecip = 1; - PollRate = 1000; } #endregion Constructors @@ -713,9 +711,10 @@ namespace grapher.Models.Mouse private MouseData MouseData { get; } - private double PollRate { get; set; } - - private double PollTimeRecip { get; set; } + private double PollTimeReciprocal + { + get => Math.Abs(SettingsManager.PollRateField.Data) * 0.001; + } #endregion Properties @@ -735,12 +734,6 @@ namespace grapher.Models.Mouse outSize = GetRawInputData((IntPtr)message.LParam, RawInputCommand.Input, out rawInput, ref size, Marshal.SizeOf(typeof(RAWINPUTHEADER))); - if (SettingsManager.PollRateField.Data != PollRate) - { - PollRate = SettingsManager.PollRateField.Data; - PollTimeRecip = Math.Abs(SettingsManager.PollRateField.Data) / 1000; - } - bool relative = !rawInput.Data.Mouse.Flags.HasFlag(RawMouseFlags.MoveAbsolute); if (relative && (rawInput.Data.Mouse.LastX != 0 || rawInput.Data.Mouse.LastY != 0)) @@ -748,23 +741,23 @@ namespace grapher.Models.Mouse double x = rawInput.Data.Mouse.LastX; double y = rawInput.Data.Mouse.LastY; - // strip negative multipliers, charts calculated from positive input + // strip negative directional multipliers, charts calculated from positive input - Vec2 negMults = SettingsManager.RawAccelSettings - .AccelerationSettings.negativeMultipliers; + Vec2 dirMults = SettingsManager.RawAccelSettings + .AccelerationSettings.directionalMultipliers; - if (negMults.x > 0 && x < 0) + if (dirMults.x > 0 && x < 0) { - x /= negMults.x; + x /= dirMults.x; } - if (negMults.y > 0 && y < 0) + if (dirMults.y > 0 && y < 0) { - y /= negMults.y; + y /= dirMults.y; } MouseData.Set(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY); - AccelCharts.MakeDots(x, y, PollTimeRecip); + AccelCharts.MakeDots(x, y, PollTimeReciprocal); } } diff --git a/grapher/Models/Serialized/RawAccelSettings.cs b/grapher/Models/Serialized/RawAccelSettings.cs index 67953ac..dcaf864 100644 --- a/grapher/Models/Serialized/RawAccelSettings.cs +++ b/grapher/Models/Serialized/RawAccelSettings.cs @@ -127,8 +127,8 @@ namespace grapher.Models.Serialized return accelSettings.sensitivity.x == 1 && accelSettings.sensitivity.y == 1 && - accelSettings.negativeMultipliers.x <= 0 && - accelSettings.negativeMultipliers.y <= 0 && + accelSettings.directionalMultipliers.x <= 0 && + accelSettings.directionalMultipliers.y <= 0 && accelSettings.rotation == 0 && accelSettings.modes.x == AccelMode.noaccel && wholeOrNoY; -- cgit v1.2.3 From 2c7c24ee1513616dc6260849bf97340d8484b6b4 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Sat, 5 Dec 2020 01:21:03 -0500 Subject: add more changes from review improve version error messages revert poll time changes add range validation after text parse --- grapher/Models/AccelGUIFactory.cs | 4 ++-- grapher/Models/Calculations/AccelData.cs | 14 +++++++------- grapher/Models/Charts/AccelCharts.cs | 4 ++-- grapher/Models/Charts/ChartState/ChartState.cs | 2 +- grapher/Models/Charts/ChartState/CombinedState.cs | 4 ++-- grapher/Models/Charts/ChartState/XYOneGraphState.cs | 4 ++-- grapher/Models/Charts/ChartState/XYTwoGraphState.cs | 4 ++-- grapher/Models/Fields/Field.cs | 20 +++++++++++++------- grapher/Models/Mouse/MouseWatcher.cs | 6 +++--- 9 files changed, 34 insertions(+), 28 deletions(-) (limited to 'grapher/Models') diff --git a/grapher/Models/AccelGUIFactory.cs b/grapher/Models/AccelGUIFactory.cs index d789593..901a1b5 100644 --- a/grapher/Models/AccelGUIFactory.cs +++ b/grapher/Models/AccelGUIFactory.cs @@ -105,8 +105,8 @@ namespace grapher.Models Label mouseLabel) { var accelCalculator = new AccelCalculator( - new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI), - new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate)); + new Field(dpiTextBox.TextBox, form, Constants.DefaultDPI, 1), + new Field(pollRateTextBox.TextBox, form, Constants.DefaultPollRate, 1)); var accelCharts = new AccelCharts( form, diff --git a/grapher/Models/Calculations/AccelData.cs b/grapher/Models/Calculations/AccelData.cs index 778c5a2..d35217f 100644 --- a/grapher/Models/Calculations/AccelData.cs +++ b/grapher/Models/Calculations/AccelData.cs @@ -56,9 +56,9 @@ namespace grapher.Models.Calculations OutVelocityToPoints.Clear(); } - public void CalculateDots(double x, double y, double timeInMsRecip) + public void CalculateDots(double x, double y, double timeInMs) { - var outVelocity = AccelCalculator.Magnitude(x, y) * timeInMsRecip; + var outVelocity = AccelCalculator.Velocity(x, y, timeInMs); (var inCombVel, var combSens, var combGain) = Combined.FindPointValuesFromOut(outVelocity); Estimated.Velocity.Set(inCombVel, outVelocity); @@ -66,10 +66,10 @@ namespace grapher.Models.Calculations Estimated.Gain.Set(inCombVel, combGain); } - public void CalculateDotsXY(double x, double y, double timeInMsRecip) + public void CalculateDotsXY(double x, double y, double timeInMs) { - var outX = Math.Abs(x) * timeInMsRecip; - var outY = Math.Abs(y) * timeInMsRecip; + var outX = Math.Abs(x) / timeInMs; + var outY = Math.Abs(y) / timeInMs; (var inXVelocity, var xSensitivity, var xGain) = X.FindPointValuesFromOut(outX); EstimatedX.Velocity.Set(inXVelocity, outX); @@ -82,10 +82,10 @@ namespace grapher.Models.Calculations EstimatedY.Gain.Set(inYVelocity, yGain); } - public void CalculateDotsCombinedDiffSens(double x, double y, double timeInMsRecip, DriverSettings settings) + public void CalculateDotsCombinedDiffSens(double x, double y, double timeInMs, DriverSettings settings) { (var xStripped, var yStripped) = AccelCalculator.StripSens(x, y, settings.sensitivity.x, settings.sensitivity.y); - var outVelocity = AccelCalculator.Magnitude(xStripped, yStripped) * timeInMsRecip; + var outVelocity = AccelCalculator.Velocity(xStripped, yStripped, timeInMs); if (OutVelocityToPoints.TryGetValue(outVelocity, out var points)) { diff --git a/grapher/Models/Charts/AccelCharts.cs b/grapher/Models/Charts/AccelCharts.cs index 188db10..b7abb35 100644 --- a/grapher/Models/Charts/AccelCharts.cs +++ b/grapher/Models/Charts/AccelCharts.cs @@ -99,9 +99,9 @@ namespace grapher #region Methods - public void MakeDots(double x, double y, double timeInMsRecip) + public void MakeDots(double x, double y, double timeInMs) { - ChartState.MakeDots(x, y, timeInMsRecip); + ChartState.MakeDots(x, y, timeInMs); } public void DrawLastMovement() diff --git a/grapher/Models/Charts/ChartState/ChartState.cs b/grapher/Models/Charts/ChartState/ChartState.cs index c1b8e9b..0bb141e 100644 --- a/grapher/Models/Charts/ChartState/ChartState.cs +++ b/grapher/Models/Charts/ChartState/ChartState.cs @@ -40,7 +40,7 @@ namespace grapher.Models.Charts.ChartState internal bool TwoDotsPerGraph { get; set; } - public abstract void MakeDots(double x, double y, double timeInMsRecip); + public abstract void MakeDots(double x, double y, double timeInMs); public abstract void Bind(); diff --git a/grapher/Models/Charts/ChartState/CombinedState.cs b/grapher/Models/Charts/ChartState/CombinedState.cs index 9fcdc11..9eadb87 100644 --- a/grapher/Models/Charts/ChartState/CombinedState.cs +++ b/grapher/Models/Charts/ChartState/CombinedState.cs @@ -30,9 +30,9 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(double x, double y, double timeInMsRecip) + public override void MakeDots(double x, double y, double timeInMs) { - Data.CalculateDots(x, y, timeInMsRecip); + Data.CalculateDots(x, y, timeInMs); } public override void Bind() diff --git a/grapher/Models/Charts/ChartState/XYOneGraphState.cs b/grapher/Models/Charts/ChartState/XYOneGraphState.cs index 95c4b20..2b3cd9c 100644 --- a/grapher/Models/Charts/ChartState/XYOneGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYOneGraphState.cs @@ -28,9 +28,9 @@ namespace grapher.Models.Charts.ChartState GainChart.SetCombined(); } - public override void MakeDots(double x, double y, double timeInMsRecip) + public override void MakeDots(double x, double y, double timeInMs) { - Data.CalculateDotsCombinedDiffSens(x, y, timeInMsRecip, Settings); + Data.CalculateDotsCombinedDiffSens(x, y, timeInMs, Settings); } public override void Bind() diff --git a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs index 075cc0f..732ea3c 100644 --- a/grapher/Models/Charts/ChartState/XYTwoGraphState.cs +++ b/grapher/Models/Charts/ChartState/XYTwoGraphState.cs @@ -33,9 +33,9 @@ namespace grapher.Models.Charts.ChartState GainChart.ClearSecondDots(); } - public override void MakeDots(double x, double y, double timeInMsRecip) + public override void MakeDots(double x, double y, double timeInMs) { - Data.CalculateDotsXY(x, y, timeInMsRecip); + Data.CalculateDotsXY(x, y, timeInMs); } public override void Bind() diff --git a/grapher/Models/Fields/Field.cs b/grapher/Models/Fields/Field.cs index 541bbe2..345f814 100644 --- a/grapher/Models/Fields/Field.cs +++ b/grapher/Models/Fields/Field.cs @@ -27,12 +27,16 @@ namespace grapher #region Constructors - public Field(TextBox box, Form containingForm, double defaultData) + public Field(TextBox box, Form containingForm, double defaultData, + double minData = double.MinValue, + double maxData = double.MaxValue) { DefaultText = DecimalString(defaultData); Box = box; _data = defaultData; DefaultData = defaultData; + MinData = minData; + MaxData = maxData; State = FieldState.Undefined; ContainingForm = containingForm; FormatString = Constants.DefaultFieldFormatString; @@ -69,7 +73,7 @@ namespace grapher { return DefaultData; } - } + } } public int Top @@ -122,6 +126,10 @@ namespace grapher private double DefaultData { get; set; } + private double MinData { get; } + + private double MaxData { get; } + #endregion Properties #region Methods @@ -268,12 +276,10 @@ namespace grapher private void TextToData() { - try - { - _data = Convert.ToDouble(Box.Text); - } - catch + if (double.TryParse(Box.Text, out double value) && + value <= MaxData && value >= MinData) { + _data = value; } Box.Text = DecimalString(Data); diff --git a/grapher/Models/Mouse/MouseWatcher.cs b/grapher/Models/Mouse/MouseWatcher.cs index ae48a76..cbfc119 100644 --- a/grapher/Models/Mouse/MouseWatcher.cs +++ b/grapher/Models/Mouse/MouseWatcher.cs @@ -711,9 +711,9 @@ namespace grapher.Models.Mouse private MouseData MouseData { get; } - private double PollTimeReciprocal + private double PollTime { - get => Math.Abs(SettingsManager.PollRateField.Data) * 0.001; + get => 1000 / SettingsManager.PollRateField.Data; } #endregion Properties @@ -757,7 +757,7 @@ namespace grapher.Models.Mouse } MouseData.Set(rawInput.Data.Mouse.LastX, rawInput.Data.Mouse.LastY); - AccelCharts.MakeDots(x, y, PollTimeReciprocal); + AccelCharts.MakeDots(x, y, PollTime); } } -- cgit v1.2.3