From 4b3e9bb779e0ff745ebe6ab044067c877f7a172c Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Fri, 4 Apr 2025 11:04:44 -0400 Subject: [PATCH 1/2] mat3x2: fix scale comment Signed-off-by: Vincent Davis Jr --- include/cglm/mat3x2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/mat3x2.h b/include/cglm/mat3x2.h index 4328132..52173c0 100644 --- a/include/cglm/mat3x2.h +++ b/include/cglm/mat3x2.h @@ -133,7 +133,7 @@ glm_mat3x2_transpose(mat3x2 src, mat2x3 dest) { } /*! - * @brief Multiply mat2x4 (m) by scalar constant (s). + * @brief Multiply mat3x2 (m) by scalar constant (s). * * @param[in, out] m (src, dest) * @param[in] s float (scalar) From bdca98ba487e9243bd7a33635114b54cfc0f0a40 Mon Sep 17 00:00:00 2001 From: Vincent Davis Jr Date: Fri, 4 Apr 2025 11:11:49 -0400 Subject: [PATCH 2/2] mat4x2: add tables to docs & fix comments Signed-off-by: Vincent Davis Jr --- docs/source/mat4x2.rst | 132 +++++++++++++++++++++++++---------- include/cglm/call/mat4x2.h | 6 +- include/cglm/mat4x2.h | 83 +++++++++------------- include/cglm/struct/mat4x2.h | 70 +++++++++---------- src/mat4x2.c | 12 ++-- 5 files changed, 173 insertions(+), 130 deletions(-) diff --git a/docs/source/mat4x2.rst b/docs/source/mat4x2.rst index 35ab2b8..7e0824d 100644 --- a/docs/source/mat4x2.rst +++ b/docs/source/mat4x2.rst @@ -35,51 +35,93 @@ Represented Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ -.. c:function:: void glm_mat4x2_copy(mat4x2 mat, mat4x2 dest) +.. c:function:: void glm_mat4x2_copy(mat4x2 src, mat4x2 dest) - copy mat4x2 to another one (dest). + Copy mat4x2 (src) to mat4x2 (dest). Parameters: - | *[in]* **mat** source - | *[out]* **dest** destination + | *[in]* **src** mat4x2 (left) + | *[out]* **dest** destination (result, mat4x2) -.. c:function:: void glm_mat4x2_zero(mat4x2 mat) + .. csv-table:: mat4x2 **(src)** + :header: "", "column 1", "column 2", "column 3", "column 4" - make given matrix zero + "row 1", "a00", "a10", "a20", "a30" + "row 2", "a01", "a11", "a21", "a31" + + .. csv-table:: ma4x2 **(dest)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "b00 = a00", "b10 = a10", "b20 = a20", "b30 = a30" + "row 2", "b01 = a01", "b11 = a11", "b21 = a21", "b31 = a31" + +.. c:function:: void glm_mat4x2_zero(mat4x2 m) + + Zero out the mat4x2 (m). Parameters: - | *[in,out]* **mat** matrix + | *[in, out]* **m** mat4x2 (src, dest) + + .. csv-table:: mat4x2 **(m)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "0.00", "2.00", "15.00", "44.00" + "row 2", "5.00", "4.00", "6.00", "12.00" + + .. csv-table:: mat4x2 **(m)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "0.00", "0.00", "0.00", "0.00" + "row 2", "0.00", "0.00", "0.00", "0.00" .. c:function:: void glm_mat4x2_make(const float * __restrict src, mat4x2 dest) - Create mat4x2 matrix from pointer + Create mat4x2 (dest) from pointer (src). .. note:: **@src** must contain at least 8 elements. Parameters: - | *[in]* **src** pointer to an array of floats - | *[out]* **dest** destination matrix4x2 + | *[in]* **src** pointer to an array of floats (left) + | *[out]* **dest** destination (result, mat4x2) + + .. csv-table:: float array (1x8) **(src)** + :header: "", "column 1" + + "row 1", "v0" + "row 2", "v1" + "row 3", "v2" + "row 4", "v3" + "row 5", "v4" + "row 6", "v5" + "row 7", "v6" + "row 8", "v7" + + .. csv-table:: mat4x2 **(dest)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "v0", "v2", "v4", "v6" + "row 2", "v1", "v3", "v5", "v7" .. c:function:: void glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat2 dest) - multiply m1 and m2 to dest + Multiply mat4x2 (m1) by mat2x4 (m2) and store in mat2 (dest). .. code-block:: c glm_mat4x2_mul(mat4x2, mat2x4, mat2); Parameters: - | *[in]* **m1** left matrix (mat4x2) - | *[in]* **m2** right matrix (mat2x4) - | *[out]* **dest** destination matrix (mat2) + | *[in]* **m1** mat4x2 (left) + | *[in]* **m2** mat2x4 (right) + | *[out]* **dest** destination (result, mat2) - .. csv-table:: mat4x2 + .. csv-table:: mat4x2 **(m1)** :header: "", "column 1", "column 2", "column 3", "column 4" "row 1", "a00", "a10", "a20", "a30" "row 2", "a01", "a11", "a21", "a31" - .. csv-table:: mat2x4 + .. csv-table:: mat2x4 **(m2)** :header: "", "column 1", "column 2" "row 1", "b00", "b10" @@ -87,7 +129,7 @@ Functions documentation "row 3", "b02", "b12" "row 4", "b03", "b13" - .. csv-table:: mat2x2 + .. csv-table:: mat2x2 **(dest)** :header: "", "column 1", "column 2" "row 1", "a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03", "a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13" @@ -95,22 +137,20 @@ Functions documentation .. c:function:: void glm_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest) - multiply mat4x2 with vec4 (column vector) and store in dest vector + Multiply mat4x2 (m) by vec4 (v) and store in vec2 (dest). Parameters: - | *[in]* **m** mat4x2 (left) - | *[in]* **v** vec4 (right, column vector) - | *[out]* **dest** destination (result, column vector) + | *[in]* **m** mat4x2 (left) + | *[in]* **v** vec4 (right, column vector) + | *[out]* **dest** destination (result, column vector) - .. csv-table:: mat4x2 - :header: "", "column 1", "column 2", "column 3" + .. csv-table:: mat4x2 **(m)** + :header: "", "column 1", "column 2", "column 3", "column 4" - "row 1", "m00", "m10", "m20" - "row 2", "m01", "m11", "m21" - "row 3", "m02", "m12", "m22" - "row 4", "m03", "m13", "m23" + "row 1", "m00", "m10", "m20", "m30" + "row 2", "m01", "m11", "m21", "m31" - .. csv-table:: column vec4 (1x4) + .. csv-table:: column vec4 (1x4) **(v)** :header: "", "column 1" "row 1", "v0" @@ -118,24 +158,44 @@ Functions documentation "row 3", "v2" "row 4", "v3" - .. csv-table:: column vec2 (1x2) + .. csv-table:: column vec2 (1x2) **(dest)** :header: "", "column 1" "row 1", "m00 * v0 + m10 * v1 + m20 * v2 + m30 * v3" "row 2", "m01 * v0 + m11 * v1 + m21 * v2 + m31 * v3" -.. c:function:: void glm_mat4x2_transpose(mat4x2 m, mat2x4 dest) +.. c:function:: void glm_mat4x2_transpose(mat4x2 src, mat2x4 dest) - transpose matrix and store in dest + Transpose mat4x2 (src) and store in mat2x4 (dest). Parameters: - | *[in]* **m** matrix - | *[out]* **dest** destination + | *[in]* **src** mat4x2 (left) + | *[out]* **dest** destination (result, mat2x4) + + .. csv-table:: mat4x2 **(src)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "a00", "a10", "a20", "a30" + "row 2", "a01", "a11", "a21", "a31" + + .. csv-table:: mat2x4 **(dest)** + :header: "", "column 1", "column 2" + + "row 1", "b00 = a00", "b10 = a01" + "row 2", "b01 = a10", "b11 = a11" + "row 3", "b02 = a20", "b12 = a21" + "row 4", "b03 = a30", "b13 = a31" .. c:function:: void glm_mat4x2_scale(mat4x2 m, float s) - multiply matrix with scalar + Multiply mat4x2 (m) by scalar constant (s). Parameters: - | *[in, out]* **m** matrix - | *[in]* **s** scalar + | *[in, out]* **m** mat4x2 (src, dest) + | *[in]* **s** float (scalar) + + .. csv-table:: mat4x2 **(m)** + :header: "", "column 1", "column 2", "column 3", "column 4" + + "row 1", "m00 = m00 * s", "m10 = m10 * s", "m20 = m20 * s", "m30 = m30 * s" + "row 2", "m01 = m01 * s", "m11 = m11 * s", "m21 = m21 * s", "m31 = m31 * s" diff --git a/include/cglm/call/mat4x2.h b/include/cglm/call/mat4x2.h index 2989124..4711d2b 100644 --- a/include/cglm/call/mat4x2.h +++ b/include/cglm/call/mat4x2.h @@ -15,11 +15,11 @@ extern "C" { CGLM_EXPORT void -glmc_mat4x2_copy(mat4x2 mat, mat4x2 dest); +glmc_mat4x2_copy(mat4x2 src, mat4x2 dest); CGLM_EXPORT void -glmc_mat4x2_zero(mat4x2 mat); +glmc_mat4x2_zero(mat4x2 m); CGLM_EXPORT void @@ -35,7 +35,7 @@ glmc_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest); CGLM_EXPORT void -glmc_mat4x2_transpose(mat4x2 m, mat2x4 dest); +glmc_mat4x2_transpose(mat4x2 src, mat2x4 dest); CGLM_EXPORT void diff --git a/include/cglm/mat4x2.h b/include/cglm/mat4x2.h index d3f0ad5..91684e4 100644 --- a/include/cglm/mat4x2.h +++ b/include/cglm/mat4x2.h @@ -11,12 +11,12 @@ GLM_MAT4X2_ZERO Functions: - CGLM_INLINE void glm_mat4x2_copy(mat4x2 mat, mat4x2 dest); - CGLM_INLINE void glm_mat4x2_zero(mat4x2 mat); + CGLM_INLINE void glm_mat4x2_copy(mat4x2 src, mat4x2 dest); + CGLM_INLINE void glm_mat4x2_zero(mat4x2 m); CGLM_INLINE void glm_mat4x2_make(const float * __restrict src, mat4x2 dest); CGLM_INLINE void glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat2 dest); CGLM_INLINE void glm_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest); - CGLM_INLINE void glm_mat4x2_transpose(mat4x2 m, mat2x4 dest); + CGLM_INLINE void glm_mat4x2_transpose(mat4x2 src, mat2x4 dest); CGLM_INLINE void glm_mat4x2_scale(mat4x2 m, float s); */ @@ -31,44 +31,37 @@ #define GLM_MAT4X2_ZERO GLM_MAT4X2_ZERO_INIT /*! - * @brief copy all members of [mat] to [dest] + * @brief Copy mat4x2 (src) to mat4x2 (dest). * - * @param[in] mat source - * @param[out] dest destination + * @param[in] src mat4x2 (left) + * @param[out] dest destination (result, mat4x2) */ CGLM_INLINE void -glm_mat4x2_copy(mat4x2 mat, mat4x2 dest) { - dest[0][0] = mat[0][0]; - dest[0][1] = mat[0][1]; - - dest[1][0] = mat[1][0]; - dest[1][1] = mat[1][1]; - - dest[2][0] = mat[2][0]; - dest[2][1] = mat[2][1]; - - dest[3][0] = mat[3][0]; - dest[3][1] = mat[3][1]; +glm_mat4x2_copy(mat4x2 src, mat4x2 dest) { + glm_vec2_copy(src[0], dest[0]); + glm_vec2_copy(src[1], dest[1]); + glm_vec2_copy(src[2], dest[2]); + glm_vec2_copy(src[3], dest[3]); } /*! - * @brief make given matrix zero. + * @brief Zero out the mat4x2 (m). * - * @param[in, out] mat matrix + * @param[in, out] mat4x2 (src, dest) */ CGLM_INLINE void -glm_mat4x2_zero(mat4x2 mat) { +glm_mat4x2_zero(mat4x2 m) { CGLM_ALIGN_MAT mat4x2 t = GLM_MAT4X2_ZERO_INIT; - glm_mat4x2_copy(t, mat); + glm_mat4x2_copy(t, m); } /*! - * @brief Create mat4x2 matrix from pointer + * @brief Create mat4x2 (dest) from pointer (src). * - * @param[in] src pointer to an array of floats - * @param[out] dest matrix + * @param[in] src pointer to an array of floats (left) + * @param[out] dest destination (result, mat4x2) */ CGLM_INLINE void @@ -87,15 +80,15 @@ glm_mat4x2_make(const float * __restrict src, mat4x2 dest) { } /*! - * @brief multiply m1 and m2 to dest + * @brief Multiply mat4x2 (m1) by mat2x4 (m2) and store in mat2 (dest). * * @code * glm_mat4x2_mul(mat4x2, mat2x4, mat2); * @endcode * - * @param[in] m1 left matrix (mat4x2) - * @param[in] m2 right matrix (mat2x4) - * @param[out] dest destination matrix (mat2) + * @param[in] m1 mat4x2 (left) + * @param[in] m2 mat2x4 (right) + * @param[out] dest destination (result, mat2) */ CGLM_INLINE void @@ -116,11 +109,11 @@ glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat2 dest) { } /*! - * @brief multiply matrix with column vector and store in dest column vector + * @brief Multiply mat4x2 (m) by vec4 (v) and store in vec2 (dest). * - * @param[in] m matrix (left) - * @param[in] v vector (right, column vector) - * @param[out] dest result vector + * @param[in] m mat4x2 (left) + * @param[in] v vec4 (right, column vector) + * @param[out] dest destination (result, column vector) */ CGLM_INLINE void @@ -132,31 +125,23 @@ glm_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest) { } /*! - * @brief transpose matrix and store in dest + * @brief Transpose mat4x2 (src) and store in mat2x4 (dest). * - * @param[in] m matrix - * @param[out] dest result + * @param[in] src mat4x2 (left) + * @param[out] dest destination (result, mat2x4) */ CGLM_INLINE void glm_mat4x2_transpose(mat4x2 m, mat2x4 dest) { - dest[0][0] = m[0][0]; - dest[0][1] = m[1][0]; - dest[0][2] = m[2][0]; - dest[0][3] = m[3][0]; - dest[1][0] = m[0][1]; - dest[1][1] = m[1][1]; - dest[1][2] = m[2][1]; - dest[1][3] = m[3][1]; + dest[0][0] = m[0][0]; dest[0][1] = m[1][0]; dest[0][2] = m[2][0]; dest[0][3] = m[3][0]; + dest[1][0] = m[0][1]; dest[1][1] = m[1][1]; dest[1][2] = m[2][1]; dest[1][3] = m[3][1]; } /*! - * @brief scale (multiply with scalar) matrix + * @brief Multiply mat4x2 (m) by scalar constant (s). * - * multiply matrix with scalar - * - * @param[in, out] m matrix - * @param[in] s scalar + * @param[in, out] m (src, dest) + * @param[in] s float (scalar) */ CGLM_INLINE void diff --git a/include/cglm/struct/mat4x2.h b/include/cglm/struct/mat4x2.h index 17589bc..6c68abe 100644 --- a/include/cglm/struct/mat4x2.h +++ b/include/cglm/struct/mat4x2.h @@ -36,87 +36,85 @@ /*! - * @brief make given matrix zero. + * @brief Zero out the mat4x2s (dest). * - * @param[in, out] mat matrix + * @return[out] dest constructed mat4x2s from raw pointer */ CGLM_INLINE mat4x2s glms_mat4x2_(zero)(void) { - mat4x2s r; - glm_mat4x2_zero(r.raw); - return r; + mat4x2s dest; + glm_mat4x2_zero(dest.raw); + return dest; } /*! - * @brief Create mat4x2 matrix from pointer + * @brief Create mat4x2s (dest) from pointer (src). * - * @param[in] src pointer to an array of floats - * @return constructed matrix from raw pointer + * @param[in] src pointer to an array of floats + * @return[out] dest constructed mat4x2s from raw pointer */ CGLM_INLINE mat4x2s glms_mat4x2_(make)(const float * __restrict src) { - mat4x2s r; - glm_mat4x2_make(src, r.raw); - return r; + mat4x2s dest; + glm_mat4x2_make(src, dest.raw); + return dest; } /*! - * @brief multiply m1 and m2 to dest + * @brief Multiply mat4x2s (m1) by mat2x4s (m2) and store in mat2s (dest). * * @code * r = glms_mat4x2_mul(mat4x2s, mat2x4s); * @endcode * - * @param[in] m1 left matrix (mat4x2s) - * @param[in] m2 right matrix (mat2x4s) - * @returns destination matrix (mat2s) + * @param[in] m1 mat4x2s (left) + * @param[in] m2 mat2x4s (right) + * @return[out] dest constructed mat2s from raw pointers */ CGLM_INLINE mat2s glms_mat4x2_(mul)(mat4x2s m1, mat2x4s m2) { - mat2s r; - glm_mat4x2_mul(m1.raw, m2.raw, r.raw); - return r; + mat2s dest; + glm_mat4x2_mul(m1.raw, m2.raw, dest.raw); + return dest; } /*! - * @brief multiply matrix with column vector and store in dest column vector + * @brief Multiply mat4x2s (m) by vec4s (v) and store in vec2s (dest). * - * @param[in] m matrix (left) - * @param[in] v vector (right, column vector) - * @returns destination vector (vec2s) + * @param[in] m mat4x2s (left) + * @param[in] v vec4s (right, column vector) + * @return[out] dest constructed vec2s from raw pointers */ CGLM_INLINE vec2s glms_mat4x2_(mulv)(mat4x2s m, vec4s v) { - vec2s r; - glm_mat4x2_mulv(m.raw, v.raw, r.raw); - return r; + vec2s dest; + glm_mat4x2_mulv(m.raw, v.raw, dest.raw); + return dest; } /*! - * @brief transpose matrix and store in dest + * @brief Transpose mat4x2s (m) and store in mat2x4s (dest). * - * @param[in] m matrix - * @param[out] dest result + * @param[in] m mat4x2s (left) + * @return[out] dest constructed mat2x4s from raw pointers */ CGLM_INLINE mat2x4s glms_mat4x2_(transpose)(mat4x2s m) { - mat2x4s r; - glm_mat4x2_transpose(m.raw, r.raw); - return r; + mat2x4s dest; + glm_mat4x2_transpose(m.raw, dest.raw); + return dest; } /*! - * @brief scale (multiply with scalar) matrix + * @brief Multiply mat4x2s (m) by scalar constant (s). * - * multiply matrix with scalar - * - * @param[in, out] m matrix - * @param[in] s scalar + * @param[in, out] m mat4x2s (src, dest) + * @param[in] s float (scalar) */ CGLM_INLINE mat4x2s diff --git a/src/mat4x2.c b/src/mat4x2.c index 32015f2..5c296b5 100644 --- a/src/mat4x2.c +++ b/src/mat4x2.c @@ -10,14 +10,14 @@ CGLM_EXPORT void -glmc_mat4x2_copy(mat4x2 mat, mat4x2 dest) { - glm_mat4x2_copy(mat, dest); +glmc_mat4x2_copy(mat4x2 src, mat4x2 dest) { + glm_mat4x2_copy(src, dest); } CGLM_EXPORT void -glmc_mat4x2_zero(mat4x2 mat) { - glm_mat4x2_zero(mat); +glmc_mat4x2_zero(mat4x2 m) { + glm_mat4x2_zero(m); } CGLM_EXPORT @@ -40,8 +40,8 @@ glmc_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest) { CGLM_EXPORT void -glmc_mat4x2_transpose(mat4x2 m, mat2x4 dest) { - glm_mat4x2_transpose(m, dest); +glmc_mat4x2_transpose(mat4x2 src, mat2x4 dest) { + glm_mat4x2_transpose(src, dest); } CGLM_EXPORT