math.h 2.02 KB
Newer Older
RobLoach's avatar
RobLoach committed
1
2
#ifndef SRC_LOVE_MATH_H_
#define SRC_LOVE_MATH_H_
RobLoach's avatar
RobLoach committed
3

4
5
#include <string>

RobLoach's avatar
RobLoach committed
6
namespace love {
RobLoach's avatar
RobLoach committed
7
/**
RobLoach's avatar
RobLoach committed
8
 * Provides system-independent mathematical functions.
RobLoach's avatar
RobLoach committed
9
10
11
12
 */
class math {
	public:
	bool load();
RobLoach's avatar
RobLoach committed
13

RobLoach's avatar
RobLoach committed
14
	/**
RobLoach's avatar
RobLoach committed
15
	 * Get uniformly distributed pseudo-random number, between the given numbers.
RobLoach's avatar
RobLoach committed
16
17
18
19
	 *
	 * @param min (0.0f) The minimum value.
	 * @param max (1.0f) The max value.
	 *
RobLoach's avatar
RobLoach committed
20
	 * @return A number between the two given min and max values.
RobLoach's avatar
RobLoach committed
21
22
23
24
25
26
	 *
	 * @code
	 * love.math.random(5, 10) // 5-10
	 * love.math.random(10)    // 0-10
	 * love.math.random()      // 0.0f-1.0f
	 * @endcode
RobLoach's avatar
RobLoach committed
27
	 */
RobLoach's avatar
RobLoach committed
28
29
30
	float random(float min, float max);
	float random(float max);
	float random();
RobLoach's avatar
RobLoach committed
31
32
33
34
	int random(int min, int max);
	int random(int max);
	double random(double min, double max);
	double random(double max);
RobLoach's avatar
RobLoach committed
35

RobLoach's avatar
RobLoach committed
36
	/**
RobLoach's avatar
RobLoach committed
37
	 * Sets the random seed to a random seed between the given min and max values.
RobLoach's avatar
RobLoach committed
38
39
	 *
	 * @param min The lower 32 bits of the seed value.
RobLoach's avatar
0.28.0    
RobLoach committed
40
	 * @param max The higher 32 bits of the seed value.
RobLoach's avatar
RobLoach committed
41
42
	 *
	 * @return The math module, to allow for method chaining.
RobLoach's avatar
RobLoach committed
43
44
	 *
	 * @see love.math.getRandomSeed
RobLoach's avatar
RobLoach committed
45
	 */
RobLoach's avatar
RobLoach committed
46
	math& setRandomSeed(int min, int max);
RobLoach's avatar
RobLoach committed
47

RobLoach's avatar
RobLoach committed
48
	/**
RobLoach's avatar
RobLoach committed
49
	 * Sets the seed of the random number generator.
RobLoach's avatar
RobLoach committed
50
51
	 *
	 * @param seed The integer number with which you want to seed the randomization.
RobLoach's avatar
RobLoach committed
52
53
	 *
	 * @return The math module, to allow for method chaining.
RobLoach's avatar
RobLoach committed
54
55
	 *
	 * @see love.math.getRandomSeed
RobLoach's avatar
RobLoach committed
56
	 */
RobLoach's avatar
RobLoach committed
57
	math& setRandomSeed(int seed);
RobLoach's avatar
RobLoach committed
58

RobLoach's avatar
RobLoach committed
59
	/**
RobLoach's avatar
RobLoach committed
60
	 * Gets the seed of the random number generator.
RobLoach's avatar
RobLoach committed
61
62
	 *
	 * @see love.math.setRandomSeed
RobLoach's avatar
RobLoach committed
63
64
	 */
	int getRandomSeed();
RobLoach's avatar
RobLoach committed
65

66
	/**
RobLoach's avatar
RobLoach committed
67
	 * Converts from degrees to radians.
RobLoach's avatar
RobLoach committed
68
69
	 *
	 * @see love.math.degrees
70
71
72
73
	 */
	float rad(float degrees);

	/**
RobLoach's avatar
RobLoach committed
74
	 * Converts from radians to degrees.
RobLoach's avatar
RobLoach committed
75
76
	 *
	 * @see love.math.rad
77
78
79
	 */
	float degrees(float rad);

RobLoach's avatar
RobLoach committed
80
	/**
RobLoach's avatar
RobLoach committed
81
	 * Mathematic constant: e
RobLoach's avatar
RobLoach committed
82
	 *
RobLoach's avatar
RobLoach committed
83
	 * @see https://en.wikipedia.org/wiki/E_(mathematical_constant)
RobLoach's avatar
RobLoach committed
84
85
	 */
	const float e = 2.718281828459045f;
RobLoach's avatar
RobLoach committed
86
87

	/**
RobLoach's avatar
RobLoach committed
88
	 * Mathematics constant: Pi
RobLoach's avatar
RobLoach committed
89
90
	 *
	 * @see https://en.wikipedia.org/wiki/Pi
RobLoach's avatar
RobLoach committed
91
	 */
RobLoach's avatar
RobLoach committed
92
93
	const float pi = 3.14159265358979323846f;

RobLoach's avatar
RobLoach committed
94
	private:
RobLoach's avatar
RobLoach committed
95
	int m_seed = 0;
RobLoach's avatar
RobLoach committed
96
};
97

RobLoach's avatar
RobLoach committed
98
}  // namespace love
RobLoach's avatar
RobLoach committed
99

RobLoach's avatar
RobLoach committed
100
#endif  // SRC_LOVE_MATH_H_