From 9de3af1cbc75de93153ef139fd7b950e14412a0e Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Mon, 21 Nov 2022 18:38:29 +0100 Subject: [PATCH] Functions: interpolate brackets and spacing --- src/lib/mathlib/math/Functions.hpp | 4 ++-- src/lib/mathlib/math/FunctionsTest.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/mathlib/math/Functions.hpp b/src/lib/mathlib/math/Functions.hpp index b81459ff678..7fb54442d9b 100644 --- a/src/lib/mathlib/math/Functions.hpp +++ b/src/lib/mathlib/math/Functions.hpp @@ -160,8 +160,8 @@ const T interpolate(const T &value, const T &x_low, const T &x_high, const T &y_ } else { /* linear function between the two points */ T a = (y_high - y_low) / (x_high - x_low); - T b = y_low - a * x_low; - return a * value + b; + T b = y_low - (a * x_low); + return (a * value) + b; } } diff --git a/src/lib/mathlib/math/FunctionsTest.cpp b/src/lib/mathlib/math/FunctionsTest.cpp index 8788651f267..ebc4e496702 100644 --- a/src/lib/mathlib/math/FunctionsTest.cpp +++ b/src/lib/mathlib/math/FunctionsTest.cpp @@ -172,7 +172,7 @@ TEST(FunctionsTest, interpolate) // corner case when y_low > y_high EXPECT_FLOAT_EQ(interpolate(1.5f, 1.f, 2.f, 6.f, 4.f), 5.f); - // corner case when x_low == x_high == y_low == y_high == 0.f + // corner case when x_low == x_high == y_low == y_high == 0.f EXPECT_FLOAT_EQ(interpolate(0.f, 0.f, 0.f, 0.f, 0.f), 0.f); }