From 2631d3b5eaf94c96ee310771e07e8aa4ab8690c4 Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Sun, 14 May 2023 19:38:58 -0500 Subject: [PATCH 1/4] README: update meson option for running test Running on an already built build directory meson configure -Denable_tests=true build/ Leads to ERROR: Unknown options: "enable_tests" Seems the meson option was updated Signed-off-by: Vincent Davis Jr --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f50000e..17b7027 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ $ sudo ninja install # [Optional] c_std=c11 buildtype=release default_library=shared -enable_tests=false # to run tests: ninja test +build_tests=true # to run tests: ninja test ``` #### Use with your Meson project * Example: From e17f115f9164d1ae7c5f02652ff45f058a7d3784 Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Sat, 13 May 2023 16:45:34 -0500 Subject: [PATCH 2/4] mat4: add new function glm_mat4_make Function takes in a 16 element float array and converts it into a mat4 matrix. Signed-off-by: Vincent Davis Jr --- docs/source/mat4.rst | 11 +++++++++++ include/cglm/call/mat4.h | 4 ++++ include/cglm/mat4.h | 21 +++++++++++++++++++++ include/cglm/struct/mat4.h | 13 +++++++++++++ src/mat4.c | 6 ++++++ test/src/test_mat4.h | 18 ++++++++++++++++++ test/tests.h | 4 ++++ 7 files changed, 77 insertions(+) diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 33251b9..31817a4 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -47,6 +47,7 @@ Functions: #. :c:func:`glm_mat4_swap_col` #. :c:func:`glm_mat4_swap_row` #. :c:func:`glm_mat4_rmc` +#. :c:func:`glm_mat4_make` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -302,3 +303,13 @@ Functions documentation Returns: scalar value e.g. Matrix1x1 + +.. c:function:: void glm_mat4_make(float * __restrict src, mat4 dest) + + Create mat4 matrix from pointer + + | NOTE: **@src** must contain 16 elements. + + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination matrix4x4 diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 1c71da1..f85ef2d 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -121,6 +121,10 @@ CGLM_EXPORT float glmc_mat4_rmc(vec4 r, mat4 m, vec4 c); +CGLM_EXPORT +void +glmc_mat4_make(float * __restrict src, mat4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 932878d..32ecdf2 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -43,6 +43,7 @@ CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2); CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2); CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c); + CGLM_INLINE void glm_mat4_make(float * restrict src, mat4 dest); */ #ifndef cglm_mat_h @@ -781,4 +782,24 @@ glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { return glm_vec4_dot(r, tmp); } +/*! + * @brief Create mat4 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +void +glm_mat4_make(float * __restrict src, mat4 dest) { + dest[0][0] = src[0]; dest[1][0] = src[4]; + dest[0][1] = src[1]; dest[1][1] = src[5]; + dest[0][2] = src[2]; dest[1][2] = src[6]; + dest[0][3] = src[3]; dest[1][3] = src[7]; + + dest[2][0] = src[8]; dest[3][0] = src[12]; + dest[2][1] = src[9]; dest[3][1] = src[13]; + dest[2][2] = src[10]; dest[3][2] = src[14]; + dest[2][3] = src[11]; dest[3][3] = src[15]; +} + #endif /* cglm_mat_h */ diff --git a/include/cglm/struct/mat4.h b/include/cglm/struct/mat4.h index 6517f5c..222ab5d 100644 --- a/include/cglm/struct/mat4.h +++ b/include/cglm/struct/mat4.h @@ -459,4 +459,17 @@ glms_mat4_(rmc)(vec4s r, mat4s m, vec4s c) { return glm_mat4_rmc(r.raw, m.raw, c.raw); } +/*! + * @brief Create mat4 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +mat4s +glms_mat4_(make)(float * __restrict src, mat4s dest) { + glm_mat4_make(src, dest.raw); + return dest; +} + #endif /* cglms_mat4s_h */ diff --git a/src/mat4.c b/src/mat4.c index a9f39c6..44c6c58 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -163,3 +163,9 @@ float glmc_mat4_rmc(vec4 r, mat4 m, vec4 c) { return glm_mat4_rmc(r, m, c); } + +CGLM_EXPORT +void +glmc_mat4_make(float * __restrict src, mat4 dest) { + glm_mat4_make(src, dest); +} diff --git a/test/src/test_mat4.h b/test/src/test_mat4.h index d42e457..19cfc51 100644 --- a/test/src/test_mat4.h +++ b/test/src/test_mat4.h @@ -9,6 +9,7 @@ #define A_MATRIX {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}} #define A_MATRIX3 {{1,2,3},{5,6,7},{9,10,11}} +#define MAT4_ARRAY {1, 5, 2, 7, 12, 1, 4, 6, 0, 8, 1, 0, 6, 5, 0, 1} TEST_IMPL(GLM_PREFIX, mat4_ucopy) { mat4 m1 = A_MATRIX; @@ -484,5 +485,22 @@ TEST_IMPL(GLM_PREFIX, mat4_rmc) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, mat4_make) { + mat4 dest; + unsigned int i, j; + float src[16] = MAT4_ARRAY; + + GLM(mat4_make)(src, dest); + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=4, j++) { + ASSERT(test_eq(dest[j][0], src[i])) + ASSERT(test_eq(dest[j][1], src[i+1])) + ASSERT(test_eq(dest[j][2], src[i+2])) + ASSERT(test_eq(dest[j][3], src[i+3])) + } + + TEST_SUCCESS +} + #undef A_MATRIX #undef A_MATRIX3 diff --git a/test/tests.h b/test/tests.h index 035ac33..97e1af8 100644 --- a/test/tests.h +++ b/test/tests.h @@ -124,6 +124,7 @@ TEST_DECLARE(glm_mat4_inv_precise) TEST_DECLARE(glm_mat4_swap_col) TEST_DECLARE(glm_mat4_swap_row) TEST_DECLARE(glm_mat4_rmc) +TEST_DECLARE(glm_mat4_make) TEST_DECLARE(glmc_mat4_ucopy) TEST_DECLARE(glmc_mat4_copy) @@ -150,6 +151,7 @@ TEST_DECLARE(glmc_mat4_inv_fast) TEST_DECLARE(glmc_mat4_swap_col) TEST_DECLARE(glmc_mat4_swap_row) TEST_DECLARE(glmc_mat4_rmc) +TEST_DECLARE(glmc_mat4_make) /* mat3 */ TEST_DECLARE(glm_mat3_copy) @@ -965,6 +967,7 @@ TEST_LIST { TEST_ENTRY(glm_mat4_swap_col) TEST_ENTRY(glm_mat4_swap_row) TEST_ENTRY(glm_mat4_rmc) + TEST_ENTRY(glm_mat4_make) TEST_ENTRY(glmc_mat4_ucopy) TEST_ENTRY(glmc_mat4_copy) @@ -991,6 +994,7 @@ TEST_LIST { TEST_ENTRY(glmc_mat4_swap_col) TEST_ENTRY(glmc_mat4_swap_row) TEST_ENTRY(glmc_mat4_rmc) + TEST_ENTRY(glmc_mat4_make) /* mat3 */ TEST_ENTRY(glm_mat3_copy) From e6681e78c84cde1036cc7913acc3883d9b4d4b13 Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Sun, 14 May 2023 20:08:51 -0500 Subject: [PATCH 3/4] mat2: add new function glm_mat2_make Function takes in a 4 element float array and converts it into a mat2 matrix. Signed-off-by: Vincent Davis Jr --- docs/source/mat2.rst | 11 +++++++++++ include/cglm/call/mat2.h | 4 ++++ include/cglm/mat2.h | 16 ++++++++++++++++ include/cglm/struct/mat2.h | 13 +++++++++++++ src/mat2.c | 6 ++++++ test/src/test_mat2.h | 16 ++++++++++++++++ test/tests.h | 4 ++++ 7 files changed, 70 insertions(+) diff --git a/docs/source/mat2.rst b/docs/source/mat2.rst index 6e55c83..73c5951 100644 --- a/docs/source/mat2.rst +++ b/docs/source/mat2.rst @@ -32,6 +32,7 @@ Functions: #. :c:func:`glm_mat2_swap_col` #. :c:func:`glm_mat2_swap_row` #. :c:func:`glm_mat2_rmc` +#. :c:func:`glm_mat2_make` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -177,3 +178,13 @@ Functions documentation Returns: scalar value e.g. Matrix1x1 + +.. c:function:: void glm_mat2_make(float * __restrict src, mat2 dest) + + Create mat2 matrix from pointer + + | NOTE: **@src** must contain 4 elements. + + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination matrix2x2 diff --git a/include/cglm/call/mat2.h b/include/cglm/call/mat2.h index 91234a3..fbac296 100644 --- a/include/cglm/call/mat2.h +++ b/include/cglm/call/mat2.h @@ -73,6 +73,10 @@ CGLM_EXPORT float glmc_mat2_rmc(vec2 r, mat2 m, vec2 c); +CGLM_EXPORT +void +glmc_mat2_make(float * __restrict src, mat2 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat2.h b/include/cglm/mat2.h index 918e965..c427f32 100644 --- a/include/cglm/mat2.h +++ b/include/cglm/mat2.h @@ -28,6 +28,7 @@ CGLM_INLINE void glm_mat2_swap_col(mat2 mat, int col1, int col2) CGLM_INLINE void glm_mat2_swap_row(mat2 mat, int row1, int row2) CGLM_INLINE float glm_mat2_rmc(vec2 r, mat2 m, vec2 c) + CGLM_INLINE void glm_mat2_make(float * restrict src, mat2 dest) */ #ifndef cglm_mat2_h @@ -345,4 +346,19 @@ glm_mat2_rmc(vec2 r, mat2 m, vec2 c) { return glm_vec2_dot(r, tmp); } +/*! + * @brief Create mat2 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +void +glm_mat2_make(float * __restrict src, mat2 dest) { + dest[0][0] = src[0]; + dest[0][1] = src[1]; + dest[1][0] = src[2]; + dest[1][1] = src[3]; +} + #endif /* cglm_mat2_h */ diff --git a/include/cglm/struct/mat2.h b/include/cglm/struct/mat2.h index 382d57d..3c24bc6 100644 --- a/include/cglm/struct/mat2.h +++ b/include/cglm/struct/mat2.h @@ -258,4 +258,17 @@ glms_mat2_(rmc)(vec2s r, mat2s m, vec2s c) { return glm_mat2_rmc(r.raw, m.raw, c.raw); } +/*! + * @brief Create mat2 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +mat2s +glms_mat2_(make)(float * __restrict src, mat2s dest) { + glm_mat2_make(src, dest.raw); + return dest; +} + #endif /* cglms_mat2_h */ diff --git a/src/mat2.c b/src/mat2.c index 99a282d..118668e 100644 --- a/src/mat2.c +++ b/src/mat2.c @@ -97,3 +97,9 @@ float glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) { return glm_mat2_rmc(r, m, c); } + +CGLM_EXPORT +void +glmc_mat2_make(float * __restrict src, mat2 dest) { + glm_mat2_make(src, dest); +} diff --git a/test/src/test_mat2.h b/test/src/test_mat2.h index 9141caf..69ee403 100644 --- a/test/src/test_mat2.h +++ b/test/src/test_mat2.h @@ -8,6 +8,7 @@ #include "test_common.h" #define A_MATRIX2x2 {{1,2},{5,6}} +#define MAT2_ARRAY {1, 5, 2, 7} #ifndef CGLM_TEST_MAT2_ONCE #define CGLM_TEST_MAT2_ONCE @@ -283,4 +284,19 @@ TEST_IMPL(GLM_PREFIX, mat2_rmc) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, mat2_make) { + mat2 dest; + unsigned int i, j; + float src[4] = MAT2_ARRAY; + + GLM(mat2_make)(src, dest); + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=2, j++) { + ASSERT(test_eq(dest[j][0], src[i])) + ASSERT(test_eq(dest[j][1], src[i+1])) + } + + TEST_SUCCESS +} + #undef A_MATRIX2x2 diff --git a/test/tests.h b/test/tests.h index 035ac33..5a4111c 100644 --- a/test/tests.h +++ b/test/tests.h @@ -205,6 +205,7 @@ TEST_DECLARE(glm_mat2_inv) TEST_DECLARE(glm_mat2_swap_col) TEST_DECLARE(glm_mat2_swap_row) TEST_DECLARE(glm_mat2_rmc) +TEST_DECLARE(glm_mat2_make) TEST_DECLARE(glmc_mat2_copy) TEST_DECLARE(glmc_mat2_identity) @@ -221,6 +222,7 @@ TEST_DECLARE(glmc_mat2_inv) TEST_DECLARE(glmc_mat2_swap_col) TEST_DECLARE(glmc_mat2_swap_row) TEST_DECLARE(glmc_mat2_rmc) +TEST_DECLARE(glmc_mat2_make) /* camera (incl [LR]H cross [NZ]O) */ TEST_DECLARE(glm_perspective_lh_zo) @@ -1046,6 +1048,7 @@ TEST_LIST { TEST_ENTRY(glm_mat2_swap_col) TEST_ENTRY(glm_mat2_swap_row) TEST_ENTRY(glm_mat2_rmc) + TEST_ENTRY(glm_mat2_make) TEST_ENTRY(glmc_mat2_copy) TEST_ENTRY(glmc_mat2_identity) @@ -1062,6 +1065,7 @@ TEST_LIST { TEST_ENTRY(glmc_mat2_swap_col) TEST_ENTRY(glmc_mat2_swap_row) TEST_ENTRY(glmc_mat2_rmc) + TEST_ENTRY(glmc_mat2_make) /* camera (incl [LR]H cross [NZ]O) */ TEST_ENTRY(glm_perspective_lh_zo) From 0566a040c084275d3279a51b4e8391aa25359bbf Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Sun, 14 May 2023 20:56:25 -0500 Subject: [PATCH 4/4] mat3: add new function glm_mat3_make Function takes in a 9 element float array and converts it into a mat3 matrix. Signed-off-by: Vincent Davis Jr --- docs/source/mat3.rst | 11 +++++++++++ include/cglm/call/mat3.h | 4 ++++ include/cglm/mat3.h | 23 +++++++++++++++++++++++ include/cglm/struct/mat3.h | 13 +++++++++++++ src/mat3.c | 6 ++++++ test/src/test_mat3.h | 18 ++++++++++++++++++ test/tests.h | 4 ++++ 7 files changed, 79 insertions(+) diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index e577ce4..ec45dd5 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -34,6 +34,7 @@ Functions: #. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_row` #. :c:func:`glm_mat3_rmc` +#. :c:func:`glm_mat3_make` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -187,3 +188,13 @@ Functions documentation Returns: scalar value e.g. Matrix1x1 + +.. c:function:: void glm_mat3_make(float * __restrict src, mat3 dest) + + Create mat3 matrix from pointer + + | NOTE: **@src** must contain 9 elements. + + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination matrix3x3 diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index 36dcb27..9738fb4 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -80,6 +80,10 @@ CGLM_EXPORT float glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); +CGLM_EXPORT +void +glmc_mat3_make(float * __restrict src, mat3 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 69f0454..c09dc29 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -30,6 +30,7 @@ CGLM_INLINE void glm_mat3_swap_col(mat3 mat, int col1, int col2); CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2); CGLM_INLINE float glm_mat3_rmc(vec3 r, mat3 m, vec3 c); + CGLM_INLINE void glm_mat3_make(float * restrict src, mat3 dest); */ #ifndef cglm_mat3_h @@ -427,4 +428,26 @@ glm_mat3_rmc(vec3 r, mat3 m, vec3 c) { return glm_vec3_dot(r, tmp); } +/*! + * @brief Create mat3 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +void +glm_mat3_make(float * __restrict src, mat3 dest) { + dest[0][0] = src[0]; + dest[0][1] = src[1]; + dest[0][2] = src[2]; + + dest[1][0] = src[3]; + dest[1][1] = src[4]; + dest[1][2] = src[5]; + + dest[2][0] = src[6]; + dest[2][1] = src[7]; + dest[2][2] = src[8]; +} + #endif /* cglm_mat3_h */ diff --git a/include/cglm/struct/mat3.h b/include/cglm/struct/mat3.h index 8414973..3401fd4 100644 --- a/include/cglm/struct/mat3.h +++ b/include/cglm/struct/mat3.h @@ -285,4 +285,17 @@ glms_mat3_(rmc)(vec3s r, mat3s m, vec3s c) { return glm_mat3_rmc(r.raw, m.raw, c.raw); } +/*! + * @brief Create mat3 matrix from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest matrix + */ +CGLM_INLINE +mat3s +glms_mat3_(make)(float * __restrict src, mat3s dest) { + glm_mat3_make(src, dest.raw); + return dest; +} + #endif /* cglms_mat3s_h */ diff --git a/src/mat3.c b/src/mat3.c index 1286bd9..3933274 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -103,3 +103,9 @@ float glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { return glm_mat3_rmc(r, m, c); } + +CGLM_EXPORT +void +glmc_mat3_make(float * __restrict src, mat3 dest) { + glm_mat3_make(src, dest); +} diff --git a/test/src/test_mat3.h b/test/src/test_mat3.h index 76b1786..92fe7eb 100644 --- a/test/src/test_mat3.h +++ b/test/src/test_mat3.h @@ -8,6 +8,7 @@ #include "test_common.h" #define A_MATRIX {{1,2,3},{5,6,7},{9,10,11}} +#define MAT3_ARRAY {1, 5, 2, 7, 12, 1, 4, 6, 0} TEST_IMPL(GLM_PREFIX, mat3_copy) { mat3 m1 = A_MATRIX; @@ -308,4 +309,21 @@ TEST_IMPL(GLM_PREFIX, mat3_rmc) { TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, mat3_make) { + mat3 dest; + unsigned int i, j; + float src[9] = MAT3_ARRAY; + + GLM(mat3_make)(src, dest); + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=3, j++) { + ASSERT(test_eq(dest[j][0], src[i])) + ASSERT(test_eq(dest[j][1], src[i+1])) + ASSERT(test_eq(dest[j][2], src[i+2])) + } + + TEST_SUCCESS +} + #undef A_MATRIX diff --git a/test/tests.h b/test/tests.h index 035ac33..ba1b68f 100644 --- a/test/tests.h +++ b/test/tests.h @@ -168,6 +168,7 @@ TEST_DECLARE(glm_mat3_inv) TEST_DECLARE(glm_mat3_swap_col) TEST_DECLARE(glm_mat3_swap_row) TEST_DECLARE(glm_mat3_rmc) +TEST_DECLARE(glm_mat3_make) TEST_DECLARE(glmc_mat3_copy) TEST_DECLARE(glmc_mat3_identity) @@ -185,6 +186,7 @@ TEST_DECLARE(glmc_mat3_inv) TEST_DECLARE(glmc_mat3_swap_col) TEST_DECLARE(glmc_mat3_swap_row) TEST_DECLARE(glmc_mat3_rmc) +TEST_DECLARE(glmc_mat3_make) TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY_INIT) TEST_DECLARE(MACRO_GLM_MAT2_ZERO_INIT) @@ -1009,6 +1011,7 @@ TEST_LIST { TEST_ENTRY(glm_mat3_swap_col) TEST_ENTRY(glm_mat3_swap_row) TEST_ENTRY(glm_mat3_rmc) + TEST_ENTRY(glm_mat3_make) TEST_ENTRY(glmc_mat3_copy) TEST_ENTRY(glmc_mat3_identity) @@ -1026,6 +1029,7 @@ TEST_LIST { TEST_ENTRY(glmc_mat3_swap_col) TEST_ENTRY(glmc_mat3_swap_row) TEST_ENTRY(glmc_mat3_rmc) + TEST_ENTRY(glmc_mat3_make) TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY_INIT) TEST_ENTRY(MACRO_GLM_MAT2_ZERO_INIT)