From 2f900d84abd2b3d99c85a63eb7b743eb0761e9bf Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Mon, 24 Oct 2022 16:03:52 +0200 Subject: [PATCH] Add a helper function to convert QPointF to QPoint using floor instead of round In a bunch of cases, we want to floor when converting to QPoint rather than rounding. As it gets tedious to repeat the same code over and over, add a helper function. --- src/libkwineffects/kwineffects.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index bbda989da9..7bacf30d56 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -206,6 +206,17 @@ KWINEFFECTS_EXPORT inline QVector2D roundVector(const QVector2D &input) return QVector2D(std::round(input.x()), std::round(input.y())); } +/** + * Convert a QPointF to a QPoint by flooring instead of rounding. + * + * By default, QPointF::toPoint() rounds which can cause problems in certain + * cases. + */ +KWINEFFECTS_EXPORT inline QPoint flooredPoint(const QPointF &point) +{ + return QPoint(std::floor(point.x()), std::floor(point.y())); +} + /** * @short Base class for all KWin effects *