From 5a0db3165d1ad050fd5e3f48d290f5ec7289a4f2 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 29 Mar 2021 19:41:42 -0400 Subject: add jump type --- common/accel-jump.hpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 common/accel-jump.hpp (limited to 'common/accel-jump.hpp') diff --git a/common/accel-jump.hpp b/common/accel-jump.hpp new file mode 100644 index 0000000..2d13cae --- /dev/null +++ b/common/accel-jump.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include "rawaccel-base.hpp" + +#define _USE_MATH_DEFINES +#include + +namespace rawaccel { + + struct jump_base { + vec2d step; + double smooth_rate; + + jump_base(const accel_args& args) : + step({ args.offset, args.cap - 1 }) + { + if (args.smooth == 0 || args.offset == 0) { + smooth_rate = 0; + } + else { + smooth_rate = 2 * M_PI / (args.offset * args.smooth); + } + + } + + bool is_smooth() const + { + return smooth_rate != 0; + } + + double decay(double x) const + { + return exp(smooth_rate * (step.x - x)); + } + + double smooth(double x) const + { + return step.y * 1 / (1 + decay(x)); + } + + double smooth_antideriv(double x) const + { + return step.y * (x + log(1 + decay(x)) / smooth_rate); + } + }; + + struct jump_legacy : jump_base { + using jump_base::jump_base; + + double operator()(double x) const + { + if (is_smooth()) return smooth(x) + 1; + else if (x < step.x) return 1; + else return step.y; + } + }; + + struct jump : jump_base { + double C; + + jump(const accel_args& args) : + jump_base(args), + C(-smooth_antideriv(0)) {} + + double operator()(double x) const + { + if (is_smooth()) return 1 + (smooth_antideriv(x) + C) / x; + else if (x < step.x) return 1; + else return 1 + step.y * (x - step.x) / x; + } + }; + +} -- cgit v1.2.3