summaryrefslogtreecommitdiff
path: root/common/accel-logarithm.hpp
blob: 044d23c1222d4ecf89a727fa3da5d9dc2889a876 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

#include <math.h>

#include "accel-base.hpp"

namespace rawaccel {

	/// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
	struct logarithm_impl {
		double rate;
		double offset;
		double additive_const;

		logarithm_impl (const accel_args& args) :
			rate(args.rate), offset (args.offset) {
			additive_const = offset * rate;
		}

		inline double operator()(double speed) const {
			double scaled_speed = rate * speed + 1;
			double base_speed = speed + offset;

			return (scaled_speed * log(scaled_speed) + additive_const ) / ( rate * base_speed) - 1;
		}

		inline double legacy_offset(double speed) const { return operator()(speed); }
	};

	using accel_logarithm = additive_accel<logarithm_impl>;

}