Browse Source

Math: no Vector::operator-() and Vector2::perpendicular() on unsigned.

Reported by MSVC on Magnum Python Bindings.
pull/326/merge
Vladimír Vondruš 7 years ago
parent
commit
bc88faa215
  1. 2
      doc/changelog.dox
  2. 20
      src/Magnum/Math/Vector.h
  3. 10
      src/Magnum/Math/Vector2.h

2
doc/changelog.dox

@ -385,6 +385,8 @@ See also:
- @ref Math::sincos() now uses the `__builtin_sincos` intrinsic on GCC, - @ref Math::sincos() now uses the `__builtin_sincos` intrinsic on GCC,
making it potentially faster in case the optimizer doesn't figure out the making it potentially faster in case the optimizer doesn't figure out the
same same
- @ref Math::Vector::operator-() and @ref Math::Vector2::perpendicular() are
now enabled only for signed types to prevent accidents
@subsubsection changelog-latest-changes-meshtools MeshTools library @subsubsection changelog-latest-changes-meshtools MeshTools library

20
src/Magnum/Math/Vector.h

@ -313,12 +313,17 @@ template<std::size_t size, class T> class Vector {
/** /**
* @brief Negated vector * @brief Negated vector
* *
* @f[ * Enabled only for signed types. @f[
* \boldsymbol b_i = -\boldsymbol a_i * \boldsymbol b_i = -\boldsymbol a_i
* @f] * @f]
* @see @ref Vector2::perpendicular() * @see @ref Vector2::perpendicular()
*/ */
Vector<size, T> operator-() const; #ifdef DOXYGEN_GENERATING_OUTPUT
Vector<size, T>
#else
template<class U = T> typename std::enable_if<std::is_signed<U>::value, Vector<size, T>>::type
#endif
operator-() const;
/** /**
* @brief Add and assign a vector * @brief Add and assign a vector
@ -1224,7 +1229,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
return Math::Vector<size, T>::pad(a, value); \ return Math::Vector<size, T>::pad(a, value); \
} \ } \
\ \
Type<T> operator-() const { \ template<class U = T> typename std::enable_if<std::is_signed<U>::value, Type<T>>::type \
operator-() const { \
return Math::Vector<size, T>::operator-(); \ return Math::Vector<size, T>::operator-(); \
} \ } \
Type<T>& operator+=(const Math::Vector<size, T>& other) { \ Type<T>& operator+=(const Math::Vector<size, T>& other) { \
@ -1420,7 +1426,13 @@ template<std::size_t size, class T> inline BoolVector<size> Vector<size, T>::ope
return out; return out;
} }
template<std::size_t size, class T> inline Vector<size, T> Vector<size, T>::operator-() const { template<std::size_t size, class T>
#ifdef DOXYGEN_GENERATING_OUTPUT
inline Vector<size, T>
#else
template<class U> inline typename std::enable_if<std::is_signed<U>::value, Vector<size, T>>::type
#endif
Vector<size, T>::operator-() const {
Vector<size, T> out; Vector<size, T> out;
for(std::size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)

10
src/Magnum/Math/Vector2.h

@ -149,14 +149,20 @@ template<class T> class Vector2: public Vector<2, T> {
/** /**
* @brief Perpendicular vector * @brief Perpendicular vector
* *
* Returns vector rotated 90° counterclockwise. @f[ * Returns vector rotated 90° counterclockwise. Enabled only for signed
* types. @f[
* \boldsymbol v_\bot = \begin{pmatrix} -v_y \\ v_x \end{pmatrix} * \boldsymbol v_\bot = \begin{pmatrix} -v_y \\ v_x \end{pmatrix}
* @f] * @f]
* @see @ref cross(), * @see @ref cross(),
* @ref dot(const Vector<size, T>&, const Vector<size, T>&), * @ref dot(const Vector<size, T>&, const Vector<size, T>&),
* @ref operator-() const * @ref operator-() const
*/ */
Vector2<T> perpendicular() const { return {-y(), x()}; } #ifdef DOXYGEN_GENERATING_OUTPUT
Vector2<T>
#else
template<class U = T> typename std::enable_if<std::is_signed<U>::value, Vector2<T>>::type
#endif
perpendicular() const { return {-y(), x()}; }
/** /**
* @brief Aspect ratio * @brief Aspect ratio

Loading…
Cancel
Save