All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Math Namespace Reference

Math functions and constants for Nimble. More...

Functions

template<class T >
Average (const T &a, const T &b)
 Calculates the average of arguments a and b. More...
 
template<class T >
bilerp (const T &s00, const T &s10, const T &s01, const T &s11, float u, float v)
 Perform bi-linear interpolation between four samples.
 
template<class T >
calculateAbsSum (const T *values, int n)
 Calculates the sum of the absolute values in the argument array. More...
 
template<class T >
void calculateMeanVariance (const T *values, int n, T *mean, T *variance)
 Calculates the mean and variance of a buffer of values.
 
template<class T , class U >
void calculatePrincipalAxes (const T *values, int n, U &axis1, U &axis2, float *variance1=0, float *variance2=0)
 Calculate the two principal axes in 2d data Length of the axes are the corresponding eigenvalues. More...
 
template<class T >
Clamp (T x, T low, T high)
 Clamp a value between minimum and maximum values. More...
 
double degToRad (const double degrees)
 Converts degrees into radians.
 
template<class T >
Det (T a, T b, T c, T d)
 Calculates the determinant of a 2x2 matrix, which is given in the argument values. More...
 
template<class T >
Fraction (T x)
 Calculates the fraction of the floating point number.
 
template<typename T >
bool fuzzyCompare (const T &a, const T &b)
 Compare two values. More...
 
template<>
bool fuzzyCompare (const int &a, const int &b)
 
float InvSqrt (float v)
 Returns the inverse square root.
 
double InvSqrt (double v)
 Returns the inverse square root.
 
template<class T >
bool IsClose (const T &a, const T &b, const T &limit)
 Checks if two (floating point) numbers are close to each other. More...
 
bool isFinite (float v)
 Checks if the given value if finite.
 
bool isNAN (float v)
 Checks if the given number is a NaN. More...
 
template<class T >
lerp (const T &a, const T &b, float t)
 Perform linear interpolation between two samples.
 
float Log2 (float v)
 Returns the logarithm in base 2.
 
double Log2 (double v)
 Returns the logarithm in base 2.
 
template<class T >
Max (T x, T y)
 Returns the maximum of the values.
 
template<class T >
Max (T a, T b, T c)
 Returns the maximum of the values.
 
template<class T >
Max (T a, T b, T c, T d)
 Returns the maximum of the values.
 
template<class T >
Min (T x, T y)
 Returns the minimum of the values.
 
template<class T >
Min (T a, T b, T c)
 Returns the minimum of the values.
 
template<class T >
Min (T a, T b, T c, T d)
 Returns the minimum of the values.
 
double radToDeg (const double radians)
 Converts radians to degrees.
 
int Round (float x)
 Rounds the given number to nearest integer.
 
int Round (double x)
 Rounds the given number to nearest integer.
 
template<class T >
Vector2T< int > Round (const Vector2T< T > &that)
 Round the vector component-wise to the given vector.
 
template<typename T >
Roundf (T x)
 Same thing as std::round with floating point types Only exists because visual studio 2012 doesn't implement std::round.
 
template<class T >
int Sign (T v)
 Return sign.
 
template<class T >
smoothstep (const T &a, const T &b, float t)
 Interpolate smoothly between two values based on third (Texturing and Modeling, Third Edition: A Procedural Approach, by Ken Perlin)
 
template<class T >
threePointInterpolation (float x1, const T &v1, float x2, const T &v2, float x3, const T &v3, float x)
 Given three points on a line, interpolate between them.
 
template<class T >
Wrap (T x, T low, T high)
 Wraps the input value between minimum and maximum values For example you can normalize radians by Wrap(angle, 0, 2*PI) More...
 

Variables

const double HALF_PI = 1.57079632679489660
 Pi divided by two.
 
const double PI = 3.1415926535897931
 Pi.
 
const double QUARTER_PI = 0.78539816339744828
 Pi divided by four.
 
const double SQRT2 = 1.41421356237309514547
 Square root of two.
 
const double SQRT2_PER2 = 0.70710678118654757273
 Square root of two divided by two.
 
const double TWO_PI = 6.2831853071795862
 Pi times two.
 

Detailed Description

Math functions and constants for Nimble.

This namespace contains mathematics constants (pi, ln2 etc.) and basic functions.

Function Documentation

template<class T >
T Nimble::Math::Average ( const T &  a,
const T &  b 
)
inline

Calculates the average of arguments a and b.

Parameters
afirst argument
bsecond argument
Returns
(a + b) * 0.5f;
template<class T >
T Nimble::Math::calculateAbsSum ( const T *  values,
int  n 
)
inline

Calculates the sum of the absolute values in the argument array.

Parameters
valuesArray of values
nNumber of elements in the array
Returns
Sum of absolute values
template<class T , class U >
void Nimble::Math::calculatePrincipalAxes ( const T *  values,
int  n,
U &  axis1,
U &  axis2,
float *  variance1 = 0,
float *  variance2 = 0 
)

Calculate the two principal axes in 2d data Length of the axes are the corresponding eigenvalues.

Parameters
valuesArray of values, the value type must support operator[] for indices 0 and 1
nNumber of values
axis1The major axis
axis2The minor axis
variance1Variance for the projection of values to the major axis
variance2Variance for the projection of values to the minor axis
template<class T >
T Nimble::Math::Clamp ( x,
low,
high 
)
inline

Clamp a value between minimum and maximum values.

Parameters
xThe input value to limit.
lowThe minimum value for comparison
highThe maximum value for comparison
Returns
Clamped value
template<class T >
T Nimble::Math::Det ( a,
b,
c,
d 
)
inline

Calculates the determinant of a 2x2 matrix, which is given in the argument values.

Parameters
aupper-left of the matrix
bupper-right of the matrix
clower-left of the matrix
dlower-right of the matrix
Returns
Determinant
template<typename T >
bool Nimble::Math::fuzzyCompare ( const T &  a,
const T &  b 
)

Compare two values.

Parameters
afirst value to compare
bsecond value to compare
Returns
true if the values are close to identical; otherwise false
template<class T >
bool Nimble::Math::IsClose ( const T &  a,
const T &  b,
const T &  limit 
)

Checks if two (floating point) numbers are close to each other.

This function is usually used to check if two floating-point numbers are close to each other - the numbers do not need to be exactly the same.

Parameters
aThe first value to compare.
bThe second value to compare.
limitThe maximum difference between the values.
Returns
True if the difference between the numbers is small enough
bool Nimble::Math::isNAN ( float  v)
inline

Checks if the given number is a NaN.

Parameters
vnumber to check
Returns
Check result
template<class T >
T Nimble::Math::Wrap ( x,
low,
high 
)
inline

Wraps the input value between minimum and maximum values For example you can normalize radians by Wrap(angle, 0, 2*PI)

Parameters
xThe input value to wrap.
lowThe minimum value
highThe maximum value
Returns
Wrapped values