From 52992c588a823255a5ad28060a6ea36dba9396bc Mon Sep 17 00:00:00 2001 From: Jouni Date: Sun, 23 Jan 2022 23:14:55 +0300 Subject: [PATCH] Replace math_util min and max with std::min and std::max (#2579) --- include/components/bar.hpp | 2 +- include/utils/math.hpp | 16 ---------------- src/modules/battery.cpp | 4 ++-- tests/unit_tests/utils/math.cpp | 12 ------------ 4 files changed, 3 insertions(+), 31 deletions(-) diff --git a/include/components/bar.hpp b/include/components/bar.hpp index ea0091c8..83ded49b 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -42,7 +42,7 @@ inline double geom_format_to_pixels(std::string str, double max) { if ((i = str.find(':')) != std::string::npos) { std::string a = str.substr(0, i - 1); std::string b = str.substr(i + 1); - return math_util::max( + return std::max( 0, math_util::percentage_to_value(strtod(a.c_str(), nullptr), max) + strtod(b.c_str(), nullptr)); } else { if (str.find('%') != std::string::npos) { diff --git a/include/utils/math.hpp b/include/utils/math.hpp index 7bf7b276..652a9f3b 100644 --- a/include/utils/math.hpp +++ b/include/utils/math.hpp @@ -8,22 +8,6 @@ POLYBAR_NS namespace math_util { - /** - * Get the min value - */ - template - ValueType min(ValueType one, ValueType two) { - return one < two ? one : two; - } - - /** - * Get the max value - */ - template - ValueType max(ValueType one, ValueType two) { - return one > two ? one : two; - } - /** * Limit value T by min and max bounds */ diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 1bdff9bc..63b1494b 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -26,8 +26,8 @@ namespace modules { battery_module::battery_module(const bar_settings& bar, string name_) : inotify_module(bar, move(name_)) { // Load configuration values - m_fullat = math_util::min(m_conf.get(name(), "full-at", m_fullat), 100); - m_lowat = math_util::max(m_conf.get(name(), "low-at", m_lowat), 0); + m_fullat = std::min(m_conf.get(name(), "full-at", m_fullat), 100); + m_lowat = std::max(m_conf.get(name(), "low-at", m_lowat), 0); m_interval = m_conf.get(name(), "poll-interval", 5s); m_lastpoll = chrono::steady_clock::now(); diff --git a/tests/unit_tests/utils/math.cpp b/tests/unit_tests/utils/math.cpp index ab44e2b2..0b0cba86 100644 --- a/tests/unit_tests/utils/math.cpp +++ b/tests/unit_tests/utils/math.cpp @@ -4,18 +4,6 @@ using namespace polybar; -TEST(Math, min) { - EXPECT_EQ(2, math_util::min(2, 5)); - EXPECT_EQ(-50, math_util::min(-8, -50)); - EXPECT_EQ(0, math_util::min(0, -5)); -} - -TEST(Math, max) { - EXPECT_EQ(5, math_util::max(2, 5)); - EXPECT_EQ(-8, math_util::max(-8, -50)); - EXPECT_EQ(251, math_util::max(0, (1 << 8) - 5)); -} - TEST(Math, cap) { EXPECT_EQ(8, math_util::cap(8, 0, 10)); EXPECT_EQ(0, math_util::cap(-8, 0, 10));