diff --git a/glm/core/_vectorize.hpp b/glm/core/_vectorize.hpp index bfabdf3b..24140dd3 100644 --- a/glm/core/_vectorize.hpp +++ b/glm/core/_vectorize.hpp @@ -26,7 +26,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -#define VECTORIZE_1PARAM(func) \ +#define VECTORIZE2_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec2 func( \ detail::tvec2 const & v) \ @@ -34,8 +34,9 @@ return detail::tvec2( \ func(v.x), \ func(v.y)); \ - } \ - \ + } + +#define VECTORIZE3_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec3 func( \ detail::tvec3 const & v) \ @@ -44,8 +45,9 @@ func(v.x), \ func(v.y), \ func(v.z)); \ - } \ - \ + } + +#define VECTORIZE4_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec4 func( \ detail::tvec4 const & v) \ @@ -57,7 +59,59 @@ func(v.w)); \ } -#define VECTORIZE_2PARAMS(func) \ +#define VECTORIZE_VEC(func) \ + VECTORIZE2_VEC(func) \ + VECTORIZE3_VEC(func) \ + VECTORIZE4_VEC(func) + +#define VECTORIZE2_VEC_SCA(func) \ + template \ + GLM_FUNC_QUALIFIER detail::tvec2 func \ + ( \ + detail::tvec2 const & x, \ + typename detail::tvec2::value_type const & y \ + ) \ + { \ + return detail::tvec2( \ + func(x.x, y), \ + func(x.y, y)); \ + } + +#define VECTORIZE3_VEC_SCA(func) \ + template \ + GLM_FUNC_QUALIFIER detail::tvec3 func \ + ( \ + detail::tvec3 const & x, \ + typename detail::tvec3::value_type const & y \ + ) \ + { \ + return detail::tvec3( \ + func(x.x, y), \ + func(x.y, y), \ + func(x.z, y)); \ + } + +#define VECTORIZE4_VEC_SCA(func) \ + template \ + GLM_FUNC_QUALIFIER detail::tvec4 func \ + ( \ + detail::tvec4 const & x, \ + typename detail::tvec4::value_type const & y \ + ) \ + { \ + return detail::tvec4( \ + func(x.x, y), \ + func(x.y, y), \ + func(x.z, y), \ + func(x.w, y)); \ + } + +#define VECTORIZE_VEC_SCA(func) \ + VECTORIZE2_VEC_SCA(func) \ + VECTORIZE3_VEC_SCA(func) \ + VECTORIZE4_VEC_SCA(func) + +#define VECTORIZE2_VEC_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec2 func \ ( \ @@ -68,8 +122,9 @@ return detail::tvec2( \ func(x.x, y.x), \ func(x.y, y.y)); \ - } \ - \ + } + +#define VECTORIZE3_VEC_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec3 func \ ( \ @@ -81,8 +136,9 @@ func(x.x, y.x), \ func(x.y, y.y), \ func(x.z, y.z)); \ - } \ - \ + } + +#define VECTORIZE4_VEC_VEC(func) \ template \ GLM_FUNC_QUALIFIER detail::tvec4 func \ ( \ @@ -96,3 +152,8 @@ func(x.z, y.z), \ func(x.w, y.w)); \ } + +#define VECTORIZE_VEC_VEC(func) \ + VECTORIZE2_VEC_VEC(func) \ + VECTORIZE3_VEC_VEC(func) \ + VECTORIZE4_VEC_VEC(func) diff --git a/glm/core/func_common.hpp b/glm/core/func_common.hpp index 9832319c..1409f9d3 100644 --- a/glm/core/func_common.hpp +++ b/glm/core/func_common.hpp @@ -44,72 +44,90 @@ namespace glm /// @{ /// Returns x if x >= 0; otherwise, it returns -x. + /// + /// @tparam genType floating-point or signed integer; scalar or vector types. /// /// @see - GLSL abs man page /// @see - GLSL 4.20.8 specification, section 8.3 - template - genFIType abs(genFIType const & x); + template + genType abs(genType const & x); /// Returns 1.0 if x > 0, 0.0 if x == 0, or -1.0 if x < 0. - /// + /// + /// @tparam genType Floating-point or signed integer; scalar or vector types. + /// /// @see - GLSL sign man page /// @see - GLSL 4.20.8 specification, section 8.3 - template - genFIType sign(genFIType const & x); + template + genType sign(genType const & x); - //! Returns a value equal to the nearest integer that is less then or equal to x. - //! + /// Returns a value equal to the nearest integer that is less then or equal to x. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL floor man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType floor(genType const & x); - //! Returns a value equal to the nearest integer to x - //! whose absolute value is not larger than the absolute value of x. - //! + /// Returns a value equal to the nearest integer to x + /// whose absolute value is not larger than the absolute value of x. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL trunc man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType trunc(genType const & x); - //! Returns a value equal to the nearest integer to x. - //! The fraction 0.5 will round in a direction chosen by the - //! implementation, presumably the direction that is fastest. - //! This includes the possibility that round(x) returns the - //! same value as roundEven(x) for all values of x. - //! + /// Returns a value equal to the nearest integer to x. + /// The fraction 0.5 will round in a direction chosen by the + /// implementation, presumably the direction that is fastest. + /// This includes the possibility that round(x) returns the + /// same value as roundEven(x) for all values of x. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL round man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType round(genType const & x); - //! Returns a value equal to the nearest integer to x. - //! A fractional part of 0.5 will round toward the nearest even - //! integer. (Both 3.5 and 4.5 for x will return 4.0.) - //! + /// Returns a value equal to the nearest integer to x. + /// A fractional part of 0.5 will round toward the nearest even + /// integer. (Both 3.5 and 4.5 for x will return 4.0.) + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL roundEven man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType roundEven(genType const & x); - //! Returns a value equal to the nearest integer - //! that is greater than or equal to x. - //! + /// Returns a value equal to the nearest integer + /// that is greater than or equal to x. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL ceil man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType ceil(genType const & x); - //! Return x - floor(x). - //! + /// Return x - floor(x). + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL fract man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType fract(genType const & x); - //! Modulus. Returns x - y * floor(x / y) - //! for each component in x using the floating point value y. - //! + /// Modulus. Returns x - y * floor(x / y) + /// for each component in x using the floating point value y. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL mod man page /// @see - GLSL 4.20.8 specification, section 8.3 template @@ -117,9 +135,11 @@ namespace glm genType const & x, genType const & y); - //! Modulus. Returns x - y * floor(x / y) - //! for each component in x using the floating point value y. - //! + /// Modulus. Returns x - y * floor(x / y) + /// for each component in x using the floating point value y. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL mod man page /// @see - GLSL 4.20.8 specification, section 8.3 template @@ -127,11 +147,13 @@ namespace glm genType const & x, typename genType::value_type const & y); - //! Returns the fractional part of x and sets i to the integer - //! part (as a whole number floating point value). Both the - //! return value and the output parameter will have the same - //! sign as x. - //! + /// Returns the fractional part of x and sets i to the integer + /// part (as a whole number floating point value). Both the + /// return value and the output parameter will have the same + /// sign as x. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL modf man page /// @see - GLSL 4.20.8 specification, section 8.3 template @@ -140,6 +162,8 @@ namespace glm genType & i); /// Returns y if y < x; otherwise, it returns x. + /// + /// @tparam genType Floating-point or integer; scalar or vector types. /// /// @see - GLSL min man page /// @see - GLSL 4.20.8 specification, section 8.3 @@ -154,6 +178,8 @@ namespace glm typename genType::value_type const & y); /// Returns y if x < y; otherwise, it returns x. + /// + /// @tparam genType Floating-point or integer; scalar or vector types. /// /// @see - GLSL max man page /// @see - GLSL 4.20.8 specification, section 8.3 @@ -167,9 +193,11 @@ namespace glm genType const & x, typename genType::value_type const & y); - //! Returns min(max(x, minVal), maxVal) for each component in x - //! using the floating-point values minVal and maxVal. - //! + /// Returns min(max(x, minVal), maxVal) for each component in x + /// using the floating-point values minVal and maxVal. + /// + /// @tparam genType Floating-point or integer; scalar or vector types. + /// /// @see - GLSL clamp man page /// @see - GLSL 4.20.8 specification, section 8.3 template @@ -243,16 +271,18 @@ namespace glm typename genType::value_type const & edge, genType const & x); - //! Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and - //! performs smooth Hermite interpolation between 0 and 1 - //! when edge0 < x < edge1. This is useful in cases where - //! you would want a threshold function with a smooth - //! transition. This is equivalent to: - //! genType t; - //! t = clamp ((x – edge0) / (edge1 – edge0), 0, 1); - //! return t * t * (3 – 2 * t); - //! Results are undefined if edge0 >= edge1. - //! + /// Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and + /// performs smooth Hermite interpolation between 0 and 1 + /// when edge0 < x < edge1. This is useful in cases where + /// you would want a threshold function with a smooth + /// transition. This is equivalent to: + /// genType t; + /// t = clamp ((x – edge0) / (edge1 – edge0), 0, 1); + /// return t * t * (3 – 2 * t); + /// Results are undefined if edge0 >= edge1. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL smoothstep man page /// @see - GLSL 4.20.8 specification, section 8.3 template @@ -267,97 +297,123 @@ namespace glm typename genType::value_type const & edge1, genType const & x); - //! Returns true if x holds a NaN (not a number) - //! representation in the underlying implementation's set of - //! floating point representations. Returns false otherwise, - //! including for implementations with no NaN - //! representations. - //! + /// Returns true if x holds a NaN (not a number) + /// representation in the underlying implementation's set of + /// floating point representations. Returns false otherwise, + /// including for implementations with no NaN + /// representations. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL isnan man page /// @see - GLSL 4.20.8 specification, section 8.3 template typename genType::bool_type isnan(genType const & x); - //! Returns true if x holds a positive infinity or negative - //! infinity representation in the underlying implementation's - //! set of floating point representations. Returns false - //! otherwise, including for implementations with no infinity - //! representations. - //! + /// Returns true if x holds a positive infinity or negative + /// infinity representation in the underlying implementation's + /// set of floating point representations. Returns false + /// otherwise, including for implementations with no infinity + /// representations. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL isinf man page /// @see - GLSL 4.20.8 specification, section 8.3 template typename genType::bool_type isinf(genType const & x); - //! Returns a signed integer value representing - //! the encoding of a floating-point value. The floatingpoint - //! value's bit-level representation is preserved. - //! + /// Returns a signed integer value representing + /// the encoding of a floating-point value. The floatingpoint + /// value's bit-level representation is preserved. + /// + /// @tparam genType Single-precision floating-point scalar or vector types. + /// @tparam genIType Signed integer scalar or vector types. + /// /// @see - GLSL floatBitsToInt man page /// @see - GLSL 4.20.8 specification, section 8.3 template genIType floatBitsToInt(genType const & value); - //! Returns a unsigned integer value representing - //! the encoding of a floating-point value. The floatingpoint - //! value's bit-level representation is preserved. - //! + /// Returns a unsigned integer value representing + /// the encoding of a floating-point value. The floatingpoint + /// value's bit-level representation is preserved. + /// + /// @tparam genType Single-precision floating-point scalar or vector types. + /// @tparam genUType Unsigned integer scalar or vector types. + /// /// @see - GLSL floatBitsToUint man page /// @see - GLSL 4.20.8 specification, section 8.3 template genUType floatBitsToUint(genType const & value); - //! Returns a floating-point value corresponding to a signed - //! integer encoding of a floating-point value. - //! If an inf or NaN is passed in, it will not signal, and the - //! resulting floating point value is unspecified. Otherwise, - //! the bit-level representation is preserved. - //! + /// Returns a floating-point value corresponding to a signed + /// integer encoding of a floating-point value. + /// If an inf or NaN is passed in, it will not signal, and the + /// resulting floating point value is unspecified. Otherwise, + /// the bit-level representation is preserved. + /// + /// @tparam genType Single-precision floating-point scalar or vector types. + /// @tparam genIType Signed integer scalar or vector types. + /// /// @see - GLSL intBitsToFloat man page /// @see - GLSL 4.20.8 specification, section 8.3 + /// + /// @todo - Clarify this declaration, we don't need to actually specify the return type template genType intBitsToFloat(genIType const & value); - //! Returns a floating-point value corresponding to a - //! unsigned integer encoding of a floating-point value. - //! If an inf or NaN is passed in, it will not signal, and the - //! resulting floating point value is unspecified. Otherwise, - //! the bit-level representation is preserved. - //! + /// Returns a floating-point value corresponding to a + /// unsigned integer encoding of a floating-point value. + /// If an inf or NaN is passed in, it will not signal, and the + /// resulting floating point value is unspecified. Otherwise, + /// the bit-level representation is preserved. + /// + /// @tparam genType Single-precision floating-point scalar or vector types. + /// @tparam genUType Unsigned integer scalar or vector types. + /// /// @see - GLSL uintBitsToFloat man page /// @see - GLSL 4.20.8 specification, section 8.3 + /// + /// @todo - Clarify this declaration, we don't need to actually specify the return type template genType uintBitsToFloat(genUType const & value); - //! Computes and returns a * b + c. - //! + /// Computes and returns a * b + c. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL fma man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType fma(genType const & a, genType const & b, genType const & c); - //! Splits x into a floating-point significand in the range - //! [0.5, 1.0) and an integral exponent of two, such that: - //! x = significand * exp(2, exponent) - //! - //! The significand is returned by the function and the - //! exponent is returned in the parameter exp. For a - //! floating-point value of zero, the significant and exponent - //! are both zero. For a floating-point value that is an - //! infinity or is not a number, the results are undefined. - //! + /// Splits x into a floating-point significand in the range + /// [0.5, 1.0) and an integral exponent of two, such that: + /// x = significand * exp(2, exponent) + /// + /// The significand is returned by the function and the + /// exponent is returned in the parameter exp. For a + /// floating-point value of zero, the significant and exponent + /// are both zero. For a floating-point value that is an + /// infinity or is not a number, the results are undefined. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL frexp man page /// @see - GLSL 4.20.8 specification, section 8.3 template genType frexp(genType const & x, genIType & exp); - //! Builds a floating-point number from x and the - //! corresponding integral exponent of two in exp, returning: - //! significand * exp(2, exponent) - //! - //! If this product is too large to be represented in the - //! floating-point type, the result is undefined. - //! + /// Builds a floating-point number from x and the + /// corresponding integral exponent of two in exp, returning: + /// significand * exp(2, exponent) + /// + /// If this product is too large to be represented in the + /// floating-point type, the result is undefined. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL ldexp man page; /// @see - GLSL 4.20.8 specification, section 8.3 template diff --git a/glm/core/func_common.inl b/glm/core/func_common.inl index dfb54431..430708bb 100644 --- a/glm/core/func_common.inl +++ b/glm/core/func_common.inl @@ -70,7 +70,7 @@ namespace detail return detail::Abs_::is_signed>::get(x); } - VECTORIZE_1PARAM(abs) + VECTORIZE_VEC(abs) // sign //Try something like based on x >> 31 to get the sign bit @@ -94,7 +94,7 @@ namespace detail return result; } - VECTORIZE_1PARAM(sign) + VECTORIZE_VEC(sign) // floor template <> @@ -111,7 +111,7 @@ namespace detail return ::std::floor(x); } - VECTORIZE_1PARAM(floor) + VECTORIZE_VEC(floor) // trunc template @@ -121,7 +121,7 @@ namespace detail return x < 0 ? -floor(-x) : floor(x); } - VECTORIZE_1PARAM(trunc) + VECTORIZE_VEC(trunc) // round template @@ -134,7 +134,7 @@ namespace detail return genType(int(x + genType(0.5))); } - VECTORIZE_1PARAM(round) + VECTORIZE_VEC(round) /* // roundEven @@ -161,7 +161,7 @@ namespace detail return genType(int(x + RoundValue)); } - VECTORIZE_1PARAM(roundEven) + VECTORIZE_VEC(roundEven) // ceil template @@ -172,7 +172,7 @@ namespace detail return ::std::ceil(x); } - VECTORIZE_1PARAM(ceil) + VECTORIZE_VEC(ceil) // fract template @@ -186,7 +186,7 @@ namespace detail return x - ::std::floor(x); } - VECTORIZE_1PARAM(fract) + VECTORIZE_VEC(fract) // mod template @@ -201,83 +201,8 @@ namespace detail return x - y * floor(x / y); } - template - GLM_FUNC_QUALIFIER detail::tvec2 mod - ( - detail::tvec2 const & x, - typename detail::tvec2::value_type const & y - ) - { - return detail::tvec2( - mod(x.x, y), - mod(x.y, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 mod - ( - detail::tvec3 const & x, - typename detail::tvec3::value_type const & y - ) - { - return detail::tvec3( - mod(x.x, y), - mod(x.y, y), - mod(x.z, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mod - ( - detail::tvec4 const & x, - typename detail::tvec4::value_type const & y - ) - { - return detail::tvec4( - mod(x.x, y), - mod(x.y, y), - mod(x.z, y), - mod(x.w, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 mod - ( - detail::tvec2 const & x, - detail::tvec2 const & y - ) - { - return detail::tvec2( - mod(x.x, y.x), - mod(x.y, y.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 mod - ( - detail::tvec3 const & x, - detail::tvec3 const & y - ) - { - return detail::tvec3( - mod(x.x, y.x), - mod(x.y, y.y), - mod(x.z, y.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 mod - ( - detail::tvec4 const & x, - detail::tvec4 const & y - ) - { - return detail::tvec4( - mod(x.x, y.x), - mod(x.y, y.y), - mod(x.z, y.z), - mod(x.w, y.w)); - } + VECTORIZE_VEC_SCA(mod) + VECTORIZE_VEC_VEC(mod) // modf template @@ -298,39 +223,39 @@ namespace detail GLM_FUNC_QUALIFIER detail::tvec2 modf ( detail::tvec2 const & x, - detail::tvec2 const & y + detail::tvec2 & i ) { return detail::tvec2( - modf(x.x, y.x), - modf(x.y, y.y)); + modf(x.x, i.x), + modf(x.y, i.y)); } template GLM_FUNC_QUALIFIER detail::tvec3 modf ( detail::tvec3 const & x, - detail::tvec3 const & y + detail::tvec3 & i ) { return detail::tvec3( - modf(x.x, y.x), - modf(x.y, y.y), - modf(x.z, y.z)); + modf(x.x, i.x), + modf(x.y, i.y), + modf(x.z, i.z)); } template GLM_FUNC_QUALIFIER detail::tvec4 modf ( detail::tvec4 const & x, - detail::tvec4 const & y + detail::tvec4 & i ) { return detail::tvec4( - modf(x.x, y.x), - modf(x.y, y.y), - modf(x.z, y.z), - modf(x.w, y.w)); + modf(x.x, i.x), + modf(x.y, i.y), + modf(x.z, i.z), + modf(x.w, i.w)); } //// Only valid if (INT_MIN <= x-y <= INT_MAX) @@ -357,83 +282,8 @@ namespace detail return x < y ? x : y; } - template - GLM_FUNC_QUALIFIER detail::tvec2 min - ( - detail::tvec2 const & x, - typename detail::tvec2::value_type const & y - ) - { - return detail::tvec2( - min(x.x, y), - min(x.y, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 min - ( - detail::tvec3 const & x, - typename detail::tvec3::value_type const & y - ) - { - return detail::tvec3( - min(x.x, y), - min(x.y, y), - min(x.z, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 min - ( - detail::tvec4 const & x, - typename detail::tvec4::value_type const & y - ) - { - return detail::tvec4( - min(x.x, y), - min(x.y, y), - min(x.z, y), - min(x.w, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 min - ( - detail::tvec2 const & x, - detail::tvec2 const & y - ) - { - return detail::tvec2( - min(x.x, y.x), - min(x.y, y.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 min - ( - detail::tvec3 const & x, - detail::tvec3 const & y - ) - { - return detail::tvec3( - min(x.x, y.x), - min(x.y, y.y), - min(x.z, y.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 min - ( - detail::tvec4 const & x, - detail::tvec4 const & y - ) - { - return detail::tvec4( - min(x.x, y.x), - min(x.y, y.y), - min(x.z, y.z), - min(x.w, y.w)); - } + VECTORIZE_VEC_SCA(min) + VECTORIZE_VEC_VEC(min) // max template @@ -451,82 +301,8 @@ namespace detail return x > y ? x : y; } - template - GLM_FUNC_QUALIFIER detail::tvec2 max - ( - detail::tvec2 const & x, - typename detail::tvec2::value_type y - ) - { - return detail::tvec2( - max(x.x, y), - max(x.y, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 max - ( - detail::tvec3 const & x, - typename detail::tvec3::value_type y - ) - { - return detail::tvec3( - max(x.x, y), - max(x.y, y), - max(x.z, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 max - ( - detail::tvec4 const & x, - typename detail::tvec4::value_type y - ) - { - return detail::tvec4( - max(x.x, y), - max(x.y, y), - max(x.z, y), - max(x.w, y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec2 max - ( - detail::tvec2 const & x, - detail::tvec2 const & y - ) - { - return detail::tvec2( - max(x.x, y.x), - max(x.y, y.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 max - ( - detail::tvec3 const & x, - detail::tvec3 const & y - ) - { - return detail::tvec3( - max(x.x, y.x), - max(x.y, y.y), - max(x.z, y.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 max - ( - detail::tvec4 const & x, - detail::tvec4 const & y) - { - return detail::tvec4( - max(x.x, y.x), - max(x.y, y.y), - max(x.z, y.z), - max(x.w, y.w)); - } + VECTORIZE_VEC_SCA(max) + VECTORIZE_VEC_VEC(max) // clamp template diff --git a/glm/core/func_exponential.hpp b/glm/core/func_exponential.hpp index b59f191f..b36a13ad 100644 --- a/glm/core/func_exponential.hpp +++ b/glm/core/func_exponential.hpp @@ -42,6 +42,9 @@ namespace glm /// @{ /// Returns x raised to the y power. + /// + /// @param x pow function is defined for input values of x defined in the range (inf-, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL pow man page /// @see - GLSL 4.20.8 specification, section 8.2 @@ -49,6 +52,9 @@ namespace glm genType pow(genType const & x, genType const & y); /// Returns the natural exponentiation of x, i.e., e^x. + /// + /// @param x exp function is defined for input values of x defined in the range (inf-, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL exp man page /// @see - GLSL 4.20.8 specification, section 8.2 @@ -58,6 +64,9 @@ namespace glm /// Returns the natural logarithm of x, i.e., /// returns the value y which satisfies the equation x = e^y. /// Results are undefined if x <= 0. + /// + /// @param x log function is defined for input values of x defined in the range (0, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL log man page /// @see - GLSL 4.20.8 specification, section 8.2 @@ -65,6 +74,9 @@ namespace glm genType log(genType const & x); /// Returns 2 raised to the x power. + /// + /// @param x exp2 function is defined for input values of x defined in the range (inf-, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL exp2 man page /// @see - GLSL 4.20.8 specification, section 8.2 @@ -74,6 +86,9 @@ namespace glm /// Returns the base 2 log of x, i.e., returns the value y, /// which satisfies the equation x = 2 ^ y. /// + /// @param x log2 function is defined for input values of x defined in the range (0, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL log2 man page /// @see - GLSL 4.20.8 specification, section 8.2 template @@ -81,6 +96,9 @@ namespace glm /// Returns the positive square root of x. /// + /// @param x sqrt function is defined for input values of x defined in the range [0, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL sqrt man page /// @see - GLSL 4.20.8 specification, section 8.2 template @@ -88,6 +106,9 @@ namespace glm /// Returns the reciprocal of the positive square root of x. /// + /// @param x inversesqrt function is defined for input values of x defined in the range [0, inf+) in the limit of the type precision. + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL inversesqrt man page /// @see - GLSL 4.20.8 specification, section 8.2 template diff --git a/glm/core/func_exponential.inl b/glm/core/func_exponential.inl index a9a5a8c0..c57852c1 100644 --- a/glm/core/func_exponential.inl +++ b/glm/core/func_exponential.inl @@ -26,6 +26,8 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#include "_vectorize.hpp" + namespace glm { // pow @@ -41,44 +43,7 @@ namespace glm return ::std::pow(x, y); } - template - GLM_FUNC_QUALIFIER detail::tvec2 pow - ( - detail::tvec2 const & x, - detail::tvec2 const & y - ) - { - return detail::tvec2( - pow(x.x, y.x), - pow(x.y, y.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 pow - ( - detail::tvec3 const & x, - detail::tvec3 const & y - ) - { - return detail::tvec3( - pow(x.x, y.x), - pow(x.y, y.y), - pow(x.z, y.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 pow - ( - detail::tvec4 const & x, - detail::tvec4 const & y - ) - { - return detail::tvec4( - pow(x.x, y.x), - pow(x.y, y.y), - pow(x.z, y.z), - pow(x.w, y.w)); - } + VECTORIZE_VEC_VEC(pow) // exp template @@ -92,41 +57,7 @@ namespace glm return ::std::exp(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 exp - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - exp(x.x), - exp(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 exp - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - exp(x.x), - exp(x.y), - exp(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 exp - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - exp(x.x), - exp(x.y), - exp(x.z), - exp(x.w)); - } + VECTORIZE_VEC(exp) // log template @@ -140,41 +71,7 @@ namespace glm return ::std::log(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 log - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - log(x.x), - log(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 log - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - log(x.x), - log(x.y), - log(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 log - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - log(x.x), - log(x.y), - log(x.z), - log(x.w)); - } + VECTORIZE_VEC(log) //exp2, ln2 = 0.69314718055994530941723212145818f template @@ -188,41 +85,7 @@ namespace glm return ::std::exp(genType(0.69314718055994530941723212145818) * x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 exp2 - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - exp2(x.x), - exp2(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 exp2 - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - exp2(x.x), - exp2(x.y), - exp2(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 exp2 - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - exp2(x.x), - exp2(x.y), - exp2(x.z), - exp2(x.w)); - } + VECTORIZE_VEC(exp2) namespace detail { @@ -255,44 +118,11 @@ namespace detail genType const & x ) { + assert(x > genType(0)); // log2 is only defined on the range (0, inf] return detail::compute_log2::ID>()(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 log2 - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - log2(x.x), - log2(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 log2 - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - log2(x.x), - log2(x.y), - log2(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 log2 - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - log2(x.x), - log2(x.y), - log2(x.z), - log2(x.w)); - } + VECTORIZE_VEC(log2) // sqrt template @@ -306,41 +136,7 @@ namespace detail return genType(::std::sqrt(x)); } - template - GLM_FUNC_QUALIFIER detail::tvec2 sqrt - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - glm::sqrt(x.x), - glm::sqrt(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 sqrt - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - glm::sqrt(x.x), - glm::sqrt(x.y), - glm::sqrt(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 sqrt - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - glm::sqrt(x.x), - glm::sqrt(x.y), - glm::sqrt(x.z), - glm::sqrt(x.w)); - } + VECTORIZE_VEC(sqrt) template GLM_FUNC_QUALIFIER genType inversesqrt @@ -353,40 +149,6 @@ namespace detail return genType(1) / ::std::sqrt(x); } - template - GLM_FUNC_QUALIFIER detail::tvec2 inversesqrt - ( - detail::tvec2 const & x - ) - { - return detail::tvec2( - inversesqrt(x.x), - inversesqrt(x.y)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 inversesqrt - ( - detail::tvec3 const & x - ) - { - return detail::tvec3( - inversesqrt(x.x), - inversesqrt(x.y), - inversesqrt(x.z)); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 inversesqrt - ( - detail::tvec4 const & x - ) - { - return detail::tvec4( - inversesqrt(x.x), - inversesqrt(x.y), - inversesqrt(x.z), - inversesqrt(x.w)); - } + VECTORIZE_VEC(inversesqrt) }//namespace glm diff --git a/glm/core/func_geometric.hpp b/glm/core/func_geometric.hpp index 9cea45de..de6bcf39 100644 --- a/glm/core/func_geometric.hpp +++ b/glm/core/func_geometric.hpp @@ -43,6 +43,8 @@ namespace glm /// Returns the length of x, i.e., sqrt(x * x). /// + /// @tparam genType Floating-point vector types. + /// /// @see - GLSL length man page /// @see - GLSL 4.20.8 specification, section 8.5 template @@ -50,6 +52,8 @@ namespace glm genType const & x); /// Returns the distance betwwen p0 and p1, i.e., length(p0 - p1). + /// + /// @tparam genType Floating-point vector types. /// /// @see - GLSL distance man page /// @see - GLSL 4.20.8 specification, section 8.5 @@ -59,6 +63,8 @@ namespace glm genType const & p1); /// Returns the dot product of x and y, i.e., result = x * y. + /// + /// @tparam genType Floating-point vector types. /// /// @see - GLSL dot man page /// @see - GLSL 4.20.8 specification, section 8.5 @@ -68,13 +74,15 @@ namespace glm genType const & y); /// Returns the cross product of x and y. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL cross man page /// @see - GLSL 4.20.8 specification, section 8.5 - template - detail::tvec3 cross( - detail::tvec3 const & x, - detail::tvec3 const & y); + template + detail::tvec3 cross( + detail::tvec3 const & x, + detail::tvec3 const & y); /// Returns a vector in the same direction as x but with length of 1. /// @@ -85,6 +93,8 @@ namespace glm genType const & x); /// If dot(Nref, I) < 0.0, return N, otherwise, return -N. + /// + /// @tparam genType Floating-point vector types. /// /// @see - GLSL faceforward man page /// @see - GLSL 4.20.8 specification, section 8.5 @@ -96,6 +106,8 @@ namespace glm /// For the incident vector I and surface orientation N, /// returns the reflection direction : result = I - 2.0 * dot(N, I) * N. + /// + /// @tparam genType Floating-point vector types. /// /// @see - GLSL reflect man page /// @see - GLSL 4.20.8 specification, section 8.5 @@ -107,6 +119,8 @@ namespace glm /// For the incident vector I and surface normal N, /// and the ratio of indices of refraction eta, /// return the refraction vector. + /// + /// @tparam genType Floating-point vector types. /// /// @see - GLSL refract man page /// @see - GLSL 4.20.8 specification, section 8.5 diff --git a/glm/core/func_geometric.inl b/glm/core/func_geometric.inl index 26a6b64e..438bef9d 100644 --- a/glm/core/func_geometric.inl +++ b/glm/core/func_geometric.inl @@ -26,6 +26,8 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#include "_vectorize.hpp" + namespace glm { // length diff --git a/glm/core/func_integer.hpp b/glm/core/func_integer.hpp index 6f30d4f2..5e438dee 100644 --- a/glm/core/func_integer.hpp +++ b/glm/core/func_integer.hpp @@ -43,10 +43,12 @@ namespace glm /// @addtogroup core_func_integer /// @{ - //! Adds 32-bit unsigned integer x and y, returning the sum - //! modulo pow(2, 32). The value carry is set to 0 if the sum was - //! less than pow(2, 32), or to 1 otherwise. - //! + /// Adds 32-bit unsigned integer x and y, returning the sum + /// modulo pow(2, 32). The value carry is set to 0 if the sum was + /// less than pow(2, 32), or to 1 otherwise. + /// + /// @tparam genUType Unsigned integer scalar or vector types. + /// /// @see - GLSL uaddCarry man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -55,10 +57,12 @@ namespace glm genUType const & y, genUType & carry); - //! Subtracts the 32-bit unsigned integer y from x, returning - //! the difference if non-negative, or pow(2, 32) plus the difference - //! otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise. - //! + /// Subtracts the 32-bit unsigned integer y from x, returning + /// the difference if non-negative, or pow(2, 32) plus the difference + /// otherwise. The value borrow is set to 0 if x >= y, or to 1 otherwise. + /// + /// @tparam genUType Unsigned integer scalar or vector types. + /// /// @see - GLSL usubBorrow man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -67,10 +71,12 @@ namespace glm genUType const & y, genUType & borrow); - //! Multiplies 32-bit integers x and y, producing a 64-bit - //! result. The 32 least-significant bits are returned in lsb. - //! The 32 most-significant bits are returned in msb. - //! + /// Multiplies 32-bit integers x and y, producing a 64-bit + /// result. The 32 least-significant bits are returned in lsb. + /// The 32 most-significant bits are returned in msb. + /// + /// @tparam genUType Unsigned integer scalar or vector types. + /// /// @see - GLSL umulExtended man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -80,10 +86,12 @@ namespace glm genUType & msb, genUType & lsb); - //! Multiplies 32-bit integers x and y, producing a 64-bit - //! result. The 32 least-significant bits are returned in lsb. - //! The 32 most-significant bits are returned in msb. - //! + /// Multiplies 32-bit integers x and y, producing a 64-bit + /// result. The 32 least-significant bits are returned in lsb. + /// The 32 most-significant bits are returned in msb. + /// + /// @tparam genIType Signed integer scalar or vector types. + /// /// @see - GLSL imulExtended man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -93,17 +101,19 @@ namespace glm genIType & msb, genIType & lsb); - //! Extracts bits [offset, offset + bits - 1] from value, - //! returning them in the least significant bits of the result. - //! For unsigned data types, the most significant bits of the - //! result will be set to zero. For signed data types, the - //! most significant bits will be set to the value of bit offset + base – 1. - //! - //! If bits is zero, the result will be zero. The result will be - //! undefined if offset or bits is negative, or if the sum of - //! offset and bits is greater than the number of bits used - //! to store the operand. - //! + /// Extracts bits [offset, offset + bits - 1] from value, + /// returning them in the least significant bits of the result. + /// For unsigned data types, the most significant bits of the + /// result will be set to zero. For signed data types, the + /// most significant bits will be set to the value of bit offset + base – 1. + /// + /// If bits is zero, the result will be zero. The result will be + /// undefined if offset or bits is negative, or if the sum of + /// offset and bits is greater than the number of bits used + /// to store the operand. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL bitfieldExtract man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -112,16 +122,18 @@ namespace glm int const & Offset, int const & Bits); - //! Returns the insertion the bits least-significant bits of insert into base. - //! - //! The result will have bits [offset, offset + bits - 1] taken - //! from bits [0, bits – 1] of insert, and all other bits taken - //! directly from the corresponding bits of base. If bits is - //! zero, the result will simply be base. The result will be - //! undefined if offset or bits is negative, or if the sum of - //! offset and bits is greater than the number of bits used to - //! store the operand. - //! + /// Returns the insertion the bits least-significant bits of insert into base. + /// + /// The result will have bits [offset, offset + bits - 1] taken + /// from bits [0, bits – 1] of insert, and all other bits taken + /// directly from the corresponding bits of base. If bits is + /// zero, the result will simply be base. The result will be + /// undefined if offset or bits is negative, or if the sum of + /// offset and bits is greater than the number of bits used to + /// store the operand. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL bitfieldInsert man page /// @see - GLSL 4.20.8 specification, section 8.8 template @@ -131,40 +143,54 @@ namespace glm int const & Offset, int const & Bits); - //! Returns the reversal of the bits of value. - //! The bit numbered n of the result will be taken from bit (bits - 1) - n of value, - //! where bits is the total number of bits used to represent value. - //! + /// Returns the reversal of the bits of value. + /// The bit numbered n of the result will be taken from bit (bits - 1) - n of value, + /// where bits is the total number of bits used to represent value. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL bitfieldReverse man page /// @see - GLSL 4.20.8 specification, section 8.8 template genIUType bitfieldReverse(genIUType const & value); - //! Returns the number of bits set to 1 in the binary representation of value. - //! + /// Returns the number of bits set to 1 in the binary representation of value. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL bitCount man page /// @see - GLSL 4.20.8 specification, section 8.8 - template class C> - typename C::signed_type bitCount(C const & Value); + /// + /// @todo Clarify the declaration to specify that scalars are suported. + template class genIUType> + typename genIUType::signed_type bitCount(genIUType const & Value); - //! Returns the bit number of the least significant bit set to - //! 1 in the binary representation of value. - //! If value is zero, -1 will be returned. - //! + /// Returns the bit number of the least significant bit set to + /// 1 in the binary representation of value. + /// If value is zero, -1 will be returned. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL findLSB man page /// @see - GLSL 4.20.8 specification, section 8.8 - template class C> - typename C::signed_type findLSB(C const & Value); + /// + /// @todo Clarify the declaration to specify that scalars are suported. + template class genIUType> + typename genIUType::signed_type findLSB(genIUType const & Value); - //! Returns the bit number of the most significant bit in the binary representation of value. - //! For positive integers, the result will be the bit number of the most significant bit set to 1. - //! For negative integers, the result will be the bit number of the most significant - //! bit set to 0. For a value of zero or negative one, -1 will be returned. - //! + /// Returns the bit number of the most significant bit in the binary representation of value. + /// For positive integers, the result will be the bit number of the most significant bit set to 1. + /// For negative integers, the result will be the bit number of the most significant + /// bit set to 0. For a value of zero or negative one, -1 will be returned. + /// + /// @tparam genIUType Signed or unsigned integer scalar or vector types. + /// /// @see - GLSL findMSB man page /// @see - GLSL 4.20.8 specification, section 8.8 - template class C> - typename C::signed_type findMSB(C const & Value); + /// + /// @todo Clarify the declaration to specify that scalars are suported. + template class genIUType> + typename genIUType::signed_type findMSB(genIUType const & Value); /// @} }//namespace glm diff --git a/glm/core/func_integer.inl b/glm/core/func_integer.inl index 31f9684f..cbbad8f3 100644 --- a/glm/core/func_integer.inl +++ b/glm/core/func_integer.inl @@ -26,6 +26,7 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#include "_vectorize.hpp" #if(GLM_COMPILER & GLM_COMPILER_VC) #include #pragma intrinsic(_BitScanReverse) @@ -415,41 +416,7 @@ namespace glm return Out; } - template - GLM_FUNC_QUALIFIER detail::tvec2 bitfieldReverse - ( - detail::tvec2 const & value - ) - { - return detail::tvec2( - bitfieldReverse(value[0]), - bitfieldReverse(value[1])); - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 bitfieldReverse - ( - detail::tvec3 const & value - ) - { - return detail::tvec3( - bitfieldReverse(value[0]), - bitfieldReverse(value[1]), - bitfieldReverse(value[2])); - } - - template - GLM_FUNC_QUALIFIER detail::tvec4 bitfieldReverse - ( - detail::tvec4 const & value - ) - { - return detail::tvec4( - bitfieldReverse(value[0]), - bitfieldReverse(value[1]), - bitfieldReverse(value[2]), - bitfieldReverse(value[3])); - } + VECTORIZE_VEC(bitfieldReverse) // bitCount template diff --git a/glm/core/func_matrix.hpp b/glm/core/func_matrix.hpp index d50bbc13..5755020c 100644 --- a/glm/core/func_matrix.hpp +++ b/glm/core/func_matrix.hpp @@ -47,6 +47,8 @@ namespace glm /// Multiply matrix x by matrix y component-wise, i.e., /// result[i][j] is the scalar product of x[i][j] and y[i][j]. + /// + /// @tparam matType Floating-point matrix types. /// /// @see - GLSL matrixCompMult man page /// @see - GLSL 4.20.8 specification, section 8.6 @@ -58,15 +60,21 @@ namespace glm /// Treats the first parameter c as a column vector /// and the second parameter r as a row vector /// and does a linear algebraic matrix multiply c * r. + /// + /// @tparam matType Floating-point matrix types. /// /// @see - GLSL outerProduct man page /// @see - GLSL 4.20.8 specification, section 8.6 + /// + /// @todo Clarify the declaration to specify that matType doesn't have to be provided when used. template matType outerProduct( vecType const & c, vecType const & r); /// Returns the transposed matrix of x + /// + /// @tparam matType Floating-point matrix types. /// /// @see - GLSL transpose man page /// @see - GLSL 4.20.8 specification, section 8.6 @@ -75,52 +83,64 @@ namespace glm matType const & x); /// Return the determinant of a mat2 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL determinant man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - typename detail::tmat2x2::value_type determinant( - detail::tmat2x2 const & m); + template + typename detail::tmat2x2::value_type determinant( + detail::tmat2x2 const & m); /// Return the determinant of a mat3 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL determinant man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - typename detail::tmat3x3::value_type determinant( - detail::tmat3x3 const & m); + template + typename detail::tmat3x3::value_type determinant( + detail::tmat3x3 const & m); /// Return the determinant of a mat4 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL determinant man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - typename detail::tmat4x4::value_type determinant( - detail::tmat4x4 const & m); + template + typename detail::tmat4x4::value_type determinant( + detail::tmat4x4 const & m); /// Return the inverse of a mat2 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL inverse man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - detail::tmat2x2 inverse( - detail::tmat2x2 const & m); + template + detail::tmat2x2 inverse( + detail::tmat2x2 const & m); /// Return the inverse of a mat3 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL inverse man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - detail::tmat3x3 inverse( - detail::tmat3x3 const & m); + template + detail::tmat3x3 inverse( + detail::tmat3x3 const & m); /// Return the inverse of a mat4 matrix. + /// + /// @tparam valType Floating-point scalar types. /// /// @see - GLSL inverse man page /// @see - GLSL 4.20.8 specification, section 8.6 - template - detail::tmat4x4 inverse( - detail::tmat4x4 const & m); + template + detail::tmat4x4 inverse( + detail::tmat4x4 const & m); /// @} }//namespace glm diff --git a/glm/core/func_matrix.inl b/glm/core/func_matrix.inl index 07bf8e2b..3b6d0418 100644 --- a/glm/core/func_matrix.inl +++ b/glm/core/func_matrix.inl @@ -26,6 +26,8 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// +#include "_vectorize.hpp" + namespace glm { // matrixCompMult diff --git a/glm/core/func_noise.hpp b/glm/core/func_noise.hpp index 5e095af2..27971729 100644 --- a/glm/core/func_noise.hpp +++ b/glm/core/func_noise.hpp @@ -44,6 +44,8 @@ namespace glm /// @{ /// Returns a 1D noise value based on the input value x. + /// + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL noise1 man page /// @see - GLSL 4.20.8 specification, section 8.13 @@ -51,6 +53,8 @@ namespace glm typename genType::value_type noise1(genType const & x); /// Returns a 2D noise value based on the input value x. + /// + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL noise2 man page /// @see - GLSL 4.20.8 specification, section 8.13 @@ -58,6 +62,8 @@ namespace glm detail::tvec2 noise2(genType const & x); /// Returns a 3D noise value based on the input value x. + /// + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL noise3 man page /// @see - GLSL 4.20.8 specification, section 8.13 @@ -65,6 +71,8 @@ namespace glm detail::tvec3 noise3(genType const & x); /// Returns a 4D noise value based on the input value x. + /// + /// @tparam genType Floating-point scalar or vector types. /// /// @see - GLSL noise4 man page /// @see - GLSL 4.20.8 specification, section 8.13 diff --git a/glm/core/func_packing.inl b/glm/core/func_packing.inl index 4b8c6bcd..844b5c53 100644 --- a/glm/core/func_packing.inl +++ b/glm/core/func_packing.inl @@ -26,134 +26,133 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm{ - -GLM_FUNC_QUALIFIER detail::uint32 packUnorm2x16(detail::tvec2 const & v) +namespace glm { - detail::uint16 A(detail::uint16(round(clamp(v.x, 0.0f, 1.0f) * 65535.0f))); - detail::uint16 B(detail::uint16(round(clamp(v.y, 0.0f, 1.0f) * 65535.0f))); - return detail::uint32((B << 16) | A); -} - -GLM_FUNC_QUALIFIER detail::tvec2 unpackUnorm2x16(detail::uint32 const & p) -{ - detail::uint32 Mask16((1 << 16) - 1); - detail::uint32 A((p >> 0) & Mask16); - detail::uint32 B((p >> 16) & Mask16); - return detail::tvec2( - A * 1.0f / 65535.0f, - B * 1.0f / 65535.0f); -} - -GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2 const & v) -{ - union iu + GLM_FUNC_QUALIFIER detail::uint32 packUnorm2x16(detail::tvec2 const & v) { - detail::int16 i; - detail::uint16 u; - } A, B; + detail::uint16 A(detail::uint16(round(clamp(v.x, 0.0f, 1.0f) * 65535.0f))); + detail::uint16 B(detail::uint16(round(clamp(v.y, 0.0f, 1.0f) * 65535.0f))); + return detail::uint32((B << 16) | A); + } + + GLM_FUNC_QUALIFIER detail::tvec2 unpackUnorm2x16(detail::uint32 const & p) + { + detail::uint32 Mask16((1 << 16) - 1); + detail::uint32 A((p >> 0) & Mask16); + detail::uint32 B((p >> 16) & Mask16); + return detail::tvec2( + A * 1.0f / 65535.0f, + B * 1.0f / 65535.0f); + } + + GLM_FUNC_QUALIFIER detail::uint32 packSnorm2x16(detail::tvec2 const & v) + { + union iu + { + detail::int16 i; + detail::uint16 u; + } A, B; - detail::tvec2 Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f; - A.i = detail::int16(round(Unpack.x)); - B.i = detail::int16(round(Unpack.y)); - detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0); - return Pack; -} + detail::tvec2 Unpack = clamp(v ,-1.0f, 1.0f) * 32767.0f; + A.i = detail::int16(round(Unpack.x)); + B.i = detail::int16(round(Unpack.y)); + detail::uint32 Pack = (detail::uint32(B.u) << 16) | (detail::uint32(A.u) << 0); + return Pack; + } -GLM_FUNC_QUALIFIER detail::tvec2 unpackSnorm2x16(detail::uint32 const & p) -{ - union iu + GLM_FUNC_QUALIFIER detail::tvec2 unpackSnorm2x16(detail::uint32 const & p) { - detail::int16 i; - detail::uint16 u; - } A, B; + union iu + { + detail::int16 i; + detail::uint16 u; + } A, B; - detail::uint32 Mask16((1 << 16) - 1); - A.u = detail::uint16((p >> 0) & Mask16); - B.u = detail::uint16((p >> 16) & Mask16); - detail::tvec2 Pack(A.i, B.i); + detail::uint32 Mask16((1 << 16) - 1); + A.u = detail::uint16((p >> 0) & Mask16); + B.u = detail::uint16((p >> 16) & Mask16); + detail::tvec2 Pack(A.i, B.i); - return clamp(Pack * 1.0f / 32767.0f, -1.0f, 1.0f); -} + return clamp(Pack * 1.0f / 32767.0f, -1.0f, 1.0f); + } -GLM_FUNC_QUALIFIER detail::uint32 packUnorm4x8(detail::tvec4 const & v) -{ - detail::uint8 A((detail::uint8)round(clamp(v.x, 0.0f, 1.0f) * 255.0f)); - detail::uint8 B((detail::uint8)round(clamp(v.y, 0.0f, 1.0f) * 255.0f)); - detail::uint8 C((detail::uint8)round(clamp(v.z, 0.0f, 1.0f) * 255.0f)); - detail::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f)); - return detail::uint32((D << 24) | (C << 16) | (B << 8) | A); -} - -GLM_FUNC_QUALIFIER detail::tvec4 unpackUnorm4x8(detail::uint32 const & p) -{ - detail::uint32 Mask8((1 << 8) - 1); - detail::uint32 A((p >> 0) & Mask8); - detail::uint32 B((p >> 8) & Mask8); - detail::uint32 C((p >> 16) & Mask8); - detail::uint32 D((p >> 24) & Mask8); - return detail::tvec4( - A * 1.0f / 255.0f, - B * 1.0f / 255.0f, - C * 1.0f / 255.0f, - D * 1.0f / 255.0f); -} - -GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4 const & v) -{ - union iu + GLM_FUNC_QUALIFIER detail::uint32 packUnorm4x8(detail::tvec4 const & v) { - detail::int8 i; - detail::uint8 u; - } A, B, C, D; + detail::uint8 A((detail::uint8)round(clamp(v.x, 0.0f, 1.0f) * 255.0f)); + detail::uint8 B((detail::uint8)round(clamp(v.y, 0.0f, 1.0f) * 255.0f)); + detail::uint8 C((detail::uint8)round(clamp(v.z, 0.0f, 1.0f) * 255.0f)); + detail::uint8 D((detail::uint8)round(clamp(v.w, 0.0f, 1.0f) * 255.0f)); + return detail::uint32((D << 24) | (C << 16) | (B << 8) | A); + } + + GLM_FUNC_QUALIFIER detail::tvec4 unpackUnorm4x8(detail::uint32 const & p) + { + detail::uint32 Mask8((1 << 8) - 1); + detail::uint32 A((p >> 0) & Mask8); + detail::uint32 B((p >> 8) & Mask8); + detail::uint32 C((p >> 16) & Mask8); + detail::uint32 D((p >> 24) & Mask8); + return detail::tvec4( + A * 1.0f / 255.0f, + B * 1.0f / 255.0f, + C * 1.0f / 255.0f, + D * 1.0f / 255.0f); + } - detail::tvec4 Unpack = clamp(v ,-1.0f, 1.0f) * 127.0f; - A.i = detail::int8(round(Unpack.x)); - B.i = detail::int8(round(Unpack.y)); - C.i = detail::int8(round(Unpack.z)); - D.i = detail::int8(round(Unpack.w)); - detail::uint32 Pack = (detail::uint32(D.u) << 24) | (detail::uint32(C.u) << 16) | (detail::uint32(B.u) << 8) | (detail::uint32(A.u) << 0); - return Pack; -} - -GLM_FUNC_QUALIFIER detail::tvec4 unpackSnorm4x8(detail::uint32 const & p) -{ - union iu + GLM_FUNC_QUALIFIER detail::uint32 packSnorm4x8(detail::tvec4 const & v) { - detail::int8 i; - detail::uint8 u; - } A, B, C, D; + union iu + { + detail::int8 i; + detail::uint8 u; + } A, B, C, D; - detail::uint32 Mask8((1 << 8) - 1); - A.u = detail::uint8((p >> 0) & Mask8); - B.u = detail::uint8((p >> 8) & Mask8); - C.u = detail::uint8((p >> 16) & Mask8); - D.u = detail::uint8((p >> 24) & Mask8); - detail::tvec4 Pack(A.i, B.i, C.i, D.i); + detail::tvec4 Unpack = clamp(v ,-1.0f, 1.0f) * 127.0f; + A.i = detail::int8(round(Unpack.x)); + B.i = detail::int8(round(Unpack.y)); + C.i = detail::int8(round(Unpack.z)); + D.i = detail::int8(round(Unpack.w)); + detail::uint32 Pack = (detail::uint32(D.u) << 24) | (detail::uint32(C.u) << 16) | (detail::uint32(B.u) << 8) | (detail::uint32(A.u) << 0); + return Pack; + } - return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f); -} + GLM_FUNC_QUALIFIER detail::tvec4 unpackSnorm4x8(detail::uint32 const & p) + { + union iu + { + detail::int8 i; + detail::uint8 u; + } A, B, C, D; + + detail::uint32 Mask8((1 << 8) - 1); + A.u = detail::uint8((p >> 0) & Mask8); + B.u = detail::uint8((p >> 8) & Mask8); + C.u = detail::uint8((p >> 16) & Mask8); + D.u = detail::uint8((p >> 24) & Mask8); + detail::tvec4 Pack(A.i, B.i, C.i, D.i); + + return clamp(Pack * 1.0f / 127.0f, -1.0f, 1.0f); + } -GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2 const & v) -{ - return *(double*)&v; -} + GLM_FUNC_QUALIFIER double packDouble2x32(detail::tvec2 const & v) + { + return *(double*)&v; + } -GLM_FUNC_QUALIFIER detail::tvec2 unpackDouble2x32(double const & v) -{ - return *(detail::tvec2*)&v; -} + GLM_FUNC_QUALIFIER detail::tvec2 unpackDouble2x32(double const & v) + { + return *(detail::tvec2*)&v; + } -GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2 const & v) -{ - detail::tvec2 Pack(detail::toFloat16(v.x), detail::toFloat16(v.y)); - return *(uint*)&Pack; -} - -GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) -{ - detail::tvec2 Unpack = *(detail::tvec2*)&v; - return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y)); -} + GLM_FUNC_QUALIFIER uint packHalf2x16(detail::tvec2 const & v) + { + detail::tvec2 Pack(detail::toFloat16(v.x), detail::toFloat16(v.y)); + return *(uint*)&Pack; + } + GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) + { + detail::tvec2 Unpack = *(detail::tvec2*)&v; + return vec2(detail::toFloat32(Unpack.x), detail::toFloat32(Unpack.y)); + } }//namespace glm diff --git a/glm/core/func_trigonometric.hpp b/glm/core/func_trigonometric.hpp index f6e7c98d..f048d43b 100644 --- a/glm/core/func_trigonometric.hpp +++ b/glm/core/func_trigonometric.hpp @@ -45,119 +45,149 @@ namespace glm /// @addtogroup core_func_trigonometric /// @{ - //! Converts degrees to radians and returns the result. - //! + /// Converts degrees to radians and returns the result. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL radians man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType radians(genType const & degrees); - //! Converts radians to degrees and returns the result. - //! + /// Converts radians to degrees and returns the result. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL degrees man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType degrees(genType const & radians); - //! The standard trigonometric sine function. - //! The values returned by this function will range from [-1, 1]. - //! + /// The standard trigonometric sine function. + /// The values returned by this function will range from [-1, 1]. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL sin man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType sin(genType const & angle); - //! The standard trigonometric cosine function. - //! The values returned by this function will range from [-1, 1]. - //! + /// The standard trigonometric cosine function. + /// The values returned by this function will range from [-1, 1]. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL cos man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType cos(genType const & angle); - //! The standard trigonometric tangent function. - //! + /// The standard trigonometric tangent function. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL tan man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType tan(genType const & angle); - //! Arc sine. Returns an angle whose sine is x. - //! The range of values returned by this function is [-PI/2, PI/2]. - //! Results are undefined if |x| > 1. - //! + /// Arc sine. Returns an angle whose sine is x. + /// The range of values returned by this function is [-PI/2, PI/2]. + /// Results are undefined if |x| > 1. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL asin man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType asin(genType const & x); - //! Arc cosine. Returns an angle whose sine is x. - //! The range of values returned by this function is [0, PI]. - //! Results are undefined if |x| > 1. - //! + /// Arc cosine. Returns an angle whose sine is x. + /// The range of values returned by this function is [0, PI]. + /// Results are undefined if |x| > 1. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL acos man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType acos(genType const & x); - //! Arc tangent. Returns an angle whose tangent is y/x. - //! The signs of x and y are used to determine what - //! quadrant the angle is in. The range of values returned - //! by this function is [-PI, PI]. Results are undefined - //! if x and y are both 0. - //! + /// Arc tangent. Returns an angle whose tangent is y/x. + /// The signs of x and y are used to determine what + /// quadrant the angle is in. The range of values returned + /// by this function is [-PI, PI]. Results are undefined + /// if x and y are both 0. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL atan man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType atan(genType const & y, genType const & x); - //! Arc tangent. Returns an angle whose tangent is y_over_x. - //! The range of values returned by this function is [-PI/2, PI/2]. - //! + /// Arc tangent. Returns an angle whose tangent is y_over_x. + /// The range of values returned by this function is [-PI/2, PI/2]. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL atan man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType atan(genType const & y_over_x); - //! Returns the hyperbolic sine function, (exp(x) - exp(-x)) / 2 - //! + /// Returns the hyperbolic sine function, (exp(x) - exp(-x)) / 2 + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL sinh man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType sinh(genType const & angle); - //! Returns the hyperbolic cosine function, (exp(x) + exp(-x)) / 2 - //! + /// Returns the hyperbolic cosine function, (exp(x) + exp(-x)) / 2 + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL cosh man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType cosh(genType const & angle); - //! Returns the hyperbolic tangent function, sinh(angle) / cosh(angle) - //! + /// Returns the hyperbolic tangent function, sinh(angle) / cosh(angle) + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL tanh man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType tanh(genType const & angle); - //! Arc hyperbolic sine; returns the inverse of sinh. - //! + /// Arc hyperbolic sine; returns the inverse of sinh. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL asinh man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType asinh(genType const & x); - //! Arc hyperbolic cosine; returns the non-negative inverse - //! of cosh. Results are undefined if x < 1. - //! + /// Arc hyperbolic cosine; returns the non-negative inverse + /// of cosh. Results are undefined if x < 1. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL acosh man page /// @see - GLSL 4.20.8 specification, section 8.1 template genType acosh(genType const & x); - //! Arc hyperbolic tangent; returns the inverse of tanh. - //! Results are undefined if abs(x) >= 1. - //! + /// Arc hyperbolic tangent; returns the inverse of tanh. + /// Results are undefined if abs(x) >= 1. + /// + /// @tparam genType Floating-point scalar or vector types. + /// /// @see - GLSL atanh man page /// @see - GLSL 4.20.8 specification, section 8.1 template diff --git a/glm/core/func_trigonometric.inl b/glm/core/func_trigonometric.inl index 9e83a8fa..b77ceb95 100644 --- a/glm/core/func_trigonometric.inl +++ b/glm/core/func_trigonometric.inl @@ -26,732 +26,221 @@ /// @author Christophe Riccio /////////////////////////////////////////////////////////////////////////////////// -namespace glm{ +#include "_vectorize.hpp" -// radians -template -GLM_FUNC_QUALIFIER genType radians -( - genType const & degrees -) +namespace glm { - GLM_STATIC_ASSERT(detail::type::is_float, "'radians' only accept floating-point input"); + // radians + template + GLM_FUNC_QUALIFIER genType radians + ( + genType const & degrees + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'radians' only accept floating-point input"); - const genType pi = genType(3.1415926535897932384626433832795); - return degrees * (pi / genType(180)); -} + genType const pi = genType(3.1415926535897932384626433832795); + return degrees * (pi / genType(180)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 radians -( - detail::tvec2 const & degrees -) -{ - return detail::tvec2( - radians(degrees.x), - radians(degrees.y)); -} + VECTORIZE_VEC(radians) + + // degrees + template + GLM_FUNC_QUALIFIER genType degrees + ( + genType const & radians + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'degrees' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec3 radians -( - detail::tvec3 const & degrees -) -{ - return detail::tvec3( - radians(degrees.x), - radians(degrees.y), - radians(degrees.z)); -} + const genType pi = genType(3.1415926535897932384626433832795); + return radians * (genType(180) / pi); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 radians -( - detail::tvec4 const & degrees -) -{ - return detail::tvec4( - radians(degrees.x), - radians(degrees.y), - radians(degrees.z), - radians(degrees.w)); -} + VECTORIZE_VEC(degrees) -// degrees -template -GLM_FUNC_QUALIFIER genType degrees -( - genType const & radians -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'degrees' only accept floating-point input"); + // sin + template + GLM_FUNC_QUALIFIER genType sin + ( + genType const & angle + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'sin' only accept floating-point input"); - const genType pi = genType(3.1415926535897932384626433832795); - return radians * (genType(180) / pi); -} + return ::std::sin(angle); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 degrees -( - detail::tvec2 const & radians -) -{ - return detail::tvec2( - degrees(radians.x), - degrees(radians.y)); -} + VECTORIZE_VEC(sin) -template -GLM_FUNC_QUALIFIER detail::tvec3 degrees -( - detail::tvec3 const & radians -) -{ - return detail::tvec3( - degrees(radians.x), - degrees(radians.y), - degrees(radians.z)); -} + // cos + template + GLM_FUNC_QUALIFIER genType cos(genType const & angle) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'cos' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec4 degrees -( - detail::tvec4 const & radians -) -{ - return detail::tvec4( - degrees(radians.x), - degrees(radians.y), - degrees(radians.z), - degrees(radians.w)); -} + return ::std::cos(angle); + } -// sin -template -GLM_FUNC_QUALIFIER genType sin -( - genType const & angle -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'sin' only accept floating-point input"); + VECTORIZE_VEC(cos) - return ::std::sin(angle); -} + // tan + template + GLM_FUNC_QUALIFIER genType tan + ( + genType const & angle + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'tan' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec2 sin -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - sin(angle.x), - sin(angle.y)); -} + return ::std::tan(angle); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 sin -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - sin(angle.x), - sin(angle.y), - sin(angle.z)); -} + VECTORIZE_VEC(tan) -template -GLM_FUNC_QUALIFIER detail::tvec4 sin -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - sin(angle.x), - sin(angle.y), - sin(angle.z), - sin(angle.w)); -} + // asin + template + GLM_FUNC_QUALIFIER genType asin + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'asin' only accept floating-point input"); -// cos -template -GLM_FUNC_QUALIFIER genType cos(genType const & angle) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'cos' only accept floating-point input"); + return ::std::asin(x); + } - return ::std::cos(angle); -} + VECTORIZE_VEC(asin) -template -GLM_FUNC_QUALIFIER detail::tvec2 cos -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - cos(angle.x), - cos(angle.y)); -} + // acos + template + GLM_FUNC_QUALIFIER genType acos + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'acos' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec3 cos -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - cos(angle.x), - cos(angle.y), - cos(angle.z)); -} + return ::std::acos(x); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 cos -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - cos(angle.x), - cos(angle.y), - cos(angle.z), - cos(angle.w)); -} + VECTORIZE_VEC(acos) -// tan -template -GLM_FUNC_QUALIFIER genType tan -( - genType const & angle -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'tan' only accept floating-point input"); + // atan + template + GLM_FUNC_QUALIFIER genType atan + ( + genType const & y, + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'atan' only accept floating-point input"); - return ::std::tan(angle); -} + return ::std::atan2(y, x); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 tan -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - tan(angle.x), - tan(angle.y)); -} + VECTORIZE_VEC_VEC(atan) -template -GLM_FUNC_QUALIFIER detail::tvec3 tan -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - tan(angle.x), - tan(angle.y), - tan(angle.z)); -} + template + GLM_FUNC_QUALIFIER genType atan + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'atan' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec4 tan -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - tan(angle.x), - tan(angle.y), - tan(angle.z), - tan(angle.w)); -} + return ::std::atan(x); + } -// asin -template -GLM_FUNC_QUALIFIER genType asin -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'asin' only accept floating-point input"); + VECTORIZE_VEC(atan) - return ::std::asin(x); -} + // sinh + template + GLM_FUNC_QUALIFIER genType sinh + ( + genType const & angle + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'sinh' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec2 asin -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - asin(x.x), - asin(x.y)); -} + return std::sinh(angle); + } -template -GLM_FUNC_QUALIFIER detail::tvec3 asin -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - asin(x.x), - asin(x.y), - asin(x.z)); -} + VECTORIZE_VEC(sinh) -template -GLM_FUNC_QUALIFIER detail::tvec4 asin -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - asin(x.x), - asin(x.y), - asin(x.z), - asin(x.w)); -} + // cosh + template + GLM_FUNC_QUALIFIER genType cosh + ( + genType const & angle + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'cosh' only accept floating-point input"); -// acos -template -GLM_FUNC_QUALIFIER genType acos -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'acos' only accept floating-point input"); + return std::cosh(angle); + } - return ::std::acos(x); -} + VECTORIZE_VEC(cosh) -template -GLM_FUNC_QUALIFIER detail::tvec2 acos -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - acos(x.x), - acos(x.y)); -} + // tanh + template + GLM_FUNC_QUALIFIER genType tanh + ( + genType const & angle + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'tanh' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec3 acos -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - acos(x.x), - acos(x.y), - acos(x.z)); -} + return std::tanh(angle); + } -template -GLM_FUNC_QUALIFIER detail::tvec4 acos -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - acos(x.x), - acos(x.y), - acos(x.z), - acos(x.w)); -} + VECTORIZE_VEC(tanh) -// atan -template -GLM_FUNC_QUALIFIER genType atan -( - genType const & y, - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'atan' only accept floating-point input"); - - return ::std::atan2(y, x); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 atan -( - detail::tvec2 const & y, - detail::tvec2 const & x -) -{ - return detail::tvec2( - atan(y.x, x.x), - atan(y.y, x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 atan -( - detail::tvec3 const & y, - detail::tvec3 const & x -) -{ - return detail::tvec3( - atan(y.x, x.x), - atan(y.y, x.y), - atan(y.z, x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 atan -( - detail::tvec4 const & y, - detail::tvec4 const & x -) -{ - return detail::tvec4( - atan(y.x, x.x), - atan(y.y, x.y), - atan(y.z, x.z), - atan(y.w, x.w)); -} - -template -GLM_FUNC_QUALIFIER genType atan -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'atan' only accept floating-point input"); - - return ::std::atan(x); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 atan -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - atan(x.x), - atan(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 atan -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - atan(x.x), - atan(x.y), - atan(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 atan -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - atan(x.x), - atan(x.y), - atan(x.z), - atan(x.w)); -} - -// sinh -template -GLM_FUNC_QUALIFIER genType sinh -( - genType const & angle -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'sinh' only accept floating-point input"); - - return std::sinh(angle); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 sinh -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - sinh(angle.x), - sinh(angle.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 sinh -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - sinh(angle.x), - sinh(angle.y), - sinh(angle.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 sinh -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - sinh(angle.x), - sinh(angle.y), - sinh(angle.z), - sinh(angle.w)); -} - -// cosh -template -GLM_FUNC_QUALIFIER genType cosh -( - genType const & angle -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'cosh' only accept floating-point input"); - - return std::cosh(angle); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 cosh -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - cosh(angle.x), - cosh(angle.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 cosh -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - cosh(angle.x), - cosh(angle.y), - cosh(angle.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 cosh -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - cosh(angle.x), - cosh(angle.y), - cosh(angle.z), - cosh(angle.w)); -} - -// tanh -template -GLM_FUNC_QUALIFIER genType tanh -( - genType const & angle -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'tanh' only accept floating-point input"); - - return std::tanh(angle); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 tanh -( - detail::tvec2 const & angle -) -{ - return detail::tvec2( - tanh(angle.x), - tanh(angle.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 tanh -( - detail::tvec3 const & angle -) -{ - return detail::tvec3( - tanh(angle.x), - tanh(angle.y), - tanh(angle.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 tanh -( - detail::tvec4 const & angle -) -{ - return detail::tvec4( - tanh(angle.x), - tanh(angle.y), - tanh(angle.z), - tanh(angle.w)); -} - -// asinh -template -GLM_FUNC_QUALIFIER genType asinh -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'asinh' only accept floating-point input"); + // asinh + template + GLM_FUNC_QUALIFIER genType asinh + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'asinh' only accept floating-point input"); - return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x)); -} + return (x < genType(0) ? genType(-1) : (x > genType(0) ? genType(1) : genType(0))) * log(abs(x) + sqrt(genType(1) + x * x)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 asinh -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - asinh(x.x), - asinh(x.y)); -} + VECTORIZE_VEC(asinh) -template -GLM_FUNC_QUALIFIER detail::tvec3 asinh -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - asinh(x.x), - asinh(x.y), - asinh(x.z)); -} + // acosh + template + GLM_FUNC_QUALIFIER genType acosh + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'acosh' only accept floating-point input"); -template -GLM_FUNC_QUALIFIER detail::tvec4 asinh -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - asinh(x.x), - asinh(x.y), - asinh(x.z), - asinh(x.w)); -} + if(x < genType(1)) + return genType(0); + return log(x + sqrt(x * x - genType(1))); + } -// acosh -template -GLM_FUNC_QUALIFIER genType acosh -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'acosh' only accept floating-point input"); + VECTORIZE_VEC(acosh) - if(x < genType(1)) - return genType(0); - return log(x + sqrt(x * x - genType(1))); -} - -template -GLM_FUNC_QUALIFIER detail::tvec2 acosh -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - acosh(x.x), - acosh(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 acosh -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - acosh(x.x), - acosh(x.y), - acosh(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 acosh -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - acosh(x.x), - acosh(x.y), - acosh(x.z), - acosh(x.w)); -} - -// atanh -template -GLM_FUNC_QUALIFIER genType atanh -( - genType const & x -) -{ - GLM_STATIC_ASSERT(detail::type::is_float, "'atanh' only accept floating-point input"); + // atanh + template + GLM_FUNC_QUALIFIER genType atanh + ( + genType const & x + ) + { + GLM_STATIC_ASSERT(detail::type::is_float, "'atanh' only accept floating-point input"); - if(abs(x) >= genType(1)) - return 0; - return genType(0.5) * log((genType(1) + x) / (genType(1) - x)); -} + if(abs(x) >= genType(1)) + return 0; + return genType(0.5) * log((genType(1) + x) / (genType(1) - x)); + } -template -GLM_FUNC_QUALIFIER detail::tvec2 atanh -( - detail::tvec2 const & x -) -{ - return detail::tvec2( - atanh(x.x), - atanh(x.y)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec3 atanh -( - detail::tvec3 const & x -) -{ - return detail::tvec3( - atanh(x.x), - atanh(x.y), - atanh(x.z)); -} - -template -GLM_FUNC_QUALIFIER detail::tvec4 atanh -( - detail::tvec4 const & x -) -{ - return detail::tvec4( - atanh(x.x), - atanh(x.y), - atanh(x.z), - atanh(x.w)); -} + VECTORIZE_VEC(atanh) }//namespace glm diff --git a/glm/core/func_vector_relational.hpp b/glm/core/func_vector_relational.hpp index a3cce581..1da814b8 100644 --- a/glm/core/func_vector_relational.hpp +++ b/glm/core/func_vector_relational.hpp @@ -48,65 +48,83 @@ namespace glm /// @addtogroup core_func_vector_relational /// @{ - //! Returns the component-wise comparison result of x < y. - //! + /// Returns the component-wise comparison result of x < y. + /// + /// @tparam vecType Floating-point or integer vector types. + /// /// @see - GLSL lessThan man page /// @see - GLSL 4.20.8 specification, section 8.7 - //template class vecType> - //GLM_FUNC_QUALIFIER typename vecType::bool_type lessThan(vecType const & x, vecType const & y); + template + GLM_FUNC_QUALIFIER typename vecType::bool_type lessThan(vecType const & x, vecType const & y); - //! Returns the component-wise comparison of result x <= y. - //! + /// Returns the component-wise comparison of result x <= y. + /// + /// @tparam vecType Floating-point or integer vector types. + /// /// @see - GLSL lessThanEqual man page /// @see - GLSL 4.20.8 specification, section 8.7 template class vecType> GLM_FUNC_QUALIFIER typename vecType::bool_type lessThanEqual(vecType const & x, vecType const & y); - //! Returns the component-wise comparison of result x > y. - //! + /// Returns the component-wise comparison of result x > y. + /// + /// @tparam vecType Floating-point or integer vector types. + /// /// @see - GLSL greaterThan man page /// @see - GLSL 4.20.8 specification, section 8.7 template class vecType> GLM_FUNC_QUALIFIER typename vecType::bool_type greaterThan(vecType const & x, vecType const & y); - //! Returns the component-wise comparison of result x >= y. - //! + /// Returns the component-wise comparison of result x >= y. + /// + /// @tparam vecType Floating-point or integer vector types. + /// /// @see - GLSL greaterThanEqual man page /// @see - GLSL 4.20.8 specification, section 8.7 template class vecType> typename vecType::bool_type greaterThanEqual(vecType const & x, vecType const & y); - //! Returns the component-wise comparison of result x == y. - //! + /// Returns the component-wise comparison of result x == y. + /// + /// @tparam vecType Floating-point, integer or boolean vector types. + /// /// @see - GLSL equal man page /// @see - GLSL 4.20.8 specification, section 8.7 - //template class vecType> - //GLM_FUNC_QUALIFIER typename vecType::bool_type equal(vecType const & x, vecType const & y); + template class vecType> + GLM_FUNC_QUALIFIER typename vecType::bool_type equal(vecType const & x, vecType const & y); - //! Returns the component-wise comparison of result x != y. - //! + /// Returns the component-wise comparison of result x != y. + /// + /// @tparam vecType Floating-point, integer or boolean vector types. + /// /// @see - GLSL notEqual man page /// @see - GLSL 4.20.8 specification, section 8.7 template class vecType> typename vecType::bool_type notEqual(vecType const & x, vecType const & y); - //! Returns true if any component of x is true. - //! + /// Returns true if any component of x is true. + /// + /// @tparam vecType Boolean vector types. + /// /// @see - GLSL any man page /// @see - GLSL 4.20.8 specification, section 8.7 template