2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Replaced snap util function with std::clamp.

This commit is contained in:
23rd
2021-01-23 06:29:50 +03:00
parent 4895e5e110
commit dd01ece14a
44 changed files with 193 additions and 92 deletions

View File

@@ -124,11 +124,6 @@ T rand_value() {
return result;
}
template <typename T>
inline T snap(const T &v, const T &_min, const T &_max) {
return (v < _min) ? _min : ((v > _max) ? _max : v);
}
QString translitRusEng(const QString &rus);
QString rusKeyboardLayoutSwitch(const QString &from);
@@ -150,16 +145,22 @@ inline int rowscount(int fullCount, int countPerRow) {
return (fullCount + countPerRow - 1) / countPerRow;
}
inline int floorclamp(int value, int step, int lowest, int highest) {
return qMin(qMax(value / step, lowest), highest);
return std::clamp(value / step, lowest, highest);
}
inline int floorclamp(float64 value, int step, int lowest, int highest) {
return qMin(qMax(static_cast<int>(std::floor(value / step)), lowest), highest);
return std::clamp(
static_cast<int>(std::floor(value / step)),
lowest,
highest);
}
inline int ceilclamp(int value, int step, int lowest, int highest) {
return qMax(qMin((value + step - 1) / step, highest), lowest);
return std::clamp((value + step - 1) / step, lowest, highest);
}
inline int ceilclamp(float64 value, int32 step, int32 lowest, int32 highest) {
return qMax(qMin(static_cast<int>(std::ceil(value / step)), highest), lowest);
return std::clamp(
static_cast<int>(std::ceil(value / step)),
lowest,
highest);
}
static int32 FullArcLength = 360 * 16;