From d4caf28183b2d88f6681ee4ffdc2aaead3bcfc4c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 5 Mar 2024 13:10:33 +0100 Subject: [PATCH] Math: add a vector + scalar fmod() overload. --- src/Magnum/Math/Functions.h | 11 +++++++++++ src/Magnum/Math/Test/FunctionsTest.cpp | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Math/Functions.h b/src/Magnum/Math/Functions.h index 8040f894f..90c8fbe29 100644 --- a/src/Magnum/Math/Functions.h +++ b/src/Magnum/Math/Functions.h @@ -494,6 +494,17 @@ template inline Vector fmod(const Vector inline Vector fmod(const Vector& a, T b) { + Vector out{Magnum::NoInit}; + for(std::size_t i = 0; i != size; ++i) + out[i] = Math::fmod(a[i], b); + return out; +} + /** @brief Linear interpolation of two values @param a First value diff --git a/src/Magnum/Math/Test/FunctionsTest.cpp b/src/Magnum/Math/Test/FunctionsTest.cpp index 5b93dd312..e7834c7bb 100644 --- a/src/Magnum/Math/Test/FunctionsTest.cpp +++ b/src/Magnum/Math/Test/FunctionsTest.cpp @@ -357,7 +357,8 @@ void FunctionsTest::binomialCoefficientOverflow() { void FunctionsTest::fmod() { CORRADE_COMPARE(Math::fmod(5.1f, 3.0f), 2.1f); - CORRADE_COMPARE(Math::fmod(Vector3(5.1f, -5.1f, 6.8f), Vector3(3.0f, 3.0f, 1.1f)), Vector3(2.1f, -2.1f, 0.2f)); + CORRADE_COMPARE(Math::fmod(Vector3(5.1f, -5.1f, 6.8f), Vector3(3.0f, -2.0f, 1.1f)), Vector3(2.1f, -1.1f, 0.2f)); + CORRADE_COMPARE(Math::fmod(Vector3(5.1f, -5.1f, 6.8f), 3.0f), Vector3(2.1f, -2.1f, 0.8f)); /* Wrapped types */ CORRADE_COMPARE(Math::fmod(2.7_degf, 1.3_degf), 0.1_degf);