From 6a9272d3af202274dfbced245f0ba20b263fcd8b Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 3 Sep 2021 18:09:00 -0400 Subject: refactor vec2/math --- common/accel-classic.hpp | 1 - common/accel-jump.hpp | 4 +--- common/accel-lookup.hpp | 2 -- common/accel-motivity.hpp | 2 -- common/accel-natural.hpp | 2 -- common/accel-power.hpp | 1 - common/common.vcxitems | 2 +- common/math-vec2.hpp | 36 ++++++++++++++++++++++++++++++++++++ common/rawaccel-base.hpp | 3 +-- common/rawaccel.hpp | 34 +++++----------------------------- common/vec2.h | 9 --------- 11 files changed, 44 insertions(+), 52 deletions(-) create mode 100644 common/math-vec2.hpp delete mode 100644 common/vec2.h 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 #include 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 - 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 - 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 - namespace rawaccel { template 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 - namespace rawaccel { /// Struct to hold "natural" (vanishing difference) acceleration implementation. 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 #include 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 @@ - + \ 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 + +template +struct vec2 { + T x; + T y; +}; + +using vec2d = vec2; + +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 -struct vec2 { - T x; - T y; -}; - -using vec2d = vec2; -- cgit v1.2.3