1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

Replace math_util min and max with std::min and std::max (#2579)

This commit is contained in:
Jouni 2022-01-23 23:14:55 +03:00 committed by GitHub
parent c2f087225c
commit 52992c588a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 3 additions and 31 deletions

View file

@ -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<double>(
return std::max<double>(
0, math_util::percentage_to_value<double>(strtod(a.c_str(), nullptr), max) + strtod(b.c_str(), nullptr));
} else {
if (str.find('%') != std::string::npos) {

View file

@ -8,22 +8,6 @@
POLYBAR_NS
namespace math_util {
/**
* Get the min value
*/
template <typename ValueType>
ValueType min(ValueType one, ValueType two) {
return one < two ? one : two;
}
/**
* Get the max value
*/
template <typename ValueType>
ValueType max(ValueType one, ValueType two) {
return one > two ? one : two;
}
/**
* Limit value T by min and max bounds
*/

View file

@ -26,8 +26,8 @@ namespace modules {
battery_module::battery_module(const bar_settings& bar, string name_)
: inotify_module<battery_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<decltype(m_interval)>(name(), "poll-interval", 5s);
m_lastpoll = chrono::steady_clock::now();

View file

@ -4,18 +4,6 @@
using namespace polybar;
TEST(Math, min) {
EXPECT_EQ(2, math_util::min<int>(2, 5));
EXPECT_EQ(-50, math_util::min<int>(-8, -50));
EXPECT_EQ(0, math_util::min<unsigned char>(0, -5));
}
TEST(Math, max) {
EXPECT_EQ(5, math_util::max<int>(2, 5));
EXPECT_EQ(-8, math_util::max<int>(-8, -50));
EXPECT_EQ(251, math_util::max<unsigned char>(0, (1 << 8) - 5));
}
TEST(Math, cap) {
EXPECT_EQ(8, math_util::cap<int>(8, 0, 10));
EXPECT_EQ(0, math_util::cap<int>(-8, 0, 10));