From c2ebef38670d1ed7b67845b40c723bd61f900a24 Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 18 Jan 2025 19:05:24 +0000 Subject: [PATCH] change steps -> stepr and move to ext --- include/cglm/noise.h | 35 ++--------------------------------- include/cglm/vec2-ext.h | 32 ++++++++++++++++++++++++++++++++ include/cglm/vec3-ext.h | 34 ++++++++++++++++++++++++++++++++++ include/cglm/vec4-ext.h | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 33 deletions(-) diff --git a/include/cglm/noise.h b/include/cglm/noise.h index f687b6e..64e8e22 100644 --- a/include/cglm/noise.h +++ b/include/cglm/noise.h @@ -28,37 +28,6 @@ ////////////////////////////// // Proposed vec4_ext functions -/*! - * @brief threshold function with scalar - * - * @param[in] edge threshold - * @param[in] x value to test against threshold - * @param[out] dest destination - */ -CGLM_INLINE -void -_glm_vec4_steps(vec4 edge, float x, vec4 dest) { - dest[0] = glm_step(edge[0], x); - dest[1] = glm_step(edge[1], x); - dest[2] = glm_step(edge[2], x); - dest[3] = glm_step(edge[3], x); -} - -/*! - * @brief threshold function with scalar - * - * @param[in] edge threshold - * @param[in] x value to test against threshold - * @param[out] dest destination - */ -CGLM_INLINE -void -_glm_vec3_steps(vec3 edge, float x, vec3 dest) { - dest[0] = glm_step(edge[0], x); - dest[1] = glm_step(edge[1], x); - dest[2] = glm_step(edge[2], x); -} - /*! * @brief set all elements of dest to value * @@ -281,7 +250,7 @@ _glm_noiseDetail_i2gxyzw( // sw = step(gw, 0.0); vec4 sw; - _glm_vec4_steps(gw, 0.0f, sw); // sw = step(gw, 0.0) + glm_vec4_stepr(gw, 0.0f, sw); // sw = step(gw, 0.0) // gx -= sw * (step(vec4(0), gx) - T(0.5)); vec4 temp = {0.0f}; // temp = 0.0 @@ -337,7 +306,7 @@ _glm_noiseDetail_i2gxyz( // sz = step(gw, 0.0); vec4 sz; - _glm_vec4_steps(gz, 0.0f, sz); // sz = step(gz, 0.0) + glm_vec4_stepr(gz, 0.0f, sz); // sz = step(gz, 0.0) // gx0 -= sz0 * (step(0.0, gx0) - T(0.5)); vec4 temp = {0.0f}; // temp = 0.0 diff --git a/include/cglm/vec2-ext.h b/include/cglm/vec2-ext.h index 0f80c67..4322618 100644 --- a/include/cglm/vec2-ext.h +++ b/include/cglm/vec2-ext.h @@ -23,6 +23,8 @@ 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 float glm_vec2_steps(float edge, vec2 v, vec2 dest); + CGLM_INLINE void glm_vec2_stepr(vec2 edge, float v, 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) @@ -271,6 +273,36 @@ glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) { dest[1] = ti; } +/*! + * @brief threshold each vector item with scalar + * condition is: (x[i] < edge) ? 0.0 : 1.0 + * + * @param[in] edge threshold + * @param[in] x vector to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_steps(float edge, vec2 x, vec2 dest) { + dest[0] = glm_step(edge, x[0]); + dest[1] = glm_step(edge, x[1]); +} + +/*! + * @brief threshold a value with *vector* as the threshold + * condition is: (x < edge[i]) ? 0.0 : 1.0 + * + * @param[in] edge threshold vector + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_stepr(vec2 edge, float x, vec2 dest) { + dest[0] = glm_step(edge[0], x); + dest[1] = glm_step(edge[1], x); +} + /*! * @brief treat vectors as complex numbers and divide them as such. * diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index cb8cc49..6b8c041 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -28,6 +28,8 @@ 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_steps(float edge, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_stepr(vec3 edge, float v, vec3 dest); CGLM_INLINE float glm_vec3_hadd(vec3 v); CGLM_INLINE void glm_vec3_sqrt(vec3 v, vec3 dest); */ @@ -281,6 +283,38 @@ glm_vec3_mods(vec3 x, float y, vec3 dest) { dest[2] = fmodf(x[2], y); } +/*! + * @brief threshold each vector item with scalar + * condition is: (x[i] < edge) ? 0.0 : 1.0 + * + * @param[in] edge threshold + * @param[in] x vector to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_steps(float edge, vec3 x, vec3 dest) { + dest[0] = glm_step(edge, x[0]); + dest[1] = glm_step(edge, x[1]); + dest[2] = glm_step(edge, x[2]); +} + +/*! + * @brief threshold a value with *vector* as the threshold + * condition is: (x < edge[i]) ? 0.0 : 1.0 + * + * @param[in] edge threshold vector + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_stepr(vec3 edge, float x, vec3 dest) { + dest[0] = glm_step(edge[0], x); + dest[1] = glm_step(edge[1], x); + dest[2] = glm_step(edge[2], x); +} + /*! * @brief vector reduction by summation * @warning could overflow diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 965d3d1..1f03eea 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -28,6 +28,8 @@ CGLM_INLINE void glm_vec4_fract(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_floor(vec4 v, vec4 dest); CGLM_INLINE float glm_vec4_mods(vec4 v, float s, vec4 dest); + CGLM_INLINE float glm_vec4_steps(float edge, vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_stepr(vec4 edge, float v, vec4 dest); CGLM_INLINE float glm_vec4_hadd(vec4 v); CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); */ @@ -321,6 +323,40 @@ glm_vec4_mods(vec4 x, float y, vec4 dest) { dest[3] = fmodf(x[3], y); } +/*! + * @brief threshold each vector item with scalar + * condition is: (x[i] < edge) ? 0.0 : 1.0 + * + * @param[in] edge threshold + * @param[in] x vector to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_steps(float edge, vec4 x, vec4 dest) { + dest[0] = glm_step(edge, x[0]); + dest[1] = glm_step(edge, x[1]); + dest[2] = glm_step(edge, x[2]); + dest[3] = glm_step(edge, x[3]); +} + +/*! + * @brief threshold a value with *vector* as the threshold + * condition is: (x < edge[i]) ? 0.0 : 1.0 + * + * @param[in] edge threshold vector + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_stepr(vec4 edge, float x, vec4 dest) { + dest[0] = glm_step(edge[0], x); + dest[1] = glm_step(edge[1], x); + dest[2] = glm_step(edge[2], x); + dest[3] = glm_step(edge[3], x); +} + /*! * @brief vector reduction by summation * @warning could overflow