diff --git a/src/lib/mathlib/math/Functions.hpp b/src/lib/mathlib/math/Functions.hpp index d3ac322a23..486ea52b6e 100644 --- a/src/lib/mathlib/math/Functions.hpp +++ b/src/lib/mathlib/math/Functions.hpp @@ -140,7 +140,7 @@ const T expo_deadzone(const T &value, const T &e, const T &dz) template const T gradual(const T &value, const T &x_low, const T &x_high, const T &y_low, const T &y_high) { - if (value < x_low) { + if (value <= x_low) { return y_low; } else if (value > x_high) { diff --git a/src/lib/mathlib/math/FunctionsTest.cpp b/src/lib/mathlib/math/FunctionsTest.cpp index dba2ef81d2..324f7f12fe 100644 --- a/src/lib/mathlib/math/FunctionsTest.cpp +++ b/src/lib/mathlib/math/FunctionsTest.cpp @@ -150,6 +150,12 @@ TEST(FunctionsTest, gradual) EXPECT_FLOAT_EQ(gradual(1.75f, 1.f, 2.f, 4.f, 6.f), 5.5f); EXPECT_FLOAT_EQ(gradual(2.f, 1.f, 2.f, 4.f, 6.f), 6.f); EXPECT_FLOAT_EQ(gradual(12.f, 1.f, 2.f, 4.f, 6.f), 6.f); + + // corner case when x_low == x_high == value + EXPECT_FLOAT_EQ(gradual(1.f, 1.f, 1.f, 4.f, 6.f), 4.f); + + // corner case when x_low > x_high + EXPECT_FLOAT_EQ(gradual(1.05f, 1.1f, 1.f, 4.f, 6.f), 4.f); } TEST(FunctionsTest, gradual3)