mirror of
https://github.com/recp/cglm.git
synced 2025-12-26 10:35:10 +00:00
Merge branch 'master' into proj
This commit is contained in:
30
test/src/test_clamp.c
Normal file
30
test/src/test_clamp.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
void
|
||||
test_clamp(void **state) {
|
||||
vec3 v3 = {15.07, 0.4, 17.3};
|
||||
vec4 v4 = {5.07, 2.3, 1.3, 1.4};
|
||||
|
||||
assert_true(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f);
|
||||
assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f);
|
||||
assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f);
|
||||
|
||||
glm_vec_clamp(v3, 0.0, 1.0);
|
||||
glm_vec4_clamp(v4, 1.5, 3.0);
|
||||
|
||||
assert_true(v3[0] == 1.0f);
|
||||
assert_true(v3[1] == 0.4f);
|
||||
assert_true(v3[2] == 1.0f);
|
||||
|
||||
assert_true(v4[0] == 3.0f);
|
||||
assert_true(v4[1] == 2.3f);
|
||||
assert_true(v4[2] == 1.5f);
|
||||
assert_true(v4[3] == 1.5f);
|
||||
}
|
||||
@@ -50,3 +50,10 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_assert_vec3_eq(vec3 v1, vec3 v2) {
|
||||
assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009);
|
||||
assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009);
|
||||
assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009);
|
||||
}
|
||||
|
||||
@@ -31,4 +31,7 @@ test_assert_mat4_eq(mat4 m1, mat4 m2);
|
||||
void
|
||||
test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps);
|
||||
|
||||
void
|
||||
test_assert_vec3_eq(vec3 v1, vec3 v2);
|
||||
|
||||
#endif /* test_common_h */
|
||||
|
||||
44
test/src/test_euler.c
Normal file
44
test/src/test_euler.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
void
|
||||
test_euler(void **state) {
|
||||
mat4 rot1, rot2;
|
||||
vec3 inAngles, outAngles;
|
||||
|
||||
inAngles[0] = glm_rad(-45.0f); /* X angle */
|
||||
inAngles[1] = glm_rad(88.0f); /* Y angle */
|
||||
inAngles[2] = glm_rad(18.0f); /* Z angle */
|
||||
|
||||
glm_euler_xyz(inAngles, rot1);
|
||||
|
||||
/* extract angles */
|
||||
glmc_euler_angles(rot1, outAngles);
|
||||
|
||||
/* angles must be equal in that range */
|
||||
test_assert_vec3_eq(inAngles, outAngles);
|
||||
|
||||
/* matrices must be equal */
|
||||
glmc_euler_xyz(outAngles, rot2);
|
||||
test_assert_mat4_eq(rot1, rot2);
|
||||
|
||||
/* change range */
|
||||
inAngles[0] = glm_rad(-145.0f); /* X angle */
|
||||
inAngles[1] = glm_rad(818.0f); /* Y angle */
|
||||
inAngles[2] = glm_rad(181.0f); /* Z angle */
|
||||
|
||||
glm_euler_xyz(inAngles, rot1);
|
||||
glmc_euler_angles(rot1, outAngles);
|
||||
|
||||
/* angles may not be equal but matrices MUST! */
|
||||
|
||||
/* matrices must be equal */
|
||||
glmc_euler_xyz(outAngles, rot2);
|
||||
test_assert_mat4_eq(rot1, rot2);
|
||||
}
|
||||
@@ -18,6 +18,12 @@ main(int argc, const char * argv[]) {
|
||||
|
||||
/* project */
|
||||
cmocka_unit_test(test_project)
|
||||
|
||||
/* vector */
|
||||
cmocka_unit_test(test_clamp),
|
||||
|
||||
/* euler */
|
||||
cmocka_unit_test(test_euler)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
@@ -19,4 +19,10 @@ test_camera_decomp(void **state);
|
||||
void
|
||||
test_project(void **state);
|
||||
|
||||
void
|
||||
test_clamp(void **state);
|
||||
|
||||
void
|
||||
test_euler(void **state);
|
||||
|
||||
#endif /* test_tests_h */
|
||||
|
||||
Reference in New Issue
Block a user