vec: some useful functions (#103)

These functions are added:
- abs(): absolute value
- fract(): fractional part
- norm_one(): L1 norm
- norm_inf(): infinity norm
- hadd(): horizontal add
- hmax(): horizontal max
This commit is contained in:
Luigi Castelli
2019-08-31 23:30:15 +02:00
committed by Recep Aslantas
parent 6af1f5af04
commit 27cc9c3351
14 changed files with 552 additions and 0 deletions

View File

@@ -24,6 +24,9 @@
CGLM_INLINE bool glms_vec3_isinf(vec3s v);
CGLM_INLINE bool glms_vec3_isvalid(vec3s v);
CGLM_INLINE vec3s glms_vec3_sign(vec3s v);
CGLM_INLINE vec3s glms_vec3_abs(vec3s v);
CGLM_INLINE vec3s glms_vec3_fract(vec3s v);
CGLM_INLINE float glms_vec3_hadd(vec3s v);
CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v);
*/
@@ -196,6 +199,47 @@ glms_vec3_sign(vec3s v) {
return r;
}
/*!
* @brief absolute value of each vector item
*
* @param[in] v vector
* @return destination vector
*/
CGLM_INLINE
vec3s
glms_vec3_abs(vec3s v) {
vec3s r;
glm_vec3_abs(v.raw, r.raw);
return r;
}
/*!
* @brief fractional part of each vector item
*
* @param[in] v vector
* @return dest destination vector
*/
CGLM_INLINE
vec3s
glms_vec3_fract(vec3s v) {
vec3s r;
glm_vec3_fract(v.raw, r.raw);
return r;
}
/*!
* @brief vector reduction by summation
* @warning could overflow
*
* @param[in] v vector
* @return sum of all vector's elements
*/
CGLM_INLINE
float
glms_vec3_hadd(vec3s v) {
return glm_vec3_hadd(v.raw);
}
/*!
* @brief square root of each vector item
*