summaryrefslogtreecommitdiff
path: root/common/accel-linear.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/accel-linear.hpp')
-rw-r--r--common/accel-linear.hpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp
index a943594..2bd57b8 100644
--- a/common/accel-linear.hpp
+++ b/common/accel-linear.hpp
@@ -7,13 +7,23 @@ namespace rawaccel {
/// <summary> Struct to hold linear acceleration implementation. </summary>
struct linear_impl {
double accel;
+ double offset;
+ double subtractive_const;
+ double divisive_const;
- linear_impl(const accel_args& args) : accel(args.accel) {}
+ linear_impl(const accel_args& args) : accel(args.accel), offset(args.offset) {
+ subtractive_const = 2 * accel * offset;
+ divisive_const = accel * offset * offset;
+ }
inline double operator()(double speed) const {
- return accel * speed;
+ double base_speed = speed + offset;
+ return accel * base_speed - subtractive_const + divisive_const / base_speed;
}
+ inline double legacy_offset(double speed) const {
+ return accel * speed;
+ }
};
using accel_linear = additive_accel<linear_impl>;