summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-03 18:09:00 -0400
committera1xd <[email protected]>2021-09-23 22:28:44 -0400
commit6a9272d3af202274dfbced245f0ba20b263fcd8b (patch)
treeb139e1d21aac0febc6105ac0d4c480f352d3064a
parentadd per-device configuration (diff)
downloadrawaccel-6a9272d3af202274dfbced245f0ba20b263fcd8b.tar.xz
rawaccel-6a9272d3af202274dfbced245f0ba20b263fcd8b.zip
refactor vec2/math
-rw-r--r--common/accel-classic.hpp1
-rw-r--r--common/accel-jump.hpp4
-rw-r--r--common/accel-lookup.hpp2
-rw-r--r--common/accel-motivity.hpp2
-rw-r--r--common/accel-natural.hpp2
-rw-r--r--common/accel-power.hpp1
-rw-r--r--common/common.vcxitems2
-rw-r--r--common/math-vec2.hpp36
-rw-r--r--common/rawaccel-base.hpp3
-rw-r--r--common/rawaccel.hpp34
-rw-r--r--common/vec2.h9
11 files changed, 44 insertions, 52 deletions
diff --git a/common/accel-classic.hpp b/common/accel-classic.hpp
index ce343e7..9f6a037 100644
--- a/common/accel-classic.hpp
+++ b/common/accel-classic.hpp
@@ -3,7 +3,6 @@
#include "rawaccel-base.hpp"
#include "utility.hpp"
-#include <math.h>
#include <float.h>
namespace rawaccel {
diff --git a/common/accel-jump.hpp b/common/accel-jump.hpp
index c036810..e3d798e 100644
--- a/common/accel-jump.hpp
+++ b/common/accel-jump.hpp
@@ -2,12 +2,10 @@
#include "rawaccel-base.hpp"
-#include <math.h>
-
namespace rawaccel {
struct jump_base {
- static constexpr double smooth_scale = 2 * PI;
+ static constexpr double smooth_scale = 2 * M_PI;
vec2d step;
double smooth_rate;
diff --git a/common/accel-lookup.hpp b/common/accel-lookup.hpp
index b7e8b68..b8c689a 100644
--- a/common/accel-lookup.hpp
+++ b/common/accel-lookup.hpp
@@ -3,8 +3,6 @@
#include "rawaccel-base.hpp"
#include "utility.hpp"
-#include <math.h>
-
namespace rawaccel {
// represents the range [2^start, 2^stop], with num - 1
diff --git a/common/accel-motivity.hpp b/common/accel-motivity.hpp
index 0cd60f8..f35e9ca 100644
--- a/common/accel-motivity.hpp
+++ b/common/accel-motivity.hpp
@@ -2,8 +2,6 @@
#include "accel-lookup.hpp"
-#include <math.h>
-
namespace rawaccel {
template <bool Gain> struct loglog_sigmoid;
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp
index c5e1c32..521a1ae 100644
--- a/common/accel-natural.hpp
+++ b/common/accel-natural.hpp
@@ -2,8 +2,6 @@
#include "rawaccel-base.hpp"
-#include <math.h>
-
namespace rawaccel {
/// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary>
diff --git a/common/accel-power.hpp b/common/accel-power.hpp
index f727369..b3e16fb 100644
--- a/common/accel-power.hpp
+++ b/common/accel-power.hpp
@@ -2,7 +2,6 @@
#include "rawaccel-base.hpp"
-#include <math.h>
#include <float.h>
namespace rawaccel {
diff --git a/common/common.vcxitems b/common/common.vcxitems
index 85af72e..b49acd2 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -30,7 +30,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-version.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)utility-install.hpp" />
- <ClInclude Include="$(MSBuildThisFileDirectory)vec2.h" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)math-vec2.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)utility.hpp" />
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/common/math-vec2.hpp b/common/math-vec2.hpp
new file mode 100644
index 0000000..2622926
--- /dev/null
+++ b/common/math-vec2.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+template <typename T>
+struct vec2 {
+ T x;
+ T y;
+};
+
+using vec2d = vec2<double>;
+
+inline vec2d direction(double degrees)
+{
+ double radians = degrees * M_PI / 180;
+ return { cos(radians), sin(radians) };
+}
+
+constexpr vec2d rotate(const vec2d& v, const vec2d& direction)
+{
+ return {
+ v.x * direction.x - v.y * direction.y,
+ v.x * direction.y + v.y * direction.x
+ };
+}
+
+inline double magnitude(const vec2d& v)
+{
+ return sqrt(v.x * v.x + v.y * v.y);
+}
+
+inline double lp_distance(const vec2d& v, double p)
+{
+ return pow(pow(v.x, p) + pow(v.y, p), 1 / p);
+}
diff --git a/common/rawaccel-base.hpp b/common/rawaccel-base.hpp
index ce6c103..8a49681 100644
--- a/common/rawaccel-base.hpp
+++ b/common/rawaccel-base.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "vec2.h"
+#include "math-vec2.hpp"
namespace rawaccel {
using milliseconds = double;
@@ -22,7 +22,6 @@ namespace rawaccel {
inline constexpr size_t LUT_POINTS_CAPACITY = LUT_RAW_DATA_CAPACITY / 2;
inline constexpr double MAX_NORM = 16;
- inline constexpr double PI = 3.14159265358979323846;
inline constexpr bool LEGACY = 0;
inline constexpr bool GAIN = 1;
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 4f98c8d..b7e632b 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -4,30 +4,6 @@
namespace rawaccel {
- inline vec2d direction(double degrees)
- {
- double radians = degrees * PI / 180;
- return { cos(radians), sin(radians) };
- }
-
- constexpr vec2d rotate(const vec2d& v, const vec2d& direction)
- {
- return {
- v.x * direction.x - v.y * direction.y,
- v.x * direction.y + v.y * direction.x
- };
- }
-
- inline double magnitude(const vec2d& v)
- {
- return sqrt(v.x * v.x + v.y * v.y);
- }
-
- inline double lp_distance(const vec2d& v, double p)
- {
- return pow(pow(v.x, p) + pow(v.y, p), 1 / p);
- }
-
struct time_clamp {
milliseconds min = DEFAULT_TIME_MIN;
milliseconds max = DEFAULT_TIME_MAX;
@@ -100,16 +76,16 @@ namespace rawaccel {
if (compute_ref_angle && in.y != 0) {
if (in.x == 0) {
- reference_angle = PI / 2;
+ reference_angle = M_PI / 2;
}
else {
reference_angle = atan(fabs(in.y / in.x));
if (apply_snap) {
- double snap = args.degrees_snap * PI / 180;
+ double snap = args.degrees_snap * M_PI / 180;
- if (reference_angle > PI / 2 - snap) {
- reference_angle = PI / 2;
+ if (reference_angle > M_PI / 2 - snap) {
+ reference_angle = M_PI / 2;
in = { 0, _copysign(magnitude(in), in.y) };
}
else if (reference_angle < snap) {
@@ -153,7 +129,7 @@ namespace rawaccel {
if (apply_directional_weight) {
double diff = args.range_weights.y - args.range_weights.x;
- weight += 2 / PI * reference_angle * diff;
+ weight += 2 / M_PI * reference_angle * diff;
}
double scale = (*cb_x)(data.accel_x, args.accel_x, speed, weight);
diff --git a/common/vec2.h b/common/vec2.h
deleted file mode 100644
index 6484e69..0000000
--- a/common/vec2.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-template <typename T>
-struct vec2 {
- T x;
- T y;
-};
-
-using vec2d = vec2<double>;