From 0483362f5ca29e16ca7957f56bc49245c1addd0a Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 18 Jan 2025 16:47:07 +0000 Subject: [PATCH] move mods to ext --- include/cglm/noise.h | 42 +++++------------------------------------ include/cglm/vec2-ext.h | 15 +++++++++++++++ include/cglm/vec3-ext.h | 16 ++++++++++++++++ include/cglm/vec4-ext.h | 17 +++++++++++++++++ 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/include/cglm/noise.h b/include/cglm/noise.h index 621a74a..f687b6e 100644 --- a/include/cglm/noise.h +++ b/include/cglm/noise.h @@ -28,38 +28,6 @@ ////////////////////////////// // Proposed vec4_ext functions -/*! - * @brief mod v by a scalar, result is written to dest (dest = v % s) - * - * @param[in] v vector - * @param[in] s scalar - * @param[out] dest destination vector - */ -CGLM_INLINE -void -_glm_vec4_mods(vec4 x, float y, vec4 dest) { - dest[0] = fmodf(x[0], y); - dest[1] = fmodf(x[1], y); - dest[2] = fmodf(x[2], y); - dest[3] = fmodf(x[3], y); -} - -/*! - * @brief mod v by a scalar, result is written to dest (dest = v % s) - * - * @param[in] v vector - * @param[in] s scalar - * @param[out] dest destination vector - */ -CGLM_INLINE -void -_glm_vec3_mods(vec3 x, float y, vec3 dest) { - dest[0] = fmodf(x[0], y); - dest[1] = fmodf(x[1], y); - dest[2] = fmodf(x[2], y); -} - - /*! * @brief threshold function with scalar * @@ -440,8 +408,8 @@ glm_perlin_vec4(vec4 point) { vec4 Pi1; glm_vec4_adds(Pi0, 1.0f, Pi1); // Pi1 = Pi0 + 1.0f; - _glm_vec4_mods(Pi0, 289.0f, Pi0); // Pi0 = mod(Pi0, 289.0f); - _glm_vec4_mods(Pi1, 289.0f, Pi1); // Pi1 = mod(Pi1, 289.0f); + glm_vec4_mods(Pi0, 289.0f, Pi0); // Pi0 = mod(Pi0, 289.0f); + glm_vec4_mods(Pi1, 289.0f, Pi1); // Pi1 = mod(Pi1, 289.0f); // Fractional part of p for interpolation vec4 Pf0; @@ -650,8 +618,8 @@ glm_perlin_vec3(vec3 point) { vec3 Pi1; glm_vec3_adds(Pi0, 1.0f, Pi1); // Pi1 = Pi0 + 1.0f; - _glm_vec3_mods(Pi0, 289.0f, Pi0); // Pi0 = mod(Pi0, 289.0f); - _glm_vec3_mods(Pi1, 289.0f, Pi1); // Pi1 = mod(Pi1, 289.0f); + glm_vec3_mods(Pi0, 289.0f, Pi0); // Pi0 = mod(Pi0, 289.0f); + glm_vec3_mods(Pi1, 289.0f, Pi1); // Pi1 = mod(Pi1, 289.0f); // Fractional part of p for interpolation vec3 Pf0; @@ -785,7 +753,7 @@ glm_perlin_vec2(vec2 point) { Pf[3] -= 1.0f; // Pf.w -= 1.0 // Mod to avoid truncation effects in permutation - _glm_vec4_mods(Pi, 289.0f, Pi); // Pi = mod(Pi, 289.0f); + glm_vec4_mods(Pi, 289.0f, Pi); // Pi = mod(Pi, 289.0f); vec4 ix = {Pi[0], Pi[2], Pi[0], Pi[2]}; // ix = vec4(Pi.x, Pi.z, Pi.x, Pi.z) vec4 iy = {Pi[1], Pi[1], Pi[3], Pi[3]}; // iy = vec4(Pi.y, Pi.y, Pi.w, Pi.w) diff --git a/include/cglm/vec2-ext.h b/include/cglm/vec2-ext.h index 3aeac97..0f80c67 100644 --- a/include/cglm/vec2-ext.h +++ b/include/cglm/vec2-ext.h @@ -22,6 +22,7 @@ CGLM_INLINE void glm_vec2_abs(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_fract(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_floor(vec2 v, vec2 dest); + CGLM_INLINE float glm_vec2_mods(vec2 v, float s, vec2 dest); CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) CGLM_INLINE void glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest) @@ -226,6 +227,20 @@ glm_vec2_floor(vec2 x, vec2 dest) { dest[1] = floorf(x[1]); } +/*! + * @brief mod of each vector item, result is written to dest (dest = v % s) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_mods(vec2 x, float y, vec2 dest) { + dest[0] = fmodf(x[0], y); + dest[1] = fmodf(x[1], y); +} + /*! * @brief square root of each vector item * diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index d374659..cb8cc49 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -27,6 +27,7 @@ CGLM_INLINE void glm_vec3_abs(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_fract(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_floor(vec3 v, vec3 dest); + CGLM_INLINE float glm_vec3_mods(vec3 v, float s, vec3 dest); CGLM_INLINE float glm_vec3_hadd(vec3 v); CGLM_INLINE void glm_vec3_sqrt(vec3 v, vec3 dest); */ @@ -265,6 +266,21 @@ glm_vec3_floor(vec3 x, vec3 dest) { dest[2] = floorf(x[2]); } +/*! + * @brief mod of each vector item, result is written to dest (dest = v % s) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_mods(vec3 x, float y, vec3 dest) { + dest[0] = fmodf(x[0], y); + dest[1] = fmodf(x[1], y); + dest[2] = fmodf(x[2], y); +} + /*! * @brief vector reduction by summation * @warning could overflow diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 6e56171..e19ac6c 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -26,6 +26,7 @@ CGLM_INLINE void glm_vec4_sign(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_abs(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_fract(vec4 v, vec4 dest); + CGLM_INLINE float glm_vec4_mods(vec4 v, float val); CGLM_INLINE float glm_vec4_hadd(vec4 v); CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); */ @@ -303,6 +304,22 @@ glm_vec4_floor(vec4 x, vec4 dest) { dest[3] = floorf(x[3]); } +/*! + * @brief mod of each vector item, result is written to dest (dest = v % s) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_mods(vec4 x, float y, vec4 dest) { + dest[0] = fmodf(x[0], y); + dest[1] = fmodf(x[1], y); + dest[2] = fmodf(x[2], y); + dest[3] = fmodf(x[3], y); +} + /*! * @brief vector reduction by summation * @warning could overflow