From f815918a7427374806e387c47b6833d61c59d789 Mon Sep 17 00:00:00 2001 From: duarm Date: Mon, 20 Jan 2025 13:29:21 -0300 Subject: [PATCH] rename struct/aabb2d.h functions to match aabb2d.h, add tests --- CMakeLists.txt | 1 + include/cglm/struct/aabb2d.h | 23 +++++++++++++++++++++-- meson.build | 1 + test/src/test_aabb2d.h | 28 ++++++++++++++++++++++++++++ test/src/tests.c | 2 ++ test/tests.h | 6 ++++++ 6 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/src/test_aabb2d.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 01086fa..e80bd8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ add_library(${PROJECT_NAME} src/plane.c src/frustum.c src/box.c + src/aabb2d.c src/project.c src/sphere.c src/ease.c diff --git a/include/cglm/struct/aabb2d.h b/include/cglm/struct/aabb2d.h index 71317fa..936a3a0 100644 --- a/include/cglm/struct/aabb2d.h +++ b/include/cglm/struct/aabb2d.h @@ -137,8 +137,27 @@ glms_aabb2d_(isvalid)(vec2s aabb[2]) { */ CGLM_INLINE float -glms_aabb2d_(size)(vec2s aabb[2]) { - return glm_vec2_distance(aabb[0].raw, aabb[1].raw); +glms_aabb2d_(diag)(vec2s aabb[2]) { + vec2 rawAabb[2]; + glms_vec2_(unpack)(rawAabb, aabb, 2); + return glm_aabb2d_diag(rawAabb); +} + + +/*! + * @brief size of aabb + * + * @param[in] aabb bounding aabb + * @param[out] dest size + */ +CGLM_INLINE +vec2s +glms_aabb2d_(sizev)(vec2s aabb[2]) { + vec2s size; + vec2 rawAabb[2]; + glms_vec2_(unpack)(rawAabb, aabb, 2); + glm_aabb2d_sizev(rawAabb, size.raw); + return size; } /*! diff --git a/meson.build b/meson.build index 3afdc4f..663f2ba 100644 --- a/meson.build +++ b/meson.build @@ -58,6 +58,7 @@ cglm_src = files( 'src/plane.c', 'src/frustum.c', 'src/box.c', + 'src/aabb2d.c', 'src/project.c', 'src/sphere.c', 'src/ease.c', diff --git a/test/src/test_aabb2d.h b/test/src/test_aabb2d.h new file mode 100644 index 0000000..d2ce9fc --- /dev/null +++ b/test/src/test_aabb2d.h @@ -0,0 +1,28 @@ +/* + * 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" + +#ifndef CGLM_TEST_AABB2D_ONCE +#define CGLM_TEST_AABB2D_ONCE + +/* Macros */ +/* Deprecated */ + +#endif /* CGLM_TEST_VEC4_ONCE */ + +/* --- */ +TEST_IMPL(GLM_PREFIX, aabb2d_sizev) { + vec2 a[2] = {{10.0f, 10.0f}, {20.0f, 20.0f}}; + vec2 size = {0}; + + GLM(aabb2d_sizev)(a, size); + + ASSERTIFY(test_assert_vec2_eq(size, (vec2){10.0f, 10.0f})) + + TEST_SUCCESS +} diff --git a/test/src/tests.c b/test/src/tests.c index 4d93294..b9a00b2 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -33,6 +33,7 @@ #include "test_affine.h" #include "test_affine2d.h" #include "test_affine_mat.h" +#include "test_aabb2d.h" #include "test_ray.h" #include "test_cam.h" #include "test_cam_lh_no.h" @@ -72,6 +73,7 @@ #include "test_affine.h" #include "test_affine2d.h" #include "test_affine_mat.h" +#include "test_aabb2d.h" #include "test_ray.h" #include "test_cam.h" #include "test_cam_lh_no.h" diff --git a/test/tests.h b/test/tests.h index bcb2fda..751095e 100644 --- a/test/tests.h +++ b/test/tests.h @@ -97,6 +97,9 @@ TEST_DECLARE(glmc_rotate2d_make) TEST_DECLARE(glmc_rotate2d) TEST_DECLARE(glmc_rotate2d_to) +/* aabb2d */ +TEST_DECLARE(glm_aabb2d_sizev) + /* mat4 */ TEST_DECLARE(glm_mat4_ucopy) TEST_DECLARE(glm_mat4_copy) @@ -1274,6 +1277,9 @@ TEST_LIST { TEST_ENTRY(glmc_rotate2d_make) TEST_ENTRY(glmc_rotate2d) TEST_ENTRY(glmc_rotate2d_to) + + /* aabb2d */ + TEST_ENTRY(glm_aabb2d_sizev) /* mat4 */ TEST_ENTRY(glm_mat4_ucopy)