Initial implementation of struct type vec4s

This commit is contained in:
acoto87
2019-04-03 22:25:49 -06:00
parent 674e05213a
commit c25469829a
8 changed files with 178 additions and 29 deletions

View File

@@ -57,6 +57,14 @@ test_rand_vec4(vec4 dest) {
dest[3] = drand48();
}
vec4s
test_rand_vec4s()
{
vec4s r;
test_rand_vec4(r.raw);
return r;
}
float
test_rand(void) {
srand((unsigned int)time(NULL));
@@ -127,6 +135,12 @@ test_assert_vec4_eq(vec4 v1, vec4 v2) {
assert_true(fabsf(v1[3] - v2[3]) <= 0.000009);
}
void
test_assert_vec4s_eq(vec4s v1, vec4s v2)
{
test_assert_vec4_eq(v1.raw, v2.raw);
}
void
test_assert_quat_eq_abs(versor v1, versor v2) {
assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */

View File

@@ -20,6 +20,7 @@
#include <stdbool.h>
#include <cglm/cglm.h>
#include <cglm/cglms.h>
#include <cglm/call.h>
void
@@ -46,6 +47,9 @@ test_assert_vec3_eq(vec3 v1, vec3 v2);
void
test_assert_vec4_eq(vec4 v1, vec4 v2);
void
test_assert_vec4s_eq(vec4s v1, vec4s v2);
void
test_assert_quat_eq(versor v1, versor v2);
@@ -56,7 +60,10 @@ void
test_rand_vec3(vec3 dest);
void
test_rand_vec4(vec4 dest) ;
test_rand_vec4(vec4 dest);
vec4s
test_rand_vec4s();
float
test_rand(void);

View File

@@ -44,9 +44,11 @@ test_quat(void **state) {
test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */
/* 4. test SSE mul and raw mul */
#if defined( __SSE__ ) || defined( __SSE2__ )
test_quat_mul_raw(inQuat, outQuat, q3);
glm_quat_mul_sse2(inQuat, outQuat, q4);
test_assert_quat_eq(q3, q4);
#endif
}
/* 5. test lookat */

View File

@@ -65,10 +65,10 @@ test_vec4_clamp(vec4 v, float minVal, float maxVal) {
void
test_vec4(void **state) {
vec4 v, v1, v2, v3, v4;
vec4s vs1, vs2, vs3, vs4;
int i;
float d1, d2;
for (i = 0; i < 1000; i++) {
/* 1. test SSE/SIMD dot product */
test_rand_vec4(v);
@@ -175,4 +175,12 @@ test_vec4(void **state) {
assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001);
assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001);
assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001);
/* structs */
vs1 = test_rand_vec4s();
vs2 = test_rand_vec4s();
vs3 = glms_vec4_add(vs1, vs2);
vs4 = glms_vec4_maxv(vs1, vs3);
test_assert_vec4s_eq(vs3, vs4);
}