Rebel Fork Framework
MathDefs.h File Reference
#include "../Math/Random.h"
#include <EASTL/span.h>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <limits>
#include <type_traits>

Enumerations

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

Functions

template<class T >
bool Urho3D::Equals (T lhs, T rhs, T eps=M_EPSILON)
 
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::VectorClamp (const T &value, const T &min, const T &max)
 Per-component clamp of vector.
 
template<class T >
Urho3D::SmoothStep (T lhs, T rhs, T t)
 
template<class T >
Urho3D::ExponentialDecay (T x)
 Calculate exponential decay function.
 
template<class T >
Urho3D::InverseExponentialDecay (T x)
 
template<class T , class U >
Urho3D::Smooth (const T &lhs, const T &rhs, U t)
 
template<class T , class U >
Urho3D::Smooth (const T &lhs, const T &rhs, U halfTime, U timeStep)
 Same as Smooth(lhs, rhs, timeStep / halfTime).
 
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 >
Urho3D::SnapFloor (T x, T y)
 Round value down to nearest number that can be represented as i*y, where i is integer.
 
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 >
Urho3D::SnapRound (T x, T y)
 Round value to nearest number that can be represented as i*y, where i is integer.
 
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 >
Urho3D::SnapCeil (T x, T y)
 Round value up to nearest number that can be represented as i*y, where i is integer.
 
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.
 
template<typename T >
Urho3D::Wrap (T value, T min, T max)
 Wrap a value fitting it in the range defined by [min, max)
 
void Urho3D::SinCos (float angle, float &sin, float &cos)
 Calculate both sine and cosine, with angle in degrees.
 
template<class T >
unsigned Urho3D::EncodeVariableLength (T value, ea::span< unsigned char, MaxVariableLengthBytes< T >> dest)
 
template<class T >
bool Urho3D::DecodeVariableLength (T &value, unsigned &offset, unsigned char byte)
 

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
 
template<class T >
constexpr size_t Urho3D::MaxVariableLengthBytes = (sizeof(T) * 8 + 6) / 7
 Return max number of bytes taken by a variable-length encoded integer of the given type.
 

Function Documentation

◆ Abs()

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

Return absolute value of a value.

◆ Acos()

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

Return arc cosine in degrees.

◆ Asin()

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

Return arc sine in degrees.

◆ Atan()

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

Return arc tangent in degrees.

◆ Atan2()

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

Return arc tangent of y/x in degrees.

◆ Ceil()

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

Round value up.

◆ CeilToInt()

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

Round value up.

◆ Clamp()

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

Clamp a number to a range.

◆ Cos()

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

Return cosine of an angle in degrees.

◆ DecodeVariableLength()

template<class T >
bool Urho3D::DecodeVariableLength ( T &  value,
unsigned &  offset,
unsigned char  byte 
)

Decode variable-length encoded integer (one step). Return true if the value is complete.

◆ EncodeVariableLength()

template<class T >
unsigned Urho3D::EncodeVariableLength ( value,
ea::span< unsigned char, MaxVariableLengthBytes< T >>  dest 
)

Convert integer to variable-length encoded byte array. Returns the number of bytes written.

◆ Equals()

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

Check whether two floating point values are equal within accuracy.

◆ Floor()

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

Round value down.

◆ FloorToInt()

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

Round value down. Returns integer value.

◆ Fract()

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

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

◆ InverseLerp()

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

Inverse linear interpolation between two values.

◆ IsNaN()

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

Check whether a floating point value is NaN.

◆ Lerp()

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

Linear interpolation between two values.

◆ Ln()

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

Return natural logarithm of X.

◆ Max()

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

Return the larger of two values.

◆ Min()

template<class T , class U >
T Urho3D::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 Urho3D::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 Urho3D::Pow ( x,
y 
)
inline

Return X in power Y.

◆ Random() [1/2]

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

Return a random integer between min and max - 1.

◆ Random() [2/2]

int Urho3D::Random ( int  range)
inline

Return a random integer between 0 and range - 1.

◆ Round()

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

Round value to nearest integer.

◆ RoundToInt()

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

Round value to nearest integer.

◆ Sign()

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

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

◆ Sin()

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

Return sine of an angle in degrees.

◆ Smooth()

template<class T , class U >
T Urho3D::Smooth ( const T &  lhs,
const T &  rhs,
t 
)

Apply exponential smoothing to raw value. Typical usage: smoothValue = Smooth(smoothValue, rawValue, timeStep / halfTimeOfSmoothing) or smoothValue = Smooth(smoothValue, rawValue, timeStep * smoothingRate)

◆ SmoothStep()

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

Smoothly damp between values.

◆ Sqrt()

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

Return square root of X.

◆ Tan()

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

Return tangent of an angle in degrees.