diff options
| author | a1xd <[email protected]> | 2020-07-31 05:12:04 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-07-31 05:12:04 -0400 |
| commit | d5c012bcd5b7321671f9591a3e58d0b2c9507467 (patch) | |
| tree | fe64110f7678607947d19c5ba0b46ea2b15d69c4 /common/accel-natural.hpp | |
| parent | Merge pull request #5 from JacobPalecki/WrapperAndGrapher (diff) | |
| parent | update grapher/wrapper for st-refactor (diff) | |
| download | rawaccel-d5c012bcd5b7321671f9591a3e58d0b2c9507467.tar.xz rawaccel-d5c012bcd5b7321671f9591a3e58d0b2c9507467.zip | |
Merge pull request #6 from a1xd/st-refactor
Refactor
Diffstat (limited to 'common/accel-natural.hpp')
| -rw-r--r-- | common/accel-natural.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp new file mode 100644 index 0000000..c87fda8 --- /dev/null +++ b/common/accel-natural.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold "natural" (vanishing difference) acceleration implementation. </summary> + struct accel_natural : accel_base { + double limit = 1; + double midpoint = 0; + + accel_natural(const accel_args& args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + speed_coeff /= limit; + } + + inline double accelerate(double speed) const { + // f(x) = k(1-e^(-mx)) + return limit - (limit * exp(-speed_coeff * speed)); + } + + void verify(const accel_args& args) const { + if (args.limit <= 1) error("limit must be greater than 1"); + } + }; + +} |