From e422044f47af543829236ff91c5b6bd372beec76 Mon Sep 17 00:00:00 2001 From: Rahil Doshi <rahil.doshi@fau.de> Date: Wed, 2 Apr 2025 17:24:32 +0200 Subject: [PATCH] Refactor interpolate_binary_search_cpp.h --- .../interpolate_binary_search_cpp.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h b/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h index 49fb0d6..1e1361d 100644 --- a/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h +++ b/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h @@ -33,12 +33,13 @@ double interpolate_binary_search_cpp( } } - // Linear interpolation - const double x1 = arrs.y_bs[right]; - const double x2 = arrs.y_bs[left]; - const double y1 = arrs.x_bs[right]; - const double y2 = arrs.x_bs[left]; + // Get interpolation points + const double x1 = arrs.x_bs[left]; + const double x2 = arrs.x_bs[right]; + const double y1 = arrs.y_bs[left]; + const double y2 = arrs.y_bs[right]; - const double slope = (y2 - y1) / (x2 - x1); - return y1 + slope * (y_target - x1); + // Linear interpolation + const double inv_slope = (x2 - x1) / (y2 - y1); + return x1 + inv_slope * (y_target - y1); } -- GitLab