diff options
| author | a1xd <[email protected]> | 2021-07-06 22:01:35 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-07-06 22:01:35 -0400 |
| commit | 2b2e93576c44d5bf4a49d48f052175273396e49e (patch) | |
| tree | 0a1193c2a420cfb045baa28aac023ef428513d17 /common | |
| parent | fix double error message on gui version check (diff) | |
| download | rawaccel-2b2e93576c44d5bf4a49d48f052175273396e49e.tar.xz rawaccel-2b2e93576c44d5bf4a49d48f052175273396e49e.zip | |
guard against large values of smooth_rate for jump types
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-jump.hpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/common/accel-jump.hpp b/common/accel-jump.hpp index 198891a..47a1a30 100644 --- a/common/accel-jump.hpp +++ b/common/accel-jump.hpp @@ -5,19 +5,23 @@ namespace rawaccel { struct jump_base { + static constexpr double smooth_scale = 2 * PI; + vec2d step; double smooth_rate; + // requirements: args.smooth in range [0, 1] jump_base(const accel_args& args) : step({ args.offset, args.cap - 1 }) { - if (args.smooth == 0 || args.offset == 0) { + double rate_inverse = args.smooth * step.x; + + if (rate_inverse < 1) { smooth_rate = 0; } else { - smooth_rate = 2 * PI / (args.offset * args.smooth); + smooth_rate = smooth_scale / rate_inverse; } - } bool is_smooth() const |