MathDefs.h File Reference
#include "../Math/Random.h"
#include <cstdlib>
#include <cmath>
#include <limits>
#include <type_traits>
Include dependency graph for MathDefs.h:
This graph shows which files directly or indirectly include this file:

Enumerations

enum  Urho3D::Intersection { OUTSIDE, INTERSECTS, INSIDE }
 Intersection test result.
 

Functions

template<class T >
bool Urho3D::Equals (T lhs, T rhs)
 
template<class T , class U >
Urho3D::Lerp (T lhs, T rhs, U t)
 
template<class T >
Urho3D::InverseLerp (T lhs, T rhs, T x)
 
template<class T , class U >
Urho3D::Min (T lhs, U rhs)
 
template<class T , class U >
Urho3D::Max (T lhs, U rhs)
 
template<class T >
Urho3D::Abs (T value)
 
template<class T >
Urho3D::Sign (T value)
 
template<class T >
Urho3D::ToRadians (const T degrees)
 Convert degrees to radians.
 
template<class T >
Urho3D::ToDegrees (const T radians)
 Convert radians to degrees.
 
unsigned Urho3D::FloatToRawIntBits (float value)
 Return a representation of the specified floating-point value as a single format bit layout.
 
template<class T >
bool Urho3D::IsNaN (T value)
 
template<class T >
bool Urho3D::IsInf (T value)
 Check whether a floating point value is positive or negative infinity.
 
template<class T >
Urho3D::Clamp (T value, T min, T max)
 
template<class T >
Urho3D::SmoothStep (T lhs, T rhs, T t)
 
template<class T >
Urho3D::Sin (T angle)
 
template<class T >
Urho3D::Cos (T angle)
 
template<class T >
Urho3D::Tan (T angle)
 
template<class T >
Urho3D::Asin (T x)
 
template<class T >
Urho3D::Acos (T x)
 
template<class T >
Urho3D::Atan (T x)
 
template<class T >
Urho3D::Atan2 (T y, T x)
 
template<class T >
Urho3D::Pow (T x, T y)
 
template<class T >
Urho3D::Ln (T x)
 
template<class T >
Urho3D::Sqrt (T x)
 
template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
Urho3D::Mod (T x, T y)
 Return remainder of X/Y for float values. More...
 
template<class T >
Urho3D::AbsMod (T x, T y)
 Return always positive remainder of X/Y.
 
template<class T >
Urho3D::Fract (T value)
 
template<class T >
Urho3D::Floor (T x)
 
template<class T >
int Urho3D::FloorToInt (T x)
 
template<class T >
Urho3D::Round (T x)
 
template<class Iterator >
auto Urho3D::Average (Iterator begin, Iterator end) -> typename std::decay< decltype(*begin)>::type
 Compute average value of the range.
 
template<class T >
int Urho3D::RoundToInt (T x)
 
template<class T >
Urho3D::RoundToNearestMultiple (T x, T multiple)
 Round value to nearest multiple.
 
template<class T >
Urho3D::Ceil (T x)
 
template<class T >
int Urho3D::CeilToInt (T x)
 
bool Urho3D::IsPowerOfTwo (unsigned value)
 Check whether an unsigned integer is a power of two.
 
unsigned Urho3D::NextPowerOfTwo (unsigned value)
 Round up to next power of two.
 
unsigned Urho3D::ClosestPowerOfTwo (unsigned value)
 Round up or down to the closest power of two.
 
unsigned Urho3D::LogBaseTwo (unsigned value)
 Return log base two or the MSB position of the given value.
 
unsigned Urho3D::CountSetBits (unsigned value)
 Count the number of set bits in a mask.
 
constexpr unsigned Urho3D::SDBMHash (unsigned hash, unsigned char c)
 Update a hash with the given 8-bit value using the SDBM algorithm.
 
float Urho3D::Random ()
 Return a random float between 0.0 (inclusive) and 1.0 (exclusive).
 
float Urho3D::Random (float range)
 Return a random float between 0.0 and range, inclusive from both ends.
 
float Urho3D::Random (float min, float max)
 Return a random float between min and max, inclusive from both ends.
 
int Urho3D::Random (int range)
 
int Urho3D::Random (int min, int max)
 
float Urho3D::RandomNormal (float meanValue, float variance)
 Return a random normal distributed number with the given mean value and variance.
 
unsigned short Urho3D::FloatToHalf (float value)
 Convert float to half float. From https://gist.github.com/martinkallman/5049614.
 
float Urho3D::HalfToFloat (unsigned short value)
 Convert half float to float. From https://gist.github.com/martinkallman/5049614.
 
void Urho3D::SinCos (float angle, float &sin, float &cos)
 Calculate both sine and cosine, with angle in degrees.
 

Variables

static const float Urho3D::M_PI = 3.14159265358979323846264338327950288f
 
static const float Urho3D::M_HALF_PI = M_PI * 0.5f
 
static const int Urho3D::M_MIN_INT = 0x80000000
 
static const int Urho3D::M_MAX_INT = 0x7fffffff
 
static const unsigned Urho3D::M_MIN_UNSIGNED = 0x00000000
 
static const unsigned Urho3D::M_MAX_UNSIGNED = 0xffffffff
 
static const float Urho3D::M_EPSILON = 0.000001f
 
static const float Urho3D::M_LARGE_EPSILON = 0.00005f
 
static const float Urho3D::M_MIN_NEARCLIP = 0.01f
 
static const float Urho3D::M_MAX_FOV = 160.0f
 
static const float Urho3D::M_LARGE_VALUE = 100000000.0f
 
static const float Urho3D::M_INFINITY = (float)HUGE_VAL
 
static const float Urho3D::M_DEGTORAD = M_PI / 180.0f
 
static const float Urho3D::M_DEGTORAD_2 = M_PI / 360.0f
 
static const float Urho3D::M_RADTODEG = 1.0f / M_DEGTORAD
 

Function Documentation

◆ Abs()

template<class T >
T Urho3D::Abs ( value)
inline

Return absolute value of a value.

Here is the call graph for this function:

◆ Acos()

template<class T >
T Urho3D::Acos ( x)
inline

Return arc cosine in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Asin()

template<class T >
T Urho3D::Asin ( x)
inline

Return arc sine in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Atan()

template<class T >
T Urho3D::Atan ( x)
inline

Return arc tangent in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Atan2()

template<class T >
T Urho3D::Atan2 ( y,
x 
)
inline

Return arc tangent of y/x in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ceil()

template<class T >
T Urho3D::Ceil ( x)
inline

Round value up.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CeilToInt()

template<class T >
int Urho3D::CeilToInt ( x)
inline

Round value up.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clamp()

template<class T >
T Urho3D::Clamp ( value,
min,
max 
)
inline

Clamp a number to a range.

Here is the call graph for this function:

◆ Cos()

template<class T >
T Urho3D::Cos ( angle)
inline

Return cosine of an angle in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Equals()

template<class T >
bool Urho3D::Equals ( lhs,
rhs 
)
inline

Check whether two floating point values are equal within accuracy.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Floor()

template<class T >
T Urho3D::Floor ( x)
inline

Round value down.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FloorToInt()

template<class T >
int Urho3D::FloorToInt ( x)
inline

Round value down. Returns integer value.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Fract()

template<class T >
T Urho3D::Fract ( value)
inline

Return fractional part of passed value in range [0, 1).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InverseLerp()

template<class T >
T Urho3D::InverseLerp ( lhs,
rhs,
x 
)
inline

Inverse linear interpolation between two values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsNaN()

template<class T >
bool Urho3D::IsNaN ( value)
inline

Check whether a floating point value is NaN.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Lerp()

template<class T , class U >
T Urho3D::Lerp ( lhs,
rhs,
t 
)
inline

Linear interpolation between two values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ln()

template<class T >
T Urho3D::Ln ( x)
inline

Return natural logarithm of X.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Max()

template<class T , class U >
T Urho3D::Max ( lhs,
rhs 
)
inline

Return the larger of two values.

Here is the call graph for this function:

◆ Min()

template<class T , class U >
T Urho3D::Min ( lhs,
rhs 
)
inline

Return the smaller of two values.

Here is the call graph for this function:

◆ Mod()

template<class T , typename std::enable_if< std::is_floating_point< T >::value >::type * = nullptr>
T Urho3D::Mod ( x,
y 
)
inline

Return remainder of X/Y for float values.

Return remainder of X/Y for integer values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Pow()

template<class T >
T Urho3D::Pow ( x,
y 
)
inline

Return X in power Y.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Random() [1/2]

int Urho3D::Random ( int  min,
int  max 
)
inline

Return a random integer between min and max - 1.

Here is the call graph for this function:

◆ Random() [2/2]

int Urho3D::Random ( int  range)
inline

Return a random integer between 0 and range - 1.

Here is the call graph for this function:

◆ Round()

template<class T >
T Urho3D::Round ( x)
inline

Round value to nearest integer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RoundToInt()

template<class T >
int Urho3D::RoundToInt ( x)
inline

Round value to nearest integer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sign()

template<class T >
T Urho3D::Sign ( value)
inline

Return the sign of a float (-1, 0 or 1).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sin()

template<class T >
T Urho3D::Sin ( angle)
inline

Return sine of an angle in degrees.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SmoothStep()

template<class T >
T Urho3D::SmoothStep ( lhs,
rhs,
t 
)
inline

Smoothly damp between values.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sqrt()

template<class T >
T Urho3D::Sqrt ( x)
inline

Return square root of X.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Tan()

template<class T >
T Urho3D::Tan ( angle)
inline

Return tangent of an angle in degrees.

Here is the call graph for this function:
Here is the caller graph for this function: