diff --git a/test/src/test_common.c b/test/src/test_common.c index f499e1c..63b6fd9 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -22,6 +22,21 @@ test_rand_mat4(mat4 dest) { /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ } +void +test_rand_mat4x2(mat4x2 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[3][0] = drand48(); + dest[3][1] = drand48(); +} + void test_rand_mat3(mat3 dest) { mat4 m4; @@ -59,6 +74,18 @@ test_rand_mat2x3(mat2x3 dest) { dest[1][2] = drand48(); } +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(); +} + void test_rand_vec3(vec3 dest) { dest[0] = drand48(); @@ -233,6 +260,19 @@ test_assert_mat2x4_eq_zero(mat2x4 m2x4) { TEST_SUCCESS } +test_status_t +test_assert_mat2x4_eq(mat2x4 m1, mat2x4 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + test_status_t test_assert_mat3_eq(mat3 m1, mat3 m2) { int i, j; @@ -371,6 +411,19 @@ test_assert_mat4x2_eq_zero(mat4x2 m4x2) { TEST_SUCCESS } +test_status_t +test_assert_mat4x2_eq(mat4x2 m1, mat4x2 m2) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 2; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + test_status_t test_assert_mat4x3_eq_zero(mat4x3 m4x3) { int i, j; diff --git a/test/src/test_common.h b/test/src/test_common.h index 5598322..bd4ecd9 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -17,6 +17,9 @@ void test_rand_mat4(mat4 dest); +void +test_rand_mat4x2(mat4x2 dest); + void test_rand_mat3(mat3 dest); @@ -29,6 +32,9 @@ test_rand_mat2(mat2 dest); void test_rand_mat2x3(mat2x3 dest); +void +test_rand_mat2x4(mat2x4 dest); + test_status_t test_assert_eqf(float a, float b); @@ -50,6 +56,9 @@ test_assert_mat4_eq_zero(mat4 m4); test_status_t test_assert_mat4x2_eq_zero(mat4x2 m4x2); +test_status_t +test_assert_mat4x2_eq(mat4x2 m1, mat4x2 m2); + test_status_t test_assert_mat4x3_eq_zero(mat4x3 m4x3); @@ -74,6 +83,9 @@ test_assert_mat2x3_eq(mat2x3 m1, mat2x3 m2); test_status_t test_assert_mat2x4_eq_zero(mat2x4 m2x4); +test_status_t +test_assert_mat2x4_eq(mat2x4 m1, mat2x4 m2); + test_status_t test_assert_mat3_eq(mat3 m1, mat3 m2); diff --git a/test/src/test_mat2x4.h b/test/src/test_mat2x4.h index 7348965..ea594d1 100644 --- a/test/src/test_mat2x4.h +++ b/test/src/test_mat2x4.h @@ -8,6 +8,9 @@ #include "test_common.h" +#define A_MATRIX2X4 {{1,2,3,4},{5,6,7,8}} +#define A_MATRIX2X4_TRANSPOSE {{1,5}, {2,6}, {3,7}, {4,8}} + #ifndef CGLM_TEST_MAT2X4_ONCE #define CGLM_TEST_MAT2X4_ONCE @@ -25,6 +28,31 @@ TEST_IMPL(MACRO_GLM_MAT2X4_ZERO) { #endif /* CGLM_TEST_MAT2X4_ONCE */ +TEST_IMPL(GLM_PREFIX, mat2x4_copy) { + mat2x4 m1 = A_MATRIX2X4; + mat2x4 m2 = GLM_MAT2X4_ZERO_INIT; + + GLM(mat2x4_copy)(m1, m2); + + test_assert_mat2x4_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2x4_zero) { + mat2x4 m1 = GLM_MAT2X4_ZERO_INIT; + mat2x4 m2 = GLM_MAT2X4_ZERO_INIT; + mat2x4 m3; + + GLM(mat2x4_zero)(m3); + + ASSERTIFY(test_assert_mat2x4_eq_zero(m1)) + ASSERTIFY(test_assert_mat2x4_eq_zero(m2)) + ASSERTIFY(test_assert_mat2x4_eq_zero(m3)) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, mat2x4_make) { float src[24] = { 0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f, 77.3f, 88.4f, @@ -53,3 +81,79 @@ TEST_IMPL(GLM_PREFIX, mat2x4_make) { TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, mat2x4_mul) { + mat2x4 m1 = GLM_MAT2X4_ZERO_INIT; + mat4x2 m2 = GLM_MAT4X2_ZERO_INIT; + + mat2 m3 = GLM_MAT2_ZERO_INIT; + mat2 m4 = GLM_MAT2_ZERO_INIT; + + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat2x4(m1); + test_rand_mat4x2(m2); + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + for (k = 0; k < 4; k++) { + m4[i][j] += m1[i][k] * m2[k][j]; + } + } + } + + GLM(mat2x4_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat2_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2x4_mulv) { + mat2x4 mat = A_MATRIX2X4; + vec4 v = {11.0f, 21.0f, 31.0f, 41.0f}; + + int i; + vec2 dest; + float res = 0.0; + + GLM(mat2x4_mulv)(mat, v, dest); + + for (i = 0; i < 2; i++) { + res = mat[i][0] * v[0] + mat[i][1] * v[1] + mat[i][2] * v[2] + mat[i][3] * v[3]; + ASSERT(test_eq(dest[i], res)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2x4_transpose) { + mat2x4 m1 = A_MATRIX2X4; + + mat4x2 m2; + mat4x2 m3 = A_MATRIX2X4_TRANSPOSE; + GLM(mat2x4_transpose)(m1, m2); + + ASSERTIFY(test_assert_mat4x2_eq(m2, m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2x4_scale) { + mat2x4 m1 = A_MATRIX2X4; + mat2x4 m2 = A_MATRIX2X4; + int i, j, scale; + + scale = rand() % 100; + + GLM(mat2x4_scale)(m1, (float) scale); + + for (i = 0; i < 2; i++) { + for (j = 0; j < 4; j++) { + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} diff --git a/test/tests.h b/test/tests.h index 101a268..6001886 100644 --- a/test/tests.h +++ b/test/tests.h @@ -272,9 +272,21 @@ TEST_DECLARE(glmc_mat2x3_scale) TEST_DECLARE(MACRO_GLM_MAT2X4_ZERO_INIT) TEST_DECLARE(MACRO_GLM_MAT2X4_ZERO) +TEST_DECLARE(glm_mat2x4_copy) +TEST_DECLARE(glm_mat2x4_zero) TEST_DECLARE(glm_mat2x4_make) +TEST_DECLARE(glm_mat2x4_mul) +TEST_DECLARE(glm_mat2x4_mulv) +TEST_DECLARE(glm_mat2x4_transpose) +TEST_DECLARE(glm_mat2x4_scale) +TEST_DECLARE(glmc_mat2x4_copy) +TEST_DECLARE(glmc_mat2x4_zero) TEST_DECLARE(glmc_mat2x4_make) +TEST_DECLARE(glmc_mat2x4_mul) +TEST_DECLARE(glmc_mat2x4_mulv) +TEST_DECLARE(glmc_mat2x4_transpose) +TEST_DECLARE(glmc_mat2x4_scale) /* camera (incl [LR]H cross [NZ]O) */ TEST_DECLARE(glm_perspective_lh_zo) @@ -1187,9 +1199,21 @@ TEST_LIST { TEST_ENTRY(MACRO_GLM_MAT2X4_ZERO_INIT) TEST_ENTRY(MACRO_GLM_MAT2X4_ZERO) + TEST_ENTRY(glm_mat2x4_copy) + TEST_ENTRY(glm_mat2x4_zero) TEST_ENTRY(glm_mat2x4_make) + TEST_ENTRY(glm_mat2x4_mul) + TEST_ENTRY(glm_mat2x4_mulv) + TEST_ENTRY(glm_mat2x4_transpose) + TEST_ENTRY(glm_mat2x4_scale) - TEST_ENTRY(glmc_mat2x4_make) + TEST_ENTRY(glm_mat2x4_copy) + TEST_ENTRY(glm_mat2x4_zero) + TEST_ENTRY(glm_mat2x4_make) + TEST_ENTRY(glm_mat2x4_mul) + TEST_ENTRY(glm_mat2x4_mulv) + TEST_ENTRY(glm_mat2x4_transpose) + TEST_ENTRY(glm_mat2x4_scale) /* camera (incl [LR]H cross [NZ]O) */ TEST_ENTRY(glm_perspective_lh_zo)