Skip to content

Commit

Permalink
Merge pull request #323 from EasyIP2023/feture/update-test_quat-glm_q…
Browse files Browse the repository at this point in the history
…uat_make

test_quat: add more robust quat_make test
  • Loading branch information
recp authored Jul 2, 2023
2 parents 49dd24e + 5e798a9 commit d673f3d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/source/quat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ Functions documentation
Create quaternion from pointer
| NOTE: **@src** must contain 4 elements. cglm store quaternions as [x, y, z, w].
| NOTE: **@src** must contain at least 4 elements. cglm store quaternions as [x, y, z, w].
Parameters:
| *[in]* **src** pointer to an array of floats
Expand Down
2 changes: 1 addition & 1 deletion include/cglm/struct/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
CGLM_INLINE mat4s glms_quat_rotate(mat4s m, versors q)
CGLM_INLINE mat4s glms_quat_rotate_at(mat4s m, versors q, vec3s pivot)
CGLM_INLINE mat4s glms_quat_rotate_atm(versors q, vec3s pivot)
CGLM_INLINE void glms_quat_make(float * restrict src)
CGLM_INLINE versors glms_quat_make(float * restrict src)
*/

#ifndef cglms_quat_h
Expand Down
20 changes: 15 additions & 5 deletions test/src/test_quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,22 @@ TEST_IMPL(GLM_PREFIX, quat_rotate_atm) {
}

TEST_IMPL(GLM_PREFIX, quat_make) {
versor dest;
float src[4] = {7.2f, 1.0f, 2.5f, 6.1f};
versor dest[3];
float src[12] = {
7.2f, 1.0f, 2.5f, 6.1f,
0.2f, 2.8f, 17.3f, 5.1f,
4.2f, 7.3f, 6.6f, 8.8f
};

float *srcp = src;
unsigned int i, j;

GLM(quat_make)(src, dest);
for (unsigned int i = 0; i < sizeof(src) / sizeof(float); i++) {
ASSERT(test_eq(src[i], dest[i]));
for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=4,j++) {
GLM(quat_make)(srcp + i, dest[j]);
ASSERT(test_eq(src[ i ], dest[j][0]));
ASSERT(test_eq(src[i+1], dest[j][1]));
ASSERT(test_eq(src[i+2], dest[j][2]));
ASSERT(test_eq(src[i+3], dest[j][3]));
}

TEST_SUCCESS
Expand Down

0 comments on commit d673f3d

Please sign in to comment.