Use base::SafeRound.

This commit is contained in:
John Preston 2021-09-27 12:12:31 +04:00
parent d5fb147f2c
commit e62d92f655
4 changed files with 11 additions and 8 deletions

View file

@ -99,7 +99,7 @@ TG_FORCE_INLINE float64 interpolateF(int a, int b, float64 b_ratio) {
}
TG_FORCE_INLINE int interpolate(int a, int b, float64 b_ratio) {
return std::round(interpolateF(a, b, b_ratio));
return base::SafeRound(interpolateF(a, b, b_ratio));
}
#ifdef ARCH_CPU_32_BITS

View file

@ -224,8 +224,8 @@ RadialState InfiniteRadialAnimation::computeState() {
if (anim::Disabled()) {
return { 1., 0, kFullArcLength };
}
const auto min = int(std::round(kFullArcLength * _st.arcMin));
const auto max = int(std::round(kFullArcLength * _st.arcMax));
const auto min = int(base::SafeRound(kFullArcLength * _st.arcMin));
const auto max = int(base::SafeRound(kFullArcLength * _st.arcMax));
if (now <= _workStarted) {
// zero .. _workStarted
const auto zero = _workStarted - _st.sineDuration;
@ -314,8 +314,8 @@ RadialState InfiniteRadialAnimation::computeState() {
// st.arcMax - st.arcMin,
// std::min(backCurrent, crl::time(st.sineDuration))
// / float64(st.sineDuration));
//const auto front = linear + std::round((st.arcMin + frontProgress + frontPeriods * (st.arcMax - st.arcMin)) * kFullArcLength);
//const auto from = linear + std::round((backProgress + backPeriods * (st.arcMax - st.arcMin)) * kFullArcLength);
//const auto front = linear + base::SafeRound((st.arcMin + frontProgress + frontPeriods * (st.arcMax - st.arcMin)) * kFullArcLength);
//const auto from = linear + base::SafeRound((backProgress + backPeriods * (st.arcMax - st.arcMin)) * kFullArcLength);
//const auto length = (front - from);
//return {

View file

@ -6,6 +6,8 @@
//
#pragma once
#include "base/algorithm.h"
#include <QtCore/QSize>
#include <algorithm>
@ -34,7 +36,7 @@ template <typename T>
[[nodiscard]] inline T ConvertScale(T value, int scale) {
return (value < 0.)
? (-ConvertScale(-value, scale))
: T(std::round((double(value) * scale / 100.) - 0.01));
: T(base::SafeRound((double(value) * scale / 100.) - 0.01));
}
template <typename T>

View file

@ -260,8 +260,9 @@ void VerticalLayoutReorder::updateShift(
? indexHint
: indexOf(widget);
auto &entry = _entries[index];
entry.shift = std::round(entry.shiftAnimation.value(entry.finalShift))
+ entry.deltaShift;
entry.shift = base::SafeRound(
entry.shiftAnimation.value(entry.finalShift)
) + entry.deltaShift;
if (entry.deltaShift && !entry.shiftAnimation.animating()) {
entry.finalShift += entry.deltaShift;
entry.deltaShift = 0;