From 9a1206f3f15ae6956eeeccef237385ab0762bc0d Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 18 Jan 2025 19:08:34 +0000 Subject: [PATCH] steps and stepr boilerplate --- include/cglm/call/vec2.h | 8 ++++++++ include/cglm/call/vec3.h | 8 ++++++++ include/cglm/call/vec4.h | 8 ++++++++ include/cglm/struct/vec2-ext.h | 34 ++++++++++++++++++++++++++++++++++ include/cglm/struct/vec3-ext.h | 34 ++++++++++++++++++++++++++++++++++ include/cglm/struct/vec4-ext.h | 34 ++++++++++++++++++++++++++++++++++ src/vec2.c | 12 ++++++++++++ 7 files changed, 138 insertions(+) diff --git a/include/cglm/call/vec2.h b/include/cglm/call/vec2.h index 413d261..a0c32ce 100644 --- a/include/cglm/call/vec2.h +++ b/include/cglm/call/vec2.h @@ -205,6 +205,14 @@ CGLM_EXPORT void glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest); +CGLM_EXPORT +void +glmc_vec2_steps(float edge, vec2 x, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_stepr(vec2 edge, float x, vec2 dest); + CGLM_EXPORT void glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest); diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 660e464..70aa1ab 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -330,6 +330,14 @@ CGLM_EXPORT void glmc_vec3_mods(vec3 v, float s, vec3 dest); +CGLM_EXPORT +void +glmc_vec3_steps(float edge, vec3 x, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_stepr(vec3 edge, float x, vec3 dest); + CGLM_EXPORT float glmc_vec3_hadd(vec3 v); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index c756700..cf00cc0 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -307,6 +307,14 @@ CGLM_EXPORT void glmc_vec4_mods(vec4 v, float s, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_steps(float edge, vec4 x, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_stepr(vec4 edge, float x, vec4 dest); + CGLM_EXPORT float glmc_vec4_hadd(vec4 v); diff --git a/include/cglm/struct/vec2-ext.h b/include/cglm/struct/vec2-ext.h index d1bf953..7825538 100644 --- a/include/cglm/struct/vec2-ext.h +++ b/include/cglm/struct/vec2-ext.h @@ -26,6 +26,8 @@ CGLM_INLINE vec2s glms_vec2_abs(vec2s v) CGLM_INLINE vec2s glms_vec2_fract(vec2s v) CGLM_INLINE vec2s glms_vec2_floor(vec2s v) + CGLM_INLINE vec2s glms_vec2_steps(float edge, vec2s v) + CGLM_INLINE vec2s glms_vec2_stepr(vec2s edge, float v) CGLM_INLINE vec2s glms_vec2_sqrt(vec2s v) */ @@ -244,6 +246,38 @@ glms_vec2_(mods)(vec2s v, float s) { return r; } +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_(steps)(float edge, vec2s x) { + vec2s r; + glm_vec2_steps(edge, x.raw, r.raw); + return r; +} + +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_(stepr)(vec2s edge, float x) { + vec2s r; + glm_vec2_stepr(edge.raw, x, r.raw); + return r; +} + /*! * @brief square root of each vector item * diff --git a/include/cglm/struct/vec3-ext.h b/include/cglm/struct/vec3-ext.h index bdaa42c..66a987a 100644 --- a/include/cglm/struct/vec3-ext.h +++ b/include/cglm/struct/vec3-ext.h @@ -27,6 +27,8 @@ CGLM_INLINE vec3s glms_vec3_abs(vec3s v); CGLM_INLINE vec3s glms_vec3_fract(vec3s v); CGLM_INLINE vec3s glms_vec3_floor(vec3s v); + CGLM_INLINE vec3s glms_vec3_steps(float edge, vec3s v); + CGLM_INLINE vec3s glms_vec3_stepr(vec3s edge, float v); CGLM_INLINE float glms_vec3_hadd(vec3s v); CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v); */ @@ -260,6 +262,38 @@ glms_vec3_(mods)(vec3s v, float s) { return r; } +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_(steps)(float edge, vec3s x) { + vec3s r; + glm_vec3_steps(edge, x.raw, r.raw); + return r; +} + +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_(stepr)(vec3s edge, float x) { + vec3s r; + glm_vec3_stepr(edge.raw, x, r.raw); + return r; +} + /*! * @brief vector reduction by summation * @warning could overflow diff --git a/include/cglm/struct/vec4-ext.h b/include/cglm/struct/vec4-ext.h index c6dd983..3b61431 100644 --- a/include/cglm/struct/vec4-ext.h +++ b/include/cglm/struct/vec4-ext.h @@ -27,6 +27,8 @@ CGLM_INLINE vec4s glms_vec4_abs(vec4s v); CGLM_INLINE vec4s glms_vec4_fract(vec4s v); CGLM_INLINE float glms_vec4_floor(vec4s v); + CGLM_INLINE float glms_vec4_steps(float edge, vec4s v); + CGLM_INLINE void glms_vec4_stepr(vec4s edge, float v); CGLM_INLINE float glms_vec4_hadd(vec4s v); CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); */ @@ -260,6 +262,38 @@ glms_vec4_(mods)(vec4s v, float s) { return r; } +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_(steps)(float edge, vec4s x) { + vec4s r; + glm_vec4_steps(edge, x.raw, r.raw); + return r; +} + +/*! + * @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 + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_(stepr)(vec4s edge, float x) { + vec4s r; + glm_vec4_stepr(edge.raw, x, r.raw); + return r; +} + /*! * @brief vector reduction by summation * @warning could overflow diff --git a/src/vec2.c b/src/vec2.c index f7b0b5a..079992d 100644 --- a/src/vec2.c +++ b/src/vec2.c @@ -291,6 +291,18 @@ glmc_vec2_mods(vec2 v, float s, vec2 dest) { glm_vec2_mods(v, s, dest); } +CGLM_EXPORT +void +glmc_vec2_step(vec2 edge, vec2 v, vec2 dest) { + glm_vec2_step(edge, v, dest); +} + +CGLM_EXPORT +void +glmc_vec2_steps(float edge, vec2 v, vec2 dest) { + glm_vec2_steps(edge, v, dest); +} + CGLM_EXPORT void glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) {