Math utility class containing basic functions.
More...
#include <Math.h>
|
static constexpr double | Max (const double a, const double b) |
| Will return the bigger of two values. More...
|
|
static constexpr double | Min (const double a, const double b) |
| Will return the smaller of two values. More...
|
|
static constexpr double | Clamp (const double v, const double min, const double max) |
| Will return v , but at least min , and at most max More...
|
|
static constexpr double | Lerp (double a, double b, double t) |
| Will return the linear interpolation between a and b by t More...
|
|
static constexpr double | Abs (const double a) |
| Will return the absolute value of a More...
|
|
static constexpr bool | Similar (const double a, const double b, const double epsilon=0.00001) |
| Compares two double values with a given accuracy. More...
|
|
static double | Random () |
| Will return a random double between 0 and 1 More...
|
|
static unsigned int | RandomUint () |
| Will return a random unsigned integer. More...
|
|
static unsigned int | RandomInt () |
| Will return a random integer. More...
|
|
static double | RandomRange (const double min, const double max) |
| Will return a random double within a range
These bounds are INCLUSIVE! More...
|
|
static int | RandomIntRange (const int max, const int min) |
| Will return a random integer within a range. More...
|
|
static bool | RandomChance (const double chance) |
| Will 'roll' a dice, returning true \(100 * chance\) percent of the time. More...
|
|
static double | Oscillate (const double a, const double b, const double counter, const double speed) |
| Kind of like \(sin(counter)\), but it oscillates over \([a,b]\) instead of \([-1,1]\), by a given speed. More...
|
|
Math utility class containing basic functions.
Definition at line 8 of file Math.h.
◆ Abs()
constexpr double Eule::Math::Abs |
( |
const double |
a | ) |
|
|
inlinestaticconstexpr |
Will return the absolute value of a
Definition at line 92 of file Math.h.
94 return (a > 0.0) ? a : -a;
◆ Clamp()
constexpr double Eule::Math::Clamp |
( |
const double |
v, |
|
|
const double |
min, |
|
|
const double |
max |
|
) |
| |
|
inlinestaticconstexpr |
Will return v
, but at least min
, and at most max
Definition at line 81 of file Math.h.
83 return Max(
Min(v, max), min);
◆ Lerp()
constexpr double Eule::Math::Lerp |
( |
double |
a, |
|
|
double |
b, |
|
|
double |
t |
|
) |
| |
|
inlinestaticconstexpr |
Will return the linear interpolation between a
and b
by t
Definition at line 86 of file Math.h.
88 const double it = 1.0 - t;
89 return (a * it) + (b * t);
◆ Max()
constexpr double Eule::Math::Max |
( |
const double |
a, |
|
|
const double |
b |
|
) |
| |
|
inlinestaticconstexpr |
Will return the bigger of two values.
Definition at line 71 of file Math.h.
73 return (a > b) ? a : b;
◆ Min()
constexpr double Eule::Math::Min |
( |
const double |
a, |
|
|
const double |
b |
|
) |
| |
|
inlinestaticconstexpr |
Will return the smaller of two values.
Definition at line 76 of file Math.h.
78 return (a < b) ? a : b;
◆ Oscillate()
double Math::Oscillate |
( |
const double |
a, |
|
|
const double |
b, |
|
|
const double |
counter, |
|
|
const double |
speed |
|
) |
| |
|
static |
Kind of like \(sin(counter)\), but it oscillates over \([a,b]\) instead of \([-1,1]\), by a given speed.
Given that \(speed = 1\), the result will always be a
if counter
is even, and b
if counter
is uneven.
If counter
is a rational, the result will oscillate between a
and b
, like sin()
does.
If you increase speed
, the oscillation frequency will increase. Meaning \(speed = 2\) would result in \(counter=0.5\) returning b
.
Definition at line 68 of file Math.cpp.
70 return (sin(counter * speed *
PI -
HALF_PI) * 0.5 + 0.5) * (b-a) + a;
◆ Random()
Will return a random double between 0
and 1
Definition at line 29 of file Math.cpp.
33 return (rng() % 694206942069ll) / 694206942069.0;
◆ RandomChance()
bool Math::RandomChance |
( |
const double |
chance | ) |
|
|
static |
Will 'roll' a dice, returning true
\(100 * chance\) percent of the time.
Definition at line 73 of file Math.cpp.
◆ RandomInt()
unsigned int Math::RandomInt |
( |
| ) |
|
|
static |
Will return a random integer.
Definition at line 45 of file Math.cpp.
◆ RandomIntRange()
int Math::RandomIntRange |
( |
const int |
max, |
|
|
const int |
min |
|
) |
| |
|
static |
Will return a random integer within a range.
This is faster than (int)RandomRange(x,y)
These bounds are INCLUSIVE!
Definition at line 63 of file Math.cpp.
65 return (rng() % (max + 1 - min)) + min;
◆ RandomRange()
double Math::RandomRange |
( |
const double |
min, |
|
|
const double |
max |
|
) |
| |
|
static |
Will return a random double within a range
These bounds are INCLUSIVE!
Definition at line 56 of file Math.cpp.
58 return (
Random() * (max - min)) + min;
◆ RandomUint()
unsigned int Math::RandomUint |
( |
| ) |
|
|
static |
Will return a random unsigned integer.
Definition at line 37 of file Math.cpp.
◆ Similar()
static constexpr bool Eule::Math::Similar |
( |
const double |
a, |
|
|
const double |
b, |
|
|
const double |
epsilon = 0.00001 |
|
) |
| |
|
staticconstexpr |
Compares two double values with a given accuracy.
The documentation for this class was generated from the following files: