ezEngine  Milestone 9
ezMath Namespace Reference

This namespace provides common math-functionality as functions. More...

Classes

struct  BasicType
 

Functions

template<typename T >
constexpr EZ_ALWAYS_INLINE T Square (T f)
 Returns f * f.
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Sign (T f)
 Returns the sign of f (i.e: -1, 1 or 0)
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Abs (T f)
 Returns the absolute value of f.
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Min (T f1, T f2)
 Returns the smaller value, f1 or f2.
 
template<typename T , typename... ARGS>
constexpr EZ_ALWAYS_INLINE T Min (T f1, T f2, ARGS... f)
 Returns the smaller value, f1 or f2 or ...
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Max (T f1, T f2)
 Returns the greater value, f1 or f2.
 
template<typename T , typename... ARGS>
constexpr EZ_ALWAYS_INLINE T Max (T f1, T f2, ARGS... f)
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Clamp (T value, T min_val, T max_val)
 Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already.
 
template<typename T >
constexpr EZ_ALWAYS_INLINE T Saturate (T value)
 Clamps "value" to the range [0; 1]. Returns "value", if it is inside the range already.
 
template<typename Type >
constexpr Type Invert (Type f)
 Returns 1 / f.
 
EZ_ALWAYS_INLINE ezUInt32 FirstBitLow (ezUInt32 value)
 Returns the index of the least significant bit set.
 
EZ_ALWAYS_INLINE ezUInt32 FirstBitHigh (ezUInt32 value)
 Returns the index of the most significant bit set.
 
EZ_ALWAYS_INLINE ezUInt32 CountBits (ezUInt32 value)
 Returns the number of bits set.
 
template<typename T >
EZ_ALWAYS_INLINE void Swap (T &f1, T &f2)
 Swaps the values in the two variables f1 and f2.
 
template<typename T >
EZ_FORCE_INLINE T Lerp (T f1, T f2, float factor)
 Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
 
template<typename T >
EZ_FORCE_INLINE T Lerp (T f1, T f2, double factor)
 Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
 
template<typename T >
constexpr EZ_FORCE_INLINE T Step (T value, T edge)
 Returns 0, if value < edge, and 1, if value >= edge.
 
constexpr EZ_FORCE_INLINE bool IsPowerOf2 (ezInt32 value)
 Returns true, if there exists some x with 2^x == value.
 
template<typename Type >
constexpr bool IsEqual (Type lhs, Type rhs, Type fEpsilon)
 Checks, whether fValue is in the range [fDesired - fMaxImprecision; fDesired + fMaxImprecision].
 
template<typename T >
constexpr bool IsInRange (T Value, T MinVal, T MaxVal)
 Checks whether the value of the first parameter lies between the value of the second and third.
 
template<typename Type >
bool IsZero (Type f, Type fEpsilon)
 Checks whether the given number is close to zero.
 
template<typename Type >
EZ_ALWAYS_INLINE Type Trunc (Type f)
 Returns the integer-part of f (removes the fraction).
 
template<typename Type >
EZ_ALWAYS_INLINE Type Fraction (Type f)
 Returns the fraction-part of f.
 
template<typename Type >
Type SmoothStep (Type value, Type edge1, Type edge2)
 Returns 0, if value is <= edge1, 1 if value >= edge2 and the hermite interpolation in between.
 
ezUInt8 ColorFloatToByte (float value)
 Converts a color value from float [0;1] range to unsigned byte [0;255] range, with proper rounding.
 
ezUInt16 ColorFloatToShort (float value)
 Converts a color value from float [0;1] range to unsigned short [0;65535] range, with proper rounding.
 
ezInt8 ColorFloatToSignedByte (float value)
 Converts a color value from float [-1;1] range to signed byte [-127;127] range, with proper rounding.
 
constexpr float ColorByteToFloat (ezUInt8 value)
 Converts a color value from unsigned byte [0;255] range to float [0;1] range, with proper rounding.
 
constexpr float ColorShortToFloat (ezUInt16 value)
 Converts a color value from unsigned short [0;65535] range to float [0;1] range, with proper rounding.
 
constexpr float ColorSignedByteToFloat (ezInt8 value)
 Converts a color value from signed byte [-128;127] range to float [-1;1] range, with proper rounding.
 
template<typename T , typename T2 >
EvaluateBezierCurve (T2 t, const T &startPoint, const T &controlPoint1, const T &controlPoint2, const T &endPoint)
 Evaluates the cubic spline defined by four control points at time t and returns the interpolated result. Can be used with T as float, vec2, vec3 or vec4.
 
EZ_ALWAYS_INLINE bool IsFinite (double value)
 
EZ_ALWAYS_INLINE bool IsNaN (double value)
 
EZ_ALWAYS_INLINE double Floor (double f)
 
EZ_ALWAYS_INLINE double Ceil (double f)
 
EZ_ALWAYS_INLINE double Round (double f)
 Rounds f to the next integer. More...
 
double RoundDown (double f, double fMultiple)
 Returns a multiple of fMultiple that is smaller than f.
 
double RoundUp (double f, double fMultiple)
 Returns a multiple of fMultiple that is larger than f.
 
EZ_ALWAYS_INLINE double RoundToMultiple (double f, double multiple)
 Rounds f to the closest value of multiple.
 
EZ_ALWAYS_INLINE double Exp (double f)
 
EZ_ALWAYS_INLINE double Ln (double f)
 
EZ_ALWAYS_INLINE double Log2 (double f)
 
EZ_ALWAYS_INLINE double Log10 (double f)
 
EZ_ALWAYS_INLINE double Log (double fBase, double f)
 
EZ_ALWAYS_INLINE double Pow2 (double f)
 
EZ_ALWAYS_INLINE double Pow (double base, double exp)
 
EZ_ALWAYS_INLINE double Root (double f, double NthRoot)
 
EZ_ALWAYS_INLINE double Sqrt (double f)
 Returns the square root of f.
 
EZ_ALWAYS_INLINE double Mod (double f, double div)
 Returns "value mod div" for doubles. This also works with negative numbers, both for value and for div.
 
EZ_ALWAYS_INLINE bool IsFinite (float value)
 
EZ_ALWAYS_INLINE bool IsNaN (float value)
 
EZ_ALWAYS_INLINE float Floor (float f)
 Returns the next smaller integer, closest to f. Also the SMALLER value, if f is negative.
 
EZ_ALWAYS_INLINE float Ceil (float f)
 Returns the next higher integer, closest to f. Also the HIGHER value, if f is negative.
 
EZ_ALWAYS_INLINE float Round (float f)
 Rounds f to the next integer. More...
 
EZ_ALWAYS_INLINE float RoundToMultiple (float f, float multiple)
 Rounds f to the closest value of multiple.
 
float RoundDown (float f, float fMultiple)
 Returns a multiple of fMultiple that is smaller than f.
 
float RoundUp (float f, float fMultiple)
 Returns a multiple of fMultiple that is larger than f.
 
EZ_ALWAYS_INLINE float Sin (ezAngle a)
 ***** Trigonometric Functions ***** More...
 
EZ_ALWAYS_INLINE float Cos (ezAngle a)
 Takes an angle, returns its cosine.
 
EZ_ALWAYS_INLINE float Tan (ezAngle a)
 Takes an angle, returns its tangent.
 
EZ_ALWAYS_INLINE ezAngle ASin (float f)
 Returns the arcus sinus of f.
 
EZ_ALWAYS_INLINE ezAngle ACos (float f)
 Returns the arcus cosinus of f.
 
EZ_ALWAYS_INLINE ezAngle ATan (float f)
 Returns the arcus tangent of f.
 
EZ_ALWAYS_INLINE ezAngle ATan2 (float x, float y)
 Returns the atan2 of x and y.
 
EZ_ALWAYS_INLINE float Exp (float f)
 Returns e^f.
 
EZ_ALWAYS_INLINE float Ln (float f)
 Returns the logarithmus naturalis of f.
 
EZ_ALWAYS_INLINE float Log2 (float f)
 Returns log (f), to the base 2.
 
EZ_ALWAYS_INLINE float Log10 (float f)
 Returns log (f), to the base 10.
 
EZ_ALWAYS_INLINE float Log (float fBase, float f)
 Returns log (f), to the base fBase.
 
EZ_ALWAYS_INLINE float Pow2 (float f)
 Returns 2^f.
 
EZ_ALWAYS_INLINE float Pow (float base, float exp)
 Returns base^exp.
 
EZ_ALWAYS_INLINE float Root (float f, float NthRoot)
 Returns the n-th root of f.
 
EZ_ALWAYS_INLINE float Sqrt (float f)
 Returns the square root of f.
 
EZ_ALWAYS_INLINE float Mod (float value, float div)
 Returns "value mod div" for floats. This also works with negative numbers, both for value and for div.
 
constexpr EZ_ALWAYS_INLINE ezInt32 RoundUp (ezInt32 value, ezUInt16 multiple)
 
constexpr EZ_ALWAYS_INLINE ezInt32 RoundDown (ezInt32 value, ezUInt16 multiple)
 
constexpr EZ_ALWAYS_INLINE ezUInt32 RoundUp (ezUInt32 value, ezUInt16 multiple)
 
constexpr EZ_ALWAYS_INLINE ezUInt32 RoundDown (ezUInt32 value, ezUInt16 multiple)
 
constexpr EZ_ALWAYS_INLINE bool IsOdd (ezInt32 i)
 Returns true, if i is an odd number.
 
constexpr EZ_ALWAYS_INLINE bool IsEven (ezInt32 i)
 Returns true, if i is an even number.
 
ezUInt32 Log2i (ezUInt32 val)
 Returns the integral logarithm to the base 2, that comes closest to the given integer.
 
constexpr EZ_ALWAYS_INLINE int Pow2 (ezInt32 i)
 Returns 2^f.
 
int Pow (ezInt32 base, ezInt32 exp)
 Returns base^exp.
 
template<typename T >
constexpr T Square (T f)
 Returns f * f.
 
template<typename T >
constexpr T Sign (T f)
 Returns the sign of f (i.e: -1, 1 or 0)
 
template<typename T >
constexpr T Abs (T f)
 Returns the absolute value of f.
 
template<typename T >
constexpr T Min (T f1, T f2)
 Returns the smaller value, f1 or f2.
 
template<typename T , typename... ARGS>
constexpr T Min (T f1, T f2, ARGS... f)
 Returns the smaller value, f1 or f2 or ...
 
template<typename T >
constexpr T Max (T f1, T f2)
 Returns the greater value, f1 or f2.
 
template<typename T >
constexpr T Clamp (T value, T min_val, T max_val)
 Clamps "value" to the range [min; max]. Returns "value", if it is inside the range already.
 
template<typename T >
constexpr T Saturate (T value)
 Clamps "value" to the range [0; 1]. Returns "value", if it is inside the range already.
 
template<typename Type >
Type Trunc (Type f)
 Returns the integer-part of f (removes the fraction).
 
template<typename Type >
Type Fraction (Type f)
 Returns the fraction-part of f.
 
template<typename T >
void Swap (T &f1, T &f2)
 Swaps the values in the two variables f1 and f2.
 
template<typename T >
Lerp (T f1, T f2, float factor)
 Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
 
template<typename T >
Lerp (T f1, T f2, double factor)
 Returns the linear interpolation of f1 and f2. factor is a value between 0 and 1.
 
template<typename T >
constexpr T Step (T value, T edge)
 Returns 0, if value < edge, and 1, if value >= edge.
 
EZ_FOUNDATION_DLL bool IsPowerOf (ezInt32 value, ezInt32 base)
 Returns true, if there exists some x with base^x == value.
 
EZ_FOUNDATION_DLL ezUInt32 PowerOfTwo_Floor (ezUInt32 value)
 Returns the next power-of-two that is <= value.
 
EZ_FOUNDATION_DLL ezUInt32 PowerOfTwo_Ceil (ezUInt32 value)
 Returns the next power-of-two that is >= value.
 
EZ_FOUNDATION_DLL ezUInt32 GreatestCommonDivisor (ezUInt32 a, ezUInt32 b)
 Returns the greatest common divisor.
 

Detailed Description

This namespace provides common math-functionality as functions.

It is a namespace, instead of a static class, because that allows it to be extended at other locations, which is especially useful when adding custom types.

Function Documentation

◆ Round() [1/2]

double ezMath::Round ( double  f)

Rounds f to the next integer.

If f is positive 0.5 is rounded UP (i.e. to 1), if f is negative, -0.5 is rounded DOWN (i.e. to -1).

◆ Round() [2/2]

float ezMath::Round ( float  f)

Rounds f to the next integer.

If f is positive 0.5 is rounded UP (i.e. to 1), if f is negative, -0.5 is rounded DOWN (i.e. to -1).

◆ Sin()

float ezMath::Sin ( ezAngle  a)

***** Trigonometric Functions *****

Takes an angle, returns its sine