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