From 9fa0d8c796bc84299fd5771ea426b4d40b11c665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 1 May 2016 21:41:44 +0200 Subject: [PATCH] Math: fix lerp() with BoolVector. For some reason I swapped the order and took from the second parameter when the value was 0. Probably because of the ?: operator. --- src/Magnum/Math/Functions.h | 4 ++-- src/Magnum/Math/Test/FunctionsTest.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index cdc137185..3c3ff7b57 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -453,7 +453,7 @@ component-wise selection from either @p a or @p b based on values in @p t. template inline Vector lerp(const Vector& a, const Vector& b, const BoolVector& t) { Vector out{NoInit}; for(std::size_t i = 0; i != size; ++i) - out[i] = t[i] ? a[i] : b[i]; + out[i] = t[i] ? b[i] : a[i]; return out; } @@ -461,7 +461,7 @@ template inline Vector lerp(const Vector inline BoolVector lerp(const BoolVector& a, const BoolVector& b, const BoolVector& t) { BoolVector out; for(std::size_t i = 0; i != size; ++i) - out.set(i, t[i] ? a[i] : b[i]); + out.set(i, t[i] ? b[i] : a[i]); return out; } diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 7ab9d204a..836aa9703 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -251,8 +251,8 @@ void FunctionsTest::lerp() { } void FunctionsTest::lerpBool() { - CORRADE_COMPARE(Math::lerp(Vector3i{1, 2, 3}, Vector3i{5, 6, 7}, BoolVector<3>(5)), (Vector3i{1, 6, 3})); - CORRADE_COMPARE(Math::lerp(BoolVector<3>{false}, BoolVector<3>{true}, BoolVector<3>(5)), BoolVector<3>{2}); + CORRADE_COMPARE(Math::lerp(Vector3i{1, 2, 3}, Vector3i{5, 6, 7}, BoolVector<3>(5)), (Vector3i{5, 2, 7})); + CORRADE_COMPARE(Math::lerp(BoolVector<3>{false}, BoolVector<3>{true}, BoolVector<3>(5)), BoolVector<3>{5}); } void FunctionsTest::lerpInverted() {