MathUtils: Add exponential interpolation

Change-Id: I58bb26a6e921cbd1f5532bddcd6a6700ff80b94f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-28 11:28:49 +01:00
parent 23f53dcbda
commit 12b639970f
3 changed files with 50 additions and 5 deletions
@@ -16,6 +16,8 @@ private slots:
void interpolateLinear();
void interpolateTangential_data();
void interpolateTangential();
void interpolateExponential_data();
void interpolateExponential();
};
void tst_MathUtils::interpolateLinear_data()
@@ -72,6 +74,31 @@ void tst_MathUtils::interpolateTangential()
QCOMPARE(y, result);
}
void tst_MathUtils::interpolateExponential_data()
{
QTest::addColumn<int>("x");
QTest::addColumn<int>("xHalfLife");
QTest::addColumn<int>("y1");
QTest::addColumn<int>("y2");
QTest::addColumn<int>("result");
QTest::newRow("zero") << 0 << 8 << 10 << 20 << 10;
QTest::newRow("halfLife") << 8 << 8 << 10 << 20 << 15;
QTest::newRow("approxInfinity") << 1000 << 8 << 10 << 20 << 20;
}
void tst_MathUtils::interpolateExponential()
{
QFETCH(int, x);
QFETCH(int, xHalfLife);
QFETCH(int, y1);
QFETCH(int, y2);
QFETCH(int, result);
const int y = MathUtils::interpolateExponential(x, xHalfLife, y1, y2);
QCOMPARE(y, result);
}
QTEST_GUILESS_MAIN(tst_MathUtils)
#include "tst_mathutils.moc"