summaryrefslogtreecommitdiff
path: root/common/accel-linear.hpp
blob: 95ba261af7b2ca068e4c43132a7612eb972c4a07 (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
#pragma once

#include "accel-base.hpp"

namespace rawaccel {

	/// <summary> Struct to hold linear acceleration implementation. </summary>
	struct linear_impl { 
		double accel;
		double offset;
		double subtractive_const;
		double divisive_const;
		
		linear_impl(const accel_args& args) : accel(args.accel), offset(args.offset) {
			subtractive_const = 2 * accel * offset;
			divisive_const = accel * offset * offset;
		}

		inline double operator()(double speed) const {
			double base_speed = speed + offset;
			return accel * base_speed - subtractive_const + divisive_const / base_speed;
		}

	};

	using accel_linear = additive_accel<linear_impl>;

}