Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vec4: add new function glm_vec4_make #326

Merged
merged 2 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/source/vec4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Functions:
#. :c:func:`glm_vec4_clamp`
#. :c:func:`glm_vec4_lerp`
#. :c:func:`glm_vec4_cubic`
#. :c:func:`glm_vec4_make`

Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -406,3 +407,12 @@ Functions documentation
Parameters:
| *[in]* **s** parameter
| *[out]* **dest** destination

.. c:function:: void glm_vec4_make(float * __restrict src, vec4 dest)

Create four dimensional vector from pointer

| NOTE: **@src** must contain at least 4 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination vector
4 changes: 4 additions & 0 deletions include/cglm/call/vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ CGLM_EXPORT
void
glmc_vec4_sqrt(vec4 v, vec4 dest);

CGLM_EXPORT
void
glmc_vec4_make(float * __restrict src, vec4 dest);

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 15 additions & 0 deletions include/cglm/struct/vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
CGLM_INLINE vec4s glms_vec4_smoothinterpc(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_cubic(float s);
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
*/

#ifndef cglms_vec4s_h
Expand Down Expand Up @@ -811,4 +812,18 @@ glms_vec4_(swizzle)(vec4s v, int mask) {
return dest;
}

/*!
* @brief Create four dimensional vector from pointer
*
* @param[in] src pointer to an array of floats
* @returns constructed 4D vector from raw pointer
*/
CGLM_INLINE
vec4s
glms_vec4_(make)(float * __restrict src) {
vec4s dest;
glm_vec4_make(src, dest.raw);
return dest;
}

#endif /* cglms_vec4s_h */
14 changes: 14 additions & 0 deletions include/cglm/vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
CGLM_INLINE void glm_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_swizzle(vec4 v, int mask, vec4 dest);
CGLM_INLINE void glm_vec4_make(float * restrict src, vec4 dest);

DEPRECATED:
glm_vec4_dup
Expand Down Expand Up @@ -1133,4 +1134,17 @@ glm_vec4_swizzle(vec4 v, int mask, vec4 dest) {
glm_vec4_copy(t, dest);
}

/*!
* @brief Create four dimensional vector from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest destination vector
*/
CGLM_INLINE
void
glm_vec4_make(float * __restrict src, vec4 dest) {
dest[0] = src[0]; dest[1] = src[1];
dest[2] = src[2]; dest[3] = src[3];
}

#endif /* cglm_vec4_h */
6 changes: 6 additions & 0 deletions src/vec4.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,9 @@ void
glmc_vec4_sqrt(vec4 v, vec4 dest) {
glm_vec4_sqrt(v, dest);
}

CGLM_EXPORT
void
glmc_vec4_make(float * __restrict src, vec4 dest) {
glm_vec4_make(src, dest);
}
22 changes: 22 additions & 0 deletions test/src/test_vec4.h
Original file line number Diff line number Diff line change
Expand Up @@ -1418,3 +1418,25 @@ TEST_IMPL(GLM_PREFIX, vec4_sqrt) {

TEST_SUCCESS
}

TEST_IMPL(GLM_PREFIX, vec4_make) {
float src[12] = {
7.2f, 1.0f, 5.8f, 0.0f,
2.5f, 6.1f, 9.9f, 1.0f,
17.7f, 4.3f, 3.2f, 1.0f
};
vec4 dest[3];

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

for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=4,j++) {
GLM(vec4_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
}
4 changes: 4 additions & 0 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ TEST_DECLARE(glm_vec4_abs)
TEST_DECLARE(glm_vec4_fract)
TEST_DECLARE(glm_vec4_hadd)
TEST_DECLARE(glm_vec4_sqrt)
TEST_DECLARE(glm_vec4_make)

TEST_DECLARE(glmc_vec4)
TEST_DECLARE(glmc_vec4_copy3)
Expand Down Expand Up @@ -748,6 +749,7 @@ TEST_DECLARE(glmc_vec4_abs)
TEST_DECLARE(glmc_vec4_fract)
TEST_DECLARE(glmc_vec4_hadd)
TEST_DECLARE(glmc_vec4_sqrt)
TEST_DECLARE(glmc_vec4_make)

/* ivec2 */
TEST_DECLARE(glm_ivec2)
Expand Down Expand Up @@ -1532,6 +1534,7 @@ TEST_LIST {
TEST_ENTRY(glm_vec4_fract)
TEST_ENTRY(glm_vec4_hadd)
TEST_ENTRY(glm_vec4_sqrt)
TEST_ENTRY(glm_vec4_make)

TEST_ENTRY(glmc_vec4)
TEST_ENTRY(glmc_vec4_copy3)
Expand Down Expand Up @@ -1597,6 +1600,7 @@ TEST_LIST {
TEST_ENTRY(glmc_vec4_fract)
TEST_ENTRY(glmc_vec4_hadd)
TEST_ENTRY(glmc_vec4_sqrt)
TEST_ENTRY(glmc_vec4_make)

/* ivec2 */
TEST_ENTRY(glm_ivec2)
Expand Down