Browse Source

Math: enforce that the interpolation phase in select() is unitless.

Math::lerp() enforces that already (the code won't even compile in that
case), here it accidentally worked, leading to confusion.
pull/638/head
Vladimír Vondruš 2 years ago
parent
commit
c517a6f0ee
  1. 6
      doc/changelog.dox
  2. 1
      src/Magnum/Math/Functions.h
  3. 5
      src/Magnum/Math/Test/FunctionsTest.cpp

6
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

1
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<class T, class U> constexpr T select(const T& a, const T& b, U t) {
static_assert(IsUnitless<U>::value, "expecting an unitless type for the interpolation phase");
return lerp(a, b, t >= U(1));
}

5
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() {

Loading…
Cancel
Save