From 62a59f534185e3143e71d82049806b168e2ce92c Mon Sep 17 00:00:00 2001 From: xavier Date: Wed, 6 Mar 2013 18:50:46 +0000 Subject: [PATCH] Added QET::round() and QET::roundPoint(). git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2057 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qet.cpp | 15 +++++++++++++++ sources/qet.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/sources/qet.cpp b/sources/qet.cpp index 4ad78a60d..ff4f71ac5 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -497,6 +497,21 @@ QString QET::pointerString(void *ptr) { ); } +/** + Round \a x to the nearest multiple of the invert of \a epsilon. + For instance, epsilon = 10 will round to 1/10 = 0.1 +*/ +qreal QET::round(qreal x, qreal epsilon) { + return(int(x * epsilon) / epsilon); +} + +/** + Round the coordinates of \a p to the nearest multiple of \a epsilon. +*/ +QPointF QET::roundPoint(const QPointF &p, qreal epsilon) { + return(QPointF(QET::round(p.x(), epsilon), QET::round(p.y(), epsilon))); +} + /** @param angle Un angle quelconque @return l'angle passe en parametre, mais ramene entre -360.0 + 360.0 degres diff --git a/sources/qet.h b/sources/qet.h index e98f3be17..743d73864 100644 --- a/sources/qet.h +++ b/sources/qet.h @@ -161,6 +161,8 @@ namespace QET { QString diagramAreaToString(const QET::DiagramArea &); QET::DiagramArea diagramAreaFromString(const QString &); QString pointerString(void *); + qreal round(qreal, qreal); + QPointF roundPoint(const QPointF &, qreal); qreal correctAngle(const qreal &); bool compareCanonicalFilePaths(const QString &, const QString &); QString titleBlockColumnLengthToString(const TitleBlockColumnLength &);