From 495b98a54d323992042326442e636adb632eda90 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Mon, 16 May 2022 20:51:44 +0100 Subject: [PATCH 01/29] Fix tests.h comments --- test/tests.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/tests.h b/test/tests.h index 6801298..8ebbe97 100644 --- a/test/tests.h +++ b/test/tests.h @@ -340,9 +340,7 @@ TEST_DECLARE(glmc_quat_from_vecs) /* bezier */ TEST_DECLARE(bezier) - -/* Macros */ - +/* vec2 */ TEST_DECLARE(MACRO_GLM_VEC2_ONE_INIT) TEST_DECLARE(MACRO_GLM_VEC2_ZERO_INIT) TEST_DECLARE(MACRO_GLM_VEC2_ONE) @@ -385,7 +383,6 @@ TEST_DECLARE(glm_vec2_lerp) TEST_DECLARE(glm_vec2_complex_mul) TEST_DECLARE(glm_vec2_complex_div) - TEST_DECLARE(glmc_vec2) TEST_DECLARE(glmc_vec2_copy) TEST_DECLARE(glmc_vec2_zero) @@ -588,7 +585,6 @@ TEST_DECLARE(glmc_vec3_hadd) TEST_DECLARE(glmc_vec3_sqrt) /* vec4 */ - TEST_DECLARE(MACRO_GLM_VEC4_ONE_INIT) TEST_DECLARE(MACRO_GLM_VEC4_ZERO_INIT) TEST_DECLARE(MACRO_GLM_VEC4_ONE) @@ -735,7 +731,6 @@ TEST_DECLARE(glmc_vec4_hadd) TEST_DECLARE(glmc_vec4_sqrt) /* structs */ - TEST_DECLARE(mat3s_identity_init) TEST_DECLARE(mat3s_zero_init) TEST_DECLARE(mat4s_identity_init) @@ -1075,8 +1070,6 @@ TEST_LIST { TEST_ENTRY(bezier) /* vec2 */ - /* Macros */ - TEST_ENTRY(MACRO_GLM_VEC2_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC2_ZERO_INIT) TEST_ENTRY(MACRO_GLM_VEC2_ONE) @@ -1157,8 +1150,6 @@ TEST_LIST { TEST_ENTRY(glmc_vec2_complex_div) /* vec3 */ - /* Macros */ - TEST_ENTRY(MACRO_GLM_VEC3_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC3_ZERO_INIT) TEST_ENTRY(MACRO_GLM_VEC3_ONE) @@ -1322,8 +1313,6 @@ TEST_LIST { TEST_ENTRY(glmc_vec3_sqrt) /* vec4 */ - /* Macros */ - TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT) TEST_ENTRY(MACRO_GLM_VEC4_ZERO_INIT) TEST_ENTRY(MACRO_GLM_VEC4_ONE) From f7f0f661930bd6c459c9572add30b1dfed53defc Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Mon, 16 May 2022 22:14:57 +0100 Subject: [PATCH 02/29] Reorder api docs --- docs/source/api.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/api.rst b/docs/source/api.rst index 67e0fb0..a35b45b 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -34,15 +34,15 @@ Follow the :doc:`build` documentation for this box quat euler - mat4 - mat3 mat2 + mat3 + mat4 + vec2 + vec2-ext vec3 vec3-ext vec4 vec4-ext - vec2 - vec2-ext color plane project From 4c85b970a9a5aa467cb561fd278e2b350991785e Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Mon, 16 May 2022 22:41:04 +0100 Subject: [PATCH 03/29] Add ivec2 files --- CMakeLists.txt | 1 + include/cglm/call.h | 1 + include/cglm/call/ivec2.h | 23 +++++++++++++++++++++++ include/cglm/cglm.h | 1 + include/cglm/ivec2.h | 31 +++++++++++++++++++++++++++++++ src/ivec2.c | 15 +++++++++++++++ test/src/test_ivec2.h | 24 ++++++++++++++++++++++++ test/src/tests.c | 2 ++ test/tests.h | 10 ++++++++++ 9 files changed, 108 insertions(+) create mode 100644 include/cglm/call/ivec2.h create mode 100644 include/cglm/ivec2.h create mode 100644 src/ivec2.c create mode 100644 test/src/test_ivec2.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c5bd97..95e6ece 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,7 @@ add_library(${PROJECT_NAME} src/vec2.c src/vec3.c src/vec4.c + src/ivec2.c src/mat2.c src/mat3.c src/mat4.c diff --git a/include/cglm/call.h b/include/cglm/call.h index ffb3532..bc29981 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -15,6 +15,7 @@ extern "C" { #include "call/vec2.h" #include "call/vec3.h" #include "call/vec4.h" +#include "call/ivec2.h" #include "call/mat2.h" #include "call/mat3.h" #include "call/mat4.h" diff --git a/include/cglm/call/ivec2.h b/include/cglm/call/ivec2.h new file mode 100644 index 0000000..9ebf427 --- /dev/null +++ b/include/cglm/call/ivec2.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec2_h +#define cglmc_ivec2_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec2(int * __restrict v, ivec2 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec2_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 5ff3421..fa05960 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -12,6 +12,7 @@ #include "vec2.h" #include "vec3.h" #include "vec4.h" +#include "ivec2.h" #include "mat4.h" #include "mat3.h" #include "mat2.h" diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h new file mode 100644 index 0000000..f0e5bd6 --- /dev/null +++ b/include/cglm/ivec2.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* +FUNCTIONS: + CGLM_INLINE void glm_ivec2(int * __restrict v, ivec2 dest) + */ + +#ifndef cglm_ivec2_h +#define cglm_ivec2_h + +#include "common.h" + +/*! + * @brief init ivec2 using another vector + * + * @param[in] v a vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2(int * __restrict v, ivec2 dest) { + dest[0] = v[0]; + dest[1] = v[1]; +} + +#endif /* cglm_ivec2_h */ diff --git a/src/ivec2.c b/src/ivec2.c new file mode 100644 index 0000000..855035a --- /dev/null +++ b/src/ivec2.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_ivec2(int * __restrict v, ivec2 dest) { + glm_ivec2(v, dest); +} diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h new file mode 100644 index 0000000..8dc6f91 --- /dev/null +++ b/test/src/test_ivec2.h @@ -0,0 +1,24 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec2) { + ivec4 v4 = {2, 3, 5, 7}; + ivec4 v3 = {11, 13, 17}; + ivec4 v2; + + GLM(ivec2)(v4, v2); + ASSERT(test_eq(v2[0], v4[0])) + ASSERT(test_eq(v2[1], v4[1])) + + GLM(ivec2)(v3, v2); + ASSERT(test_eq(v2[0], v3[0])) + ASSERT(test_eq(v2[1], v3[1])) + + TEST_SUCCESS +} diff --git a/test/src/tests.c b/test/src/tests.c index 1cfc378..2b895ea 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -15,6 +15,7 @@ #include "test_vec2.h" #include "test_vec3.h" #include "test_vec4.h" +#include "test_ivec2.h" #include "test_mat2.h" #include "test_mat3.h" #include "test_mat4.h" @@ -39,6 +40,7 @@ #include "test_vec2.h" #include "test_vec3.h" #include "test_vec4.h" +#include "test_ivec2.h" #include "test_mat2.h" #include "test_mat3.h" #include "test_mat4.h" diff --git a/test/tests.h b/test/tests.h index 8ebbe97..80fd38c 100644 --- a/test/tests.h +++ b/test/tests.h @@ -730,6 +730,11 @@ TEST_DECLARE(glmc_vec4_fract) TEST_DECLARE(glmc_vec4_hadd) TEST_DECLARE(glmc_vec4_sqrt) +/* ivec2 */ +TEST_DECLARE(glm_ivec2) + +TEST_DECLARE(glmc_ivec2) + /* structs */ TEST_DECLARE(mat3s_identity_init) TEST_DECLARE(mat3s_zero_init) @@ -1458,6 +1463,11 @@ TEST_LIST { TEST_ENTRY(glmc_vec4_hadd) TEST_ENTRY(glmc_vec4_sqrt) + /* ivec2 */ + TEST_ENTRY(glm_ivec2) + + TEST_ENTRY(glmc_ivec2) + /* structs */ TEST_ENTRY(mat3s_identity_init) TEST_ENTRY(mat3s_zero_init) From ee09707c1c22383ba48a3342ce5acd04c43cab55 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 15:53:37 +0100 Subject: [PATCH 04/29] Fix ivec2 test --- test/src/test_ivec2.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index 8dc6f91..d46d890 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -9,8 +9,8 @@ TEST_IMPL(GLM_PREFIX, ivec2) { ivec4 v4 = {2, 3, 5, 7}; - ivec4 v3 = {11, 13, 17}; - ivec4 v2; + ivec3 v3 = {11, 13, 17}; + ivec2 v2; GLM(ivec2)(v4, v2); ASSERT(test_eq(v2[0], v4[0])) From d582146d9aa5aa114852de2dabaaea3d08e05e6c Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 16:04:47 +0100 Subject: [PATCH 05/29] Add ivec3 and ivec4 files --- CMakeLists.txt | 2 ++ include/cglm/call.h | 2 ++ include/cglm/call/ivec3.h | 23 +++++++++++++++++++++++ include/cglm/call/ivec4.h | 23 +++++++++++++++++++++++ include/cglm/cglm.h | 2 ++ include/cglm/ivec3.h | 32 ++++++++++++++++++++++++++++++++ include/cglm/ivec4.h | 34 ++++++++++++++++++++++++++++++++++ src/ivec3.c | 15 +++++++++++++++ src/ivec4.c | 15 +++++++++++++++ test/src/test_ivec3.h | 20 ++++++++++++++++++++ test/src/test_ivec4.h | 21 +++++++++++++++++++++ test/src/tests.c | 4 ++++ test/tests.h | 20 ++++++++++++++++++++ 13 files changed, 213 insertions(+) create mode 100644 include/cglm/call/ivec3.h create mode 100644 include/cglm/call/ivec4.h create mode 100644 include/cglm/ivec3.h create mode 100644 include/cglm/ivec4.h create mode 100644 src/ivec3.c create mode 100644 src/ivec4.c create mode 100644 test/src/test_ivec3.h create mode 100644 test/src/test_ivec4.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 95e6ece..f869c8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ add_library(${PROJECT_NAME} src/vec3.c src/vec4.c src/ivec2.c + src/ivec3.c + src/ivec4.c src/mat2.c src/mat3.c src/mat4.c diff --git a/include/cglm/call.h b/include/cglm/call.h index bc29981..734bd46 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -16,6 +16,8 @@ extern "C" { #include "call/vec3.h" #include "call/vec4.h" #include "call/ivec2.h" +#include "call/ivec3.h" +#include "call/ivec4.h" #include "call/mat2.h" #include "call/mat3.h" #include "call/mat4.h" diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h new file mode 100644 index 0000000..6cf1d2f --- /dev/null +++ b/include/cglm/call/ivec3.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec3_h +#define cglmc_ivec3_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec3(int * __restrict v, ivec3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec3_h */ diff --git a/include/cglm/call/ivec4.h b/include/cglm/call/ivec4.h new file mode 100644 index 0000000..d37a2d2 --- /dev/null +++ b/include/cglm/call/ivec4.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec4_h +#define cglmc_ivec4_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec4(ivec3 v3, int last, ivec4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec4_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index fa05960..1828cb4 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -13,6 +13,8 @@ #include "vec3.h" #include "vec4.h" #include "ivec2.h" +#include "ivec3.h" +#include "ivec4.h" #include "mat4.h" #include "mat3.h" #include "mat2.h" diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h new file mode 100644 index 0000000..a2056ab --- /dev/null +++ b/include/cglm/ivec3.h @@ -0,0 +1,32 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* +FUNCTIONS: + CGLM_INLINE void glm_ivec3(int * __restrict v, ivec3 dest) + */ + +#ifndef cglm_ivec3_h +#define cglm_ivec3_h + +#include "common.h" + +/*! + * @brief init ivec3 using another vector + * + * @param[in] v a vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3(int * __restrict v, ivec3 dest) { + dest[0] = v[0]; + dest[1] = v[1]; + dest[2] = v[2]; +} + +#endif /* cglm_ivec3_h */ diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h new file mode 100644 index 0000000..a6fece6 --- /dev/null +++ b/include/cglm/ivec4.h @@ -0,0 +1,34 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* +FUNCTIONS: + CGLM_INLINE void glm_ivec4(int * __restrict v, ivec4 dest) + */ + +#ifndef cglm_ivec4_h +#define cglm_ivec4_h + +#include "common.h" + +/*! + * @brief init ivec4 using ivec3 + * + * @param[in] v3 vector3 + * @param[in] last last item + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4(ivec3 v3, int last, ivec4 dest) { + dest[0] = v3[0]; + dest[1] = v3[1]; + dest[2] = v3[2]; + dest[3] = last; +} + +#endif /* cglm_ivec4_h */ diff --git a/src/ivec3.c b/src/ivec3.c new file mode 100644 index 0000000..7782c9d --- /dev/null +++ b/src/ivec3.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_ivec3(int * __restrict v, ivec3 dest) { + glm_ivec3(v, dest); +} diff --git a/src/ivec4.c b/src/ivec4.c new file mode 100644 index 0000000..dd297d8 --- /dev/null +++ b/src/ivec4.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_ivec4(ivec3 v3, int last, ivec4 dest) { + glm_ivec4(v3, last, dest); +} diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h new file mode 100644 index 0000000..c7058a4 --- /dev/null +++ b/test/src/test_ivec3.h @@ -0,0 +1,20 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec3) { + ivec4 v4 = {2, 3, 5, 7}; + ivec3 v3; + + GLM(ivec3)(v4, v3); + ASSERT(test_eq(v3[0], v4[0])) + ASSERT(test_eq(v3[1], v4[1])) + ASSERT(test_eq(v3[2], v4[2])) + + TEST_SUCCESS +} diff --git a/test/src/test_ivec4.h b/test/src/test_ivec4.h new file mode 100644 index 0000000..3ada7aa --- /dev/null +++ b/test/src/test_ivec4.h @@ -0,0 +1,21 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(GLM_PREFIX, ivec4) { + ivec3 v3 = {2, 3, 5}; + ivec4 v4; + + GLM(ivec4)(v3, 7, v4); + ASSERT(test_eq(v4[0], v3[0])) + ASSERT(test_eq(v4[1], v3[1])) + ASSERT(test_eq(v4[2], v3[2])) + ASSERT(test_eq(v4[3], 7)) + + TEST_SUCCESS +} diff --git a/test/src/tests.c b/test/src/tests.c index 2b895ea..1505e32 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -16,6 +16,8 @@ #include "test_vec3.h" #include "test_vec4.h" #include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" #include "test_mat2.h" #include "test_mat3.h" #include "test_mat4.h" @@ -41,6 +43,8 @@ #include "test_vec3.h" #include "test_vec4.h" #include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" #include "test_mat2.h" #include "test_mat3.h" #include "test_mat4.h" diff --git a/test/tests.h b/test/tests.h index 80fd38c..b9cc53c 100644 --- a/test/tests.h +++ b/test/tests.h @@ -735,6 +735,16 @@ TEST_DECLARE(glm_ivec2) TEST_DECLARE(glmc_ivec2) +/* ivec3 */ +TEST_DECLARE(glm_ivec3) + +TEST_DECLARE(glmc_ivec3) + +/* ivec4 */ +TEST_DECLARE(glm_ivec4) + +TEST_DECLARE(glmc_ivec4) + /* structs */ TEST_DECLARE(mat3s_identity_init) TEST_DECLARE(mat3s_zero_init) @@ -1468,6 +1478,16 @@ TEST_LIST { TEST_ENTRY(glmc_ivec2) + /* ivec3 */ + TEST_ENTRY(glm_ivec3) + + TEST_ENTRY(glmc_ivec3) + + /* ivec4 */ + TEST_ENTRY(glm_ivec4) + + TEST_ENTRY(glmc_ivec4) + /* structs */ TEST_ENTRY(mat3s_identity_init) TEST_ENTRY(mat3s_zero_init) From a85744430a639de9ced19ed945f755497d1fb2ec Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 22:25:10 +0100 Subject: [PATCH 06/29] Add ivec2 functions --- include/cglm/call/ivec2.h | 56 ++++++++++ include/cglm/ivec2.h | 210 ++++++++++++++++++++++++++++++++++++++ src/ivec2.c | 84 +++++++++++++++ 3 files changed, 350 insertions(+) diff --git a/include/cglm/call/ivec2.h b/include/cglm/call/ivec2.h index 9ebf427..d3b8fd2 100644 --- a/include/cglm/call/ivec2.h +++ b/include/cglm/call/ivec2.h @@ -17,6 +17,62 @@ CGLM_EXPORT void glmc_ivec2(int * __restrict v, ivec2 dest); +CGLM_EXPORT +void +glmc_ivec2_copy(ivec2 a, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_zero(ivec2 v); + +CGLM_EXPORT +void +glmc_ivec2_one(ivec2 v); + +CGLM_EXPORT +void +glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_adds(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subs(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_scale(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +int +glmc_ivec2_distance2(ivec2 a, ivec2 b); + +CGLM_EXPORT +float +glmc_ivec2_distance(ivec2 a, ivec2 b); + +CGLM_EXPORT +void +glmc_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_clamp(ivec2 v, int minVal, int maxVal); + #ifdef __cplusplus } #endif diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index f0e5bd6..6371d72 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -8,6 +8,20 @@ /* FUNCTIONS: CGLM_INLINE void glm_ivec2(int * __restrict v, ivec2 dest) + CGLM_INLINE void glm_ivec2_copy(ivec2 a, ivec2 dest) + CGLM_INLINE voidglm_ivec2_zero(ivec2 v) + CGLM_INLINE void glm_ivec2_one(ivec2 v) + CGLM_INLINE void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) + 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 int glm_ivec2_distance2(ivec2 a, ivec2 b) + CGLM_INLINE float glm_ivec2_distance(ivec2 a, ivec2 b) + CGLM_INLINE void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) */ #ifndef cglm_ivec2_h @@ -28,4 +42,200 @@ glm_ivec2(int * __restrict v, ivec2 dest) { dest[1] = v[1]; } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_copy(ivec2 a, ivec2 dest) { + dest[0] = a[0]; + dest[1] = a[1]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec2_zero(ivec2 v) { + v[0] = v[1] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec2_one(ivec2 v) { + v[0] = v[1] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; +} + +/*! + * @brief add scalar s to vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_adds(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; +} + +/*! + * @brief subtract scalar s from vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_subs(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_mul(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 store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance + */ +CGLM_INLINE +int +glm_ivec2_distance2(ivec2 a, ivec2 b) { + int xd = a[0] - b[0]; + int yd = a[1] - b[1]; + return xd * xd + yd * yd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec2_distance(ivec2 a, ivec2 b) { + return sqrtf((float)glm_ivec2_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_maxv(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 set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec2_minv(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 clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] minVal minimum value + */ +CGLM_INLINE +void +glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; +} + #endif /* cglm_ivec2_h */ diff --git a/src/ivec2.c b/src/ivec2.c index 855035a..1162c22 100644 --- a/src/ivec2.c +++ b/src/ivec2.c @@ -13,3 +13,87 @@ void glmc_ivec2(int * __restrict v, ivec2 dest) { glm_ivec2(v, dest); } + +CGLM_EXPORT +void +glmc_ivec2_copy(ivec2 a, ivec2 dest) { + glm_ivec2_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_zero(ivec2 v) { + glm_ivec2_zero(v); +} + +CGLM_EXPORT +void +glmc_ivec2_one(ivec2 v) { + glm_ivec2_one(v); +} + +CGLM_EXPORT +void +glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_adds(ivec2 v, int s, ivec2 dest) { + glm_ivec2_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subs(ivec2 v, int s, ivec2 dest) { + glm_ivec2_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_scale(ivec2 v, int s, ivec2 dest) { + glm_ivec2_scale(v, s, dest); +} + +CGLM_EXPORT +int +glmc_ivec2_distance2(ivec2 a, ivec2 b) { + return glm_ivec2_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_ivec2_distance(ivec2 a, ivec2 b) { + return glm_ivec2_distance(a, b); +} + +CGLM_EXPORT +void +glmc_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_clamp(ivec2 v, int minVal, int maxVal) { + glm_ivec2_clamp(v, minVal, maxVal); +} From db1a23d13c49a7be3c7a68a1d56eb7049d67726c Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 22:27:38 +0100 Subject: [PATCH 07/29] Add ivec2 tests --- test/src/test_ivec2.h | 170 +++++++++++++++++++++++++++++++++++++++++- test/tests.h | 56 ++++++++++++++ 2 files changed, 222 insertions(+), 4 deletions(-) diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index d46d890..e4dba4a 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -13,12 +13,174 @@ TEST_IMPL(GLM_PREFIX, ivec2) { ivec2 v2; GLM(ivec2)(v4, v2); - ASSERT(test_eq(v2[0], v4[0])) - ASSERT(test_eq(v2[1], v4[1])) + ASSERT(v2[0] == v4[0]) + ASSERT(v2[1] == v4[1]) GLM(ivec2)(v3, v2); - ASSERT(test_eq(v2[0], v3[0])) - ASSERT(test_eq(v2[1], v3[1])) + ASSERT(v2[0] == v3[0]) + ASSERT(v2[1] == v3[1]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_copy) { + ivec2 src = {7, 5}; + ivec2 dst = {10, 11}; + + GLM(ivec2_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_zero) { + ivec2 v = {2, 3}; + + GLM(ivec2_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_one) { + ivec2 v = {-2, 9}; + + GLM(ivec2_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_add) { + ivec2 a = {14, 3}; + ivec2 b = {-3, 2}; + ivec2 v = {99, 99}; + GLM(ivec2_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_adds) { + ivec2 a = {-3, 1}; + ivec2 v = {99, 99}; + int s = 2; + + GLM(ivec2_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_sub) { + ivec2 a = {-2, 9}; + ivec2 b = {3, 2}; + ivec2 v = {99, 99}; + + GLM(ivec2_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subs) { + ivec2 a = {5, -2}; + ivec2 v = {99, 99}; + int s = -3; + + GLM(ivec2_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mul) { + ivec2 a = {3, 4}; + ivec2 b = {-2, 3}; + ivec2 v = {99, 99}; + + GLM(ivec2_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_scale) { + ivec2 a = {-9, 2}; + ivec2 v = {99, 99}; + int s = -2; + + GLM(ivec2_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance2) { + ivec2 a = {-1, 3}; + ivec2 b = {5, 4}; + + int v = GLM(ivec2_distance2)(a, b); + ASSERT(v == 37) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance) { + ivec2 a = {3, 2}; + ivec2 b = {-2, 5}; + + float v = GLM(ivec2_distance)(a, b); + ASSERT(test_eq(v, 5.8309518948)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_maxv) { + ivec2 a = {9, -20}; + ivec2 b = {8, -1}; + ivec2 v = {99, 99}; + + GLM(ivec2_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_minv) { + ivec2 a = {16, 0}; + ivec2 b = {-15, 10}; + ivec2 v = {99, 99}; + + GLM(ivec2_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_clamp) { + ivec2 v = {3, -1}; + + GLM(ivec2_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + + v[0] = -15; + v[1] = 4; + GLM(ivec2_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) TEST_SUCCESS } diff --git a/test/tests.h b/test/tests.h index b9cc53c..8c57ecc 100644 --- a/test/tests.h +++ b/test/tests.h @@ -732,8 +732,36 @@ TEST_DECLARE(glmc_vec4_sqrt) /* ivec2 */ TEST_DECLARE(glm_ivec2) +TEST_DECLARE(glm_ivec2_copy) +TEST_DECLARE(glm_ivec2_zero) +TEST_DECLARE(glm_ivec2_one) +TEST_DECLARE(glm_ivec2_add) +TEST_DECLARE(glm_ivec2_adds) +TEST_DECLARE(glm_ivec2_sub) +TEST_DECLARE(glm_ivec2_subs) +TEST_DECLARE(glm_ivec2_mul) +TEST_DECLARE(glm_ivec2_scale) +TEST_DECLARE(glm_ivec2_distance2) +TEST_DECLARE(glm_ivec2_distance) +TEST_DECLARE(glm_ivec2_maxv) +TEST_DECLARE(glm_ivec2_minv) +TEST_DECLARE(glm_ivec2_clamp) TEST_DECLARE(glmc_ivec2) +TEST_DECLARE(glmc_ivec2_copy) +TEST_DECLARE(glmc_ivec2_zero) +TEST_DECLARE(glmc_ivec2_one) +TEST_DECLARE(glmc_ivec2_add) +TEST_DECLARE(glmc_ivec2_adds) +TEST_DECLARE(glmc_ivec2_sub) +TEST_DECLARE(glmc_ivec2_subs) +TEST_DECLARE(glmc_ivec2_mul) +TEST_DECLARE(glmc_ivec2_scale) +TEST_DECLARE(glmc_ivec2_distance2) +TEST_DECLARE(glmc_ivec2_distance) +TEST_DECLARE(glmc_ivec2_maxv) +TEST_DECLARE(glmc_ivec2_minv) +TEST_DECLARE(glmc_ivec2_clamp) /* ivec3 */ TEST_DECLARE(glm_ivec3) @@ -1475,8 +1503,36 @@ TEST_LIST { /* ivec2 */ TEST_ENTRY(glm_ivec2) + TEST_ENTRY(glm_ivec2_copy) + TEST_ENTRY(glm_ivec2_zero) + TEST_ENTRY(glm_ivec2_one) + TEST_ENTRY(glm_ivec2_add) + TEST_ENTRY(glm_ivec2_adds) + TEST_ENTRY(glm_ivec2_sub) + TEST_ENTRY(glm_ivec2_subs) + TEST_ENTRY(glm_ivec2_mul) + TEST_ENTRY(glm_ivec2_scale) + TEST_ENTRY(glm_ivec2_distance2) + TEST_ENTRY(glm_ivec2_distance) + TEST_ENTRY(glm_ivec2_maxv) + TEST_ENTRY(glm_ivec2_minv) + TEST_ENTRY(glm_ivec2_clamp) TEST_ENTRY(glmc_ivec2) + TEST_ENTRY(glmc_ivec2_copy) + TEST_ENTRY(glmc_ivec2_zero) + TEST_ENTRY(glmc_ivec2_one) + TEST_ENTRY(glmc_ivec2_add) + TEST_ENTRY(glmc_ivec2_adds) + TEST_ENTRY(glmc_ivec2_sub) + TEST_ENTRY(glmc_ivec2_subs) + TEST_ENTRY(glmc_ivec2_mul) + TEST_ENTRY(glmc_ivec2_scale) + TEST_ENTRY(glmc_ivec2_distance2) + TEST_ENTRY(glmc_ivec2_distance) + TEST_ENTRY(glmc_ivec2_maxv) + TEST_ENTRY(glmc_ivec2_minv) + TEST_ENTRY(glmc_ivec2_clamp) /* ivec3 */ TEST_ENTRY(glm_ivec3) From 04bd1bd633500abd989d6d0038308c869366b60c Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 23:03:26 +0100 Subject: [PATCH 08/29] Fix ivec2 doc comment --- include/cglm/ivec2.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 6371d72..aa36648 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -80,8 +80,8 @@ glm_ivec2_one(ivec2 v) { /*! * @brief add vector [a] to vector [b] and store result in [dest] * - * @param[in] a first vector - * @param[in] b second vector + * @param[in] a first vector + * @param[in] b second vector * @param[out] dest destination vector */ CGLM_INLINE From d2957e627581abdfd1bc264906a4a00a599f8803 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Wed, 18 May 2022 17:55:25 +0100 Subject: [PATCH 09/29] Fix ivec2 function list comment --- include/cglm/ivec2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index aa36648..7b1dcab 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -9,7 +9,7 @@ FUNCTIONS: CGLM_INLINE void glm_ivec2(int * __restrict v, ivec2 dest) CGLM_INLINE void glm_ivec2_copy(ivec2 a, ivec2 dest) - CGLM_INLINE voidglm_ivec2_zero(ivec2 v) + CGLM_INLINE void glm_ivec2_zero(ivec2 v) CGLM_INLINE void glm_ivec2_one(ivec2 v) CGLM_INLINE void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) From 65409bcda1af08db526ed7e33f9125880f077e06 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Wed, 18 May 2022 18:05:17 +0100 Subject: [PATCH 10/29] Add ivec3 functions --- include/cglm/call/ivec3.h | 62 +++++++++- include/cglm/ivec3.h | 231 +++++++++++++++++++++++++++++++++++++- src/ivec3.c | 86 +++++++++++++- 3 files changed, 372 insertions(+), 7 deletions(-) diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h index 6cf1d2f..71ec8c8 100644 --- a/include/cglm/call/ivec3.h +++ b/include/cglm/call/ivec3.h @@ -1,7 +1,7 @@ /* - * Copyright (c), Recep Aslantas. + * Copyright (c);, Recep Aslantas. * - * MIT License (MIT), http://opensource.org/licenses/MIT + * MIT License (MIT);, http://opensource.org/licenses/MIT * Full license can be found in the LICENSE file */ @@ -15,7 +15,63 @@ extern "C" { CGLM_EXPORT void -glmc_ivec3(int * __restrict v, ivec3 dest); +cglmc_ivec3(ivec4 v, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_copy(ivec3 a, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_zero(ivec3 v); + +CGLM_EXPORT +void +cglm_ivec3_one(ivec3 v); + +CGLM_EXPORT +void +cglm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_adds(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_subs(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_scale(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +int +cglm_ivec3_distance2(ivec3 a, ivec3 b); + +CGLM_EXPORT +float +cglm_ivec3_distance(ivec3 a, ivec3 b); + +CGLM_EXPORT +void +cglm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +cglm_ivec3_clamp(ivec3 v, int minVal, int maxVal); #ifdef __cplusplus } diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index a2056ab..3594db6 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -7,7 +7,21 @@ /* FUNCTIONS: - CGLM_INLINE void glm_ivec3(int * __restrict v, ivec3 dest) + CGLM_INLINE void glm_ivec3(ivec4 v, ivec3 dest) + CGLM_INLINE void glm_ivec3_copy(ivec3 a, ivec3 dest) + CGLM_INLINE void glm_ivec3_zero(ivec3 v) + CGLM_INLINE void glm_ivec3_one(ivec3 v) + CGLM_INLINE void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_adds(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) + 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 int glm_ivec3_distance2(ivec3 a, ivec3 b) + CGLM_INLINE float glm_ivec3_distance(ivec3 a, ivec3 b) + CGLM_INLINE void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) */ #ifndef cglm_ivec3_h @@ -16,17 +30,228 @@ FUNCTIONS: #include "common.h" /*! - * @brief init ivec3 using another vector + * @brief init ivec3 using an ivec4 * * @param[in] v a vector * @param[out] dest destination */ CGLM_INLINE void -glm_ivec3(int * __restrict v, ivec3 dest) { +glm_ivec3(ivec4 v, ivec3 dest) { dest[0] = v[0]; dest[1] = v[1]; dest[2] = v[2]; } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_copy(ivec3 a, ivec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec3_zero(ivec3 v) { + v[0] = v[1] = v[2] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec3_one(ivec3 v) { + v[0] = v[1] = v[2] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_add(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 [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_adds(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_sub(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 [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_subs(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_mul(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 store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance + */ +CGLM_INLINE +int +glm_ivec3_distance2(ivec3 a, ivec3 b) { + int xd = a[0] - b[0]; + int yd = a[1] - b[1]; + int zd = a[2] - b[2]; + return xd * xd + yd * yd + zd * zd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec3_distance(ivec3 a, ivec3 b) { + return sqrtf((float)glm_ivec3_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] > b[0] ? a[0] : b[0]; + dest[1] = a[1] > b[1] ? a[1] : b[1]; + dest[2] = a[2] > b[2] ? a[2] : b[2]; +} + +/*! + * @brief set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] < b[0] ? a[0] : b[0]; + dest[1] = a[1] < b[1] ? a[1] : b[1]; + dest[2] = a[2] < b[2] ? a[2] : b[2]; +} + +/*! + * @brief clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] minVal minimum value + */ +CGLM_INLINE +void +glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; + + if (v[2] < minVal) + v[2] = minVal; + else if(v[2] > maxVal) + v[2] = maxVal; +} + #endif /* cglm_ivec3_h */ diff --git a/src/ivec3.c b/src/ivec3.c index 7782c9d..fd7bf3f 100644 --- a/src/ivec3.c +++ b/src/ivec3.c @@ -10,6 +10,90 @@ CGLM_EXPORT void -glmc_ivec3(int * __restrict v, ivec3 dest) { +cglmc_ivec3(ivec4 v, ivec3 dest) { glm_ivec3(v, dest); } + +CGLM_EXPORT +void +cglm_ivec3_copy(ivec3 a, ivec3 dest) { + glm_ivec3_copy(a, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_zero(ivec3 v) { + glm_ivec3_zero(v); +} + +CGLM_EXPORT +void +cglm_ivec3_one(ivec3 v) { + glm_ivec3_one(v); +} + +CGLM_EXPORT +void +cglm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_add(a, b, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_adds(ivec3 v, int s, ivec3 dest) { + glm_ivec3_adds(v, s, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_sub(a, b, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_subs(ivec3 v, int s, ivec3 dest) { + glm_ivec3_subs(v, s, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_mul(a, b, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_scale(ivec3 v, int s, ivec3 dest) { + glm_ivec3_scale(v, s, dest); +} + +CGLM_EXPORT +int +cglm_ivec3_distance2(ivec3 a, ivec3 b) { + return glm_ivec3_distance2(a, b); +} + +CGLM_EXPORT +float +cglm_ivec3_distance(ivec3 a, ivec3 b) { + return glm_ivec3_distance(a, b); +} + +CGLM_EXPORT +void +cglm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_maxv(a, b, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_minv(a, b, dest); +} + +CGLM_EXPORT +void +cglm_ivec3_clamp(ivec3 v, int minVal, int maxVal) { + glm_ivec3_clamp(v, minVal, maxVal); +} From 7a19b8f8a3083b8f85502c831faa6a600bbe1711 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 16:52:10 +0100 Subject: [PATCH 11/29] Fix glmc_ivec3 naming --- include/cglm/call/ivec3.h | 30 +++++++++++++++--------------- src/ivec3.c | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h index 71ec8c8..c1c6da7 100644 --- a/include/cglm/call/ivec3.h +++ b/include/cglm/call/ivec3.h @@ -15,63 +15,63 @@ extern "C" { CGLM_EXPORT void -cglmc_ivec3(ivec4 v, ivec3 dest); +glmc_ivec3(ivec4 v, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_copy(ivec3 a, ivec3 dest); +glmc_ivec3_copy(ivec3 a, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_zero(ivec3 v); +glmc_ivec3_zero(ivec3 v); CGLM_EXPORT void -cglm_ivec3_one(ivec3 v); +glmc_ivec3_one(ivec3 v); CGLM_EXPORT void -cglm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest); +glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_adds(ivec3 v, int s, ivec3 dest); +glmc_ivec3_adds(ivec3 v, int s, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest); +glmc_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_subs(ivec3 v, int s, ivec3 dest); +glmc_ivec3_subs(ivec3 v, int s, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest); +glmc_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_scale(ivec3 v, int s, ivec3 dest); +glmc_ivec3_scale(ivec3 v, int s, ivec3 dest); CGLM_EXPORT int -cglm_ivec3_distance2(ivec3 a, ivec3 b); +glmc_ivec3_distance2(ivec3 a, ivec3 b); CGLM_EXPORT float -cglm_ivec3_distance(ivec3 a, ivec3 b); +glmc_ivec3_distance(ivec3 a, ivec3 b); CGLM_EXPORT void -cglm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest); +glmc_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest); +glmc_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest); CGLM_EXPORT void -cglm_ivec3_clamp(ivec3 v, int minVal, int maxVal); +glmc_ivec3_clamp(ivec3 v, int minVal, int maxVal); #ifdef __cplusplus } diff --git a/src/ivec3.c b/src/ivec3.c index fd7bf3f..13549af 100644 --- a/src/ivec3.c +++ b/src/ivec3.c @@ -10,90 +10,90 @@ CGLM_EXPORT void -cglmc_ivec3(ivec4 v, ivec3 dest) { +glmc_ivec3(ivec4 v, ivec3 dest) { glm_ivec3(v, dest); } CGLM_EXPORT void -cglm_ivec3_copy(ivec3 a, ivec3 dest) { +glmc_ivec3_copy(ivec3 a, ivec3 dest) { glm_ivec3_copy(a, dest); } CGLM_EXPORT void -cglm_ivec3_zero(ivec3 v) { +glmc_ivec3_zero(ivec3 v) { glm_ivec3_zero(v); } CGLM_EXPORT void -cglm_ivec3_one(ivec3 v) { +glmc_ivec3_one(ivec3 v) { glm_ivec3_one(v); } CGLM_EXPORT void -cglm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { +glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { glm_ivec3_add(a, b, dest); } CGLM_EXPORT void -cglm_ivec3_adds(ivec3 v, int s, ivec3 dest) { +glmc_ivec3_adds(ivec3 v, int s, ivec3 dest) { glm_ivec3_adds(v, s, dest); } CGLM_EXPORT void -cglm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { +glmc_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { glm_ivec3_sub(a, b, dest); } CGLM_EXPORT void -cglm_ivec3_subs(ivec3 v, int s, ivec3 dest) { +glmc_ivec3_subs(ivec3 v, int s, ivec3 dest) { glm_ivec3_subs(v, s, dest); } CGLM_EXPORT void -cglm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { +glmc_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { glm_ivec3_mul(a, b, dest); } CGLM_EXPORT void -cglm_ivec3_scale(ivec3 v, int s, ivec3 dest) { +glmc_ivec3_scale(ivec3 v, int s, ivec3 dest) { glm_ivec3_scale(v, s, dest); } CGLM_EXPORT int -cglm_ivec3_distance2(ivec3 a, ivec3 b) { +glmc_ivec3_distance2(ivec3 a, ivec3 b) { return glm_ivec3_distance2(a, b); } CGLM_EXPORT float -cglm_ivec3_distance(ivec3 a, ivec3 b) { +glmc_ivec3_distance(ivec3 a, ivec3 b) { return glm_ivec3_distance(a, b); } CGLM_EXPORT void -cglm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { +glmc_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { glm_ivec3_maxv(a, b, dest); } CGLM_EXPORT void -cglm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { +glmc_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { glm_ivec3_minv(a, b, dest); } CGLM_EXPORT void -cglm_ivec3_clamp(ivec3 v, int minVal, int maxVal) { +glmc_ivec3_clamp(ivec3 v, int minVal, int maxVal) { glm_ivec3_clamp(v, minVal, maxVal); } From 8916c50a3df68739aed8ac97da15328bb36b9b3b Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 16:52:55 +0100 Subject: [PATCH 12/29] Update glm_ivec2 test --- test/src/test_ivec2.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index e4dba4a..4cf4850 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -13,12 +13,12 @@ TEST_IMPL(GLM_PREFIX, ivec2) { ivec2 v2; GLM(ivec2)(v4, v2); - ASSERT(v2[0] == v4[0]) - ASSERT(v2[1] == v4[1]) + ASSERT(v2[0] == 2) + ASSERT(v2[1] == 3) GLM(ivec2)(v3, v2); - ASSERT(v2[0] == v3[0]) - ASSERT(v2[1] == v3[1]) + ASSERT(v2[0] == 11) + ASSERT(v2[1] == 13) TEST_SUCCESS } From cd4d0a1efeeb61205c55283234f423aad1b93657 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 17:11:58 +0100 Subject: [PATCH 13/29] Update glm_ivec2_copy test --- test/src/test_ivec2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index 4cf4850..33f3cd0 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -25,7 +25,7 @@ TEST_IMPL(GLM_PREFIX, ivec2) { TEST_IMPL(GLM_PREFIX, ivec2_copy) { ivec2 src = {7, 5}; - ivec2 dst = {10, 11}; + ivec2 dst = {99, 99}; GLM(ivec2_copy)(src, dst); ASSERT(dst[0] == 7) From bffaa13bd52b2cfbe254832fd4317fadcd00e56a Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 17:12:38 +0100 Subject: [PATCH 14/29] Add ivec3 tests --- test/src/test_ivec3.h | 178 +++++++++++++++++++++++++++++++++++++++++- test/tests.h | 56 +++++++++++++ 2 files changed, 233 insertions(+), 1 deletion(-) diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index c7058a4..025c06c 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -9,7 +9,7 @@ TEST_IMPL(GLM_PREFIX, ivec3) { ivec4 v4 = {2, 3, 5, 7}; - ivec3 v3; + ivec3 v3 = {99, 99, 99}; GLM(ivec3)(v4, v3); ASSERT(test_eq(v3[0], v4[0])) @@ -18,3 +18,179 @@ TEST_IMPL(GLM_PREFIX, ivec3) { TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, ivec3_copy) { + ivec3 src = {7, 5, 2}; + ivec3 dst = {99, 99, 99}; + + GLM(ivec3_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_zero) { + ivec3 v = {2, 3, 5}; + + GLM(ivec3_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_one) { + ivec3 v = {-2, 9, 12}; + + GLM(ivec3_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_add) { + ivec3 a = {14, 3, 2}; + ivec3 b = {-3, 2, 1}; + ivec3 v = {99, 99}; + GLM(ivec3_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_adds) { + ivec3 a = {-3, 1, 4}; + ivec3 v = {99, 99, 99}; + int s = 2; + + GLM(ivec3_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + ASSERT(v[2] == 6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_sub) { + ivec3 a = {-2, 9, 1}; + ivec3 b = {3, 2, -1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subs) { + ivec3 a = {5, -2, 6}; + ivec3 v = {99, 99, 99}; + int s = -3; + + GLM(ivec3_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + ASSERT(v[2] == 9) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mul) { + ivec3 a = {3, 4, 5}; + ivec3 b = {-2, 3, 1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_scale) { + ivec3 a = {-9, 2, 3}; + ivec3 v = {99, 99, 99}; + int s = -2; + + GLM(ivec3_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance2) { + ivec3 a = {-1, 3, 0}; + ivec3 b = {5, 4, 2}; + + int v = GLM(ivec3_distance2)(a, b); + ASSERT(v == 41) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance) { + ivec3 a = {3, 2, 4}; + ivec3 b = {-2, 5, 2}; + + float v = GLM(ivec3_distance)(a, b); + ASSERT(test_eq(v, 6.1644140029)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_maxv) { + ivec3 a = {9, -20, 5}; + ivec3 b = {8, -1, 2}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_minv) { + ivec3 a = {16, 0, 4}; + ivec3 b = {-15, 10, 8}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_clamp) { + ivec3 v = {3, -1, 10}; + + GLM(ivec3_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + GLM(ivec3_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} diff --git a/test/tests.h b/test/tests.h index 8c57ecc..038600d 100644 --- a/test/tests.h +++ b/test/tests.h @@ -765,8 +765,36 @@ TEST_DECLARE(glmc_ivec2_clamp) /* ivec3 */ TEST_DECLARE(glm_ivec3) +TEST_DECLARE(glm_ivec3_copy) +TEST_DECLARE(glm_ivec3_zero) +TEST_DECLARE(glm_ivec3_one) +TEST_DECLARE(glm_ivec3_add) +TEST_DECLARE(glm_ivec3_adds) +TEST_DECLARE(glm_ivec3_sub) +TEST_DECLARE(glm_ivec3_subs) +TEST_DECLARE(glm_ivec3_mul) +TEST_DECLARE(glm_ivec3_scale) +TEST_DECLARE(glm_ivec3_distance2) +TEST_DECLARE(glm_ivec3_distance) +TEST_DECLARE(glm_ivec3_maxv) +TEST_DECLARE(glm_ivec3_minv) +TEST_DECLARE(glm_ivec3_clamp) TEST_DECLARE(glmc_ivec3) +TEST_DECLARE(glmc_ivec3_copy) +TEST_DECLARE(glmc_ivec3_zero) +TEST_DECLARE(glmc_ivec3_one) +TEST_DECLARE(glmc_ivec3_add) +TEST_DECLARE(glmc_ivec3_adds) +TEST_DECLARE(glmc_ivec3_sub) +TEST_DECLARE(glmc_ivec3_subs) +TEST_DECLARE(glmc_ivec3_mul) +TEST_DECLARE(glmc_ivec3_scale) +TEST_DECLARE(glmc_ivec3_distance2) +TEST_DECLARE(glmc_ivec3_distance) +TEST_DECLARE(glmc_ivec3_maxv) +TEST_DECLARE(glmc_ivec3_minv) +TEST_DECLARE(glmc_ivec3_clamp) /* ivec4 */ TEST_DECLARE(glm_ivec4) @@ -1536,8 +1564,36 @@ TEST_LIST { /* ivec3 */ TEST_ENTRY(glm_ivec3) + TEST_ENTRY(glm_ivec3_copy) + TEST_ENTRY(glm_ivec3_zero) + TEST_ENTRY(glm_ivec3_one) + TEST_ENTRY(glm_ivec3_add) + TEST_ENTRY(glm_ivec3_adds) + TEST_ENTRY(glm_ivec3_sub) + TEST_ENTRY(glm_ivec3_subs) + TEST_ENTRY(glm_ivec3_mul) + TEST_ENTRY(glm_ivec3_scale) + TEST_ENTRY(glm_ivec3_distance2) + TEST_ENTRY(glm_ivec3_distance) + TEST_ENTRY(glm_ivec3_maxv) + TEST_ENTRY(glm_ivec3_minv) + TEST_ENTRY(glm_ivec3_clamp) TEST_ENTRY(glmc_ivec3) + TEST_ENTRY(glmc_ivec3_copy) + TEST_ENTRY(glmc_ivec3_zero) + TEST_ENTRY(glmc_ivec3_one) + TEST_ENTRY(glmc_ivec3_add) + TEST_ENTRY(glmc_ivec3_adds) + TEST_ENTRY(glmc_ivec3_sub) + TEST_ENTRY(glmc_ivec3_subs) + TEST_ENTRY(glmc_ivec3_mul) + TEST_ENTRY(glmc_ivec3_scale) + TEST_ENTRY(glmc_ivec3_distance2) + TEST_ENTRY(glmc_ivec3_distance) + TEST_ENTRY(glmc_ivec3_maxv) + TEST_ENTRY(glmc_ivec3_minv) + TEST_ENTRY(glmc_ivec3_clamp) /* ivec4 */ TEST_ENTRY(glm_ivec4) From a1a2a046a4450b7cec895fdb8fc1ca2732b900f1 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 17:32:01 +0100 Subject: [PATCH 15/29] Fix ivec[2|3]_clamp comment docs --- include/cglm/ivec2.h | 4 ++-- include/cglm/ivec3.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 7b1dcab..f53011c 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -221,8 +221,8 @@ glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) { * @brief clamp each member of [v] between minVal and maxVal (inclusive) * * @param[in, out] v vector - * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in] minVal minimum value + * @param[in] minVal minimum value */ CGLM_INLINE void diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 3594db6..a52cf90 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -232,8 +232,8 @@ glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { * @brief clamp each member of [v] between minVal and maxVal (inclusive) * * @param[in, out] v vector - * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in] minVal minimum value + * @param[in] minVal minimum value */ CGLM_INLINE void From 94a1e6f6e142a5f5e41055db7b73474cff6bb269 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Thu, 19 May 2022 17:43:17 +0100 Subject: [PATCH 16/29] Add ivec4 functions --- include/cglm/call/ivec4.h | 56 +++++++++ include/cglm/ivec4.h | 242 +++++++++++++++++++++++++++++++++++++- src/ivec4.c | 84 +++++++++++++ 3 files changed, 381 insertions(+), 1 deletion(-) diff --git a/include/cglm/call/ivec4.h b/include/cglm/call/ivec4.h index d37a2d2..79e11b1 100644 --- a/include/cglm/call/ivec4.h +++ b/include/cglm/call/ivec4.h @@ -17,6 +17,62 @@ CGLM_EXPORT void glmc_ivec4(ivec3 v3, int last, ivec4 dest); +CGLM_EXPORT +void +glmc_ivec4_copy(ivec4 a, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_zero(ivec4 v); + +CGLM_EXPORT +void +glmc_ivec4_one(ivec4 v); + +CGLM_EXPORT +void +glmc_ivec4_add(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_adds(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subs(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_scale(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +int +glmc_ivec4_distance2(ivec4 a, ivec4 b); + +CGLM_EXPORT +float +glmc_ivec4_distance(ivec4 a, ivec4 b); + +CGLM_EXPORT +void +glmc_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_clamp(ivec4 v, int minVal, int maxVal); + #ifdef __cplusplus } #endif diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index a6fece6..2e7b95c 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -7,7 +7,21 @@ /* FUNCTIONS: - CGLM_INLINE void glm_ivec4(int * __restrict v, ivec4 dest) + CGLM_INLINE void glm_ivec4(ivec3 v3, int last, ivec4 dest) + CGLM_INLINE void glm_ivec4_copy(ivec4 a, ivec4 dest) + CGLM_INLINE void glm_ivec4_zero(ivec4 v) + CGLM_INLINE void glm_ivec4_one(ivec4 v) + CGLM_INLINE void glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_adds(ivec4 v, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) + 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 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) + CGLM_INLINE void glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) */ #ifndef cglm_ivec4_h @@ -31,4 +45,230 @@ glm_ivec4(ivec3 v3, int last, ivec4 dest) { dest[3] = last; } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_copy(ivec4 a, ivec4 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; + dest[3] = a[3]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec4_zero(ivec4 v) { + v[0] = v[1] = v[2] = v[3] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec4_one(ivec4 v) { + v[0] = v[1] = v[2] = v[3] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_add(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 [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_adds(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; + dest[3] = v[3] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_sub(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 [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_subs(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; + dest[3] = v[3] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_mul(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 store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_scale(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; + dest[3] = v[3] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance + */ +CGLM_INLINE +int +glm_ivec4_distance2(ivec4 a, ivec4 b) { + int xd = a[0] - b[0]; + int yd = a[1] - b[1]; + int zd = a[2] - b[2]; + int wd = a[3] - b[3]; + return xd * xd + yd * yd + zd * zd + wd * wd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec4_distance(ivec4 a, ivec4 b) { + return sqrtf((float)glm_ivec4_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] > b[0] ? a[0] : b[0]; + dest[1] = a[1] > b[1] ? a[1] : b[1]; + dest[2] = a[2] > b[2] ? a[2] : b[2]; + dest[3] = a[3] > b[3] ? a[3] : b[3]; +} + +/*! + * @brief set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] < b[0] ? a[0] : b[0]; + dest[1] = a[1] < b[1] ? a[1] : b[1]; + dest[2] = a[2] < b[2] ? a[2] : b[2]; + dest[3] = a[3] < b[3] ? a[3] : b[3]; +} + +/*! + * @brief clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] minVal minimum value + */ +CGLM_INLINE +void +glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; + + if (v[2] < minVal) + v[2] = minVal; + else if(v[2] > maxVal) + v[2] = maxVal; + + if (v[3] < minVal) + v[3] = minVal; + else if(v[3] > maxVal) + v[3] = maxVal; +} + #endif /* cglm_ivec4_h */ diff --git a/src/ivec4.c b/src/ivec4.c index dd297d8..ea69042 100644 --- a/src/ivec4.c +++ b/src/ivec4.c @@ -13,3 +13,87 @@ void glmc_ivec4(ivec3 v3, int last, ivec4 dest) { glm_ivec4(v3, last, dest); } + +CGLM_EXPORT +void +glmc_ivec4_copy(ivec4 a, ivec4 dest) { + glm_ivec4_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_zero(ivec4 v) { + glm_ivec4_zero(v); +} + +CGLM_EXPORT +void +glmc_ivec4_one(ivec4 v) { + glm_ivec4_one(v); +} + +CGLM_EXPORT +void +glmc_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_adds(ivec4 v, int s, ivec4 dest) { + glm_ivec4_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subs(ivec4 v, int s, ivec4 dest) { + glm_ivec4_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_scale(ivec4 v, int s, ivec4 dest) { + glm_ivec4_scale(v, s, dest); +} + +CGLM_EXPORT +int +glmc_ivec4_distance2(ivec4 a, ivec4 b) { + return glm_ivec4_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_ivec4_distance(ivec4 a, ivec4 b) { + return glm_ivec4_distance(a, b); +} + +CGLM_EXPORT +void +glmc_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_clamp(ivec4 v, int minVal, int maxVal) { + glm_ivec4_clamp(v, minVal, maxVal); +} From 57ec29bd3138d67f537180d2b8c789614b4c7c0a Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 14:26:49 +0100 Subject: [PATCH 17/29] Update glm_ivec3 test --- test/src/test_ivec3.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index 025c06c..b0c7903 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -12,9 +12,9 @@ TEST_IMPL(GLM_PREFIX, ivec3) { ivec3 v3 = {99, 99, 99}; GLM(ivec3)(v4, v3); - ASSERT(test_eq(v3[0], v4[0])) - ASSERT(test_eq(v3[1], v4[1])) - ASSERT(test_eq(v3[2], v4[2])) + ASSERT(v3[0] == 2)) + ASSERT(v3[1] == 3)) + ASSERT(v3[2] == 5)) TEST_SUCCESS } From a3265ebe843814e067021089991e9a6966206457 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 14:27:30 +0100 Subject: [PATCH 18/29] Fix glm_ivec3_one test --- test/src/test_ivec3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index b0c7903..d53068b 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -56,7 +56,7 @@ TEST_IMPL(GLM_PREFIX, ivec3_one) { TEST_IMPL(GLM_PREFIX, ivec3_add) { ivec3 a = {14, 3, 2}; ivec3 b = {-3, 2, 1}; - ivec3 v = {99, 99}; + ivec3 v = {99, 99, 99}; GLM(ivec3_add)(a, b, v); ASSERT(v[0] == 11) ASSERT(v[1] == 5) From f27e26f6322e2976d55fe43087adbffa128a9e1d Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 14:41:59 +0100 Subject: [PATCH 19/29] Fix glm_ivec3 test --- test/src/test_ivec3.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index d53068b..33f052b 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -12,9 +12,9 @@ TEST_IMPL(GLM_PREFIX, ivec3) { ivec3 v3 = {99, 99, 99}; GLM(ivec3)(v4, v3); - ASSERT(v3[0] == 2)) - ASSERT(v3[1] == 3)) - ASSERT(v3[2] == 5)) + ASSERT(v3[0] == 2) + ASSERT(v3[1] == 3) + ASSERT(v3[2] == 5) TEST_SUCCESS } From d1bdfde48d04e22d95dc6e1431126bcf7355c289 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 14:42:42 +0100 Subject: [PATCH 20/29] Add ivec4 tests --- test/src/test_ivec4.h | 196 +++++++++++++++++++++++++++++++++++++++++- test/tests.h | 56 ++++++++++++ 2 files changed, 249 insertions(+), 3 deletions(-) diff --git a/test/src/test_ivec4.h b/test/src/test_ivec4.h index 3ada7aa..cdeea48 100644 --- a/test/src/test_ivec4.h +++ b/test/src/test_ivec4.h @@ -12,10 +12,200 @@ TEST_IMPL(GLM_PREFIX, ivec4) { ivec4 v4; GLM(ivec4)(v3, 7, v4); - ASSERT(test_eq(v4[0], v3[0])) - ASSERT(test_eq(v4[1], v3[1])) - ASSERT(test_eq(v4[2], v3[2])) + ASSERT(test_eq(v4[0], 2)) + ASSERT(test_eq(v4[1], 3)) + ASSERT(test_eq(v4[2], 5)) ASSERT(test_eq(v4[3], 7)) TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, ivec4_copy) { + ivec4 src = {7, 5, 2, 11}; + ivec4 dst = {99, 99, 99, 99}; + + GLM(ivec4_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + ASSERT(dst[3] == 11) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_zero) { + ivec4 v = {2, 3, 5, 7}; + + GLM(ivec4_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_one) { + ivec4 v = {-2, 9, 12, 7}; + + GLM(ivec4_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + ASSERT(v[3] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_add) { + ivec4 a = {14, 3, 2, -4}; + ivec4 b = {-3, 2, 1, -1}; + ivec4 v = {99, 99, 99, 99}; + GLM(ivec4_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + ASSERT(v[3] == -5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_adds) { + ivec4 a = {-3, 1, 4, 2}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_adds)(a, s, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == -1) + ASSERT(v[2] == 2) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_sub) { + ivec4 a = {-2, 9, 1, 5}; + ivec4 b = {3, 2, -1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + ASSERT(v[3] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subs) { + ivec4 a = {5, -2, 6, 1}; + ivec4 v = {99, 99, 99, 99}; + int s = 2; + + GLM(ivec4_subs)(a, s, v); + ASSERT(v[0] == 3) + ASSERT(v[1] == -4) + ASSERT(v[2] == 4) + ASSERT(v[3] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_mul) { + ivec4 a = {3, 4, 5, -3}; + ivec4 b = {-2, 3, 1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + ASSERT(v[3] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_scale) { + ivec4 a = {-9, 2, 3, 0}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance2) { + ivec4 a = {-1, 3, 0, 4}; + ivec4 b = {5, 4, 2, 6}; + + int v = GLM(ivec4_distance2)(a, b); + ASSERT(v == 45) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance) { + ivec4 a = {3, 2, 4, -1}; + ivec4 b = {-2, 5, 2, 4}; + + float v = GLM(ivec4_distance)(a, b); + ASSERT(test_eq(v, 7.9372539331)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_maxv) { + ivec4 a = {9, -20, 5, -3}; + ivec4 b = {8, -1, 2, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_minv) { + ivec4 a = {16, 0, 4, 5}; + ivec4 b = {-15, 10, 8, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_clamp) { + ivec4 v = {3, -1, 10, -100}; + + GLM(ivec4_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + ASSERT(v[3] == -2) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + v[3] = 0; + GLM(ivec4_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} diff --git a/test/tests.h b/test/tests.h index 038600d..361b485 100644 --- a/test/tests.h +++ b/test/tests.h @@ -798,8 +798,36 @@ TEST_DECLARE(glmc_ivec3_clamp) /* ivec4 */ TEST_DECLARE(glm_ivec4) +TEST_DECLARE(glm_ivec4_copy) +TEST_DECLARE(glm_ivec4_zero) +TEST_DECLARE(glm_ivec4_one) +TEST_DECLARE(glm_ivec4_add) +TEST_DECLARE(glm_ivec4_adds) +TEST_DECLARE(glm_ivec4_sub) +TEST_DECLARE(glm_ivec4_subs) +TEST_DECLARE(glm_ivec4_mul) +TEST_DECLARE(glm_ivec4_scale) +TEST_DECLARE(glm_ivec4_distance2) +TEST_DECLARE(glm_ivec4_distance) +TEST_DECLARE(glm_ivec4_maxv) +TEST_DECLARE(glm_ivec4_minv) +TEST_DECLARE(glm_ivec4_clamp) TEST_DECLARE(glmc_ivec4) +TEST_DECLARE(glmc_ivec4_copy) +TEST_DECLARE(glmc_ivec4_zero) +TEST_DECLARE(glmc_ivec4_one) +TEST_DECLARE(glmc_ivec4_add) +TEST_DECLARE(glmc_ivec4_adds) +TEST_DECLARE(glmc_ivec4_sub) +TEST_DECLARE(glmc_ivec4_subs) +TEST_DECLARE(glmc_ivec4_mul) +TEST_DECLARE(glmc_ivec4_scale) +TEST_DECLARE(glmc_ivec4_distance2) +TEST_DECLARE(glmc_ivec4_distance) +TEST_DECLARE(glmc_ivec4_maxv) +TEST_DECLARE(glmc_ivec4_minv) +TEST_DECLARE(glmc_ivec4_clamp) /* structs */ TEST_DECLARE(mat3s_identity_init) @@ -1597,8 +1625,36 @@ TEST_LIST { /* ivec4 */ TEST_ENTRY(glm_ivec4) + TEST_ENTRY(glm_ivec4_copy) + TEST_ENTRY(glm_ivec4_zero) + TEST_ENTRY(glm_ivec4_one) + TEST_ENTRY(glm_ivec4_add) + TEST_ENTRY(glm_ivec4_adds) + TEST_ENTRY(glm_ivec4_sub) + TEST_ENTRY(glm_ivec4_subs) + TEST_ENTRY(glm_ivec4_mul) + TEST_ENTRY(glm_ivec4_scale) + TEST_ENTRY(glm_ivec4_distance2) + TEST_ENTRY(glm_ivec4_distance) + TEST_ENTRY(glm_ivec4_maxv) + TEST_ENTRY(glm_ivec4_minv) + TEST_ENTRY(glm_ivec4_clamp) TEST_ENTRY(glmc_ivec4) + TEST_ENTRY(glmc_ivec4_copy) + TEST_ENTRY(glmc_ivec4_zero) + TEST_ENTRY(glmc_ivec4_one) + TEST_ENTRY(glmc_ivec4_add) + TEST_ENTRY(glmc_ivec4_adds) + TEST_ENTRY(glmc_ivec4_sub) + TEST_ENTRY(glmc_ivec4_subs) + TEST_ENTRY(glmc_ivec4_mul) + TEST_ENTRY(glmc_ivec4_scale) + TEST_ENTRY(glmc_ivec4_distance2) + TEST_ENTRY(glmc_ivec4_distance) + TEST_ENTRY(glmc_ivec4_maxv) + TEST_ENTRY(glmc_ivec4_minv) + TEST_ENTRY(glmc_ivec4_clamp) /* structs */ TEST_ENTRY(mat3s_identity_init) From 4aef2510e9f41624dafe0a18933fda9af7b2e544 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 15:02:58 +0100 Subject: [PATCH 21/29] Init ivec[2|3|4] docs --- docs/source/api.rst | 3 +++ docs/source/index.rst | 2 -- docs/source/ivec2.rst | 10 ++++++++++ docs/source/ivec3.rst | 9 +++++++++ docs/source/ivec4.rst | 9 +++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 docs/source/ivec2.rst create mode 100644 docs/source/ivec3.rst create mode 100644 docs/source/ivec4.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index a35b45b..7ffb823 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -43,6 +43,9 @@ Follow the :doc:`build` documentation for this vec3-ext vec4 vec4-ext + ivec2 + ivec3 + ivec4 color plane project diff --git a/docs/source/index.rst b/docs/source/index.rst index a01c96b..34a71c4 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,8 +13,6 @@ It is similar to the original **glm** library, except **cglm** is mainly for **cglm** stores matrices as column-major order but in the future row-major is considered to be supported as optional. -Currently only **float** type is supported for most operations. - .. toctree:: :maxdepth: 2 :caption: Getting Started: diff --git a/docs/source/ivec2.rst b/docs/source/ivec2.rst new file mode 100644 index 0000000..26a4b3c --- /dev/null +++ b/docs/source/ivec2.rst @@ -0,0 +1,10 @@ + +.. default-domain:: C + +ivec2 +===== + +Header: cglm/ivec2.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/ivec3.rst b/docs/source/ivec3.rst new file mode 100644 index 0000000..de9e77b --- /dev/null +++ b/docs/source/ivec3.rst @@ -0,0 +1,9 @@ +.. default-domain:: C + +ivec3 +===== + +Header: cglm/ivec3.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/ivec4.rst b/docs/source/ivec4.rst new file mode 100644 index 0000000..f86365f --- /dev/null +++ b/docs/source/ivec4.rst @@ -0,0 +1,9 @@ +.. default-domain:: C + +ivec4 +===== + +Header: cglm/ivec4.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 1b3e2fdaec60106bf638fdf0e8981c5eef0fdd6e Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 15:24:36 +0100 Subject: [PATCH 22/29] Improve ivec[2|3|4] documentation comments --- include/cglm/call/ivec3.h | 2 +- include/cglm/ivec2.h | 22 +++++++++++----------- include/cglm/ivec3.h | 32 ++++++++++++++++---------------- include/cglm/ivec4.h | 24 ++++++++++++------------ src/ivec3.c | 4 ++-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h index c1c6da7..3c28811 100644 --- a/include/cglm/call/ivec3.h +++ b/include/cglm/call/ivec3.h @@ -15,7 +15,7 @@ extern "C" { CGLM_EXPORT void -glmc_ivec3(ivec4 v, ivec3 dest); +glmc_ivec3(ivec4 v4, ivec3 dest); CGLM_EXPORT void diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index f53011c..3831a32 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -30,9 +30,9 @@ FUNCTIONS: #include "common.h" /*! - * @brief init ivec2 using another vector + * @brief init ivec2 using vec3 or vec4 * - * @param[in] v a vector + * @param[in] v vector * @param[out] dest destination */ CGLM_INLINE @@ -46,7 +46,7 @@ glm_ivec2(int * __restrict v, ivec2 dest) { * @brief copy all members of [a] to [dest] * * @param[in] a source vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -82,7 +82,7 @@ glm_ivec2_one(ivec2 v) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -96,7 +96,7 @@ glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -110,7 +110,7 @@ glm_ivec2_adds(ivec2 v, int s, ivec2 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -124,7 +124,7 @@ glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -138,7 +138,7 @@ glm_ivec2_subs(ivec2 v, int s, ivec2 dest) { * * @param[in] a frist vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -152,7 +152,7 @@ glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -194,7 +194,7 @@ glm_ivec2_distance(ivec2 a, ivec2 b) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -208,7 +208,7 @@ glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index a52cf90..00edf84 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -7,7 +7,7 @@ /* FUNCTIONS: - CGLM_INLINE void glm_ivec3(ivec4 v, ivec3 dest) + CGLM_INLINE void glm_ivec3(ivec4 v4, ivec3 dest) CGLM_INLINE void glm_ivec3_copy(ivec3 a, ivec3 dest) CGLM_INLINE void glm_ivec3_zero(ivec3 v) CGLM_INLINE void glm_ivec3_one(ivec3 v) @@ -30,24 +30,24 @@ FUNCTIONS: #include "common.h" /*! - * @brief init ivec3 using an ivec4 + * @brief init ivec3 using ivec4 * - * @param[in] v a vector + * @param[in] v4 vector4 * @param[out] dest destination */ CGLM_INLINE void -glm_ivec3(ivec4 v, ivec3 dest) { - dest[0] = v[0]; - dest[1] = v[1]; - dest[2] = v[2]; +glm_ivec3(ivec4 v4, ivec3 dest) { + dest[0] = v4[0]; + dest[1] = v4[1]; + dest[2] = v4[2]; } /*! * @brief copy all members of [a] to [dest] * * @param[in] a source vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -84,7 +84,7 @@ glm_ivec3_one(ivec3 v) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -99,7 +99,7 @@ glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -114,7 +114,7 @@ glm_ivec3_adds(ivec3 v, int s, ivec3 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -129,7 +129,7 @@ glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -144,7 +144,7 @@ glm_ivec3_subs(ivec3 v, int s, ivec3 dest) { * * @param[in] a frist vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -159,7 +159,7 @@ glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -203,7 +203,7 @@ glm_ivec3_distance(ivec3 a, ivec3 b) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -218,7 +218,7 @@ glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index 2e7b95c..0a837bb 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -49,7 +49,7 @@ glm_ivec4(ivec3 v3, int last, ivec4 dest) { * @brief copy all members of [a] to [dest] * * @param[in] a source vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -87,7 +87,7 @@ glm_ivec4_one(ivec4 v) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -103,7 +103,7 @@ glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -119,7 +119,7 @@ glm_ivec4_adds(ivec4 v, int s, ivec4 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -135,7 +135,7 @@ glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -151,7 +151,7 @@ glm_ivec4_subs(ivec4 v, int s, ivec4 dest) { * * @param[in] a frist vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -167,7 +167,7 @@ glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) { * * @param[in] v vector * @param[in] s scalar - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -213,7 +213,7 @@ glm_ivec4_distance(ivec4 a, ivec4 b) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -229,7 +229,7 @@ glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) { * * @param[in] a first vector * @param[in] b second vector - * @param[out] dest destination vector + * @param[out] dest destination */ CGLM_INLINE void @@ -243,9 +243,9 @@ glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { /*! * @brief clamp each member of [v] between minVal and maxVal (inclusive) * - * @param[in, out] v vector - * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] minVal minimum value */ CGLM_INLINE void diff --git a/src/ivec3.c b/src/ivec3.c index 13549af..1e14dd3 100644 --- a/src/ivec3.c +++ b/src/ivec3.c @@ -10,8 +10,8 @@ CGLM_EXPORT void -glmc_ivec3(ivec4 v, ivec3 dest) { - glm_ivec3(v, dest); +glmc_ivec3(ivec4 v4, ivec3 dest) { + glm_ivec3(v4, dest); } CGLM_EXPORT From 09155986fe8caf1aba1bf7d691feb7f3ad99d148 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 16:49:23 +0100 Subject: [PATCH 23/29] Update ivec[2|3|4]_distance2 doc comments --- include/cglm/ivec2.h | 2 +- include/cglm/ivec3.h | 2 +- include/cglm/ivec4.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 3831a32..f4b2bdb 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -166,7 +166,7 @@ glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { * * @param[in] a first vector * @param[in] b second vector - * @return returns squared distance + * @return returns squared distance (distance * distance) */ CGLM_INLINE int diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 00edf84..621434d 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -174,7 +174,7 @@ glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { * * @param[in] a first vector * @param[in] b second vector - * @return returns squared distance + * @return returns squared distance (distance * distance) */ CGLM_INLINE int diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index 0a837bb..8724e3c 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -183,7 +183,7 @@ glm_ivec4_scale(ivec4 v, int s, ivec4 dest) { * * @param[in] a first vector * @param[in] b second vector - * @return returns squared distance + * @return returns squared distance (distance * distance) */ CGLM_INLINE int From dbe3b719c7de91a470d87f76b8d2cf41b4c4a5f0 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 16:53:02 +0100 Subject: [PATCH 24/29] Fix ivec[2|3|4]_clamp doc comments --- include/cglm/ivec2.h | 2 +- include/cglm/ivec3.h | 2 +- include/cglm/ivec4.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index f4b2bdb..1bd181d 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -222,7 +222,7 @@ glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) { * * @param[in, out] v vector * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in] maxVal maximum value */ CGLM_INLINE void diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 621434d..1599637 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -233,7 +233,7 @@ glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { * * @param[in, out] v vector * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in] maxVal maximum value */ CGLM_INLINE void diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index 8724e3c..6cff8c8 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -245,7 +245,7 @@ glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { * * @param[in, out] v vector * @param[in] minVal minimum value - * @param[in] minVal minimum value + * @param[in] maxVal maximum value */ CGLM_INLINE void From 82982abaefd124bb64d1132775187ee9252902b0 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 17:07:16 +0100 Subject: [PATCH 25/29] Add ivec2 documentation --- docs/source/ivec2.rst | 156 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 1 deletion(-) diff --git a/docs/source/ivec2.rst b/docs/source/ivec2.rst index 26a4b3c..62a8976 100644 --- a/docs/source/ivec2.rst +++ b/docs/source/ivec2.rst @@ -1,4 +1,3 @@ - .. default-domain:: C ivec2 @@ -8,3 +7,158 @@ Header: cglm/ivec2.h Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec2` +#. :c:func:`glm_ivec2_copy` +#. :c:func:`glm_ivec2_zero` +#. :c:func:`glm_ivec2_one` +#. :c:func:`glm_ivec2_add` +#. :c:func:`glm_ivec2_adds` +#. :c:func:`glm_ivec2_sub` +#. :c:func:`glm_ivec2_subs` +#. :c:func:`glm_ivec2_mul` +#. :c:func:`glm_ivec2_scale` +#. :c:func:`glm_ivec2_distance2` +#. :c:func:`glm_ivec2_distance` +#. :c:func:`glm_ivec2_maxv` +#. :c:func:`glm_ivec2_minv` +#. :c:func:`glm_ivec2_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + + +.. c:function:: void glm_ivec2(int * v, ivec2 dest) + + init ivec2 using vec3 or vec4 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_copy(ivec2 a, ivec2 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_zero(ivec2 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec2_one(ivec2 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_subs(ivec2 v, int s, ivec2 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_scale(ivec2 v, int s, ivec2 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec2_distance2(ivec2 a, ivec2 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec2_distance(ivec2 a, ivec2 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value From 7bb765367e7c4cb7bb0b6b8320d7266e93816891 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 17:16:09 +0100 Subject: [PATCH 26/29] Small ivec2 docs fix --- docs/source/ivec2.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/ivec2.rst b/docs/source/ivec2.rst index 62a8976..c10bc4c 100644 --- a/docs/source/ivec2.rst +++ b/docs/source/ivec2.rst @@ -29,7 +29,6 @@ Functions: Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ - .. c:function:: void glm_ivec2(int * v, ivec2 dest) init ivec2 using vec3 or vec4 From e3981b6d963b77b159e0cfc05c9a89f43cc346f2 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 17:16:41 +0100 Subject: [PATCH 27/29] Add ivec[3|4] docs --- docs/source/ivec3.rst | 154 ++++++++++++++++++++++++++++++++++++++++++ docs/source/ivec4.rst | 154 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 308 insertions(+) diff --git a/docs/source/ivec3.rst b/docs/source/ivec3.rst index de9e77b..312078a 100644 --- a/docs/source/ivec3.rst +++ b/docs/source/ivec3.rst @@ -7,3 +7,157 @@ Header: cglm/ivec3.h Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec3` +#. :c:func:`glm_ivec3_copy` +#. :c:func:`glm_ivec3_zero` +#. :c:func:`glm_ivec3_one` +#. :c:func:`glm_ivec3_add` +#. :c:func:`glm_ivec3_adds` +#. :c:func:`glm_ivec3_sub` +#. :c:func:`glm_ivec3_subs` +#. :c:func:`glm_ivec3_mul` +#. :c:func:`glm_ivec3_scale` +#. :c:func:`glm_ivec3_distance2` +#. :c:func:`glm_ivec3_distance` +#. :c:func:`glm_ivec3_maxv` +#. :c:func:`glm_ivec3_minv` +#. :c:func:`glm_ivec3_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_ivec3(ivec4 v4, ivec3 dest) + + init ivec3 using ivec4 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_copy(ivec3 a, ivec3 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_zero(ivec3 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec3_one(ivec3 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_adds(ivec3 v, int s, ivec3 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_subs(ivec3 v, int s, ivec3 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_scale(ivec3 v, int s, ivec3 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec3_distance2(ivec3 a, ivec3 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec3_distance(ivec3 a, ivec3 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value diff --git a/docs/source/ivec4.rst b/docs/source/ivec4.rst index f86365f..a175631 100644 --- a/docs/source/ivec4.rst +++ b/docs/source/ivec4.rst @@ -7,3 +7,157 @@ Header: cglm/ivec4.h Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec4` +#. :c:func:`glm_ivec4_copy` +#. :c:func:`glm_ivec4_zero` +#. :c:func:`glm_ivec4_one` +#. :c:func:`glm_ivec4_add` +#. :c:func:`glm_ivec4_adds` +#. :c:func:`glm_ivec4_sub` +#. :c:func:`glm_ivec4_subs` +#. :c:func:`glm_ivec4_mul` +#. :c:func:`glm_ivec4_scale` +#. :c:func:`glm_ivec4_distance2` +#. :c:func:`glm_ivec4_distance` +#. :c:func:`glm_ivec4_maxv` +#. :c:func:`glm_ivec4_minv` +#. :c:func:`glm_ivec4_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_ivec4(ivec3 v3, int last, ivec4 dest) + + init ivec4 using ivec3 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_copy(ivec4 a, ivec4 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_zero(ivec4 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec4_one(ivec4 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_adds(ivec4 v, int s, ivec4 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_subs(ivec4 v, int s, ivec4 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_scale(ivec4 v, int s, ivec4 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec4_distance2(ivec4 a, ivec4 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec4_distance(ivec4 a, ivec4 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value From 838124af49901351d426eb93e3969e111c84e69b Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Fri, 20 May 2022 17:30:54 +0100 Subject: [PATCH 28/29] Declare varables at top of scope for ivec[2|3|4] --- include/cglm/ivec2.h | 5 +++-- include/cglm/ivec3.h | 7 ++++--- include/cglm/ivec4.h | 9 +++++---- test/src/test_ivec2.h | 7 +++++-- test/src/test_ivec3.h | 7 +++++-- test/src/test_ivec4.h | 7 +++++-- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 1bd181d..c1209a9 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -171,8 +171,9 @@ glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { CGLM_INLINE int glm_ivec2_distance2(ivec2 a, ivec2 b) { - int xd = a[0] - b[0]; - int yd = a[1] - b[1]; + int xd, yd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; return xd * xd + yd * yd; } diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 1599637..69f27f3 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -179,9 +179,10 @@ glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { CGLM_INLINE int glm_ivec3_distance2(ivec3 a, ivec3 b) { - int xd = a[0] - b[0]; - int yd = a[1] - b[1]; - int zd = a[2] - b[2]; + int xd, yd, zd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; + zd = a[2] - b[2]; return xd * xd + yd * yd + zd * zd; } diff --git a/include/cglm/ivec4.h b/include/cglm/ivec4.h index 6cff8c8..363ee58 100644 --- a/include/cglm/ivec4.h +++ b/include/cglm/ivec4.h @@ -188,10 +188,11 @@ glm_ivec4_scale(ivec4 v, int s, ivec4 dest) { CGLM_INLINE int glm_ivec4_distance2(ivec4 a, ivec4 b) { - int xd = a[0] - b[0]; - int yd = a[1] - b[1]; - int zd = a[2] - b[2]; - int wd = a[3] - b[3]; + int xd, yd, zd, wd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; + zd = a[2] - b[2]; + wd = a[3] - b[3]; return xd * xd + yd * yd + zd * zd + wd * wd; } diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index 33f3cd0..5374688 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -58,6 +58,7 @@ TEST_IMPL(GLM_PREFIX, ivec2_add) { ivec2 a = {14, 3}; ivec2 b = {-3, 2}; ivec2 v = {99, 99}; + GLM(ivec2_add)(a, b, v); ASSERT(v[0] == 11) ASSERT(v[1] == 5) @@ -128,8 +129,9 @@ TEST_IMPL(GLM_PREFIX, ivec2_scale) { TEST_IMPL(GLM_PREFIX, ivec2_distance2) { ivec2 a = {-1, 3}; ivec2 b = {5, 4}; + int v; - int v = GLM(ivec2_distance2)(a, b); + v = GLM(ivec2_distance2)(a, b); ASSERT(v == 37) TEST_SUCCESS @@ -138,8 +140,9 @@ TEST_IMPL(GLM_PREFIX, ivec2_distance2) { TEST_IMPL(GLM_PREFIX, ivec2_distance) { ivec2 a = {3, 2}; ivec2 b = {-2, 5}; + float v; - float v = GLM(ivec2_distance)(a, b); + v = GLM(ivec2_distance)(a, b); ASSERT(test_eq(v, 5.8309518948)) TEST_SUCCESS diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index 33f052b..dfa8794 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -57,6 +57,7 @@ TEST_IMPL(GLM_PREFIX, ivec3_add) { ivec3 a = {14, 3, 2}; ivec3 b = {-3, 2, 1}; ivec3 v = {99, 99, 99}; + GLM(ivec3_add)(a, b, v); ASSERT(v[0] == 11) ASSERT(v[1] == 5) @@ -133,8 +134,9 @@ TEST_IMPL(GLM_PREFIX, ivec3_scale) { TEST_IMPL(GLM_PREFIX, ivec3_distance2) { ivec3 a = {-1, 3, 0}; ivec3 b = {5, 4, 2}; + int v; - int v = GLM(ivec3_distance2)(a, b); + v = GLM(ivec3_distance2)(a, b); ASSERT(v == 41) TEST_SUCCESS @@ -143,8 +145,9 @@ TEST_IMPL(GLM_PREFIX, ivec3_distance2) { TEST_IMPL(GLM_PREFIX, ivec3_distance) { ivec3 a = {3, 2, 4}; ivec3 b = {-2, 5, 2}; + float v; - float v = GLM(ivec3_distance)(a, b); + v = GLM(ivec3_distance)(a, b); ASSERT(test_eq(v, 6.1644140029)) TEST_SUCCESS diff --git a/test/src/test_ivec4.h b/test/src/test_ivec4.h index cdeea48..dd2d606 100644 --- a/test/src/test_ivec4.h +++ b/test/src/test_ivec4.h @@ -61,6 +61,7 @@ TEST_IMPL(GLM_PREFIX, ivec4_add) { ivec4 a = {14, 3, 2, -4}; ivec4 b = {-3, 2, 1, -1}; ivec4 v = {99, 99, 99, 99}; + GLM(ivec4_add)(a, b, v); ASSERT(v[0] == 11) ASSERT(v[1] == 5) @@ -143,8 +144,9 @@ TEST_IMPL(GLM_PREFIX, ivec4_scale) { TEST_IMPL(GLM_PREFIX, ivec4_distance2) { ivec4 a = {-1, 3, 0, 4}; ivec4 b = {5, 4, 2, 6}; + int v; - int v = GLM(ivec4_distance2)(a, b); + v = GLM(ivec4_distance2)(a, b); ASSERT(v == 45) TEST_SUCCESS @@ -153,8 +155,9 @@ TEST_IMPL(GLM_PREFIX, ivec4_distance2) { TEST_IMPL(GLM_PREFIX, ivec4_distance) { ivec4 a = {3, 2, 4, -1}; ivec4 b = {-2, 5, 2, 4}; + float v; - float v = GLM(ivec4_distance)(a, b); + v = GLM(ivec4_distance)(a, b); ASSERT(test_eq(v, 7.9372539331)) TEST_SUCCESS From cd0ae1945929cef14f5fe5b2b42d8cbd3b079af7 Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Sat, 21 May 2022 11:10:37 +0100 Subject: [PATCH 29/29] Add ivec[2|3|4] sources to meson.build --- meson.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meson.build b/meson.build index e2034ec..8f9cdc4 100644 --- a/meson.build +++ b/meson.build @@ -49,6 +49,9 @@ cglm_src = files( 'src/vec2.c', 'src/vec3.c', 'src/vec4.c', + 'src/ivec2.c', + 'src/ivec3.c', + 'src/ivec4.c', 'src/clipspace/ortho_lh_no.c', 'src/clipspace/ortho_lh_zo.c', 'src/clipspace/ortho_rh_no.c',