mirror of
https://github.com/recp/cglm.git
synced 2025-12-24 04:22:36 +00:00
additional utils
This commit is contained in:
@@ -136,3 +136,38 @@ Functions documentation
|
||||
|
||||
Returns:
|
||||
interpolated value
|
||||
|
||||
.. c:function:: bool glm_eq(float a, float b)
|
||||
|
||||
check if two float equal with using EPSILON
|
||||
|
||||
Parameters:
|
||||
| *[in]* **a** a
|
||||
| *[in]* **b** b
|
||||
|
||||
Returns:
|
||||
true if a and b equals
|
||||
|
||||
.. c:function:: float glm_percent(float from, float to, float current)
|
||||
|
||||
percentage of current value between start and end value
|
||||
|
||||
Parameters:
|
||||
| *[in]* **from** from value
|
||||
| *[in]* **to** to value
|
||||
| *[in]* **current** value between from and to values
|
||||
|
||||
Returns:
|
||||
clamped normalized percent (0-100 in 0-1)
|
||||
|
||||
.. c:function:: float glm_percentc(float from, float to, float current)
|
||||
|
||||
clamped percentage of current value between start and end value
|
||||
|
||||
Parameters:
|
||||
| *[in]* **from** from value
|
||||
| *[in]* **to** to value
|
||||
| *[in]* **current** value between from and to values
|
||||
|
||||
Returns:
|
||||
clamped normalized percent (0-100 in 0-1)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define cglm_util_h
|
||||
|
||||
#include "common.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/*!
|
||||
* @brief get sign of 32 bit integer as +1, -1, 0
|
||||
@@ -157,4 +158,44 @@ glm_lerp(float from, float to, float t) {
|
||||
return from + glm_clamp(t, 0.0f, 1.0f) * (to - from);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief check if two float equal with using EPSILON
|
||||
*
|
||||
* @param[in] a a
|
||||
* @param[in] b b
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
glm_eq(float a, float b) {
|
||||
return fabsf(a - b) <= FLT_EPSILON;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief percentage of current value between start and end value
|
||||
*
|
||||
* maybe fraction could be alternative name.
|
||||
*
|
||||
* @param[in] from from value
|
||||
* @param[in] to to value
|
||||
* @param[in] t current value
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_percent(float from, float to, float current) {
|
||||
return (current - from) / (to - from);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief clamped percentage of current value between start and end value
|
||||
*
|
||||
* @param[in] from from value
|
||||
* @param[in] to to value
|
||||
* @param[in] t current value
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_percentc(float from, float to, float current) {
|
||||
return glm_clamp(glm_percent(from, to, current), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
#endif /* cglm_util_h */
|
||||
|
||||
Reference in New Issue
Block a user