Urho3D
Enumerations | Functions | Variables
MathDefs.h File Reference
#include "../Math/Random.h"
#include <cstdlib>
#include <cmath>
#include <limits>
#include <type_traits>

Enumerations

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

Functions

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

Variables

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

Function Documentation

◆ Abs()

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

Return absolute value of a value.

◆ Acos()

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

Return arc cosine in degrees.

◆ Asin()

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

Return arc sine in degrees.

◆ Atan()

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

Return arc tangent in degrees.

◆ Atan2()

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

Return arc tangent of y/x in degrees.

◆ Ceil()

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

Round value up.

◆ CeilToInt()

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

Round value up.

◆ Clamp()

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

Clamp a number to a range.

◆ Cos()

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

Return cosine of an angle in degrees.

◆ Equals()

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

Check whether two floating point values are equal within accuracy.

◆ Floor()

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

Round value down.

◆ FloorToInt()

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

Round value down. Returns integer value.

◆ Fract()

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

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

◆ InverseLerp()

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

Inverse linear interpolation between two values.

◆ IsNaN()

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

Check whether a floating point value is NaN.

◆ Lerp()

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

Linear interpolation between two values.

◆ Ln()

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

Return natural logarithm of X.

◆ Max()

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

Return the larger of two values.

◆ Min()

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

Return the smaller of two values.

◆ Mod()

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

Return remainder of X/Y for float values.

Return remainder of X/Y for integer values.

◆ Pow()

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

Return X in power Y.

◆ Random() [1/2]

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

Return a random integer between min and max - 1.

◆ Random() [2/2]

int Dviglo::Random ( int  range)
inline

Return a random integer between 0 and range - 1.

◆ Round()

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

Round value to nearest integer.

◆ RoundToInt()

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

Round value to nearest integer.

◆ Sign()

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

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

◆ Sin()

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

Return sine of an angle in degrees.

◆ SmoothStep()

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

Smoothly damp between values.

◆ Sqrt()

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

Return square root of X.

◆ Tan()

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

Return tangent of an angle in degrees.