Math
Approximate double comparison. More...
Functions
| Name | |
|---|---|
| FORCE_INLINE bool | areElementsSame(const glm::vec3 vec) |
| FORCE_INLINE bool | eq(const float lhs, const float rhs, const float epsilon)<br>Comparison of two floats using epsilon, useful for comparison to zero and to one. |
| FORCE_INLINE bool | eq(const float lhs, const float rhs, const int factor =FACTOR_SIMILAR)<br>Comparison of two floats using factor * difference to nextafter() value, useful for comparison of two floats of unknown value. |
| FORCE_INLINE bool | eq(const glm::mat4 & lhs, const glm::mat4 & rhs, const float epsilon) |
| FORCE_INLINE bool | eq(const glm::mat4 & lhs, const glm::mat4 & rhs, const int factor =FACTOR_SIMILAR) |
| FORCE_INLINE bool | eq(const glm::quat & lhs, const glm::quat & rhs, const int factor =FACTOR_SIMILAR) |
| FORCE_INLINE bool | eq(const glm::vec3 & lhs, const glm::vec3 & rhs, const int factor =FACTOR_SIMILAR) |
| FORCE_INLINE bool | eq(const glm::vec4 & lhs, const glm::vec4 & rhs, const int factor =FACTOR_SIMILAR) |
| FORCE_INLINE bool | eqToOne(const float value, const float epsilon =FLT_EPSILON_FIVE_DECIMALS) |
| FORCE_INLINE bool | eqToZero(const float value, const float epsilon =FLT_EPSILON_FIVE_DECIMALS) |
| template <typename T > <br>bool | isNormalized(const T & val) |
| glm::mat4 | lerp(const glm::mat4 & lhs, const glm::mat4 & rhs, float alpha, bool useQuat =false)<br>Linear interpolation between two 4x4 matrices lhs and rhs including translation columns. |
| glm::vec3 | lerp(glm::vec3 a, glm::vec3 b, float alpha)<br>Linear interpolation between two vectors vec3 a and b. |
| glm::vec4 | lerp(glm::vec4 a, glm::vec4 b, float alpha)<br>Linear interpolation between two vectors vec4 a and b. |
| void | prefixSum(std::vector< int > & arr) |
| float | randomf()<br>Random float from interval 0 . |
| float | randomfHalf()<br>Random float from interval -0.5 . |
| int | randomi(const int downIncluded, const int topNotInclude)<br>Random integer from interval downIncluded . |
| int | randomi(const int topNotInclude)<br>Random integer from interval 0..topNotInclude. |
| glm::vec3 | randomVec() |
| float | range(const float value, const float low1, const float high1, const float low2, const float high2) |
| float | smoothAlpha(const float a)<br>Fifth order interpolation. |
| template <typename T > <br>FORCE_INLINE bool | withinInterval(T val, T from, T to)<br>Inclusive interval. |
Attributes
| Name | |
|---|---|
| constexpr int | FACTOR_NEARLY_EQUAL <br>interval weight for comparison of nearly equal values |
| constexpr int | FACTOR_ROUGHLY_SIMILAR <br>interval weight for comparison of very roughly similar values |
| constexpr int | FACTOR_SIMILAR <br>interval weight for comparison of similar values |
| constexpr float | FLT_EPSILON_10 <br>1.192093 E-6 |
| constexpr float | FLT_EPSILON_100 <br>1.192093 E-5 |
| constexpr float | FLT_EPSILON_1000 <br>1.192093 E-4 |
| constexpr float | FLT_EPSILON_FIVE_DECIMALS <br>simple interval (1.0 +- epsilon) |
Detailed Description
Approximate double comparison.
Parameters:
- a first double
- b second double
- factor a factor of epsilon
Return: true if the double values represent nearly the same value (precision interval is widened by factor)
Functions Documentation
function areElementsSame
FORCE_INLINE bool areElementsSame(
const glm::vec3 vec
)FORCE_INLINE bool areElementsSame(
const glm::vec3 vec
)function eq
FORCE_INLINE bool eq(
const float lhs,
const float rhs,
const float epsilon
)FORCE_INLINE bool eq(
const float lhs,
const float rhs,
const float epsilon
)Comparison of two floats using epsilon, useful for comparison to zero and to one.
Parameters:
- lhs First value
- rhs Second value
- epsilon interval size - roughly defining the number of decimal places
Return: epsilon comparison
function eq
FORCE_INLINE bool eq(
const float lhs,
const float rhs,
const int factor =FACTOR_SIMILAR
)FORCE_INLINE bool eq(
const float lhs,
const float rhs,
const int factor =FACTOR_SIMILAR
)Comparison of two floats using factor * difference to nextafter() value, useful for comparison of two floats of unknown value.
Parameters:
- lhs First value
- rhs Second value
- factor multiplies the distance to the nextafter() value used as a size of comparison interval
Return: factor based comparison
function eq
FORCE_INLINE bool eq(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
const float epsilon
)FORCE_INLINE bool eq(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
const float epsilon
)function eq
FORCE_INLINE bool eq(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
const int factor =FACTOR_SIMILAR
)FORCE_INLINE bool eq(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
const int factor =FACTOR_SIMILAR
)function eq
FORCE_INLINE bool eq(
const glm::quat & lhs,
const glm::quat & rhs,
const int factor =FACTOR_SIMILAR
)FORCE_INLINE bool eq(
const glm::quat & lhs,
const glm::quat & rhs,
const int factor =FACTOR_SIMILAR
)function eq
FORCE_INLINE bool eq(
const glm::vec3 & lhs,
const glm::vec3 & rhs,
const int factor =FACTOR_SIMILAR
)FORCE_INLINE bool eq(
const glm::vec3 & lhs,
const glm::vec3 & rhs,
const int factor =FACTOR_SIMILAR
)function eq
FORCE_INLINE bool eq(
const glm::vec4 & lhs,
const glm::vec4 & rhs,
const int factor =FACTOR_SIMILAR
)FORCE_INLINE bool eq(
const glm::vec4 & lhs,
const glm::vec4 & rhs,
const int factor =FACTOR_SIMILAR
)function eqToOne
FORCE_INLINE bool eqToOne(
const float value,
const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)FORCE_INLINE bool eqToOne(
const float value,
const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)function eqToZero
FORCE_INLINE bool eqToZero(
const float value,
const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)FORCE_INLINE bool eqToZero(
const float value,
const float epsilon =FLT_EPSILON_FIVE_DECIMALS
)function isNormalized
template <typename T >
bool isNormalized(
const T & val
)template <typename T >
bool isNormalized(
const T & val
)function lerp
glm::mat4 lerp(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
float alpha,
bool useQuat =false
)glm::mat4 lerp(
const glm::mat4 & lhs,
const glm::mat4 & rhs,
float alpha,
bool useQuat =false
)Linear interpolation between two 4x4 matrices lhs and rhs including translation columns.
Function depends on the parameter useQuat:
- true - A correct interpolation of rotational matrices using quaternions
- false - Incorrect interpolation, just for teaching purposes (how not to do it). lhsthe first matrix
rhsthe second matrix
alphainterpolation parameter - must be from interval (0..1) interpolation parameter - must be from interval (0..1)
useQuatuse quaternion interpolation, if true
linear interpolation of two matrices vectors [wrong for useQuat == false!]
function lerp
static glm::vec3 lerp(
glm::vec3 a,
glm::vec3 b,
float alpha
)static glm::vec3 lerp(
glm::vec3 a,
glm::vec3 b,
float alpha
)Linear interpolation between two vectors vec3 a and b.
Parameters:
- a
- b
- alpha interpolation parameter - must be from interval (0..1)
Return: linear interpolation of two vec3 vectors
function lerp
static glm::vec4 lerp(
glm::vec4 a,
glm::vec4 b,
float alpha
)static glm::vec4 lerp(
glm::vec4 a,
glm::vec4 b,
float alpha
)Linear interpolation between two vectors vec4 a and b.
Parameters:
- a the first vector
- b the second vector
- alpha interpolation parameter - must be from interval (0..1)
Return: linear interpolation of two vec4 vectors
function prefixSum
static void prefixSum(
std::vector< int > & arr
)static void prefixSum(
std::vector< int > & arr
)function randomf
static float randomf()static float randomf()Random float from interval 0 .
Return: random float
. 0.999
function randomfHalf
static float randomfHalf()static float randomfHalf()Random float from interval -0.5 .
Return: random float
. +0.499
function randomi
static int randomi(
const int downIncluded,
const int topNotInclude
)static int randomi(
const int downIncluded,
const int topNotInclude
)Random integer from interval downIncluded .
Parameters:
- downIncluded [min generated value
- topNotInclude max) generated value
Return: Random integer
. topNotInclude
function randomi
static int randomi(
const int topNotInclude
)static int randomi(
const int topNotInclude
)Random integer from interval 0..topNotInclude.
Parameters:
- topNotInclude maximum value of the interval
Return: Random integer
function randomVec
static glm::vec3 randomVec()static glm::vec3 randomVec()function range
static float range(
const float value,
const float low1,
const float high1,
const float low2,
const float high2
)static float range(
const float value,
const float low1,
const float high1,
const float low2,
const float high2
)function smoothAlpha
static float smoothAlpha(
const float a
)static float smoothAlpha(
const float a
)Fifth order interpolation.
Parameters:
- a alpha
Return: smoothed alpha
function withinInterval
template <typename T >
FORCE_INLINE bool withinInterval(
T val,
T from,
T to
)template <typename T >
FORCE_INLINE bool withinInterval(
T val,
T from,
T to
)Inclusive interval.
Attributes Documentation
variable FACTOR_NEARLY_EQUAL
static constexpr int FACTOR_NEARLY_EQUAL = 0x01 << 8;static constexpr int FACTOR_NEARLY_EQUAL = 0x01 << 8;interval weight for comparison of nearly equal values
variable FACTOR_ROUGHLY_SIMILAR
static constexpr int FACTOR_ROUGHLY_SIMILAR = 0x01
<< 14;static constexpr int FACTOR_ROUGHLY_SIMILAR = 0x01
<< 14;interval weight for comparison of very roughly similar values
variable FACTOR_SIMILAR
static constexpr int FACTOR_SIMILAR = 0x01 << 12;static constexpr int FACTOR_SIMILAR = 0x01 << 12;interval weight for comparison of similar values
variable FLT_EPSILON_10
static constexpr float FLT_EPSILON_10 = 10.0f * FLT_EPSILON;static constexpr float FLT_EPSILON_10 = 10.0f * FLT_EPSILON;1.192093 E-6
variable FLT_EPSILON_100
static constexpr float FLT_EPSILON_100 = 100.0f * FLT_EPSILON;static constexpr float FLT_EPSILON_100 = 100.0f * FLT_EPSILON;1.192093 E-5
variable FLT_EPSILON_1000
static constexpr float FLT_EPSILON_1000 = 1000.0f * FLT_EPSILON;static constexpr float FLT_EPSILON_1000 = 1000.0f * FLT_EPSILON;1.192093 E-4
variable FLT_EPSILON_FIVE_DECIMALS
static constexpr float FLT_EPSILON_FIVE_DECIMALS = 0.00001f;static constexpr float FLT_EPSILON_FIVE_DECIMALS = 0.00001f;simple interval (1.0 +- epsilon)
Updated on 2025-09-07 at 16:13:51 +0000