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 &);