Introducing vRound function.

Shortcut to round double to X points decimal.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-11-19 15:46:11 +02:00
parent 0c0207aa6f
commit 9e25e6de24
2 changed files with 9 additions and 4 deletions

View File

@ -28,6 +28,7 @@
#include "vabstractlayoutdialog.h"
#include "../core/vapplication.h"
#include "../vmisc/vmath.h"
//must be the same order as PaperSizeTemplate constants
const VAbstractLayoutDialog::FormatsVector VAbstractLayoutDialog::pageFormatNames
@ -172,12 +173,12 @@ QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit
case Unit::Cm:
case Unit::Mm:
case Unit::Px:
w = qRound(width * 100.0) / 100.0;
h = qRound(height * 100.0) / 100.0;
w = vRound(width, 2);
h = vRound(height, 2);
return QSizeF(w, h);
case Unit::Inch:
w = qRound(width * 100000.0) / 100000.0;
h = qRound(height * 100000.0) / 100000.0;
w = vRound(width, 5);
h = vRound(height, 5);
return QSizeF(w, h);
default:
break;

View File

@ -51,5 +51,9 @@
#define M_EULER (0.57721566490153286060)
#endif
template <typename T>
Q_DECL_CONSTEXPR inline T vRound(T d, int p)
{ return p > 0 ? qRound(d * (p * 10.0)) / (p * 10.0) : qRound(d); }
#endif // VMATH_H