Browse Source

Math: fix tweakable Angle parsers to compile with negative literals.

The result of e.g. -15.0_degf is not Deg, but rather
Math::Unit<Math::Deg, Float>, and those didn't have a corresponding
TweakableParser defined. Now they do.

Funny how I didn't run into this until now.
pull/605/head
Vladimír Vondruš 4 years ago
parent
commit
9d22a03c92
  1. 2
      doc/changelog.dox
  2. 20
      src/Magnum/Math/Angle.h
  3. 28
      src/Magnum/Math/Test/AngleTest.cpp

2
doc/changelog.dox

@ -737,6 +737,8 @@ See also:
off-by-one on desktop GLSL < 330.
- Fixed assertions related to OpenGL driver workarounds when the proprietary
AMDGPU PRO drivers are used on Linux
- Fixed @relativeref{Corrade,Utility::Tweakable} parsers to compile with
negative @ref Math::Angle literals such as @cpp _(-15.0_degf) @ce
- Fixed an assertion when using @ref MeshTools::removeDuplicates() on an
interleaved @ref Trade::MeshData that included padding at the beginning or
end of each vertex

20
src/Magnum/Math/Angle.h

@ -270,6 +270,11 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Deg<Magnum::Float>
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Float>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Needed to parse e.g. -1.0_degf, which is the base class type */
template<> struct TweakableParser<Magnum::Math::Unit<Magnum::Math::Deg, Magnum::Float>>: TweakableParser<Magnum::Math::Deg<Magnum::Float>> {};
#endif
/**
@tweakableliteral{Magnum::Math::Deg}
@ -283,6 +288,11 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Deg<Magnum::Double
static std::pair<TweakableState, Magnum::Math::Deg<Magnum::Double>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Needed to parse e.g. -1.0_deg, which is the base class type */
template<> struct TweakableParser<Magnum::Math::Unit<Magnum::Math::Deg, Magnum::Double>>: TweakableParser<Magnum::Math::Deg<Magnum::Double>> {};
#endif
/**
@tweakableliteral{Magnum::Math::Rad}
@ -296,6 +306,11 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Rad<Magnum::Float>
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Float>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Needed to parse e.g. -1.0_radf, which is the base class type */
template<> struct TweakableParser<Magnum::Math::Unit<Magnum::Math::Rad, Magnum::Float>>: TweakableParser<Magnum::Math::Rad<Magnum::Float>> {};
#endif
/**
@tweakableliteral{Magnum::Math::Rad}
@ -308,6 +323,11 @@ template<> struct MAGNUM_EXPORT TweakableParser<Magnum::Math::Rad<Magnum::Double
/** @brief Parse the value */
static std::pair<TweakableState, Magnum::Math::Rad<Magnum::Double>> parse(Containers::StringView value);
};
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Needed to parse e.g. -1.0_rad, which is the base class type */
template<> struct TweakableParser<Magnum::Math::Unit<Magnum::Math::Rad, Magnum::Double>>: TweakableParser<Magnum::Math::Rad<Magnum::Double>> {};
#endif
#endif
}}

28
src/Magnum/Math/Test/AngleTest.cpp

@ -102,18 +102,34 @@ template<> struct TweakableTraits<Deg> {
static const char* name() { return "Deg"; }
static const char* literal() { return "degf"; }
};
template<> struct TweakableTraits<Unit<Math::Deg, Float>> {
static const char* name() { return "Unit<Deg, Float>"; }
static const char* literal() { return "degf"; }
};
template<> struct TweakableTraits<Degd> {
static const char* name() { return "Degd"; }
static const char* literal() { return "deg"; }
};
template<> struct TweakableTraits<Unit<Math::Deg, Double>> {
static const char* name() { return "Unit<Deg, Double>"; }
static const char* literal() { return "deg"; }
};
template<> struct TweakableTraits<Rad> {
static const char* name() { return "Rad"; }
static const char* literal() { return "radf"; }
};
template<> struct TweakableTraits<Unit<Math::Rad, Float>> {
static const char* name() { return "Unit<Rad, Float>"; }
static const char* literal() { return "radf"; }
};
template<> struct TweakableTraits<Radd> {
static const char* name() { return "Radd"; }
static const char* literal() { return "rad"; }
};
template<> struct TweakableTraits<Unit<Math::Rad, Double>> {
static const char* name() { return "Unit<Rad, Double>"; }
static const char* literal() { return "rad"; }
};
#endif
AngleTest::AngleTest() {
@ -134,16 +150,24 @@ AngleTest::AngleTest() {
#if defined(DOXYGEN_GENERATING_OUTPUT) || defined(CORRADE_TARGET_UNIX) || (defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)) || defined(CORRADE_TARGET_EMSCRIPTEN)
addInstancedTests<AngleTest>({
&AngleTest::tweakable<Deg>,
&AngleTest::tweakable<Unit<Math::Deg, Float>>,
&AngleTest::tweakable<Degd>,
&AngleTest::tweakable<Unit<Math::Deg, Double>>,
&AngleTest::tweakable<Rad>,
&AngleTest::tweakable<Radd>},
&AngleTest::tweakable<Unit<Math::Rad, Float>>,
&AngleTest::tweakable<Radd>,
&AngleTest::tweakable<Unit<Math::Rad, Double>>},
Corrade::Containers::arraySize(TweakableData));
addInstancedTests<AngleTest>({
&AngleTest::tweakableError<Deg>,
&AngleTest::tweakableError<Unit<Math::Deg, Float>>,
&AngleTest::tweakableError<Degd>,
&AngleTest::tweakableError<Unit<Math::Deg, Double>>,
&AngleTest::tweakableError<Rad>,
&AngleTest::tweakableError<Radd>},
&AngleTest::tweakableError<Unit<Math::Rad, Float>>,
&AngleTest::tweakableError<Radd>,
&AngleTest::tweakableError<Unit<Math::Rad, Double>>},
Corrade::Containers::arraySize(TweakableErrorData));
#endif
}

Loading…
Cancel
Save