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.
This commit is contained in:
Arjen Hiemstra 2022-10-24 16:03:52 +02:00
parent a1191bea18
commit 2f900d84ab

View file

@ -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
*