From 6bc980f3d904aa08badd16ee743e944b9915f928 Mon Sep 17 00:00:00 2001 From: Marcin Date: Sat, 18 Jan 2025 19:17:58 +0000 Subject: [PATCH] add missing vec2 step --- include/cglm/call/vec2.h | 4 ++++ include/cglm/struct/vec2.h | 16 ++++++++++++++++ include/cglm/vec2.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/include/cglm/call/vec2.h b/include/cglm/call/vec2.h index a0c32ce..2fbd3ee 100644 --- a/include/cglm/call/vec2.h +++ b/include/cglm/call/vec2.h @@ -205,6 +205,10 @@ CGLM_EXPORT void glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest); +CGLM_EXPORT +void +glmc_vec2_step(vec2 edge, vec2 x, vec2 dest); + CGLM_EXPORT void glmc_vec2_steps(float edge, vec2 x, vec2 dest); diff --git a/include/cglm/struct/vec2.h b/include/cglm/struct/vec2.h index e1190e2..40ed659 100644 --- a/include/cglm/struct/vec2.h +++ b/include/cglm/struct/vec2.h @@ -53,6 +53,7 @@ CGLM_INLINE vec2s glms_vec2_minv(vec2s a, vec2s b) CGLM_INLINE vec2s glms_vec2_clamp(vec2s v, float minVal, float maxVal) CGLM_INLINE vec2s glms_vec2_lerp(vec2s from, vec2s to, float t) + CGLM_INLINE vec2s glms_vec2_step(vec2s edge, vec2s x) CGLM_INLINE vec2s glms_vec2_make(float * restrict src) CGLM_INLINE vec2s glms_vec2_reflect(vec2s v, vec2s n) CGLM_INLINE bool glms_vec2_refract(vec2s v, vec2s n, float eta, vec2s *dest) @@ -679,6 +680,21 @@ glms_vec2_(lerp)(vec2s from, vec2s to, float t) { return r; } +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_(step)(vec2s edge, vec2s x) { + vec2s r; + glm_vec2_step(edge.raw, x.raw, r.raw); + return r; +} + /*! * @brief Create two dimensional vector from pointer * diff --git a/include/cglm/vec2.h b/include/cglm/vec2.h index 98cd4df..090e5e8 100644 --- a/include/cglm/vec2.h +++ b/include/cglm/vec2.h @@ -54,6 +54,7 @@ CGLM_INLINE void glm_vec2_minv(vec2 v1, vec2 v2, vec2 dest) CGLM_INLINE void glm_vec2_clamp(vec2 v, float minVal, float maxVal) CGLM_INLINE void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) + CGLM_INLINE void glm_vec2_step(vec2 edge, vec2 x, vec2 dest) CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest) CGLM_INLINE void glm_vec2_reflect(vec2 v, vec2 n, vec2 dest) CGLM_INLINE void glm_vec2_refract(vec2 v, vec2 n, float eta, vec2 dest) @@ -701,6 +702,20 @@ glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) { glm_vec2_add(from, v, dest); } +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_step(vec2 edge, vec2 x, vec2 dest) { + dest[0] = glm_step(edge[0], x[0]); + dest[1] = glm_step(edge[1], x[1]); +} + /*! * @brief Create two dimensional vector from pointer *