Browse Source

Math: minor coding style cleanup.

simd
Vladimír Vondruš 8 years ago
parent
commit
f5e30bb5d3
  1. 6
      doc/snippets/MagnumMath.cpp
  2. 4
      src/Magnum/Math/Bezier.h
  3. 5
      src/Magnum/Math/BoolVector.h
  4. 5
      src/Magnum/Math/Color.h
  5. 3
      src/Magnum/Math/Complex.h
  6. 2
      src/Magnum/Math/CubicHermite.h
  7. 3
      src/Magnum/Math/Dual.h
  8. 3
      src/Magnum/Math/DualComplex.h
  9. 3
      src/Magnum/Math/DualQuaternion.h
  10. 7
      src/Magnum/Math/Half.h
  11. 2
      src/Magnum/Math/Math.h
  12. 2
      src/Magnum/Math/Matrix.h
  13. 3
      src/Magnum/Math/Matrix3.h
  14. 3
      src/Magnum/Math/Matrix4.h
  15. 3
      src/Magnum/Math/Quaternion.h
  16. 2
      src/Magnum/Math/Range.h
  17. 5
      src/Magnum/Math/RectangularMatrix.h
  18. 14
      src/Magnum/Math/StrictWeakOrdering.h
  19. 22
      src/Magnum/Math/Test/StrictWeakOrderingTest.cpp
  20. 5
      src/Magnum/Math/Vector.h
  21. 2
      src/Magnum/Math/Vector2.h
  22. 2
      src/Magnum/Math/Vector3.h
  23. 2
      src/Magnum/Math/Vector4.h

6
doc/snippets/MagnumMath.cpp

@ -23,6 +23,9 @@
DEALINGS IN THE SOFTWARE.
*/
#include <map>
#include <set>
#include "Magnum/Magnum.h"
#include "Magnum/Math/Color.h"
#include "Magnum/Math/Bezier.h"
@ -34,9 +37,6 @@
#include "Magnum/Math/Algorithms/GramSchmidt.h"
#include "Magnum/Math/StrictWeakOrdering.h"
#include <map>
#include <set>
using namespace Magnum;
using namespace Magnum::Math::Literals;

4
src/Magnum/Math/Bezier.h

@ -318,6 +318,7 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
#endif
namespace Implementation {
template<UnsignedInt order, UnsignedInt dimensions, class T> struct StrictWeakOrdering<Bezier<order, dimensions, T>> {
bool operator()(const Bezier<order, dimensions, T>& a, const Bezier<order, dimensions, T>& b) const {
StrictWeakOrdering<Vector<dimensions, T>> o;
@ -328,9 +329,10 @@ template<UnsignedInt order, UnsignedInt dimensions, class T> struct StrictWeakOr
return false;
}
return false; // a and b are equivalent
return false; /* a and b are equivalent */
}
};
}
}}

5
src/Magnum/Math/BoolVector.h

@ -304,8 +304,8 @@ template<std::size_t size> inline BoolVector<size> BoolVector<size>::operator~()
return out;
}
/* Specialization of helper types*/
namespace Implementation {
template<std::size_t size> struct StrictWeakOrdering<BoolVector<size>> {
bool operator()(const BoolVector<size>& a, const BoolVector<size>& b) const {
auto ad = a.data();
@ -317,12 +317,13 @@ template<std::size_t size> struct StrictWeakOrdering<BoolVector<size>> {
return false;
}
// mask last element with to hide unused bits
/* Mask last element with to hide padding bits */
constexpr UnsignedByte mask = UnsignedByte(0xFF) >> (BoolVector<size>::DataSize * 8 - size);
constexpr std::size_t i = BoolVector<size>::DataSize - 1;
return (ad[i] & mask) < (bd[i] & mask);
}
};
}
}}

5
src/Magnum/Math/Color.h

@ -1273,9 +1273,8 @@ namespace Implementation {
template<class T> struct TypeForSize<4, Color3<T>> { typedef Color4<T> Type; };
template<class T> struct TypeForSize<4, Color4<T>> { typedef Color4<T> Type; };
template<class T> struct StrictWeakOrdering<Color3<T>> : public StrictWeakOrdering<Vector<3, T>> {};
template<class T> struct StrictWeakOrdering<Color4<T>> : public StrictWeakOrdering<Vector<4, T>> {};
template<class T> struct StrictWeakOrdering<Color3<T>>: StrictWeakOrdering<Vector<3, T>> {};
template<class T> struct StrictWeakOrdering<Color4<T>>: StrictWeakOrdering<Vector<4, T>> {};
}
}}

3
src/Magnum/Math/Complex.h

@ -620,8 +620,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const Complex<Double>&);
#endif
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<Complex<T>> {
bool operator()(const Complex<T>& a, const Complex<T>& b) const {
if(a.real() < b.real())
@ -632,6 +632,7 @@ template<class T> struct StrictWeakOrdering<Complex<T>> {
return a.imaginary() < b.imaginary();
}
};
}
}}

2
src/Magnum/Math/CubicHermite.h

@ -539,6 +539,7 @@ template<class T> inline bool CubicHermite<T>::operator==(const CubicHermite<T>&
}
namespace Implementation {
template<class T> struct StrictWeakOrdering<CubicHermite<T>> {
bool operator()(const CubicHermite<T>& a, const CubicHermite<T>& b) const {
StrictWeakOrdering<T> o;
@ -553,6 +554,7 @@ template<class T> struct StrictWeakOrdering<CubicHermite<T>> {
return o(a.outTangent(), b.outTangent());
}
};
}
}}

3
src/Magnum/Math/Dual.h

@ -395,8 +395,8 @@ template<class T> std::pair<Dual<T>, Dual<T>> sincos(const Dual<Unit<Rad, T>>& a
template<class T> std::pair<Dual<T>, Dual<T>> sincos(const Dual<Unit<Deg, T>>& angle) { return sincos(Dual<Rad<T>>(angle)); }
#endif
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<Dual<T>> {
bool operator()(const Dual<T>& a, const Dual<T>& b) const {
StrictWeakOrdering<T> o;
@ -408,6 +408,7 @@ template<class T> struct StrictWeakOrdering<Dual<T>> {
return o(a.dual(), b.dual());
}
};
}
}}

3
src/Magnum/Math/DualComplex.h

@ -385,9 +385,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const DualComplex<Double>&);
#endif
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<DualComplex<T>>: public StrictWeakOrdering<Dual<Complex<T>>> {};
template<class T> struct StrictWeakOrdering<DualComplex<T>>: StrictWeakOrdering<Dual<Complex<T>>> {};
}
}}

3
src/Magnum/Math/DualQuaternion.h

@ -545,9 +545,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const DualQuaternion<Double>&);
#endif
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<DualQuaternion<T>>: public StrictWeakOrdering<Dual<Quaternion<T>>> {};
template<class T> struct StrictWeakOrdering<DualQuaternion<T>>: StrictWeakOrdering<Dual<Quaternion<T>>> {};
}
}}

7
src/Magnum/Math/Half.h

@ -162,11 +162,14 @@ Prints the value with 4 significant digits.
MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value);
namespace Implementation {
template <> struct StrictWeakOrdering<Half> {
template<> struct StrictWeakOrdering<Half> {
bool operator()(Half a, Half b) const {
return a.data() < b.data(); // Not mathematically equivalent to <, but does order
/* Not mathematically equivalent to <, but does order */
return a.data() < b.data();
}
};
}
}}

2
src/Magnum/Math/Math.h

@ -103,7 +103,7 @@ template<class> class Range2D;
template<class> class Range3D;
namespace Implementation {
template <class T> struct StrictWeakOrdering;
template<class> struct StrictWeakOrdering;
}
#endif

2
src/Magnum/Math/Matrix.h

@ -321,7 +321,7 @@ template<class T> struct MatrixDeterminant<1, T> {
}
};
template<std::size_t size, class T> struct StrictWeakOrdering<Matrix<size, T>>: public StrictWeakOrdering<RectangularMatrix<size, size, T>> {};
template<std::size_t size, class T> struct StrictWeakOrdering<Matrix<size, T>>: StrictWeakOrdering<RectangularMatrix<size, size, T>> {};
}
#endif

3
src/Magnum/Math/Matrix3.h

@ -692,9 +692,8 @@ template<class T> inline Matrix3<T> Matrix3<T>::invertedRigid() const {
return from(inverseRotation, inverseRotation*-translation());
}
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<Matrix3<T>>: public StrictWeakOrdering<RectangularMatrix<3, 3, T>> {};
template<class T> struct StrictWeakOrdering<Matrix3<T>>: StrictWeakOrdering<RectangularMatrix<3, 3, T>> {};
}
}}

3
src/Magnum/Math/Matrix4.h

@ -1024,9 +1024,8 @@ template<class T> Matrix4<T> Matrix4<T>::invertedRigid() const {
return from(inverseRotation, inverseRotation*-translation());
}
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<Matrix4<T>>: public StrictWeakOrdering<RectangularMatrix<4, 4, T>> {};
template<class T> struct StrictWeakOrdering<Matrix4<T>>: StrictWeakOrdering<RectangularMatrix<4, 4, T>> {};
}
}}

3
src/Magnum/Math/Quaternion.h

@ -739,8 +739,8 @@ template<class T> inline Vector3<T> Quaternion<T>::transformVectorNormalized(con
return vector + _scalar*t + Math::cross(_vector, t);
}
/* Specialization of helper types*/
namespace Implementation {
template<class T> struct StrictWeakOrdering<Quaternion<T>> {
bool operator()(const Quaternion<T>& a, const Quaternion<T>& b) const {
StrictWeakOrdering<Vector3<T>> o;
@ -752,6 +752,7 @@ template<class T> struct StrictWeakOrdering<Quaternion<T>> {
return a.scalar() < b.scalar();
}
};
}
}}

2
src/Magnum/Math/Range.h

@ -760,6 +760,7 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
#endif
namespace Implementation {
template<UnsignedInt dimensions, class T> struct StrictWeakOrdering<Range<dimensions, T>> {
bool operator()(const Range<dimensions, T>& a, const Range<dimensions, T>& b) const {
StrictWeakOrdering<typename Range<dimensions, T>::VectorType> o;
@ -770,6 +771,7 @@ template<UnsignedInt dimensions, class T> struct StrictWeakOrdering<Range<dimens
return o(a.max(), b.max());
}
};
}
}}

5
src/Magnum/Math/RectangularMatrix.h

@ -760,8 +760,8 @@ template<std::size_t cols, std::size_t rows, class T> template<std::size_t ...se
}
#endif
/* Specialization of helper types*/
namespace Implementation {
template<std::size_t cols, std::size_t rows, class T> struct StrictWeakOrdering<RectangularMatrix<cols, rows, T>> {
bool operator()(const RectangularMatrix<cols, rows, T>& a, const RectangularMatrix<cols, rows, T>& b) const {
StrictWeakOrdering<Vector<rows, T>> o;
@ -772,9 +772,10 @@ template<std::size_t cols, std::size_t rows, class T> struct StrictWeakOrdering<
return false;
}
return false; // a and b are equivalent
return false; /* a and b are equivalent */
}
};
}
}}

14
src/Magnum/Math/StrictWeakOrdering.h

@ -32,11 +32,13 @@
namespace Magnum { namespace Math {
namespace Implementation {
template <class T> struct StrictWeakOrdering { // Specialized for supported types
template<class T> struct StrictWeakOrdering { /* Specialized for supported types */
bool operator()(const T& a, const T& b) const {
return a < b;
}
};
}
/**
@ -63,11 +65,11 @@ struct StrictWeakOrdering {
*
* For scalar types this is equivalent to operator <
*/
template <class T> bool operator()(const T& a, const T& b) const {
// Instantiate a specialization of Implementation::StrictWeakOrdering
// If users want to enable this for their own types, they must create
// a specialization of Magnum::Math::Implementation::StrictWeakOrdering
// for them.
template<class T> bool operator()(const T& a, const T& b) const {
/* Instantiate a specialization of Implementation::StrictWeakOrdering.
If users want to enable this for their own types, they must create
a specialization of Magnum::Math::Implementation::StrictWeakOrdering
for them. */
Implementation::StrictWeakOrdering<T> o;
return o(a, b);
}

22
src/Magnum/Math/Test/StrictWeakOrderingTest.cpp

@ -26,26 +26,19 @@
#include <map>
#include <set>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/Configuration.h>
#include "Magnum/Math/Vector2.h"
#include "Magnum/Math/StrictWeakOrdering.h"
namespace std
{
template <> struct less<Magnum::Math::Vector2<float>>
: public Magnum::Math::Implementation::StrictWeakOrdering<Magnum::Math::Vector2<float>>
{};
namespace std {
template<> struct less<Magnum::Math::Vector2<float>>: public Magnum::Math::Implementation::StrictWeakOrdering<Magnum::Math::Vector2<float>> {};
}
namespace Magnum {
namespace Math {
namespace Test {
namespace Magnum { namespace Math { namespace Test {
using Vector2 = Magnum::Math::Vector2<float>;
struct StrictWeakOrderingTest : Corrade::TestSuite::Tester {
struct StrictWeakOrderingTest: Corrade::TestSuite::Tester {
explicit StrictWeakOrderingTest();
void base();
@ -57,11 +50,10 @@ struct StrictWeakOrderingTest : Corrade::TestSuite::Tester {
void map();
void mapShort();
void mapLess();
};
StrictWeakOrderingTest::StrictWeakOrderingTest() {
addTests({ &StrictWeakOrderingTest::base,
addTests({&StrictWeakOrderingTest::base,
&StrictWeakOrderingTest::set,
&StrictWeakOrderingTest::setShort,
@ -171,8 +163,6 @@ void StrictWeakOrderingTest::mapLess() {
CORRADE_VERIFY(m.begin()->second == 99);
}
}
}
}
}}}
CORRADE_TEST_MAIN(Magnum::Math::Test::StrictWeakOrderingTest)

5
src/Magnum/Math/Vector.h

@ -1413,8 +1413,8 @@ template<std::size_t size, class T> inline std::pair<T, T> Vector<size, T>::minm
return {min, max};
}
/* Specialization of helper types*/
namespace Implementation {
template<std::size_t size, class T> struct StrictWeakOrdering<Vector<size, T>> {
bool operator()(const Vector<size, T>& a, const Vector<size, T>& b) const {
for(std::size_t i = 0; i < size; ++i) {
@ -1424,9 +1424,10 @@ template<std::size_t size, class T> struct StrictWeakOrdering<Vector<size, T>> {
return false;
}
return false; // a and b are equivalent
return false; /* a and b are equivalent */
}
};
}
}}

2
src/Magnum/Math/Vector2.h

@ -191,7 +191,7 @@ namespace Implementation {
template<std::size_t, class> struct TypeForSize;
template<class T> struct TypeForSize<2, T> { typedef Math::Vector2<typename T::Type> Type; };
template<class T> struct StrictWeakOrdering<Vector2<T>>: public StrictWeakOrdering<Vector<2, T>> {};
template<class T> struct StrictWeakOrdering<Vector2<T>>: StrictWeakOrdering<Vector<2, T>> {};
}
}}

2
src/Magnum/Math/Vector3.h

@ -246,7 +246,7 @@ MAGNUM_VECTORn_OPERATOR_IMPLEMENTATION(3, Vector3)
namespace Implementation {
template<class T> struct TypeForSize<3, T> { typedef Math::Vector3<typename T::Type> Type; };
template<class T> struct StrictWeakOrdering<Vector3<T>>: public StrictWeakOrdering<Vector<3, T>> {};
template<class T> struct StrictWeakOrdering<Vector3<T>>: StrictWeakOrdering<Vector<3, T>> {};
}
}}

2
src/Magnum/Math/Vector4.h

@ -255,7 +255,7 @@ MAGNUM_VECTORn_OPERATOR_IMPLEMENTATION(4, Vector4)
namespace Implementation {
template<class T> struct TypeForSize<4, T> { typedef Math::Vector4<typename T::Type> Type; };
template<class T> struct StrictWeakOrdering<Vector4<T>>: public StrictWeakOrdering<Vector<4, T>> {};
template<class T> struct StrictWeakOrdering<Vector4<T>>: StrictWeakOrdering<Vector<4, T>> {};
}
}}

Loading…
Cancel
Save