From e8417a29fb2153ea035a757f36bfa300cf8b480d Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 30 Jul 2020 17:07:35 -0400 Subject: add tweaks for st-refactor --- common/accel-natural.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 common/accel-natural.hpp (limited to 'common/accel-natural.hpp') diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp new file mode 100644 index 0000000..6ccb193 --- /dev/null +++ b/common/accel-natural.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "accel-base.hpp" + +namespace rawaccel { + + /// Struct to hold "natural" (vanishing difference) acceleration implementation. + struct accel_natural : accel_base { + double limit = 1; + double midpoint = 0; + + accel_natural(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(accel_args args) const { + if (args.limit <= 1) error("limit must be greater than 1"); + } + }; + +} -- cgit v1.2.3 From b3ed8fd4e4fcad0b749126dee62588260d74b106 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Fri, 31 Jul 2020 01:37:41 -0400 Subject: add more tweaks for st-refactor --- common/accel-natural.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/accel-natural.hpp') diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp index 6ccb193..c87fda8 100644 --- a/common/accel-natural.hpp +++ b/common/accel-natural.hpp @@ -11,7 +11,7 @@ namespace rawaccel { double limit = 1; double midpoint = 0; - accel_natural(accel_args args) : accel_base(args) { + accel_natural(const accel_args& args) : accel_base(args) { verify(args); limit = args.limit - 1; @@ -23,7 +23,7 @@ namespace rawaccel { return limit - (limit * exp(-speed_coeff * speed)); } - void verify(accel_args args) const { + void verify(const accel_args& args) const { if (args.limit <= 1) error("limit must be greater than 1"); } }; -- cgit v1.2.3