From d9da018af7a8c2cb86c0b0af4e3f9127eb827546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 25 May 2019 00:29:19 +0200 Subject: [PATCH] Math: don't hide the vector/scalar overloads from docs. People should be able to see the IsScalar requirements and how the vector types are passed around as well. --- src/Magnum/Math/Dual.h | 2 +- src/Magnum/Math/Functions.h | 96 +++++++++++++------------------------ 2 files changed, 35 insertions(+), 63 deletions(-) diff --git a/src/Magnum/Math/Dual.h b/src/Magnum/Math/Dual.h index 6fd067acc..f95f6aabb 100644 --- a/src/Magnum/Math/Dual.h +++ b/src/Magnum/Math/Dual.h @@ -363,7 +363,7 @@ template Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& d @f[ \sqrt{\hat a} = \sqrt{a_0} + \epsilon \frac{a_\epsilon}{2 \sqrt{a_0}} @f] -@see @ref sqrt(const T&) +@see @ref sqrt(T) */ template Dual sqrt(const Dual& dual) { T sqrt0 = std::sqrt(dual.real()); diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index 45731f25b..3330f308c 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -219,20 +219,18 @@ Returns integral power of base to the exponent. Works only on types that satisfy @ref IsUnitless. @see @ref pow(T, T) */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template constexpr T pow(T base); -#else template constexpr typename std::enable_if::value, T>::type pow(T base) { static_assert(IsUnitless::value, "expected an unitless type"); return Implementation::Pow::pow(base); } + +/** @overload */ template inline Vector pow(const Vector& base) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::pow(base[i]); return out; } -#endif /** @brief Power @@ -241,20 +239,18 @@ Returns power of @p base to the @p exponent. Works only on types that satisfy @ref IsUnitless. @see @ref pow(T), @ref exp() */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template T pow(T base, T exponent); -#else template inline typename std::enable_if::value, T>::type pow(T base, T exponent) { static_assert(IsUnitless::value, "expected an unitless type"); return std::pow(base, exponent); } + +/** @overload */ template inline Vector pow(const Vector& base, T exponent) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::pow(base[i], exponent); return out; } -#endif /** @brief Minimum @@ -263,17 +259,16 @@ template inline Vector pow(const Vector), @ref Vector::min() */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T min(T value, T min); -#else -/* min() for scalars defined in Vector.h */ +/* defined in Vector.h */ +template constexpr typename std::enable_if::value, T>::type min(T value, T min); + +/** @overload */ template inline Vector min(const Vector& value, const Vector& min) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::min(value[i], min[i]); return out; } -#endif /** @overload */ template inline Vector min(const Vector& value, T min) { @@ -290,17 +285,16 @@ template inline Vector min(const Vector), @ref Vector::max() */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T max(T value, T max); -#else -/* max() for scalars defined in Vector.h */ +/* defined in Vector.h */ +template constexpr typename std::enable_if::value, T>::type max(T a, T b); + +/** @overload */ template Vector max(const Vector& value, const Vector& max) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::max(value[i], max[i]); return out; } -#endif /** @overload */ template inline Vector max(const Vector& value, T max) { @@ -317,12 +311,11 @@ template inline Vector max(const Vector), @ref Vector::minmax(), @ref Range::Range(const std::pair&) */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline std::pair minmax(const T& a, const T& b); -#else template inline typename std::enable_if::value, std::pair>::type minmax(T a, T b) { return a < b ? std::make_pair(a, b) : std::make_pair(b, a); } + +/** @overload */ template inline std::pair, Vector> minmax(const Vector& a, const Vector& b) { using std::swap; std::pair, Vector> out{a, b}; @@ -330,7 +323,6 @@ template inline std::pair, Vector out.second[i]) swap(out.first[i], out.second[i]); return out; } -#endif /** @brief Clamp value @@ -343,19 +335,17 @@ set to @p max. Equivalent to: NaNs passed in @p value parameter are propagated. @see @ref min(), @ref max() */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T clamp(const T& value, const T& min, const T& max); -#else template inline typename std::enable_if::value, T>::type clamp(T value, T min, T max) { return Math::min(Math::max(value, min), max); } + +/** @overload */ template inline Vector clamp(const Vector& value, const Vector& min, const Vector& max) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::clamp(value[i], min[i], max[i]); return out; } -#endif /** @overload */ template inline Vector clamp(const Vector& value, T min, T max) { @@ -370,81 +360,71 @@ template inline Vector clamp(const Vector 0, `0` if @p x = 0 and `-1` if @p x < 0. */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T sign(const T scalar); -#else template inline typename std::enable_if::value, T>::type sign(const T& scalar) { if(scalar > T(0)) return T(1); if(scalar < T(0)) return T(-1); return T(0); } + +/** @overload */ template inline Vector sign(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::sign(a[i]); return out; } -#endif /** @brief Absolute value */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T abs(const T& a); -#else template inline typename std::enable_if::value, T>::type abs(T a) { return T(std::abs(UnderlyingTypeOf(a))); } + +/** @overload */ template inline Vector abs(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::abs(a[i]); return out; } -#endif /** @brief Nearest not larger integer */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T floor(const T& a); -#else template inline typename std::enable_if::value, T>::type floor(T a) { return T(std::floor(UnderlyingTypeOf(a))); } + +/** @overload */ template inline Vector floor(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::floor(a[i]); return out; } -#endif /** @brief Round value to nearest integer */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T round(const T& a); -#else template inline typename std::enable_if::value, T>::type round(T a) { return T(std::round(UnderlyingTypeOf(a))); } + +/** @overload */ template inline Vector round(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::round(a[i]); return out; } -#endif /** @brief Nearest not smaller integer */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T ceil(const T& a); -#else template inline typename std::enable_if::value, T>::type ceil(T a) { return T(std::ceil(UnderlyingTypeOf(a))); } + +/** @overload */ template inline Vector ceil(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::ceil(a[i]); return out; } -#endif /** @brief Square root @@ -452,20 +432,18 @@ template inline Vector ceil(const Vector&) */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T sqrt(const T& a); -#else template inline typename std::enable_if::value, T>::type sqrt(T a) { static_assert(IsUnitless::value, "expecting an unitless type"); return std::sqrt(a); } + +/** @overload */ template inline Vector sqrt(const Vector& a) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) out[i] = Math::sqrt(a[i]); return out; } -#endif /** @brief Inverse square root @@ -474,17 +452,15 @@ Works only on types that satisfy @ref IsUnitless. @see @ref sqrt(), @ref Vector::lengthInverted() @m_keyword{inversesqrt(),GLSL inversesqrt(),} */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T sqrtInverted(const T& a); -#else template inline typename std::enable_if::value, T>::type sqrtInverted(T a) { static_assert(IsUnitless::value, "expecting an unitless type"); return T(1)/std::sqrt(a); } + +/** @overload */ template inline Vector sqrtInverted(const Vector& a) { return Vector(T(1))/Math::sqrt(a); } -#endif /** @brief Linear interpolation of two values @@ -557,16 +533,14 @@ Returns interpolation phase *t*: @f[ @f] @see @ref lerp(), @ref select() */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T lerpInverted(const T& a, const T& b, const T& lerp); -#else template inline UnderlyingTypeOf::value, T>::type> lerpInverted(T a, T b, T lerp) { return (lerp - a)/(b - a); } + +/** @overload */ template inline Vector> lerpInverted(const Vector& a, const Vector& b, const Vector& lerp) { return (lerp - a)/(b - a); } -#endif /** @brief Constant interpolation of two values @@ -594,9 +568,6 @@ Computes and returns @f$ ab + c @f$. On some architectures might be faster than doing the computation manually. Works only on types that satisfy @ref IsUnitless. */ -#ifdef DOXYGEN_GENERATING_OUTPUT -template inline T fma(const T& a, const T& b, const T& c); -#else template inline typename std::enable_if::value, T>::type fma(T a, T b, T c) { static_assert(IsUnitless::value, "expecting an unitless type"); /* On Emscripten it works with -O2 but not with -O1 (function not defined). @@ -607,11 +578,12 @@ template inline typename std::enable_if::value, T>::type fm return a*b + c; #endif } + +/** @overload */ template inline Vector fma(const Vector& a, const Vector& b, const Vector& c) { static_assert(IsUnitless::value, "expecting an unitless type"); return a*b + c; } -#endif /*@}*/