From 2b2e93576c44d5bf4a49d48f052175273396e49e Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 6 Jul 2021 22:01:35 -0400 Subject: guard against large values of smooth_rate for jump types --- common/accel-jump.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'common') 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 -- cgit v1.2.3