From d341478342414b90eba14423af268dfcbe31367c Mon Sep 17 00:00:00 2001 From: BeeverFeever Date: Mon, 11 Dec 2023 20:18:18 +1100 Subject: [PATCH 1/4] testing new ivec* funcs --- include/cglm/ivec2.h | 272 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index ba805392c..75e02d816 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -23,6 +23,22 @@ CGLM_INLINE void glm_ivec2_subs(ivec2 v, int s, ivec2 dest) CGLM_INLINE void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_scale(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_addadds(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_subadds(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_muladds(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_subsubs(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_addsubs(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_mulsubs(ivec2 a, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE int glm_ivec2_distance2(ivec2 a, ivec2 b) CGLM_INLINE float glm_ivec2_distance(ivec2 a, ivec2 b) CGLM_INLINE void glm_ivec2_fill(ivec2 v, int val); @@ -177,6 +193,262 @@ glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { dest[1] = v[1] * s; } +/*! + * @brief add vector [a] with vector [b] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a + b) + */ +CGLM_INLINE +void +glm_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; +} + +/*! + * @brief add scalar [s] onto vector [a] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a + s) + */ +CGLM_INLINE +void +glm_ivec2_addadds(ivec2 a, int s, ivec2 dest) { + dest[0] += a[0] + s; + dest[1] += a[1] + s; +} + +/*! + * @brief subtract vector [a] from vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a - b) + */ +CGLM_INLINE +void +glm_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first + * @param[in] s scalar + * @param[out] dest dest += (a - s) + */ +CGLM_INLINE +void +glm_ivec2_subadds(ivec2 a, int s, ivec2 dest) { + dest[0] += a[0] - s; + dest[1] += a[1] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a * b) + */ +CGLM_INLINE +void +glm_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a * s) + */ +CGLM_INLINE +void +glm_ivec2_muladds(ivec2 a, int s, ivec2 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * s; +} + +/*! + * @brief add maximum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += max(a, b) + */ +CGLM_INLINE +void +glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] += a[0] > b[0] ? a[0] : b[0]; + dest[1] += a[1] > b[1] ? a[1] : b[1]; +} + +/*! + * @brief add minimum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] += a[0] < b[0] ? a[0] : b[0]; + dest[1] += a[1] < b[1] ? a[1] : b[1]; +} + +/*! + * @brief subtract vector [a] from vector [b] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= (a - b) + */ +CGLM_INLINE +void +glm_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] -= a[0] - b[0]; + dest[1] -= a[1] - b[1]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a - s) + */ +CGLM_INLINE +void +glm_ivec2_subsubs(ivec2 a, int s, ivec2 dest) { + dest[0] -= a[0] - s; + dest[1] -= a[1] - s; +} + +/*! + * @brief add vector [a] to vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] -= a[0] + b[0]; + dest[1] -= a[1] + b[1]; +} + +/*! + * @brief add scalar [s] to vector [a] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec2_addsubs(ivec2 a, int s, ivec2 dest) { + dest[0] -= a[0] + s; + dest[1] -= a[1] + s; +} + +/*! + * @brief multiply vector [a] and vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * b) + */ +CGLM_INLINE +void +glm_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] -= a[0] * b[0]; + dest[1] -= a[1] * b[1]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * s) + */ +CGLM_INLINE +void +glm_ivec2_mulsubs(ivec2 a, int s, ivec2 dest) { + dest[0] -= a[0] * s; + dest[1] -= a[1] * s; +} + +/*! + * @brief subtract maximum of vector [a] and vector [b] from vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= max(a, b) + */ +CGLM_INLINE +void +glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] -= a[0] > b[0] ? a[0] : b[0]; + dest[1] -= a[1] > b[1] ? a[1] : b[1]; +} + +/*! + * @brief subtract minimum of vector [a] and vector [b] from vector [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= min(a, b) + */ +CGLM_INLINE +void +glm_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] -= a[0] < b[0] ? a[0] : b[0]; + dest[1] -= a[1] < b[1] ? a[1] : b[1]; +} + /*! * @brief squared distance between two vectors * From 7701a1a78918340f1730d178a1d019b55bc6e150 Mon Sep 17 00:00:00 2001 From: BeeverFeever Date: Mon, 25 Dec 2023 12:50:29 +1100 Subject: [PATCH 2/4] Add int min and max functions --- include/cglm/util.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/cglm/util.h b/include/cglm/util.h index 53b1ed5df..dbba8efb7 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -147,6 +147,38 @@ glm_max(float a, float b) { return b; } +/*! + * @brief find minimum of given two values + * + * @param[in] a number 1 + * @param[in] b number 2 + * + * @return smallest of the two values + */ +CGLM_INLINE +int +glm_imin(int a, int b) { + if (a < b) + return a; + return b; +} + +/*! + * @brief find maximum of given two values + * + * @param[in] a number 1 + * @param[in] b number 2 + * + * @return largest of the two values + */ +CGLM_INLINE +int +glm_imax(int a, int b) { + if (a > b) + return a; + return b; +} + /*! * @brief clamp a number between min and max * From 921ab6640b1ef7365aecc32806e8bdc60e42c5a1 Mon Sep 17 00:00:00 2001 From: BeeverFeever Date: Mon, 25 Dec 2023 12:51:10 +1100 Subject: [PATCH 3/4] Implement -= and += functions for ivecs --- include/cglm/call/ivec2.h | 64 ++++++++ include/cglm/call/ivec3.h | 64 ++++++++ include/cglm/call/ivec4.h | 64 ++++++++ include/cglm/ivec2.h | 17 ++- include/cglm/ivec3.h | 289 ++++++++++++++++++++++++++++++++++++ include/cglm/ivec4.h | 305 ++++++++++++++++++++++++++++++++++++++ src/ivec2.c | 96 ++++++++++++ src/ivec3.c | 96 ++++++++++++ src/ivec4.c | 96 ++++++++++++ 9 files changed, 1083 insertions(+), 8 deletions(-) diff --git a/include/cglm/call/ivec2.h b/include/cglm/call/ivec2.h index fc2f8a91c..23624158d 100644 --- a/include/cglm/call/ivec2.h +++ b/include/cglm/call/ivec2.h @@ -53,6 +53,70 @@ CGLM_EXPORT void glmc_ivec2_scale(ivec2 v, int s, ivec2 dest); +CGLM_EXPORT +void +glmc_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_addadds(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subadds(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_muladds(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subsubs(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_addsubs(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_mulsubs(ivec2 a, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest); + CGLM_EXPORT int glmc_ivec2_distance2(ivec2 a, ivec2 b); diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h index 1e3b6b4e2..e50041fe4 100644 --- a/include/cglm/call/ivec3.h +++ b/include/cglm/call/ivec3.h @@ -53,6 +53,70 @@ CGLM_EXPORT void glmc_ivec3_scale(ivec3 v, int s, ivec3 dest); +CGLM_EXPORT +void +glmc_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_addadds(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_subadds(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_muladds(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_subsubs(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_addsubs(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_mulsubs(ivec3 a, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest); + CGLM_EXPORT int glmc_ivec3_distance2(ivec3 a, ivec3 b); diff --git a/include/cglm/call/ivec4.h b/include/cglm/call/ivec4.h index be80f89ba..0e6d72170 100644 --- a/include/cglm/call/ivec4.h +++ b/include/cglm/call/ivec4.h @@ -53,6 +53,70 @@ CGLM_EXPORT void glmc_ivec4_scale(ivec4 v, int s, ivec4 dest); +CGLM_EXPORT +void +glmc_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_addadds(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subadds(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_muladds(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subsubs(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_addsubs(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_mulsubs(ivec4 a, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest); + CGLM_EXPORT int glmc_ivec4_distance2(ivec4 a, ivec4 b); diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 75e02d816..c4de4cbdb 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -54,6 +54,7 @@ #define cglm_ivec2_h #include "common.h" +#include "util.h" #define GLM_IVEC2_ONE_INIT {1, 1} #define GLM_IVEC2_ZERO_INIT {0, 0} @@ -301,8 +302,8 @@ glm_ivec2_muladds(ivec2 a, int s, ivec2 dest) { CGLM_INLINE void glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) { - dest[0] += a[0] > b[0] ? a[0] : b[0]; - dest[1] += a[1] > b[1] ? a[1] : b[1]; + dest[0] += glm_imax(a[0], b[0]); + dest[1] += glm_imax(a[1], b[1]); } /*! @@ -317,8 +318,8 @@ glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) { CGLM_INLINE void glm_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest) { - dest[0] += a[0] < b[0] ? a[0] : b[0]; - dest[1] += a[1] < b[1] ? a[1] : b[1]; + dest[0] += glm_imin(a[0], b[0]); + dest[1] += glm_imin(a[1], b[1]); } /*! @@ -429,8 +430,8 @@ glm_ivec2_mulsubs(ivec2 a, int s, ivec2 dest) { CGLM_INLINE void glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) { - dest[0] -= a[0] > b[0] ? a[0] : b[0]; - dest[1] -= a[1] > b[1] ? a[1] : b[1]; + dest[0] -= glm_imax(a[0], b[0]); + dest[1] -= glm_imax(a[1], b[1]); } /*! @@ -445,8 +446,8 @@ glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) { CGLM_INLINE void glm_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest) { - dest[0] -= a[0] < b[0] ? a[0] : b[0]; - dest[1] -= a[1] < b[1] ? a[1] : b[1]; + dest[0] -= glm_imin(a[0], b[0]); + dest[1] -= glm_imin(a[1], b[1]); } /*! diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 3731fcfa3..4eac03a50 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -23,6 +23,22 @@ CGLM_INLINE void glm_ivec3_subs(ivec3 v, int s, ivec3 dest) CGLM_INLINE void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_scale(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_addadds(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_subadds(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_muladds(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_subsubs(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_addsubs(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_mulsubs(ivec3 a, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE int glm_ivec3_distance2(ivec3 a, ivec3 b) CGLM_INLINE float glm_ivec3_distance(ivec3 a, ivec3 b) CGLM_INLINE void glm_ivec3_fill(ivec3 v, int val); @@ -38,6 +54,7 @@ #define cglm_ivec3_h #include "common.h" +#include "util.h" #define GLM_IVEC3_ONE_INIT {1, 1, 1} #define GLM_IVEC3_ZERO_INIT {0, 0, 0} @@ -185,6 +202,278 @@ glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { dest[2] = v[2] * s; } +/*! + * @brief add vector [a] with vector [b] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a + b) + */ +CGLM_INLINE +void +glm_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; + dest[2] += a[2] + b[2]; +} + +/*! + * @brief add scalar [s] onto vector [a] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a + s) + */ +CGLM_INLINE +void +glm_ivec3_addadds(ivec3 a, int s, ivec3 dest) { + dest[0] += a[0] + s; + dest[1] += a[1] + s; + dest[2] += a[2] + s; +} + +/*! + * @brief subtract vector [a] from vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a - b) + */ +CGLM_INLINE +void +glm_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; + dest[2] += a[2] - b[2]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first + * @param[in] s scalar + * @param[out] dest dest += (a - s) + */ +CGLM_INLINE +void +glm_ivec3_subadds(ivec3 a, int s, ivec3 dest) { + dest[0] += a[0] - s; + dest[1] += a[1] - s; + dest[2] += a[2] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a * b) + */ +CGLM_INLINE +void +glm_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; + dest[2] += a[2] * b[2]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a * s) + */ +CGLM_INLINE +void +glm_ivec3_muladds(ivec3 a, int s, ivec3 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * s; + dest[2] += a[2] * s; +} + +/*! + * @brief add maximum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += max(a, b) + */ +CGLM_INLINE +void +glm_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] += glm_imax(a[0], b[0]); + dest[1] += glm_imax(a[1], b[1]); + dest[2] += glm_imax(a[2], b[2]); +} + +/*! + * @brief add minimum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] += glm_imin(a[0], b[0]); + dest[1] += glm_imin(a[1], b[1]); + dest[2] += glm_imin(a[2], b[2]); +} + +/*! + * @brief subtract vector [a] from vector [b] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= (a - b) + */ +CGLM_INLINE +void +glm_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] -= a[0] - b[0]; + dest[1] -= a[1] - b[1]; + dest[2] -= a[2] - b[2]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a - s) + */ +CGLM_INLINE +void +glm_ivec3_subsubs(ivec3 a, int s, ivec3 dest) { + dest[0] -= a[0] - s; + dest[1] -= a[1] - s; + dest[2] -= a[2] - s; +} + +/*! + * @brief add vector [a] to vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] -= a[0] + b[0]; + dest[1] -= a[1] + b[1]; + dest[2] -= a[2] + b[2]; +} + +/*! + * @brief add scalar [s] to vector [a] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec3_addsubs(ivec3 a, int s, ivec3 dest) { + dest[0] -= a[0] + s; + dest[1] -= a[1] + s; + dest[2] -= a[2] + s; +} + +/*! + * @brief multiply vector [a] and vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * b) + */ +CGLM_INLINE +void +glm_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] -= a[0] * b[0]; + dest[1] -= a[1] * b[1]; + dest[2] -= a[2] * b[2]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * s) + */ +CGLM_INLINE +void +glm_ivec3_mulsubs(ivec3 a, int s, ivec3 dest) { + dest[0] -= a[0] * s; + dest[1] -= a[1] * s; + dest[2] -= a[2] * s; +} + +/*! + * @brief subtract maximum of vector [a] and vector [b] from vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= max(a, b) + */ +CGLM_INLINE +void +glm_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] -= glm_imax(a[0], b[0]); + dest[1] -= glm_imax(a[1], b[1]); + dest[2] -= glm_imax(a[2], b[2]); +} + +/*! + * @brief subtract minimum of vector [a] and vector [b] from vector [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= min(a, b) + */ +CGLM_INLINE +void +glm_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] -= glm_imin(a[0], b[0]); + dest[1] -= glm_imin(a[1], b[1]); + dest[2] -= glm_imin(a[2], b[2]); +} + /*! * @brief squared distance between two vectors * diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index 6881f0a56..e23b19b99 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -23,6 +23,22 @@ CGLM_INLINE void glm_ivec4_subs(ivec4 v, int s, ivec4 dest) CGLM_INLINE void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) CGLM_INLINE void glm_ivec4_scale(ivec4 v, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_addadds(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_subadds(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_muladds(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_subsubs(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_addsubs(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_mulsubs(ivec4 a, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest) CGLM_INLINE int glm_ivec4_distance2(ivec4 a, ivec4 b) CGLM_INLINE float glm_ivec4_distance(ivec4 a, ivec4 b) CGLM_INLINE void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) @@ -35,6 +51,7 @@ #define cglm_ivec4_h #include "common.h" +#include "util.h" #define GLM_IVEC4_ONE_INIT {1, 1, 1, 1} #define GLM_IVEC4_ZERO_INIT {0, 0, 0, 0} @@ -191,6 +208,294 @@ glm_ivec4_scale(ivec4 v, int s, ivec4 dest) { dest[3] = v[3] * s; } +/*! + * @brief add vector [a] with vector [b] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a + b) + */ +CGLM_INLINE +void +glm_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; + dest[2] += a[2] + b[2]; + dest[3] += a[3] + b[3]; +} + +/*! + * @brief add scalar [s] onto vector [a] and add result to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a + s) + */ +CGLM_INLINE +void +glm_ivec4_addadds(ivec4 a, int s, ivec4 dest) { + dest[0] += a[0] + s; + dest[1] += a[1] + s; + dest[2] += a[2] + s; + dest[3] += a[3] + s; +} + +/*! + * @brief subtract vector [a] from vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a - b) + */ +CGLM_INLINE +void +glm_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; + dest[2] += a[2] - b[2]; + dest[3] += a[3] - b[3]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first + * @param[in] s scalar + * @param[out] dest dest += (a - s) + */ +CGLM_INLINE +void +glm_ivec4_subadds(ivec4 a, int s, ivec4 dest) { + dest[0] += a[0] - s; + dest[1] += a[1] - s; + dest[2] += a[2] - s; + dest[3] += a[3] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += (a * b) + */ +CGLM_INLINE +void +glm_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; + dest[2] += a[2] * b[2]; + dest[3] += a[3] * b[3]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and add result to [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += (a * s) + */ +CGLM_INLINE +void +glm_ivec4_muladds(ivec4 a, int s, ivec4 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * s; + dest[2] += a[2] * s; + dest[3] += a[3] * s; +} + +/*! + * @brief add maximum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += max(a, b) + */ +CGLM_INLINE +void +glm_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] += glm_imax(a[0], b[0]); + dest[1] += glm_imax(a[1], b[1]); + dest[2] += glm_imax(a[2], b[2]); + dest[3] += glm_imax(a[3], b[3]); +} + +/*! + * @brief add minimum of vector [a] and vector [b] to vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] += glm_imin(a[0], b[0]); + dest[1] += glm_imin(a[1], b[1]); + dest[2] += glm_imin(a[2], b[2]); + dest[3] += glm_imin(a[3], b[3]); +} + +/*! + * @brief subtract vector [a] from vector [b] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= (a - b) + */ +CGLM_INLINE +void +glm_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] -= a[0] - b[0]; + dest[1] -= a[1] - b[1]; + dest[2] -= a[2] - b[2]; + dest[3] -= a[3] - b[3]; +} + +/*! + * @brief subtract scalar [s] from vector [a] and subtract result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a - s) + */ +CGLM_INLINE +void +glm_ivec4_subsubs(ivec4 a, int s, ivec4 dest) { + dest[0] -= a[0] - s; + dest[1] -= a[1] - s; + dest[2] -= a[2] - s; + dest[3] -= a[3] - s; +} + +/*! + * @brief add vector [a] to vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] -= a[0] + b[0]; + dest[1] -= a[1] + b[1]; + dest[2] -= a[2] + b[2]; + dest[3] -= a[3] + b[3]; +} + +/*! + * @brief add scalar [s] to vector [a] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a + b) + */ +CGLM_INLINE +void +glm_ivec4_addsubs(ivec4 a, int s, ivec4 dest) { + dest[0] -= a[0] + s; + dest[1] -= a[1] + s; + dest[2] -= a[2] + s; + dest[3] -= a[3] + s; +} + +/*! + * @brief multiply vector [a] and vector [b] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * b) + */ +CGLM_INLINE +void +glm_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] -= a[0] * b[0]; + dest[1] -= a[1] * b[1]; + dest[2] -= a[2] * b[2]; + dest[3] -= a[3] * b[3]; +} + +/*! + * @brief multiply vector [a] with scalar [s] and subtract the result from [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest -= (a * s) + */ +CGLM_INLINE +void +glm_ivec4_mulsubs(ivec4 a, int s, ivec4 dest) { + dest[0] -= a[0] * s; + dest[1] -= a[1] * s; + dest[2] -= a[2] * s; + dest[3] -= a[3] * s; +} + +/*! + * @brief subtract maximum of vector [a] and vector [b] from vector [dest] + * + * applies += operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= max(a, b) + */ +CGLM_INLINE +void +glm_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] -= glm_imax(a[0], b[0]); + dest[1] -= glm_imax(a[1], b[1]); + dest[2] -= glm_imax(a[2], b[2]); + dest[3] -= glm_imax(a[3], b[3]); +} + +/*! + * @brief subtract minimum of vector [a] and vector [b] from vector [dest] + * + * applies -= operator so dest must be initialized + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest dest -= min(a, b) + */ +CGLM_INLINE +void +glm_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] -= glm_imin(a[0], b[0]); + dest[1] -= glm_imin(a[1], b[1]); + dest[2] -= glm_imin(a[2], b[2]); + dest[3] -= glm_imin(a[3], b[3]); +} + /*! * @brief squared distance between two vectors * diff --git a/src/ivec2.c b/src/ivec2.c index 1ec9dcab6..fbfd7ad20 100644 --- a/src/ivec2.c +++ b/src/ivec2.c @@ -68,6 +68,102 @@ glmc_ivec2_scale(ivec2 v, int s, ivec2 dest) { glm_ivec2_scale(v, s, dest); } +CGLM_EXPORT +void +glmc_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_addadds(ivec2 a, int s, ivec2 dest) { + glm_ivec2_addadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subadds(ivec2 a, int s, ivec2 dest) { + glm_ivec2_subadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_muladd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_muladds(ivec2 a, int s, ivec2 dest) { + glm_ivec2_muladds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_minadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_subsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subsubs(ivec2 a, int s, ivec2 dest) { + glm_ivec2_subsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_addsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_addsubs(ivec2 a, int s, ivec2 dest) { + glm_ivec2_addsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_mulsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_mulsubs(ivec2 a, int s, ivec2 dest) { + glm_ivec2_mulsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_maxsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_minsub(a, b, dest); +} + CGLM_EXPORT int glmc_ivec2_distance2(ivec2 a, ivec2 b) { diff --git a/src/ivec3.c b/src/ivec3.c index 4682303ad..70ebd74f2 100644 --- a/src/ivec3.c +++ b/src/ivec3.c @@ -68,6 +68,102 @@ glmc_ivec3_scale(ivec3 v, int s, ivec3 dest) { glm_ivec3_scale(v, s, dest); } +CGLM_EXPORT +void +glmc_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_addadds(ivec3 a, int s, ivec3 dest) { + glm_ivec3_addadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_subadds(ivec3 a, int s, ivec3 dest) { + glm_ivec3_subadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_muladd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_muladds(ivec3 a, int s, ivec3 dest) { + glm_ivec3_muladds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_minadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_subsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_subsubs(ivec3 a, int s, ivec3 dest) { + glm_ivec3_subsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_addsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_addsubs(ivec3 a, int s, ivec3 dest) { + glm_ivec3_addsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_mulsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_mulsubs(ivec3 a, int s, ivec3 dest) { + glm_ivec3_mulsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_maxsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_minsub(a, b, dest); +} + CGLM_EXPORT int glmc_ivec3_distance2(ivec3 a, ivec3 b) { diff --git a/src/ivec4.c b/src/ivec4.c index 89cb3050d..4f57a3b32 100644 --- a/src/ivec4.c +++ b/src/ivec4.c @@ -68,6 +68,102 @@ glmc_ivec4_scale(ivec4 v, int s, ivec4 dest) { glm_ivec4_scale(v, s, dest); } +CGLM_EXPORT +void +glmc_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_addadds(ivec4 a, int s, ivec4 dest) { + glm_ivec4_addadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subadds(ivec4 a, int s, ivec4 dest) { + glm_ivec4_subadds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_muladd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_muladds(ivec4 a, int s, ivec4 dest) { + glm_ivec4_muladds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_minadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_subsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subsubs(ivec4 a, int s, ivec4 dest) { + glm_ivec4_subsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_addsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_addsubs(ivec4 a, int s, ivec4 dest) { + glm_ivec4_addsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_mulsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_mulsubs(ivec4 a, int s, ivec4 dest) { + glm_ivec4_mulsubs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_maxsub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_minsub(a, b, dest); +} + CGLM_EXPORT int glmc_ivec4_distance2(ivec4 a, ivec4 b) { From 4c9b32324d6ce1a6e31b157930f614ed5545079b Mon Sep 17 00:00:00 2001 From: BeeverFeever Date: Mon, 25 Dec 2023 12:51:33 +1100 Subject: [PATCH 4/4] Add tests for ivec -= and += functions --- test/src/test_ivec2.h | 224 ++++++++++++++++++++++++++++++++++++ test/src/test_ivec3.h | 240 +++++++++++++++++++++++++++++++++++++++ test/src/test_ivec4.h | 257 +++++++++++++++++++++++++++++++++++++++++- test/tests.h | 192 +++++++++++++++++++++++++++++++ 4 files changed, 912 insertions(+), 1 deletion(-) diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index 1b506233e..c7ae1de1a 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -126,6 +126,230 @@ TEST_IMPL(GLM_PREFIX, ivec2_scale) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec2_addadd) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_addadd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] + b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] + b[1], c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_addadds) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_addadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] + s, c[0])) + ASSERT(test_eq(d[1] + a[1] + s, c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subadd) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_subadd)(a, b, c); + + ASSERT(test_eq(d[0] + (a[0] - b[0]), c[0])) + ASSERT(test_eq(d[1] + (a[1] - b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subadds) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_subadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] - s, c[0])) + ASSERT(test_eq(d[1] + a[1] - s, c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_muladd) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_muladd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] * b[1], c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_muladds) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_muladds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] * s, c[0])) + ASSERT(test_eq(d[1] + a[1] * s, c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_maxadd) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_maxadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imax(a[1], b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_minadd) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_minadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imin(a[1], b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subsub) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_subsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] - b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] - b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subsubs) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_subsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] - s), c[0])) + ASSERT(test_eq(d[1] - (a[1] - s), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_addsub) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_addsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] + b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] + b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_addsubs) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_addsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] + s), c[0])) + ASSERT(test_eq(d[1] - (a[1] + s), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mulsub) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_mulsub)(a, b, c); + + ASSERT(test_eq(d[0] - a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] - a[1] * b[1], c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mulsubs) { + ivec2 a = {2, -3}, + c = {1, 2}, + d = {1, 2}; + int s = 9; + + GLM(ivec2_mulsubs)(a, s, c); + + ASSERT(test_eq(d[0] - a[0] * s, c[0])) + ASSERT(test_eq(d[1] - a[1] * s, c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_maxsub) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_maxsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imax(a[1], b[1]), c[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_minsub) { + ivec2 a = {2, -3}, + b = {-3, 4}, + c = {1, 2}, + d = {1, 2}; + + GLM(ivec2_minsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imin(a[1], b[1]), c[1])) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec2_distance2) { ivec2 a = {-1, 3}; ivec2 b = {5, 4}; diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index f29ad1d5a..a651d6176 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -131,6 +131,246 @@ TEST_IMPL(GLM_PREFIX, ivec3_scale) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec3_addadd) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_addadd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] + b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] + b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] + b[2], c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_addadds) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_addadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] + s, c[0])) + ASSERT(test_eq(d[1] + a[1] + s, c[1])) + ASSERT(test_eq(d[2] + a[2] + s, c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subadd) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_subadd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] - b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] - b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] - b[2], c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subadds) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_subadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] - s, c[0])) + ASSERT(test_eq(d[1] + a[1] - s, c[1])) + ASSERT(test_eq(d[2] + a[2] - s, c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_muladd) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_muladd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] * b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] * b[2], c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_muladds) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_muladds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] * s, c[0])) + ASSERT(test_eq(d[1] + a[1] * s, c[1])) + ASSERT(test_eq(d[2] + a[2] * s, c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_maxadd) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_maxadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imax(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] += glm_imax(a[2], b[2]), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_minadd) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_minadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imin(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] += glm_imin(a[2], b[2]), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subsub) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_subsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] - b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] - b[1]), c[1])) + ASSERT(test_eq(d[2] - (a[2] - b[2]), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subsubs) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_subsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] - s), c[0])) + ASSERT(test_eq(d[1] - (a[1] - s), c[1])) + ASSERT(test_eq(d[2] - (a[2] - s), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_addsub) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_addsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] + b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] + b[1]), c[1])) + ASSERT(test_eq(d[2] - (a[2] + b[2]), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_addsubs) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_addsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] + s), c[0])) + ASSERT(test_eq(d[1] - (a[1] + s), c[1])) + ASSERT(test_eq(d[2] - (a[2] + s), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mulsub) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_mulsub)(a, b, c); + + ASSERT(test_eq(d[0] - a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] - a[1] * b[1], c[1])) + ASSERT(test_eq(d[2] - a[2] * b[2], c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mulsubs) { + ivec3 a = {2, -3, 5}, + c = {1, 2, -9}, + d = {1, 2, -9}; + int s = 9; + + GLM(ivec3_mulsubs)(a, s, c); + + ASSERT(test_eq(d[0] - a[0] * s, c[0])) + ASSERT(test_eq(d[1] - a[1] * s, c[1])) + ASSERT(test_eq(d[2] - a[2] * s, c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_maxsub) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_maxsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imax(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] -= glm_imax(a[2], b[2]), c[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_minsub) { + ivec3 a = {2, -3, 8}, + b = {-3, 4, 5}, + c = {1, 2, 6}, + d = {1, 2, 6}; + + GLM(ivec3_minsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imin(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] -= glm_imin(a[2], b[2]), c[2])) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec3_distance2) { ivec3 a = {-1, 3, 0}; ivec3 b = {5, 4, 2}; diff --git a/test/src/test_ivec4.h b/test/src/test_ivec4.h index f93d29190..6ff674a13 100644 --- a/test/src/test_ivec4.h +++ b/test/src/test_ivec4.h @@ -8,7 +8,7 @@ #include "test_common.h" TEST_IMPL(GLM_PREFIX, ivec4) { - ivec3 v3 = {2, 3, 5}; + ivec4 v3 = {2, 3, 5}; ivec4 v4; GLM(ivec4)(v3, 7, v4); @@ -141,6 +141,261 @@ TEST_IMPL(GLM_PREFIX, ivec4_scale) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec4_addadd) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_addadd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] + b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] + b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] + b[2], c[2])) + ASSERT(test_eq(d[3] + a[3] + b[3], c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_addadds) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_addadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] + s, c[0])) + ASSERT(test_eq(d[1] + a[1] + s, c[1])) + ASSERT(test_eq(d[2] + a[2] + s, c[2])) + ASSERT(test_eq(d[3] + a[3] + s, c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subadd) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_subadd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] - b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] - b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] - b[2], c[2])) + ASSERT(test_eq(d[3] + a[3] - b[3], c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subadds) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_subadds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] - s, c[0])) + ASSERT(test_eq(d[1] + a[1] - s, c[1])) + ASSERT(test_eq(d[2] + a[2] - s, c[2])) + ASSERT(test_eq(d[3] + a[3] - s, c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_muladd) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_muladd)(a, b, c); + + ASSERT(test_eq(d[0] + a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] + a[1] * b[1], c[1])) + ASSERT(test_eq(d[2] + a[2] * b[2], c[2])) + ASSERT(test_eq(d[3] + a[3] * b[3], c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_muladds) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_muladds)(a, s, c); + + ASSERT(test_eq(d[0] + a[0] * s, c[0])) + ASSERT(test_eq(d[1] + a[1] * s, c[1])) + ASSERT(test_eq(d[2] + a[2] * s, c[2])) + ASSERT(test_eq(d[3] + a[3] * s, c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_maxadd) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_maxadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imax(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] += glm_imax(a[2], b[2]), c[2])) + ASSERT(test_eq(d[3] += glm_imax(a[3], b[3]), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_minadd) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_minadd)(a, b, c); + + ASSERT(test_eq(d[0] += glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] += glm_imin(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] += glm_imin(a[2], b[2]), c[2])) + ASSERT(test_eq(d[3] += glm_imin(a[3], b[3]), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subsub) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_subsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] - b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] - b[1]), c[1])) + ASSERT(test_eq(d[2] - (a[2] - b[2]), c[2])) + ASSERT(test_eq(d[3] - (a[3] - b[3]), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subsubs) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_subsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] - s), c[0])) + ASSERT(test_eq(d[1] - (a[1] - s), c[1])) + ASSERT(test_eq(d[2] - (a[2] - s), c[2])) + ASSERT(test_eq(d[3] - (a[3] - s), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_addsub) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_addsub)(a, b, c); + + ASSERT(test_eq(d[0] - (a[0] + b[0]), c[0])) + ASSERT(test_eq(d[1] - (a[1] + b[1]), c[1])) + ASSERT(test_eq(d[2] - (a[2] + b[2]), c[2])) + ASSERT(test_eq(d[3] - (a[3] + b[3]), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_addsubs) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_addsubs)(a, s, c); + + ASSERT(test_eq(d[0] - (a[0] + s), c[0])) + ASSERT(test_eq(d[1] - (a[1] + s), c[1])) + ASSERT(test_eq(d[2] - (a[2] + s), c[2])) + ASSERT(test_eq(d[3] - (a[3] + s), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_mulsub) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_mulsub)(a, b, c); + + ASSERT(test_eq(d[0] - a[0] * b[0], c[0])) + ASSERT(test_eq(d[1] - a[1] * b[1], c[1])) + ASSERT(test_eq(d[2] - a[2] * b[2], c[2])) + ASSERT(test_eq(d[3] - a[3] * b[3], c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_mulsubs) { + ivec4 a = {2, -3, 4, 7}, + c = {1, 2, -8, 5}, + d = {1, 2, -8, 5}; + int s = 9; + + GLM(ivec4_mulsubs)(a, s, c); + + ASSERT(test_eq(d[0] - a[0] * s, c[0])) + ASSERT(test_eq(d[1] - a[1] * s, c[1])) + ASSERT(test_eq(d[2] - a[2] * s, c[2])) + ASSERT(test_eq(d[3] - a[3] * s, c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_maxsub) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_maxsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imax(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imax(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] -= glm_imax(a[2], b[2]), c[2])) + ASSERT(test_eq(d[3] -= glm_imax(a[3], b[3]), c[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_minsub) { + ivec4 a = {2, -3, 8, -7}, + b = {-3, 4, 5, -2}, + c = {1, 2, 6, 15}, + d = {1, 2, 6, 15}; + + GLM(ivec4_minsub)(a, b, c); + + ASSERT(test_eq(d[0] -= glm_imin(a[0], b[0]), c[0])) + ASSERT(test_eq(d[1] -= glm_imin(a[1], b[1]), c[1])) + ASSERT(test_eq(d[2] -= glm_imin(a[2], b[2]), c[2])) + ASSERT(test_eq(d[3] -= glm_imin(a[3], b[3]), c[3])) + + TEST_SUCCESS +} TEST_IMPL(GLM_PREFIX, ivec4_distance2) { ivec4 a = {-1, 3, 0, 4}; ivec4 b = {5, 4, 2, 6}; diff --git a/test/tests.h b/test/tests.h index 2f2667542..eb3b58b49 100644 --- a/test/tests.h +++ b/test/tests.h @@ -898,6 +898,22 @@ TEST_DECLARE(glm_ivec2_sub) TEST_DECLARE(glm_ivec2_subs) TEST_DECLARE(glm_ivec2_mul) TEST_DECLARE(glm_ivec2_scale) +TEST_DECLARE(glm_ivec2_addadd) +TEST_DECLARE(glm_ivec2_addadds) +TEST_DECLARE(glm_ivec2_subadd) +TEST_DECLARE(glm_ivec2_subadds) +TEST_DECLARE(glm_ivec2_muladd) +TEST_DECLARE(glm_ivec2_muladds) +TEST_DECLARE(glm_ivec2_maxadd) +TEST_DECLARE(glm_ivec2_minadd) +TEST_DECLARE(glm_ivec2_subsub) +TEST_DECLARE(glm_ivec2_subsubs) +TEST_DECLARE(glm_ivec2_addsub) +TEST_DECLARE(glm_ivec2_addsubs) +TEST_DECLARE(glm_ivec2_mulsub) +TEST_DECLARE(glm_ivec2_mulsubs) +TEST_DECLARE(glm_ivec2_maxsub) +TEST_DECLARE(glm_ivec2_minsub) TEST_DECLARE(glm_ivec2_distance2) TEST_DECLARE(glm_ivec2_distance) TEST_DECLARE(glm_ivec2_fill) @@ -918,6 +934,22 @@ TEST_DECLARE(glmc_ivec2_sub) TEST_DECLARE(glmc_ivec2_subs) TEST_DECLARE(glmc_ivec2_mul) TEST_DECLARE(glmc_ivec2_scale) +TEST_DECLARE(glmc_ivec2_addadd) +TEST_DECLARE(glmc_ivec2_addadds) +TEST_DECLARE(glmc_ivec2_subadd) +TEST_DECLARE(glmc_ivec2_subadds) +TEST_DECLARE(glmc_ivec2_muladd) +TEST_DECLARE(glmc_ivec2_muladds) +TEST_DECLARE(glmc_ivec2_maxadd) +TEST_DECLARE(glmc_ivec2_minadd) +TEST_DECLARE(glmc_ivec2_subsub) +TEST_DECLARE(glmc_ivec2_subsubs) +TEST_DECLARE(glmc_ivec2_addsub) +TEST_DECLARE(glmc_ivec2_addsubs) +TEST_DECLARE(glmc_ivec2_mulsub) +TEST_DECLARE(glmc_ivec2_mulsubs) +TEST_DECLARE(glmc_ivec2_maxsub) +TEST_DECLARE(glmc_ivec2_minsub) TEST_DECLARE(glmc_ivec2_distance2) TEST_DECLARE(glmc_ivec2_distance) TEST_DECLARE(glmc_ivec2_fill) @@ -939,6 +971,22 @@ TEST_DECLARE(glm_ivec3_sub) TEST_DECLARE(glm_ivec3_subs) TEST_DECLARE(glm_ivec3_mul) TEST_DECLARE(glm_ivec3_scale) +TEST_DECLARE(glm_ivec3_addadd) +TEST_DECLARE(glm_ivec3_addadds) +TEST_DECLARE(glm_ivec3_subadd) +TEST_DECLARE(glm_ivec3_subadds) +TEST_DECLARE(glm_ivec3_muladd) +TEST_DECLARE(glm_ivec3_muladds) +TEST_DECLARE(glm_ivec3_maxadd) +TEST_DECLARE(glm_ivec3_minadd) +TEST_DECLARE(glm_ivec3_subsub) +TEST_DECLARE(glm_ivec3_subsubs) +TEST_DECLARE(glm_ivec3_addsub) +TEST_DECLARE(glm_ivec3_addsubs) +TEST_DECLARE(glm_ivec3_mulsub) +TEST_DECLARE(glm_ivec3_mulsubs) +TEST_DECLARE(glm_ivec3_maxsub) +TEST_DECLARE(glm_ivec3_minsub) TEST_DECLARE(glm_ivec3_distance2) TEST_DECLARE(glm_ivec3_distance) TEST_DECLARE(glm_ivec3_fill) @@ -958,6 +1006,22 @@ TEST_DECLARE(glmc_ivec3_sub) TEST_DECLARE(glmc_ivec3_subs) TEST_DECLARE(glmc_ivec3_mul) TEST_DECLARE(glmc_ivec3_scale) +TEST_DECLARE(glmc_ivec3_addadd) +TEST_DECLARE(glmc_ivec3_addadds) +TEST_DECLARE(glmc_ivec3_subadd) +TEST_DECLARE(glmc_ivec3_subadds) +TEST_DECLARE(glmc_ivec3_muladd) +TEST_DECLARE(glmc_ivec3_muladds) +TEST_DECLARE(glmc_ivec3_maxadd) +TEST_DECLARE(glmc_ivec3_minadd) +TEST_DECLARE(glmc_ivec3_subsub) +TEST_DECLARE(glmc_ivec3_subsubs) +TEST_DECLARE(glmc_ivec3_addsub) +TEST_DECLARE(glmc_ivec3_addsubs) +TEST_DECLARE(glmc_ivec3_mulsub) +TEST_DECLARE(glmc_ivec3_mulsubs) +TEST_DECLARE(glmc_ivec3_maxsub) +TEST_DECLARE(glmc_ivec3_minsub) TEST_DECLARE(glmc_ivec3_distance2) TEST_DECLARE(glmc_ivec3_distance) TEST_DECLARE(glmc_ivec3_fill) @@ -978,6 +1042,22 @@ TEST_DECLARE(glm_ivec4_sub) TEST_DECLARE(glm_ivec4_subs) TEST_DECLARE(glm_ivec4_mul) TEST_DECLARE(glm_ivec4_scale) +TEST_DECLARE(glm_ivec4_addadd) +TEST_DECLARE(glm_ivec4_addadds) +TEST_DECLARE(glm_ivec4_subadd) +TEST_DECLARE(glm_ivec4_subadds) +TEST_DECLARE(glm_ivec4_muladd) +TEST_DECLARE(glm_ivec4_muladds) +TEST_DECLARE(glm_ivec4_maxadd) +TEST_DECLARE(glm_ivec4_minadd) +TEST_DECLARE(glm_ivec4_subsub) +TEST_DECLARE(glm_ivec4_subsubs) +TEST_DECLARE(glm_ivec4_addsub) +TEST_DECLARE(glm_ivec4_addsubs) +TEST_DECLARE(glm_ivec4_mulsub) +TEST_DECLARE(glm_ivec4_mulsubs) +TEST_DECLARE(glm_ivec4_maxsub) +TEST_DECLARE(glm_ivec4_minsub) TEST_DECLARE(glm_ivec4_distance2) TEST_DECLARE(glm_ivec4_distance) TEST_DECLARE(glm_ivec4_maxv) @@ -995,6 +1075,22 @@ TEST_DECLARE(glmc_ivec4_sub) TEST_DECLARE(glmc_ivec4_subs) TEST_DECLARE(glmc_ivec4_mul) TEST_DECLARE(glmc_ivec4_scale) +TEST_DECLARE(glmc_ivec4_addadd) +TEST_DECLARE(glmc_ivec4_addadds) +TEST_DECLARE(glmc_ivec4_subadd) +TEST_DECLARE(glmc_ivec4_subadds) +TEST_DECLARE(glmc_ivec4_muladd) +TEST_DECLARE(glmc_ivec4_muladds) +TEST_DECLARE(glmc_ivec4_maxadd) +TEST_DECLARE(glmc_ivec4_minadd) +TEST_DECLARE(glmc_ivec4_subsub) +TEST_DECLARE(glmc_ivec4_subsubs) +TEST_DECLARE(glmc_ivec4_addsub) +TEST_DECLARE(glmc_ivec4_addsubs) +TEST_DECLARE(glmc_ivec4_mulsub) +TEST_DECLARE(glmc_ivec4_mulsubs) +TEST_DECLARE(glmc_ivec4_maxsub) +TEST_DECLARE(glmc_ivec4_minsub) TEST_DECLARE(glmc_ivec4_distance2) TEST_DECLARE(glmc_ivec4_distance) TEST_DECLARE(glmc_ivec4_maxv) @@ -1909,6 +2005,22 @@ TEST_LIST { TEST_ENTRY(glm_ivec2_subs) TEST_ENTRY(glm_ivec2_mul) TEST_ENTRY(glm_ivec2_scale) + TEST_ENTRY(glm_ivec2_addadd) + TEST_ENTRY(glm_ivec2_addadds) + TEST_ENTRY(glm_ivec2_subadd) + TEST_ENTRY(glm_ivec2_subadds) + TEST_ENTRY(glm_ivec2_muladd) + TEST_ENTRY(glm_ivec2_muladds) + TEST_ENTRY(glm_ivec2_maxadd) + TEST_ENTRY(glm_ivec2_minadd) + TEST_ENTRY(glm_ivec2_subsub) + TEST_ENTRY(glm_ivec2_subsubs) + TEST_ENTRY(glm_ivec2_addsub) + TEST_ENTRY(glm_ivec2_addsubs) + TEST_ENTRY(glm_ivec2_mulsub) + TEST_ENTRY(glm_ivec2_mulsubs) + TEST_ENTRY(glm_ivec2_maxsub) + TEST_ENTRY(glm_ivec2_minsub) TEST_ENTRY(glm_ivec2_distance2) TEST_ENTRY(glm_ivec2_distance) TEST_ENTRY(glm_ivec2_fill) @@ -1929,6 +2041,22 @@ TEST_LIST { TEST_ENTRY(glmc_ivec2_subs) TEST_ENTRY(glmc_ivec2_mul) TEST_ENTRY(glmc_ivec2_scale) + TEST_ENTRY(glmc_ivec2_addadd) + TEST_ENTRY(glmc_ivec2_addadds) + TEST_ENTRY(glmc_ivec2_subadd) + TEST_ENTRY(glmc_ivec2_subadds) + TEST_ENTRY(glmc_ivec2_muladd) + TEST_ENTRY(glmc_ivec2_muladds) + TEST_ENTRY(glmc_ivec2_maxadd) + TEST_ENTRY(glmc_ivec2_minadd) + TEST_ENTRY(glmc_ivec2_subsub) + TEST_ENTRY(glmc_ivec2_subsubs) + TEST_ENTRY(glmc_ivec2_addsub) + TEST_ENTRY(glmc_ivec2_addsubs) + TEST_ENTRY(glmc_ivec2_mulsub) + TEST_ENTRY(glmc_ivec2_mulsubs) + TEST_ENTRY(glmc_ivec2_maxsub) + TEST_ENTRY(glmc_ivec2_minsub) TEST_ENTRY(glmc_ivec2_distance2) TEST_ENTRY(glmc_ivec2_distance) TEST_ENTRY(glmc_ivec2_fill) @@ -1950,6 +2078,22 @@ TEST_LIST { TEST_ENTRY(glm_ivec3_subs) TEST_ENTRY(glm_ivec3_mul) TEST_ENTRY(glm_ivec3_scale) + TEST_ENTRY(glm_ivec3_addadd) + TEST_ENTRY(glm_ivec3_addadds) + TEST_ENTRY(glm_ivec3_subadd) + TEST_ENTRY(glm_ivec3_subadds) + TEST_ENTRY(glm_ivec3_muladd) + TEST_ENTRY(glm_ivec3_muladds) + TEST_ENTRY(glm_ivec3_maxadd) + TEST_ENTRY(glm_ivec3_minadd) + TEST_ENTRY(glm_ivec3_subsub) + TEST_ENTRY(glm_ivec3_subsubs) + TEST_ENTRY(glm_ivec3_addsub) + TEST_ENTRY(glm_ivec3_addsubs) + TEST_ENTRY(glm_ivec3_mulsub) + TEST_ENTRY(glm_ivec3_mulsubs) + TEST_ENTRY(glm_ivec3_maxsub) + TEST_ENTRY(glm_ivec3_minsub) TEST_ENTRY(glm_ivec3_distance2) TEST_ENTRY(glm_ivec3_distance) TEST_ENTRY(glm_ivec3_fill) @@ -1969,6 +2113,22 @@ TEST_LIST { TEST_ENTRY(glmc_ivec3_subs) TEST_ENTRY(glmc_ivec3_mul) TEST_ENTRY(glmc_ivec3_scale) + TEST_ENTRY(glmc_ivec3_addadd) + TEST_ENTRY(glmc_ivec3_addadds) + TEST_ENTRY(glmc_ivec3_subadd) + TEST_ENTRY(glmc_ivec3_subadds) + TEST_ENTRY(glmc_ivec3_muladd) + TEST_ENTRY(glmc_ivec3_muladds) + TEST_ENTRY(glmc_ivec3_maxadd) + TEST_ENTRY(glmc_ivec3_minadd) + TEST_ENTRY(glmc_ivec3_subsub) + TEST_ENTRY(glmc_ivec3_subsubs) + TEST_ENTRY(glmc_ivec3_addsub) + TEST_ENTRY(glmc_ivec3_addsubs) + TEST_ENTRY(glmc_ivec3_mulsub) + TEST_ENTRY(glmc_ivec3_mulsubs) + TEST_ENTRY(glmc_ivec3_maxsub) + TEST_ENTRY(glmc_ivec3_minsub) TEST_ENTRY(glmc_ivec3_distance2) TEST_ENTRY(glmc_ivec3_distance) TEST_ENTRY(glmc_ivec3_fill) @@ -1989,6 +2149,22 @@ TEST_LIST { TEST_ENTRY(glm_ivec4_subs) TEST_ENTRY(glm_ivec4_mul) TEST_ENTRY(glm_ivec4_scale) + TEST_ENTRY(glm_ivec4_addadd) + TEST_ENTRY(glm_ivec4_addadds) + TEST_ENTRY(glm_ivec4_subadd) + TEST_ENTRY(glm_ivec4_subadds) + TEST_ENTRY(glm_ivec4_muladd) + TEST_ENTRY(glm_ivec4_muladds) + TEST_ENTRY(glm_ivec4_maxadd) + TEST_ENTRY(glm_ivec4_minadd) + TEST_ENTRY(glm_ivec4_subsub) + TEST_ENTRY(glm_ivec4_subsubs) + TEST_ENTRY(glm_ivec4_addsub) + TEST_ENTRY(glm_ivec4_addsubs) + TEST_ENTRY(glm_ivec4_mulsub) + TEST_ENTRY(glm_ivec4_mulsubs) + TEST_ENTRY(glm_ivec4_maxsub) + TEST_ENTRY(glm_ivec4_minsub) TEST_ENTRY(glm_ivec4_distance2) TEST_ENTRY(glm_ivec4_distance) TEST_ENTRY(glm_ivec4_maxv) @@ -2005,6 +2181,22 @@ TEST_LIST { TEST_ENTRY(glmc_ivec4_subs) TEST_ENTRY(glmc_ivec4_mul) TEST_ENTRY(glmc_ivec4_scale) + TEST_ENTRY(glmc_ivec4_addadd) + TEST_ENTRY(glmc_ivec4_addadds) + TEST_ENTRY(glmc_ivec4_subadd) + TEST_ENTRY(glmc_ivec4_subadds) + TEST_ENTRY(glmc_ivec4_muladd) + TEST_ENTRY(glmc_ivec4_muladds) + TEST_ENTRY(glmc_ivec4_maxadd) + TEST_ENTRY(glmc_ivec4_minadd) + TEST_ENTRY(glmc_ivec4_subsub) + TEST_ENTRY(glmc_ivec4_subsubs) + TEST_ENTRY(glmc_ivec4_addsub) + TEST_ENTRY(glmc_ivec4_addsubs) + TEST_ENTRY(glmc_ivec4_mulsub) + TEST_ENTRY(glmc_ivec4_mulsubs) + TEST_ENTRY(glmc_ivec4_maxsub) + TEST_ENTRY(glmc_ivec4_minsub) TEST_ENTRY(glmc_ivec4_distance2) TEST_ENTRY(glmc_ivec4_distance) TEST_ENTRY(glmc_ivec4_maxv)