diff --git a/docs/source/ivec2.rst b/docs/source/ivec2.rst index 6abeb1a..0f374f7 100644 --- a/docs/source/ivec2.rst +++ b/docs/source/ivec2.rst @@ -21,12 +21,17 @@ Functions: #. :c:func:`glm_ivec2_copy` #. :c:func:`glm_ivec2_zero` #. :c:func:`glm_ivec2_one` +#. :c:func:`glm_ivec2_dot` +#. :c:func:`glm_ivec2_cross` #. :c:func:`glm_ivec2_add` #. :c:func:`glm_ivec2_adds` #. :c:func:`glm_ivec2_sub` #. :c:func:`glm_ivec2_subs` #. :c:func:`glm_ivec2_mul` #. :c:func:`glm_ivec2_scale` +#. :c:func:`glm_ivec2_div` +#. :c:func:`glm_ivec2_divs` +#. :c:func:`glm_ivec2_mod` #. :c:func:`glm_ivec2_distance2` #. :c:func:`glm_ivec2_distance` #. :c:func:`glm_ivec2_maxv` @@ -67,6 +72,30 @@ Functions documentation Parameters: | *[out]* **v** vector +.. c:function:: int glm_ivec2_dot(ivec2 a, ivec2 b) + + dot product of ivec2 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: int glm_ivec2_cross(ivec2 a, ivec2 b) + + cross product of two vector (RH) + + | ref: http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + + Returns: + Z component of cross product + .. c:function:: void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) add vector [a] to vector [b] and store result in [dest] @@ -121,6 +150,33 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination +.. c:function:: void glm_ivec2_div(ivec2 a, ivec2 b, ivec2 dest) + + div vector with another component-wise division: d = a / b + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2]) + +.. c:function:: void glm_ivec2_divs(ivec2 v, int s, ivec2 dest) + + div vector with scalar: d = v / s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s) + +.. c:function:: void glm_ivec2_mod(ivec2 a, ivec2 b, ivec2 dest) + + mod vector with another component-wise modulo: d = a % b + + Parameters: + | *[in]* **a** vector + | *[in]* **b** scalar + | *[out]* **dest** result = (a[0] % b[0], a[1] % b[1]) + .. c:function:: int glm_ivec2_distance2(ivec2 a, ivec2 b) squared distance between two vectors diff --git a/docs/source/ivec3.rst b/docs/source/ivec3.rst index 1c2daa0..460e94e 100644 --- a/docs/source/ivec3.rst +++ b/docs/source/ivec3.rst @@ -21,12 +21,18 @@ Functions: #. :c:func:`glm_ivec3_copy` #. :c:func:`glm_ivec3_zero` #. :c:func:`glm_ivec3_one` +#. :c:func:`glm_ivec3_dot` +#. :c:func:`glm_ivec3_norm2` +#. :c:func:`glm_ivec3_norm` #. :c:func:`glm_ivec3_add` #. :c:func:`glm_ivec3_adds` #. :c:func:`glm_ivec3_sub` #. :c:func:`glm_ivec3_subs` #. :c:func:`glm_ivec3_mul` #. :c:func:`glm_ivec3_scale` +#. :c:func:`glm_ivec3_div` +#. :c:func:`glm_ivec3_divs` +#. :c:func:`glm_ivec3_mod` #. :c:func:`glm_ivec3_distance2` #. :c:func:`glm_ivec3_distance` #. :c:func:`glm_ivec3_fill` @@ -70,6 +76,39 @@ Functions documentation Parameters: | *[out]* **v** vector +.. c:function:: int glm_ivec3_dot(ivec3 a, ivec3 b) + + dot product of ivec3 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: int glm_ivec3_norm2(ivec3 v) + + norm * norm (magnitude) of vector + + we can use this func instead of calling norm * norm, because it would call + sqrtf fuction twice but with this func we can avoid func call, maybe this is + not good name for this func + + Parameters: + | *[in]* **v** vector + + Returns: + square of norm / magnitude, cast to an integer + +.. c:function:: int glm_ivec3_norm(ivec3 vec) + + | euclidean norm (magnitude), also called L2 norm + | this will give magnitude of vector in euclidean space + + Parameters: + | *[in]* **vec** vector + .. c:function:: void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) add vector [a] to vector [b] and store result in [dest] @@ -124,6 +163,33 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination +.. c:function:: void glm_ivec3_div(ivec3 a, ivec3 b, ivec3 dest) + + div vector with another component-wise division: d = a / b + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2]) + +.. c:function:: void glm_ivec3_divs(ivec3 v, int s, ivec3 dest) + + div vector with scalar: d = v / s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s) + +.. c:function:: void glm_ivec3_mod(ivec3 a, ivec3 b, ivec3 dest) + + mod vector with another component-wise modulo: d = a % b + + Parameters: + | *[in]* **a** vector + | *[in]* **b** scalar + | *[out]* **dest** result = (a[0] % b[0], a[1] % b[1], a[2] % b[2]) + .. c:function:: int glm_ivec3_distance2(ivec3 a, ivec3 b) squared distance between two vectors diff --git a/include/cglm/call/ivec2.h b/include/cglm/call/ivec2.h index 2362415..82f70eb 100644 --- a/include/cglm/call/ivec2.h +++ b/include/cglm/call/ivec2.h @@ -29,6 +29,14 @@ CGLM_EXPORT void glmc_ivec2_one(ivec2 v); +CGLM_EXPORT +int +glmc_ivec2_dot(ivec2 a, ivec2 b); + +CGLM_EXPORT +int +glmc_ivec2_cross(ivec2 a, ivec2 b); + CGLM_EXPORT void glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest); @@ -53,6 +61,18 @@ CGLM_EXPORT void glmc_ivec2_scale(ivec2 v, int s, ivec2 dest); +CGLM_EXPORT +void +glmc_ivec2_div(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_divs(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_mod(ivec2 a, ivec2 b, ivec2 dest); + CGLM_EXPORT void glmc_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest); diff --git a/include/cglm/call/ivec3.h b/include/cglm/call/ivec3.h index e50041f..a6cec53 100644 --- a/include/cglm/call/ivec3.h +++ b/include/cglm/call/ivec3.h @@ -29,6 +29,18 @@ CGLM_EXPORT void glmc_ivec3_one(ivec3 v); +CGLM_EXPORT +int +glmc_ivec3_dot(ivec3 a, ivec3 b); + +CGLM_EXPORT +int +glmc_ivec3_norm2(ivec3 v); + +CGLM_EXPORT +int +glmc_ivec3_norm(ivec3 v); + CGLM_EXPORT void glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest); @@ -53,6 +65,18 @@ CGLM_EXPORT void glmc_ivec3_scale(ivec3 v, int s, ivec3 dest); +CGLM_EXPORT +void +glmc_ivec3_div(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_divs(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_mod(ivec3 a, ivec3 b, ivec3 dest); + CGLM_EXPORT void glmc_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest); diff --git a/include/cglm/ivec2.h b/include/cglm/ivec2.h index 3178514..12b3b6c 100644 --- a/include/cglm/ivec2.h +++ b/include/cglm/ivec2.h @@ -17,12 +17,17 @@ CGLM_INLINE void glm_ivec2_copy(ivec2 a, ivec2 dest) CGLM_INLINE void glm_ivec2_zero(ivec2 v) CGLM_INLINE void glm_ivec2_one(ivec2 v) + CGLM_INLINE int glm_ivec2_dot(ivec2 a, ivec2 b) + CGLM_INLINE int glm_ivec2_cross(ivec2 a, ivec2 b) CGLM_INLINE void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) CGLM_INLINE void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_subs(ivec2 v, int s, ivec2 dest) CGLM_INLINE void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_scale(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_div(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_divs(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_mod(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) CGLM_INLINE void glm_ivec2_addadds(ivec2 a, int s, ivec2 dest) CGLM_INLINE void glm_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest) @@ -110,6 +115,36 @@ glm_ivec2_one(ivec2 v) { v[0] = v[1] = 1; } +/*! + * @brief ivec2 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +int +glm_ivec2_dot(ivec2 a, ivec2 b) { + return a[0] * b[0] + a[1] * b[1]; +} + +/*! + * @brief ivec2 cross product + * + * REF: http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return Z component of cross product + */ +CGLM_INLINE +int +glm_ivec2_cross(ivec2 a, ivec2 b) { + return a[0] * b[1] - a[1] * b[0]; +} + /*! * @brief add vector [a] to vector [b] and store result in [dest] * @@ -194,6 +229,48 @@ glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { dest[1] = v[1] * s; } +/*! + * @brief div vector with another component-wise division: d = a / b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]/b[0], a[1]/b[1]) + */ +CGLM_INLINE +void +glm_ivec2_div(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] / b[0]; + dest[1] = a[1] / b[1]; +} + +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest result = (a[0]/s, a[1]/s) + */ +CGLM_INLINE +void +glm_ivec2_divs(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] / s; + dest[1] = v[1] / s; +} + +/*! + * @brief mod vector with another component-wise modulo: d = a % b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]%b[0], a[1]%b[1]) + */ +CGLM_INLINE +void +glm_ivec2_mod(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] % b[0]; + dest[1] = a[1] % b[1]; +} + /*! * @brief add vector [a] with vector [b] and add result to vector [dest] * diff --git a/include/cglm/ivec3.h b/include/cglm/ivec3.h index 1962ecd..a73a5cc 100644 --- a/include/cglm/ivec3.h +++ b/include/cglm/ivec3.h @@ -17,12 +17,18 @@ CGLM_INLINE void glm_ivec3_copy(ivec3 a, ivec3 dest) CGLM_INLINE void glm_ivec3_zero(ivec3 v) CGLM_INLINE void glm_ivec3_one(ivec3 v) + CGLM_INLINE int glm_ivec3_dot(ivec3 a, ivec3 b) + CGLM_INLINE int glm_ivec3_norm2(ivec3 v) + CGLM_INLINE int glm_ivec3_norm(ivec3 v) CGLM_INLINE void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_adds(ivec3 v, int s, ivec3 dest) CGLM_INLINE void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_subs(ivec3 v, int s, ivec3 dest) CGLM_INLINE void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_scale(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_div(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_divs(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_mod(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) CGLM_INLINE void glm_ivec3_addadds(ivec3 a, int s, ivec3 dest) CGLM_INLINE void glm_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest) @@ -112,6 +118,51 @@ glm_ivec3_one(ivec3 v) { v[0] = v[1] = v[2] = 1; } +/*! + * @brief ivec3 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +int +glm_ivec3_dot(ivec3 a, ivec3 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vector + * + * @return norm * norm + */ +CGLM_INLINE +int +glm_ivec3_norm2(ivec3 v) { + return glm_ivec3_dot(v, v); +} + +/*! + * @brief euclidean norm (magnitude), also called L2 norm + * this will give magnitude of vector in euclidean space + * + * @param[in] v vector + * + * @return norm + */ +CGLM_INLINE +int +glm_ivec3_norm(ivec3 v) { + return (int)sqrtf(glm_ivec3_norm2(v)); +} + /*! * @brief add vector [a] to vector [b] and store result in [dest] * @@ -202,6 +253,53 @@ glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { dest[2] = v[2] * s; } +/*! + * @brief div vector with another component-wise division: d = a / b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]/b[0], a[1]/b[1], a[2]/b[2]) + */ +CGLM_INLINE +void +glm_ivec3_div(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] / b[0]; + dest[1] = a[1] / b[1]; + dest[2] = a[2] / b[2]; +} + +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest result = (a[0]/s, a[1]/s, a[2]/s) + */ +CGLM_INLINE +void +glm_ivec3_divs(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] / s; + dest[1] = v[1] / s; + dest[2] = v[2] / s; +} + +/*! + * @brief Element-wise modulo operation on ivec3 vectors: dest = a % b + * + * Performs element-wise modulo on each component of vectors `a` and `b`. + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]%b[0], a[1]%b[1], a[2]%b[2]) + */ +CGLM_INLINE +void +glm_ivec3_mod(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] % b[0]; + dest[1] = a[1] % b[1]; + dest[2] = a[2] % b[2]; +} + /*! * @brief add vector [a] with vector [b] and add result to vector [dest] * diff --git a/src/ivec2.c b/src/ivec2.c index fbfd7ad..0e39b5b 100644 --- a/src/ivec2.c +++ b/src/ivec2.c @@ -32,6 +32,18 @@ glmc_ivec2_one(ivec2 v) { glm_ivec2_one(v); } +CGLM_EXPORT +int +glmc_ivec2_dot(ivec2 a, ivec2 b) { + return glm_ivec2_dot(a, b); +} + +CGLM_EXPORT +int +glmc_ivec2_cross(ivec2 a, ivec2 b) { + return glm_ivec2_cross(a, b); +} + CGLM_EXPORT void glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { @@ -68,6 +80,24 @@ glmc_ivec2_scale(ivec2 v, int s, ivec2 dest) { glm_ivec2_scale(v, s, dest); } +CGLM_EXPORT +void +glmc_ivec2_div(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_divs(ivec2 v, int s, ivec2 dest) { + glm_ivec2_divs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_mod(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_mod(a, b, dest); +} + CGLM_EXPORT void glmc_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) { diff --git a/src/ivec3.c b/src/ivec3.c index 70ebd74..7644c99 100644 --- a/src/ivec3.c +++ b/src/ivec3.c @@ -32,6 +32,24 @@ glmc_ivec3_one(ivec3 v) { glm_ivec3_one(v); } +CGLM_EXPORT +int +glmc_ivec3_dot(ivec3 a, ivec3 b) { + return glm_ivec3_dot(a, b); +} + +CGLM_EXPORT +int +glmc_ivec3_norm2(ivec3 v) { + return glm_ivec3_norm2(v); +} + +CGLM_EXPORT +int +glmc_ivec3_norm(ivec3 v) { + return glm_ivec3_norm(v); +} + CGLM_EXPORT void glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { @@ -68,6 +86,24 @@ glmc_ivec3_scale(ivec3 v, int s, ivec3 dest) { glm_ivec3_scale(v, s, dest); } +CGLM_EXPORT +void +glmc_ivec3_div(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_divs(ivec3 v, int s, ivec3 dest) { + glm_ivec3_divs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_mod(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_mod(a, b, dest); +} + CGLM_EXPORT void glmc_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) { diff --git a/test/src/test_ivec2.h b/test/src/test_ivec2.h index 7280481..edcbe84 100644 --- a/test/src/test_ivec2.h +++ b/test/src/test_ivec2.h @@ -54,6 +54,34 @@ TEST_IMPL(GLM_PREFIX, ivec2_one) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec2_dot) { + ivec2 a = {2, 3}; + ivec2 b = {4, 4}; + int dot1, dot2; + + dot1 = GLM(ivec2_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1]; + + ASSERT(test_eq(dot1, dot2)) + ASSERT(dot1 == 20) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_cross) { + ivec2 a = {10, 9}; + ivec2 b = {1, 2}; + int cross1, cross2; + + cross1 = GLM(ivec2_cross)(a, b); + cross2 = a[0] * b[1] - a[1] * b[0]; + + ASSERT(test_eq(cross1, cross2)) + ASSERT(cross1 == 11) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec2_add) { ivec2 a = {14, 3}; ivec2 b = {-3, 2}; @@ -126,6 +154,50 @@ TEST_IMPL(GLM_PREFIX, ivec2_scale) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec2_div) { + ivec2 v1 = {6, 5}, + v2 = {-2, 4}, + v3; + + GLM(ivec2_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(v3[0] == -3) + ASSERT(v3[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_divs) { + ivec2 v1 = {16, -8}, v2; + int s = 4; + + GLM(ivec2_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(v2[0] == 4) + ASSERT(v2[1] == -2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mod) { + ivec2 a = {16, -8}; + ivec2 b = {3, 5}; + ivec2 dest; + + GLM(ivec2_mod)(a, b, dest); + + ASSERT(test_eq(a[0] % b[0], dest[0])) + ASSERT(test_eq(a[1] % b[1], dest[1])) + ASSERT(dest[0] == 1) + ASSERT(dest[1] == -3) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec2_addadd) { ivec2 a = {2, -3}, b = {-3, 4}, diff --git a/test/src/test_ivec3.h b/test/src/test_ivec3.h index 365891a..432c043 100644 --- a/test/src/test_ivec3.h +++ b/test/src/test_ivec3.h @@ -53,6 +53,46 @@ TEST_IMPL(GLM_PREFIX, ivec3_one) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec3_dot) { + ivec3 a = {2, 3, 1}; + ivec3 b = {4, 4, 2}; + int dot1, dot2; + + dot1 = GLM(ivec3_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + + ASSERT(test_eq(dot1, dot2)) + ASSERT(dot1 == 22) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_norm2) { + ivec3 v = {2, 3, 4}; + int norm2_1, norm2_2; + + norm2_1 = GLM(ivec3_norm2)(v); + norm2_2 = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; + + ASSERT(test_eq(norm2_1, norm2_2)) + ASSERT(norm2_1 == 29) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_norm) { + ivec3 v = {2, 3, 4}; + int norm1, norm2; + + norm1 = GLM(ivec3_norm)(v); + norm2 = (int)sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + + ASSERT(test_eq(norm1, norm2)) + ASSERT(norm1 == 5) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec3_add) { ivec3 a = {14, 3, 2}; ivec3 b = {-3, 2, 1}; @@ -131,6 +171,56 @@ TEST_IMPL(GLM_PREFIX, ivec3_scale) { TEST_SUCCESS } +TEST_IMPL(GLM_PREFIX, ivec3_div) { + ivec3 v1 = {6, 5, 8}, + v2 = {-2, 4, 2}, + v3; + + GLM(ivec3_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(test_eq(v1[2] / v2[2], v3[2])) + ASSERT(v3[0] == -3) + ASSERT(v3[1] == 1) + ASSERT(v3[2] == 4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_divs) { + ivec3 v1 = {16, -8, 12}, v2; + int s = 4; + + GLM(ivec3_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(test_eq(v1[2] / s, v2[2])) + ASSERT(v2[0] == 4) + ASSERT(v2[1] == -2) + ASSERT(v2[2] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mod) { + ivec3 a = {16, -8, 10}; + ivec3 b = {3, 5, 4}; + ivec3 dest; + + GLM(ivec3_mod)(a, b, dest); + + ASSERT(test_eq(a[0] % b[0], dest[0])) + ASSERT(test_eq(a[1] % b[1], dest[1])) + ASSERT(test_eq(a[2] % b[2], dest[2])) + ASSERT(dest[0] == 1) + ASSERT(dest[1] == -3) + ASSERT(dest[2] == 2) + + TEST_SUCCESS +} + TEST_IMPL(GLM_PREFIX, ivec3_addadd) { ivec3 a = {2, -3, 8}, b = {-3, 4, 5}, diff --git a/test/tests.h b/test/tests.h index 432f16d..e9509bd 100644 --- a/test/tests.h +++ b/test/tests.h @@ -920,12 +920,17 @@ TEST_DECLARE(glm_ivec2) TEST_DECLARE(glm_ivec2_copy) TEST_DECLARE(glm_ivec2_zero) TEST_DECLARE(glm_ivec2_one) +TEST_DECLARE(glm_ivec2_dot) +TEST_DECLARE(glm_ivec2_cross) TEST_DECLARE(glm_ivec2_add) TEST_DECLARE(glm_ivec2_adds) TEST_DECLARE(glm_ivec2_sub) TEST_DECLARE(glm_ivec2_subs) TEST_DECLARE(glm_ivec2_mul) TEST_DECLARE(glm_ivec2_scale) +TEST_DECLARE(glm_ivec2_div) +TEST_DECLARE(glm_ivec2_divs) +TEST_DECLARE(glm_ivec2_mod) TEST_DECLARE(glm_ivec2_addadd) TEST_DECLARE(glm_ivec2_addadds) TEST_DECLARE(glm_ivec2_subadd) @@ -956,12 +961,17 @@ TEST_DECLARE(glmc_ivec2) TEST_DECLARE(glmc_ivec2_copy) TEST_DECLARE(glmc_ivec2_zero) TEST_DECLARE(glmc_ivec2_one) +TEST_DECLARE(glmc_ivec2_dot) +TEST_DECLARE(glmc_ivec2_cross) TEST_DECLARE(glmc_ivec2_add) TEST_DECLARE(glmc_ivec2_adds) TEST_DECLARE(glmc_ivec2_sub) TEST_DECLARE(glmc_ivec2_subs) TEST_DECLARE(glmc_ivec2_mul) TEST_DECLARE(glmc_ivec2_scale) +TEST_DECLARE(glmc_ivec2_div) +TEST_DECLARE(glmc_ivec2_divs) +TEST_DECLARE(glmc_ivec2_mod) TEST_DECLARE(glmc_ivec2_addadd) TEST_DECLARE(glmc_ivec2_addadds) TEST_DECLARE(glmc_ivec2_subadd) @@ -993,12 +1003,18 @@ TEST_DECLARE(glm_ivec3) TEST_DECLARE(glm_ivec3_copy) TEST_DECLARE(glm_ivec3_zero) TEST_DECLARE(glm_ivec3_one) +TEST_DECLARE(glm_ivec3_dot) +TEST_DECLARE(glm_ivec3_norm2) +TEST_DECLARE(glm_ivec3_norm) TEST_DECLARE(glm_ivec3_add) TEST_DECLARE(glm_ivec3_adds) TEST_DECLARE(glm_ivec3_sub) TEST_DECLARE(glm_ivec3_subs) TEST_DECLARE(glm_ivec3_mul) TEST_DECLARE(glm_ivec3_scale) +TEST_DECLARE(glm_ivec3_div) +TEST_DECLARE(glm_ivec3_divs) +TEST_DECLARE(glm_ivec3_mod) TEST_DECLARE(glm_ivec3_addadd) TEST_DECLARE(glm_ivec3_addadds) TEST_DECLARE(glm_ivec3_subadd) @@ -1028,12 +1044,18 @@ TEST_DECLARE(glmc_ivec3) TEST_DECLARE(glmc_ivec3_copy) TEST_DECLARE(glmc_ivec3_zero) TEST_DECLARE(glmc_ivec3_one) +TEST_DECLARE(glmc_ivec3_dot) +TEST_DECLARE(glmc_ivec3_norm2) +TEST_DECLARE(glmc_ivec3_norm) TEST_DECLARE(glmc_ivec3_add) TEST_DECLARE(glmc_ivec3_adds) TEST_DECLARE(glmc_ivec3_sub) TEST_DECLARE(glmc_ivec3_subs) TEST_DECLARE(glmc_ivec3_mul) TEST_DECLARE(glmc_ivec3_scale) +TEST_DECLARE(glmc_ivec3_div) +TEST_DECLARE(glmc_ivec3_divs) +TEST_DECLARE(glmc_ivec3_mod) TEST_DECLARE(glmc_ivec3_addadd) TEST_DECLARE(glmc_ivec3_addadds) TEST_DECLARE(glmc_ivec3_subadd) @@ -2055,12 +2077,17 @@ TEST_LIST { TEST_ENTRY(glm_ivec2_copy) TEST_ENTRY(glm_ivec2_zero) TEST_ENTRY(glm_ivec2_one) + TEST_ENTRY(glm_ivec2_dot) + TEST_ENTRY(glm_ivec2_cross) TEST_ENTRY(glm_ivec2_add) TEST_ENTRY(glm_ivec2_adds) TEST_ENTRY(glm_ivec2_sub) TEST_ENTRY(glm_ivec2_subs) TEST_ENTRY(glm_ivec2_mul) TEST_ENTRY(glm_ivec2_scale) + TEST_ENTRY(glm_ivec2_div) + TEST_ENTRY(glm_ivec2_divs) + TEST_ENTRY(glm_ivec2_mod) TEST_ENTRY(glm_ivec2_addadd) TEST_ENTRY(glm_ivec2_addadds) TEST_ENTRY(glm_ivec2_subadd) @@ -2091,12 +2118,17 @@ TEST_LIST { TEST_ENTRY(glmc_ivec2_copy) TEST_ENTRY(glmc_ivec2_zero) TEST_ENTRY(glmc_ivec2_one) + TEST_ENTRY(glmc_ivec2_dot) + TEST_ENTRY(glmc_ivec2_cross) TEST_ENTRY(glmc_ivec2_add) TEST_ENTRY(glmc_ivec2_adds) TEST_ENTRY(glmc_ivec2_sub) TEST_ENTRY(glmc_ivec2_subs) TEST_ENTRY(glmc_ivec2_mul) TEST_ENTRY(glmc_ivec2_scale) + TEST_ENTRY(glmc_ivec2_div) + TEST_ENTRY(glmc_ivec2_divs) + TEST_ENTRY(glmc_ivec2_mod) TEST_ENTRY(glmc_ivec2_addadd) TEST_ENTRY(glmc_ivec2_addadds) TEST_ENTRY(glmc_ivec2_subadd) @@ -2128,12 +2160,18 @@ TEST_LIST { TEST_ENTRY(glm_ivec3_copy) TEST_ENTRY(glm_ivec3_zero) TEST_ENTRY(glm_ivec3_one) + TEST_ENTRY(glm_ivec3_dot) + TEST_ENTRY(glm_ivec3_norm2) + TEST_ENTRY(glm_ivec3_norm) TEST_ENTRY(glm_ivec3_add) TEST_ENTRY(glm_ivec3_adds) TEST_ENTRY(glm_ivec3_sub) TEST_ENTRY(glm_ivec3_subs) TEST_ENTRY(glm_ivec3_mul) TEST_ENTRY(glm_ivec3_scale) + TEST_ENTRY(glm_ivec3_div) + TEST_ENTRY(glm_ivec3_divs) + TEST_ENTRY(glm_ivec3_mod) TEST_ENTRY(glm_ivec3_addadd) TEST_ENTRY(glm_ivec3_addadds) TEST_ENTRY(glm_ivec3_subadd) @@ -2163,12 +2201,18 @@ TEST_LIST { TEST_ENTRY(glmc_ivec3_copy) TEST_ENTRY(glmc_ivec3_zero) TEST_ENTRY(glmc_ivec3_one) + TEST_ENTRY(glmc_ivec3_dot) + TEST_ENTRY(glmc_ivec3_norm2) + TEST_ENTRY(glmc_ivec3_norm) TEST_ENTRY(glmc_ivec3_add) TEST_ENTRY(glmc_ivec3_adds) TEST_ENTRY(glmc_ivec3_sub) TEST_ENTRY(glmc_ivec3_subs) TEST_ENTRY(glmc_ivec3_mul) TEST_ENTRY(glmc_ivec3_scale) + TEST_ENTRY(glmc_ivec3_div) + TEST_ENTRY(glmc_ivec3_divs) + TEST_ENTRY(glmc_ivec3_mod) TEST_ENTRY(glmc_ivec3_addadd) TEST_ENTRY(glmc_ivec3_addadds) TEST_ENTRY(glmc_ivec3_subadd)