From b8b9236ec4bb2bcdf9dcbeca07c8f78753cabdaa Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Wed, 13 Jul 2022 17:24:37 +0200 Subject: [PATCH] Add "roundVector" function as convenience for rounding a QVector2D Otherwise we constantly need to construct and deconstruct vectors. --- src/libkwineffects/kwineffects.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index d99be81f20..fa4be72e4d 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -196,6 +197,14 @@ KWINEFFECTS_EXPORT inline QRectF scaledRect(const QRectF &rect, qreal scale) return QRectF{rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale}; } +/** + * Round a vector to nearest integer. + */ +KWINEFFECTS_EXPORT inline QVector2D roundVector(const QVector2D &input) +{ + return QVector2D(std::round(input.x()), std::round(input.y())); +} + /** * @short Base class for all KWin effects *