diff --git a/doc/changelog.dox b/doc/changelog.dox index e809cbfa8..c682ce24f 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -1644,7 +1644,11 @@ See also: pointer, which was deemed a more useful property. - @ref Math::sign() now always returns a unitless type instead of the input type itself, so it's possible to e.g. extract a sign of an angle - value and multiply other angles with it. + value and multiply other angles with it. In a similar spirit, + @ref Math::select() now enforces the interpolation phase to be a unitless + type. That was the case with @ref Math::lerp() already, where using angles + for `t` didn't even compile, this makes the behavior consistently strict + for both. - @ref MeshTools::primitiveCount() now requires the element count to follow rules defined by a particular primitive to be consistent with requirements of @ref MeshTools::generateIndices() and related APIs. Before it was just diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index ce1dbf13c..46dd7402d 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -598,6 +598,7 @@ A constant interpolation counterpart to @ref lerp(): @f[ Equivalent to calling @cpp Math::lerp(a, b, t >= U(1)) @ce. */ template constexpr T select(const T& a, const T& b, U t) { + static_assert(IsUnitless::value, "expecting an unitless type for the interpolation phase"); return lerp(a, b, t >= U(1)); } diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 7a1108240..f5e9157ca 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -428,16 +428,13 @@ void FunctionsTest::select() { CORRADE_COMPARE(Math::select(a, b, Vector3(0.25f, 1.5f, 1.0f)), Vector3(-1.0f, -2.0f, 11.0f)); /* Wrapped types */ - CORRADE_COMPARE(Math::select(2.0_degf, 5.0_degf, 0.5_degf), 2.0_degf); + CORRADE_COMPARE(Math::select(2.0_degf, 5.0_degf, 0.5f), 2.0_degf); } void FunctionsTest::selectBool() { CORRADE_COMPARE(Math::select(true, false, 0.5f), true); CORRADE_COMPARE(Math::select(Math::BitVector<4>{0xa}, Math::BitVector<4>{0x5}, 1.1f), Math::BitVector<4>{0x5}); CORRADE_COMPARE(Math::select(Math::BitVector<4>{0xa}, Math::BitVector<4>{0x5}, Vector4{1.1f, -1.0f, 1.3f, 0.5f}), Math::BitVector<4>{0xf}); - - /* Wrapped types */ - CORRADE_COMPARE(Math::select(true, false, 0.5_degf), true); } void FunctionsTest::fma() {