summaryrefslogtreecommitdiff
path: root/common/accel_power.cpp
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-07-29 15:51:53 -0700
committerJacob Palecki <[email protected]>2020-07-29 15:51:53 -0700
commit0a91af55f79d9a9d5bda600e8eee7e17c65bd0b6 (patch)
tree642659b6ed96b00bc4e9bf6d3152978889ea0079 /common/accel_power.cpp
parentadd sum types (diff)
parentUse modifier object in wrapper (diff)
downloadrawaccel-0a91af55f79d9a9d5bda600e8eee7e17c65bd0b6.tar.xz
rawaccel-0a91af55f79d9a9d5bda600e8eee7e17c65bd0b6.zip
Merge remote-tracking branch 'downstream/Inheritance' into st-refactor
Diffstat (limited to 'common/accel_power.cpp')
-rw-r--r--common/accel_power.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/accel_power.cpp b/common/accel_power.cpp
new file mode 100644
index 0000000..f104554
--- /dev/null
+++ b/common/accel_power.cpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#define _USE_MATH_DEFINES
+#include <math.h>
+
+#include "accel_types.hpp"
+
+namespace rawaccel {
+ inline accel_power::accel_power(accel_args args)
+ : accel_implentation(args)
+ { curve_constant_two++; }
+
+ inline double accel_power::accelerate(double speed) {
+ // f(x) = (mx)^k - 1
+ // The subtraction of 1 occurs with later addition of 1 in mind,
+ // so that the input vector is directly multiplied by (mx)^k (if unweighted)
+ return (offset > 0 && speed < 1) ? 0 : pow(speed * curve_constant_one, curve_constant_two) - 1;
+ }
+
+ inline void accel_power::verify(accel_args args) {
+ accel_implentation::verify(args);
+ if (args.lim_exp <= 0) error("exponent must be greater than 0");
+ }
+}