Tizen Native API
Math

Basic math classes. More...

## Classes

struct  Dali::Power< mantissa, exponent >
Compile time template to calculate base to the power of N. More...
struct  Dali::Power< mantissa, 1 >
Compile time template to calculate base to the power of N. More...
struct  Dali::Power< mantissa, 0 >
Compile time template to calculate base to the power of N. More...
struct  Dali::Log< number, base >
Compile time template to calculate base logarithm of N. More...
struct  Dali::Log< 1, base >
Compile time template to calculate base logarithm of N. More...
struct  Dali::Log< 0, base >
Compile time template to calculate base logarithm of N. More...
struct  Dali::Epsilon< N >
Compile time template to calculate the machine epsilon for a given floating point number. More...
struct  Dali::Epsilon< 1 >
Compile time template to calculate the machine epsilon for a given floating point number. More...
struct  Dali::Epsilon< 0 >
Compile time template to calculate the machine epsilon for a given floating point number. More...
struct  Dali::Degree
An angle in degrees. More...
class  Dali::Matrix
The Matrix class represents transformations and projections. More...
class  Dali::Matrix3
A 3x3 matrix. More...
class  Dali::Quaternion
The Quaternion class encapsulates the mathematics of the quaternion. More...
class  Dali::Uint16Pair
Simple class for passing around pairs of small unsigned integers. More...
struct  Dali::Vector2
A two dimensional vector. More...
struct  Dali::Vector3
A three dimensional vector. More...
struct  Dali::Vector4
A four dimensional vector. More...

## Functions

bool Dali::operator== (const Degree &lhs, const Degree &rhs)
Compare equality between two degrees.
bool Dali::operator!= (const Degree &lhs, const Degree &rhs)
Compare inequality between two degrees.
Degree Dali::Clamp (Degree angle, float min, float max)
unsigned int Dali::NextPowerOfTwo (unsigned int i)
Returns the next power of two.
bool Dali::IsPowerOfTwo (unsigned int i)
Whether a number is power of two.
template<typename T >
const T & Dali::Clamp (const T &value, const T &min, const T &max)
Clamp a value.
template<typename T >
void Dali::ClampInPlace (T &value, const T &min, const T &max)
Clamp a value directly.
template<typename T >
const T Dali::Lerp (const float offset, const T &low, const T &high)
Linear interpolation between two values.
float Dali::GetRangedEpsilon (float a, float b)
Get an epsilon that is valid for the given range.
bool Dali::EqualsZero (float value)
Helper function to compare equality of a floating point value with zero.
bool Dali::Equals (float a, float b)
Helper function to compare equality of two floating point values.
bool Dali::Equals (float a, float b, float epsilon)
Helper function to compare equality of two floating point values.
float Dali::Round (float value, int pos)
Get an float that is rounded at specified place of decimals.
float Dali::WrapInDomain (float x, float start, float end)
Wrap x in domain (start) to (end).
float Dali::ShortestDistanceInDomain (float a, float b, float start, float end)
Find the shortest distance (magnitude) and direction (sign) from (a) to (b) in domain (start) to (end).
std::ostream & Dali::operator<< (std::ostream &o, const Matrix &matrix)
Print a matrix.
std::ostream & Dali::operator<< (std::ostream &o, const Matrix3 &matrix)
Print a 3x3 matrix.
std::ostream & Dali::operator<< (std::ostream &o, const Quaternion &quaternion)
Print a Quaternion.
bool Dali::operator== (Radian lhs, Degree rhs)
Compare equality between a radian and degree.
bool Dali::operator!= (Radian lhs, Degree rhs)
Compare inequality between a radian and a degree.
bool Dali::operator== (Degree lhs, Radian rhs)
Compare equality between a degree and a radian.
bool Dali::operator!= (Degree lhs, Radian rhs)
Compare inequality between a degree and a radian.
Compare greater than between two radians.
bool Dali::operator> (Radian lhs, Degree rhs)
Compare greater than between a radian and a degree.
bool Dali::operator> (Degree lhs, Radian rhs)
Compare greater than between a radian and a degree.
Compare less than between two radians.
bool Dali::operator< (Radian lhs, Degree rhs)
Compare less than between a radian and a degree.
bool Dali::operator< (Degree lhs, Radian rhs)
Compare less than between a degree and a radian.
std::ostream & Dali::operator<< (std::ostream &o, const Vector2 &vector)
Print a Vector2.
Vector2 Dali::Min (const Vector2 &a, const Vector2 &b)
Returns a vector with components set to the minimum of the corresponding component in a and b.
Vector2 Dali::Max (const Vector2 &a, const Vector2 &b)
Returns a vector with components set to the maximum of the corresponding component in a and b.
Vector2 Dali::Clamp (const Vector2 &v, const float &min, const float &max)
Clamps each of vector v's components between minimum and maximum values.
std::ostream & Dali::operator<< (std::ostream &o, const Vector3 &vector)
Print a Vector3.
Vector3 Dali::Min (const Vector3 &a, const Vector3 &b)
Returns a vector with components set to the minimum of the corresponding component in a and b.
Vector3 Dali::Max (const Vector3 &a, const Vector3 &b)
Returns a vector with components set to the maximum of the corresponding component in a and b.
Vector3 Dali::Clamp (const Vector3 &v, const float &min, const float &max)
Clamps each of vector v's components between minimum and maximum values.
std::ostream & Dali::operator<< (std::ostream &o, const Vector4 &vector)
Print a Vector4.
Vector4 Dali::Min (const Vector4 &a, const Vector4 &b)
Returns a vector with components set to the minimum of the corresponding component in a and b.
Vector4 Dali::Max (const Vector4 &a, const Vector4 &b)
Returns a vector with components set to the maximum of the corresponding component in a and b.
Vector4 Dali::Clamp (const Vector4 &v, const float &min, const float &max)
Clamps each of vector v's components between minimum and maximum values.

## Namespaces

namespace  Dali::Random

Provides methods to generate and use random values.

## Typedefs

typedef Vector2 Dali::Size
Size is an alias of Dali::Vector2.
typedef Rect< int > Dali::Viewport
Typedef for a viewport ( a rectangle representing a screen area ).

Basic math classes.

## Typedef Documentation

 typedef Vector2 Dali::Size

Size is an alias of Dali::Vector2.

Since :
2.4
 typedef Rect Dali::Viewport

Typedef for a viewport ( a rectangle representing a screen area ).

Since :
2.4

## Function Documentation

template<typename T >
 const T& Dali::Clamp ( const T & value, const T & min, const T & max )

Clamp a value.

Since :
2.4
Parameters:
 [in] value The value to clamp [in] min The minimum allowed value [in] max The maximum allowed value
Returns:
T the clamped value
 Degree Dali::Clamp ( Degree angle, float min, float max )

Since :
2.4
Parameters:
 angle to clamp min value max value
Returns:

Since :
2.4
Parameters:
 angle to clamp min value max value
Returns:
 Vector2 Dali::Clamp ( const Vector2 & v, const float & min, const float & max )

Clamps each of vector v's components between minimum and maximum values.

Since :
2.4
Parameters:
 [in] v A vector [in] min The minimum value [in] max The maximum value
Returns:
a vector containing the clamped components of v
 Vector3 Dali::Clamp ( const Vector3 & v, const float & min, const float & max )

Clamps each of vector v's components between minimum and maximum values.

Since :
2.4
Parameters:
 [in] v A vector [in] min The minimum value [in] max The maximum value
Returns:
A vector containing the clamped components of v
 Vector4 Dali::Clamp ( const Vector4 & v, const float & min, const float & max )

Clamps each of vector v's components between minimum and maximum values.

Since :
2.4
Parameters:
 [in] v A vector [in] min The minimum value [in] max The maximum value
Returns:
A vector containing the clamped components of v
template<typename T >
 void Dali::ClampInPlace ( T & value, const T & min, const T & max )

Clamp a value directly.

Since :
2.4
Parameters:
 [in,out] value The value that will be clamped [in] min The minimum allowed value [in] max The maximum allowed valu.
 bool Dali::Equals ( float a, float b )

Helper function to compare equality of two floating point values.

Since :
2.4
Parameters:
 [in] a The first value to compare [in] b The second value to compare
Returns:
True if the values are equal within a minimal epsilon for their values.
 bool Dali::Equals ( float a, float b, float epsilon )

Helper function to compare equality of two floating point values.

Since :
2.4
Parameters:
 [in] a The first value to compare [in] b The second value to compare [in] epsilon The minimum epsilon value that will be used to consider the values different
Returns:
True if the difference between the values is less than the epsilon.
 bool Dali::EqualsZero ( float value )

Helper function to compare equality of a floating point value with zero.

Since :
2.4
Parameters:
 [in] value The value to compare
Returns:
True if the value is equal to zero.
 float Dali::GetRangedEpsilon ( float a, float b )

Get an epsilon that is valid for the given range.

Since :
2.4
Parameters:
 [in] a The first value in the range [in] b The second value in the range
Returns:
A suitable epsilon
 bool Dali::IsPowerOfTwo ( unsigned int i )

Whether a number is power of two.

Since :
2.4
Parameters:
 [in] i Input number
Returns:
True if i is power of two.
template<typename T >
 const T Dali::Lerp ( const float offset, const T & low, const T & high )

Linear interpolation between two values.

Since :
2.4
Parameters:
 [in] offset The offset through the range `low` to `high`. This value is clamped between 0 and 1. [in] low Lowest value in range [in] high Highest value in range
Returns:
A value between low and high
 Vector2 Dali::Max ( const Vector2 & a, const Vector2 & b )

Returns a vector with components set to the maximum of the corresponding component in a and b.

If a=0,1 and b=1,0 returns a vector of 1,1

Since :
2.4
Parameters:
 [in] a a vector [in] b a vector
Returns:
a vector containing the maximum of each component from a and b
 Vector3 Dali::Max ( const Vector3 & a, const Vector3 & b )

Returns a vector with components set to the maximum of the corresponding component in a and b.

If a=0,1 and b=1,0 returns a vector of 1,1

Since :
2.4
Parameters:
 [in] a A vector [in] b A vector
Returns:
A vector containing the maximum of each component from a and b
 Vector4 Dali::Max ( const Vector4 & a, const Vector4 & b )

Returns a vector with components set to the maximum of the corresponding component in a and b.

If a=0,1,2,3 and b=4,0,1,2 returns a vector of 4,1,2,3

Since :
2.4
Parameters:
 [in] a A vector [in] b A vector
Returns:
A vector containing the maximum of each component from a and b
 Vector2 Dali::Min ( const Vector2 & a, const Vector2 & b )

Returns a vector with components set to the minimum of the corresponding component in a and b.

If a=0,1 and b=1,0 returns a vector of 0,0.

Since :
2.4
Parameters:
 [in] a a vector [in] b a vector
Returns:
a vector containing the minimum of each component from a and b
 Vector3 Dali::Min ( const Vector3 & a, const Vector3 & b )

Returns a vector with components set to the minimum of the corresponding component in a and b.

If a=0,1,2 and b=2,1,0 returns a vector of 2,1,2.

Since :
2.4
Parameters:
 [in] a A vector [in] b A vector
Returns:
A vector containing the minimum of each component from a and b
 Vector4 Dali::Min ( const Vector4 & a, const Vector4 & b )

Returns a vector with components set to the minimum of the corresponding component in a and b.

If a=0,1,2,3 and b=4,0,1,2 returns a vector of 0,0,1,2

Since :
2.4
Parameters:
 [in] a A vector [in] b A vector
Returns:
A vector containing the minimum of each component from a and b
 unsigned int Dali::NextPowerOfTwo ( unsigned int i )

Returns the next power of two.

In case of numbers which are already a power of two this function returns the original number. If i is zero returns 1.

Since :
2.4
Parameters:
 [in] i Input number
Returns:
The next power of two or i itself in case it's a power of two
 bool Dali::operator!= ( const Degree & lhs, const Degree & rhs )

Compare inequality between two degrees.

Since :
2.4
Parameters:
 [in] lhs Degree to compare [in] rhs Degree to compare to
Returns:
true if the values are not identical

Since :
2.4
Parameters:
Returns:
true if the values are not identical
 bool Dali::operator!= ( Radian lhs, Degree rhs )

Compare inequality between a radian and a degree.

Since :
2.4
Parameters:
 [in] lhs Radian to compare [in] rhs Degree to compare to
Returns:
true if the values are not identical
 bool Dali::operator!= ( Degree lhs, Radian rhs )

Compare inequality between a degree and a radian.

Since :
2.4
Parameters:
 [in] lhs Degree to compare [in] rhs Radian to compare to
Returns:
true if the values are not identical

Since :
2.4
Parameters:
 [in] lhs Radian to multiply [in] rhs float to multiply
Returns:
result of the multiplication

Since :
2.4
Returns:
The negative angle

Compare less than between two radians.

Since :
2.4
Parameters:
Returns:
true if lhs is less than rhs
 bool Dali::operator< ( Radian lhs, Degree rhs )

Compare less than between a radian and a degree.

Since :
2.4
Parameters:
 [in] lhs Radian to compare [in] rhs Degree to compare to
Returns:
true if lhs is less than rhs
 bool Dali::operator< ( Degree lhs, Radian rhs )

Compare less than between a degree and a radian.

Since :
2.4
Parameters:
 [in] lhs Degree to compare [in] rhs Radian to compare to
Returns:
true if lhs is less than rhs
 std::ostream& Dali::operator<< ( std::ostream & o, const Matrix3 & matrix )

Print a 3x3 matrix.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] matrix The matrix to print.
Returns:
The output stream operator.
 std::ostream& Dali::operator<< ( std::ostream & o, const Matrix & matrix )

Print a matrix.

It is printed in memory order, i.e. each printed row is contiguous in memory.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] matrix The matrix to print.
Returns:
The output stream operator.
 std::ostream& Dali::operator<< ( std::ostream & o, const Vector2 & vector )

Print a Vector2.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] vector The vector to print.
Returns:
The output stream operator.
 std::ostream& Dali::operator<< ( std::ostream & o, const Quaternion & quaternion )

Print a Quaternion.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] quaternion The quaternion to print.
Returns:
The output stream operator.
 std::ostream& Dali::operator<< ( std::ostream & o, const Vector3 & vector )

Print a Vector3.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] vector The vector to print.
Returns:
The output stream operator.
 std::ostream& Dali::operator<< ( std::ostream & o, const Vector4 & vector )

Print a Vector4.

Since :
2.4
Parameters:
 [in] o The output stream operator. [in] vector The vector to print.
Returns:
The output stream operator.
 bool Dali::operator== ( const Degree & lhs, const Degree & rhs )

Compare equality between two degrees.

Since :
2.4
Parameters:
 [in] lhs Degree to compare [in] rhs Degree to compare to
Returns:
true if the values are identical

Since :
2.4
Parameters:
Returns:
true if the values are identical
 bool Dali::operator== ( Radian lhs, Degree rhs )

Compare equality between a radian and degree.

Since :
2.4
Parameters:
 [in] lhs Radian to compare [in] rhs Degree to compare to
Returns:
true if the values are identical
 bool Dali::operator== ( Degree lhs, Radian rhs )

Compare equality between a degree and a radian.

Since :
2.4
Parameters:
 [in] lhs Degree to compare [in] rhs Radian to compare to
Returns:
true if the values are identical

Compare greater than between two radians.

Since :
2.4
Parameters:
Returns:
true if lhs is greater than rhs
 bool Dali::operator> ( Radian lhs, Degree rhs )

Compare greater than between a radian and a degree.

Since :
2.4
Parameters:
 [in] lhs Radian to compare [in] rhs Degree to compare to
Returns:
true if lhs is greater than rhs
 bool Dali::operator> ( Degree lhs, Radian rhs )

Compare greater than between a radian and a degree.

Since :
2.4
Parameters:
 [in] lhs Radian to compare [in] rhs Degree to compare to
Returns:
true if lhs is greater than rhs
 float Dali::Round ( float value, int pos )

Get an float that is rounded at specified place of decimals.

Since :
2.4
Parameters:
 [in] value Float value [in] pos Decimal place
Returns:
A rounded float
 float Dali::ShortestDistanceInDomain ( float a, float b, float start, float end )

Find the shortest distance (magnitude) and direction (sign) from (a) to (b) in domain (start) to (end).

```  (\ / start)               (\ / end)
|-a                 b<----|
```

Knowing the shortest distance is useful with wrapped domains to solve problems such as determing the closest object to a given point, or determing whether turning left or turning right is the shortest route to get from angle 10 degrees to angle 350 degrees (clearly in a 0-360 degree domain, turning left 20 degrees is quicker than turning right 340 degrees).

The value returned holds the distance and the direction from value a to value b. For instance in the above example it would return -20. i.e. subtract 20 from current value (10) to reach target wrapped value (350).

Since :
2.4
Parameters:
 a The current value b The target value start The start of the domain end The end of the domain
Returns:
The shortest direction (the sign) and distance (the magnitude)
Note:
Assumes both (a) and (b) are already within the domain (start) to (end).
 float Dali::WrapInDomain ( float x, float start, float end )

Wrap x in domain (start) to (end).

This works like a floating point version of the % modulo operation. But with an offset (start).

For instance a domain is specified as: start: 2 end: 8

```   2                         8
(\ / start)               (\ / end)
|----x                    |
```

The value x will be confined to this domain. If x is below 2 e.g. 0, then it is wraped to 6. If x is above or equal to 8 e.g. 8.1 then it is wrapped to 2.1.

Domain wrapping is useful for various problems from calculating positions in a space that repeats, to computing angles that range from 0 to 360.

Since :
2.4
Parameters:
 [in] x The point to be wrapped within the domain [in] start The start of the domain [in] end The end of the domain
Returns:
The wrapped value over the domain (start) (end)
Note:
If start = end (i.e. size of domain 0), then wrapping will not occur and result will always be equal to start.