From d582146d9aa5aa114852de2dabaaea3d08e05e6c Mon Sep 17 00:00:00 2001 From: Christopher Lang Date: Tue, 17 May 2022 16:04:47 +0100 Subject: [PATCH] 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)