Browse Source

Math: fixed debug output operator for Deg and Rad.

It was currently not possible to print this, as the resulting type is
neither Deg nor Rad:

    Debug() << 23.0_degf - 5.0_degf;
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
4ad85dceca
  1. 8
      src/Math/Angle.cpp
  2. 12
      src/Math/Angle.h
  3. 16
      src/Math/Test/AngleTest.cpp

8
src/Math/Angle.cpp

@ -18,11 +18,11 @@
namespace Magnum { namespace Math {
#ifndef DOXYGEN_GENERATING_OUTPUT
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad<float>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg<float>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit<Rad, float>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit<Deg, float>&);
#ifndef MAGNUM_TARGET_GLES
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Rad<double>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Deg<double>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit<Rad, double>&);
template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug, const Unit<Deg, double>&);
#endif
#endif

12
src/Math/Angle.h

@ -219,7 +219,7 @@ template<class T> inline constexpr Deg<T>::Deg(Unit<Rad, T> value): Unit<Deg, T>
template<class T> inline constexpr Rad<T>::Rad(Unit<Deg, T> value): Unit<Rad, T>(T(value)*Math::Constants<T>::pi()/T(180)) {}
/** @debugoperator{Magnum::Math::Rad} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Rad<T>& value) {
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Unit<Rad, T>& value) {
debug << "Rad(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
debug << T(value) << ")";
@ -228,7 +228,7 @@ template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb
}
/** @debugoperator{Magnum::Math::Deg} */
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Deg<T>& value) {
template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Unit<Deg, T>& value) {
debug << "Deg(";
debug.setFlag(Corrade::Utility::Debug::SpaceAfterEachValue, false);
debug << T(value) << ")";
@ -238,11 +238,11 @@ template<class T> Corrade::Utility::Debug operator<<(Corrade::Utility::Debug deb
/* Explicit instantiation for commonly used types */
#ifndef DOXYGEN_GENERATING_OUTPUT
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad<float>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg<float>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit<Rad, float>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit<Deg, float>&);
#ifndef MAGNUM_TARGET_GLES
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Rad<double>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Deg<double>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit<Rad, double>&);
extern template Corrade::Utility::Debug MAGNUM_EXPORT operator<<(Corrade::Utility::Debug, const Unit<Deg, double>&);
#endif
#endif

16
src/Math/Test/AngleTest.cpp

@ -92,22 +92,32 @@ void AngleTest::conversion() {
constexpr Deg a(Rad(1.57079633f));
CORRADE_COMPARE(float(a), 90.0f);
constexpr Rad b(Deg(90.0));
constexpr Rad b(Deg(90.0f));
CORRADE_COMPARE(float(b), 1.57079633f);
}
void AngleTest::debugDeg() {
std::ostringstream o;
Debug(&o) << Deg(90.0);
Debug(&o) << Deg(90.0f);
CORRADE_COMPARE(o.str(), "Deg(90)\n");
/* Verify that this compiles */
o.str({});
Debug(&o) << Deg(56.0f) - Deg(34.0f);
CORRADE_COMPARE(o.str(), "Deg(22)\n");
}
void AngleTest::debugRad() {
std::ostringstream o;
Debug(&o) << Rad(1.5708);
Debug(&o) << Rad(1.5708f);
CORRADE_COMPARE(o.str(), "Rad(1.5708)\n");
/* Verify that this compiles */
o.str({});
Debug(&o) << Rad(1.5708f) - Rad(3.1416f);
CORRADE_COMPARE(o.str(), "Rad(-1.5708)\n");
}
}}}

Loading…
Cancel
Save