diff --git a/CMakeLists.txt b/CMakeLists.txt index eaef8fa..2cfb97c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ if(MSVC) endforeach(flag_var) endif() else() - add_compile_options(-Wall) + add_compile_options(-Wall -Wextra -Wpedantic -Wconversion) if(NOT CMAKE_BUILD_TYPE MATCHES Debug) add_compile_options(-O3) diff --git a/src/noise.c b/src/noise.c index f464202..e2868ec 100644 --- a/src/noise.c +++ b/src/noise.c @@ -24,4 +24,4 @@ CGLM_EXPORT float glmc_perlin_vec2(vec2 p) { return glm_perlin_vec2(p); -} \ No newline at end of file +} diff --git a/test/runner.c b/test/runner.c index 888831c..5852ced 100644 --- a/test/runner.c +++ b/test/runner.c @@ -17,7 +17,7 @@ main(int argc, const char * argv[]) { test_entry_t *entry; test_status_t st; int32_t i, count, passed, failed, maxlen; - double start, end, elapsed, total; + clock_t start, end, elapsed, total; (void)argc; (void)argv; @@ -70,7 +70,7 @@ main(int argc, const char * argv[]) { fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name); if (elapsed > 0.01) - fprintf(stderr, YELLOW "%.2fs", elapsed); + fprintf(stderr, YELLOW "%.2lus", elapsed); else fprintf(stderr, "0"); @@ -85,7 +85,7 @@ main(int argc, const char * argv[]) { } fprintf(stderr, - CYAN "\ncglm test results (%0.2fs):\n" RESET + CYAN "\ncglm test results (%0.2lus):\n" RESET "--------------------------\n" MAGENTA "%d" RESET " tests ran, " diff --git a/test/src/test_affine_mat.h b/test/src/test_affine_mat.h index e928f8e..227b77a 100644 --- a/test/src/test_affine_mat.h +++ b/test/src/test_affine_mat.h @@ -61,8 +61,8 @@ TEST_IMPL(GLM_PREFIX, mul_rot) { mat4 m4 = GLM_MAT4_ZERO_INIT; int i, j, k; - glm_rotate(m1, drand48(), (vec3){drand48(), drand48(), drand48()}); - glm_rotate(m2, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_rotate(m1, frand48(), (vec3){frand48(), frand48(), frand48()}); + glm_rotate(m2, frand48(), (vec3){frand48(), frand48(), frand48()}); GLM(mul_rot)(m1, m2, m3); for (i = 0; i < 4; i++) { diff --git a/test/src/test_common.c b/test/src/test_common.c index 6f44c27..73db526 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -11,49 +11,49 @@ test_rand_mat4(mat4 dest) { glm_mat4_copy(GLM_MAT4_IDENTITY, dest); /* random position */ - dest[3][0] = drand48(); - dest[3][1] = drand48(); - dest[3][2] = drand48(); + dest[3][0] = frand48(); + dest[3][1] = frand48(); + dest[3][2] = frand48(); /* random rotatation around random axis with random angle */ - glm_rotate(dest, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_rotate(dest, frand48(), (vec3){frand48(), frand48(), frand48()}); /* random scale */ - /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ + /* glm_scale(dest, (vec3){frand48(), frand48(), frand48()}); */ } void test_rand_mat4x2(mat4x2 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); - dest[2][0] = drand48(); - dest[2][1] = drand48(); + dest[2][0] = frand48(); + dest[2][1] = frand48(); - dest[3][0] = drand48(); - dest[3][1] = drand48(); + dest[3][0] = frand48(); + dest[3][1] = frand48(); } void test_rand_mat4x3(mat4x3 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[0][2] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[0][2] = frand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); - dest[1][2] = drand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); + dest[1][2] = frand48(); - dest[2][0] = drand48(); - dest[2][1] = drand48(); - dest[2][2] = drand48(); + dest[2][0] = frand48(); + dest[2][1] = frand48(); + dest[2][2] = frand48(); - dest[3][0] = drand48(); - dest[3][1] = drand48(); - dest[3][2] = drand48(); + dest[3][0] = frand48(); + dest[3][1] = frand48(); + dest[3][2] = frand48(); } void @@ -61,80 +61,80 @@ test_rand_mat3(mat3 dest) { mat4 m4; /* random rotatation around random axis with random angle */ - glm_rotate_make(m4, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_rotate_make(m4, frand48(), (vec3){frand48(), frand48(), frand48()}); glm_mat4_pick3(m4, dest); } void test_rand_mat3x2(mat3x2 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); - dest[2][0] = drand48(); - dest[2][1] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); + dest[2][0] = frand48(); + dest[2][1] = frand48(); } void test_rand_mat3x4(mat3x4 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[0][2] = drand48(); - dest[0][3] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[0][2] = frand48(); + dest[0][3] = frand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); - dest[1][2] = drand48(); - dest[1][3] = drand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); + dest[1][2] = frand48(); + dest[1][3] = frand48(); - dest[2][0] = drand48(); - dest[2][1] = drand48(); - dest[2][2] = drand48(); - dest[2][3] = drand48(); + dest[2][0] = frand48(); + dest[2][1] = frand48(); + dest[2][2] = frand48(); + dest[2][3] = frand48(); } void test_rand_mat2(mat2 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); } void test_rand_mat2x3(mat2x3 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[0][2] = drand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); - dest[1][2] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[0][2] = frand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); + dest[1][2] = frand48(); } void test_rand_mat2x4(mat2x4 dest) { - dest[0][0] = drand48(); - dest[0][1] = drand48(); - dest[0][2] = drand48(); - dest[0][3] = drand48(); - dest[1][0] = drand48(); - dest[1][1] = drand48(); - dest[1][2] = drand48(); - dest[1][3] = drand48(); + dest[0][0] = frand48(); + dest[0][1] = frand48(); + dest[0][2] = frand48(); + dest[0][3] = frand48(); + dest[1][0] = frand48(); + dest[1][1] = frand48(); + dest[1][2] = frand48(); + dest[1][3] = frand48(); } void test_rand_transform2d(mat3 dest) { - glm_translate2d_make(dest, (vec2) { drand48(), drand48() }); - glm_rotate2d(dest, drand48()); - glm_scale2d(dest, (vec2) { drand48(), drand48() }); + glm_translate2d_make(dest, (vec2) { frand48(), frand48() }); + glm_rotate2d(dest, frand48()); + glm_scale2d(dest, (vec2) { frand48(), frand48() }); } void test_rand_vec3(vec3 dest) { - dest[0] = drand48(); - dest[1] = drand48(); - dest[2] = drand48(); + dest[0] = frand48(); + dest[1] = frand48(); + dest[2] = frand48(); } vec3s @@ -146,10 +146,10 @@ test_rand_vec3s(void) { void test_rand_vec4(vec4 dest) { - dest[0] = drand48(); - dest[1] = drand48(); - dest[2] = drand48(); - dest[3] = drand48(); + dest[0] = frand48(); + dest[1] = frand48(); + dest[2] = frand48(); + dest[3] = frand48(); } vec4s @@ -161,12 +161,12 @@ test_rand_vec4s(void) { float test_rand(void) { - return drand48(); + return frand48(); } void test_rand_quat(versor q) { - glm_quat(q, drand48(), drand48(), drand48(), drand48()); + glm_quat(q, frand48(), frand48(), frand48(), frand48()); glm_quat_normalize(q); } diff --git a/test/src/test_common.h b/test/src/test_common.h index 7471dbb..938bd3f 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -176,4 +176,11 @@ test_eq_th(float a, float b, float th) { return fabsf(a - b) <= th; } +/* drand with explicit conversion to lower precision */ +CGLM_INLINE +float +frand48(void) { + return (float)drand48(); +} + #endif /* test_common_h */ diff --git a/test/src/test_mat2.h b/test/src/test_mat2.h index 6fa622a..4770b1a 100644 --- a/test/src/test_mat2.h +++ b/test/src/test_mat2.h @@ -196,11 +196,12 @@ TEST_IMPL(GLM_PREFIX, mat2_trace) { TEST_IMPL(GLM_PREFIX, mat2_scale) { mat2 m1 = A_MATRIX2x2; mat2 m2 = A_MATRIX2x2; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat2_scale)(m1, (float)scale); + GLM(mat2_scale)(m1, scale); for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { diff --git a/test/src/test_mat2x3.h b/test/src/test_mat2x3.h index 8eb8144..5d0c474 100644 --- a/test/src/test_mat2x3.h +++ b/test/src/test_mat2x3.h @@ -140,11 +140,12 @@ TEST_IMPL(GLM_PREFIX, mat2x3_transpose) { TEST_IMPL(GLM_PREFIX, mat2x3_scale) { mat2x3 m1 = A_MATRIX2X3; mat2x3 m2 = A_MATRIX2X3; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat2x3_scale)(m1, (float) scale); + GLM(mat2x3_scale)(m1, scale); for (i = 0; i < 2; i++) { for (j = 0; j < 3; j++) { diff --git a/test/src/test_mat2x4.h b/test/src/test_mat2x4.h index 17ee35f..a6532ba 100644 --- a/test/src/test_mat2x4.h +++ b/test/src/test_mat2x4.h @@ -143,11 +143,12 @@ TEST_IMPL(GLM_PREFIX, mat2x4_transpose) { TEST_IMPL(GLM_PREFIX, mat2x4_scale) { mat2x4 m1 = A_MATRIX2X4; mat2x4 m2 = A_MATRIX2X4; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat2x4_scale)(m1, (float) scale); + GLM(mat2x4_scale)(m1, scale); for (i = 0; i < 2; i++) { for (j = 0; j < 4; j++) { diff --git a/test/src/test_mat3.h b/test/src/test_mat3.h index 2f151cd..f890359 100644 --- a/test/src/test_mat3.h +++ b/test/src/test_mat3.h @@ -184,11 +184,12 @@ TEST_IMPL(GLM_PREFIX, mat3_transpose) { TEST_IMPL(GLM_PREFIX, mat3_scale) { mat3 m1 = A_MATRIX; mat3 m2 = A_MATRIX; - int i, j, k, scale; + int i, j, k; + float scale; scale = rand() % 100; - GLM(mat3_scale)(m1, (float)scale); + GLM(mat3_scale)(m1, scale); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { diff --git a/test/src/test_mat3x2.h b/test/src/test_mat3x2.h index 397879b..f9403fe 100644 --- a/test/src/test_mat3x2.h +++ b/test/src/test_mat3x2.h @@ -139,11 +139,12 @@ TEST_IMPL(GLM_PREFIX, mat3x2_transpose) { TEST_IMPL(GLM_PREFIX, mat3x2_scale) { mat3x2 m1 = A_MATRIX3X2; mat3x2 m2 = A_MATRIX3X2; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat3x2_scale)(m1, (float) scale); + GLM(mat3x2_scale)(m1, scale); for (i = 0; i < 3; i++) { for (j = 0; j < 2; j++) { diff --git a/test/src/test_mat3x4.h b/test/src/test_mat3x4.h index 16520ac..a5bb732 100644 --- a/test/src/test_mat3x4.h +++ b/test/src/test_mat3x4.h @@ -145,11 +145,12 @@ TEST_IMPL(GLM_PREFIX, mat3x4_transpose) { TEST_IMPL(GLM_PREFIX, mat3x4_scale) { mat3x4 m1 = A_MATRIX3X4; mat3x4 m2 = A_MATRIX3X4; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat3x4_scale)(m1, (float) scale); + GLM(mat3x4_scale)(m1, scale); for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { diff --git a/test/src/test_mat4.h b/test/src/test_mat4.h index 16d80bb..4524742 100644 --- a/test/src/test_mat4.h +++ b/test/src/test_mat4.h @@ -292,11 +292,12 @@ TEST_IMPL(GLM_PREFIX, mat4_transpose) { TEST_IMPL(GLM_PREFIX, mat4_scale_p) { mat4 m1 = A_MATRIX; mat4 m2 = A_MATRIX; - int i, j, k, scale; + int i, j, k; + float scale; scale = rand() % 100; - GLM(mat4_scale_p)(m1, (float)scale); + GLM(mat4_scale_p)(m1, scale); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { @@ -311,11 +312,12 @@ TEST_IMPL(GLM_PREFIX, mat4_scale_p) { TEST_IMPL(GLM_PREFIX, mat4_scale) { mat4 m1 = A_MATRIX; mat4 m2 = A_MATRIX; - int i, j, k, scale; + int i, j, k; + float scale; scale = rand() % 100; - GLM(mat4_scale)(m1, (float)scale); + GLM(mat4_scale)(m1, scale); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { diff --git a/test/src/test_mat4x2.h b/test/src/test_mat4x2.h index b58d974..4e9874f 100644 --- a/test/src/test_mat4x2.h +++ b/test/src/test_mat4x2.h @@ -142,11 +142,12 @@ TEST_IMPL(GLM_PREFIX, mat4x2_transpose) { TEST_IMPL(GLM_PREFIX, mat4x2_scale) { mat4x2 m1 = A_MATRIX4X2; mat4x2 m2 = A_MATRIX4X2; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat4x2_scale)(m1, (float) scale); + GLM(mat4x2_scale)(m1, scale); for (i = 0; i < 4; i++) { for (j = 0; j < 2; j++) { diff --git a/test/src/test_mat4x3.h b/test/src/test_mat4x3.h index dc7c28e..53de1bb 100644 --- a/test/src/test_mat4x3.h +++ b/test/src/test_mat4x3.h @@ -146,11 +146,12 @@ TEST_IMPL(GLM_PREFIX, mat4x3_transpose) { TEST_IMPL(GLM_PREFIX, mat4x3_scale) { mat4x3 m1 = A_MATRIX4X3; mat4x3 m2 = A_MATRIX4X3; - int i, j, scale; + int i, j; + float scale; scale = rand() % 100; - GLM(mat4x3_scale)(m1, (float) scale); + GLM(mat4x3_scale)(m1, scale); for (i = 0; i < 4; i++) { for (j = 0; j < 3; j++) {