summaryrefslogtreecommitdiff
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
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
-rw-r--r--common/rawaccel-settings.h2
-rw-r--r--common/rawaccel.hpp14
-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
-rw-r--r--wrapper/wrapper.cpp2
8 files changed, 40 insertions, 37 deletions
diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h
index 0f52807..649c936 100644
--- a/common/rawaccel-settings.h
+++ b/common/rawaccel-settings.h
@@ -21,7 +21,7 @@ namespace rawaccel {
vec2<accel_mode> modes = { accel_mode::noaccel, accel_mode::noaccel };
vec2<accel_args> argsv;
vec2d sens = { 1, 1 };
- vec2d neg_multipliers = {};
+ vec2d dir_multipliers = {};
milliseconds time_min = DEFAULT_TIME_MIN;
};
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index a7b9144..3e049cb 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -233,7 +233,7 @@ namespace rawaccel {
rotator rotate;
vec2<accelerator> accels;
vec2d sensitivity = { 1, 1 };
- vec2d negative_multipliers = {};
+ vec2d directional_multipliers = {};
mouse_modifier(const settings& args, vec2<si_pair*> luts = {}) :
combine_magnitudes(args.combine_mags)
@@ -246,8 +246,8 @@ namespace rawaccel {
if (args.sens.x != 0) sensitivity.x = args.sens.x;
if (args.sens.y != 0) sensitivity.y = args.sens.y;
- negative_multipliers.x = fabs(args.neg_multipliers.x);
- negative_multipliers.y = fabs(args.neg_multipliers.y);
+ directional_multipliers.x = fabs(args.dir_multipliers.x);
+ directional_multipliers.y = fabs(args.dir_multipliers.y);
if ((combine_magnitudes && args.modes.x == accel_mode::noaccel) ||
(args.modes.x == accel_mode::noaccel &&
@@ -293,11 +293,11 @@ namespace rawaccel {
movement.x *= sensitivity.x;
movement.y *= sensitivity.y;
- if (negative_multipliers.x > 0 && movement.x < 0) {
- movement.x *= negative_multipliers.x;
+ if (directional_multipliers.x > 0 && movement.x < 0) {
+ movement.x *= directional_multipliers.x;
}
- if (negative_multipliers.y > 0 && movement.y < 0) {
- movement.y *= negative_multipliers.y;
+ if (directional_multipliers.y > 0 && movement.y < 0) {
+ movement.y *= directional_multipliers.y;
}
}
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;
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index 54bfb91..c59dc00 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -73,7 +73,7 @@ public ref struct DriverSettings
Vec2<double> sensitivity;
[JsonProperty("Negative directional multipliers", Required = Required::Default)]
- Vec2<double> negativeMultipliers;
+ Vec2<double> directionalMultipliers;
[JsonProperty(Required = Required::Default)]
double minimumTime;