Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename struct/aabb2d.h functions to match aabb2d.h, add tests #442

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions include/cglm/struct/aabb2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*!
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
28 changes: 28 additions & 0 deletions test/src/test_aabb2d.h
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions test/src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading