summaryrefslogtreecommitdiff
path: root/grapher/Models
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-12-03 22:42:29 -0500
committera1xd <[email protected]>2020-12-03 22:42:29 -0500
commitc221eb3d62ccbd7f2a5203abd3e0eae8e9bf31e8 (patch)
tree10f984c905084eae140d7eb15eb81592f50d537f /grapher/Models
parentfix chart range not updating on disable (diff)
downloadrawaccel-c221eb3d62ccbd7f2a5203abd3e0eae8e9bf31e8.tar.xz
rawaccel-c221eb3d62ccbd7f2a5203abd3e0eae8e9bf31e8.zip
add changes from review
rename some vars prefer exceptions over assert refactor poll rate field usage in MouseWatcher
Diffstat (limited to 'grapher/Models')
-rw-r--r--grapher/Models/AccelGUI.cs2
-rw-r--r--grapher/Models/Calculations/AccelChartData.cs6
-rw-r--r--grapher/Models/Charts/ChartXY.cs16
-rw-r--r--grapher/Models/Mouse/MouseWatcher.cs31
-rw-r--r--grapher/Models/Serialized/RawAccelSettings.cs4
5 files changed, 31 insertions, 28 deletions
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<double> negMults = SettingsManager.RawAccelSettings
- .AccelerationSettings.negativeMultipliers;
+ Vec2<double> 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;