qskFuzzyFllor/qskFuzzyCeil added
This commit is contained in:
parent
0bcb308d1c
commit
d07e5fcf3f
|
@ -22,6 +22,8 @@ QSK_QT_PRIVATE_END
|
||||||
#include <qpa/qplatformintegration.h>
|
#include <qpa/qplatformintegration.h>
|
||||||
#include <qpa/qplatformscreen.h>
|
#include <qpa/qplatformscreen.h>
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
template< class Rect, class Value >
|
template< class Rect, class Value >
|
||||||
static inline Rect qskAlignedRect( const Rect& outerRect,
|
static inline Rect qskAlignedRect( const Rect& outerRect,
|
||||||
Value width, Value height, Qt::Alignment alignment )
|
Value width, Value height, Qt::Alignment alignment )
|
||||||
|
@ -193,3 +195,26 @@ QRect qskPlatformScreenGeometry( const QScreen* screen )
|
||||||
|
|
||||||
return screen->handle()->geometry();
|
return screen->handle()->geometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Due to the nature of floating point arithmetic
|
||||||
|
we might floor a value, that is already "aligned"
|
||||||
|
F.e static_cast< int >( 0.29 / 0.01 ) -> 28
|
||||||
|
*/
|
||||||
|
qreal qskFuzzyFloor( qreal value, qreal stepSize )
|
||||||
|
{
|
||||||
|
qreal v = std::floor( value / stepSize ) * stepSize;
|
||||||
|
if ( qFuzzyCompare( value - v, stepSize ) )
|
||||||
|
v = value;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
qreal qskFuzzyCeil( qreal value, qreal stepSize )
|
||||||
|
{
|
||||||
|
qreal v = std::ceil( value / stepSize ) * stepSize;
|
||||||
|
if ( qFuzzyCompare( v - value, stepSize ) )
|
||||||
|
v = value;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,15 @@ QSK_EXPORT QRectF qskValidOrEmptyInnerRect(
|
||||||
QSK_EXPORT qreal qskHorizontalAdvance( const QFont&, const QString& );
|
QSK_EXPORT qreal qskHorizontalAdvance( const QFont&, const QString& );
|
||||||
QSK_EXPORT qreal qskHorizontalAdvance( const QFontMetricsF&, const QString& );
|
QSK_EXPORT qreal qskHorizontalAdvance( const QFontMetricsF&, const QString& );
|
||||||
|
|
||||||
|
inline QMarginsF qskMargins( const QRectF& rect, const QRectF& innerRect )
|
||||||
|
{
|
||||||
|
return QMarginsF(
|
||||||
|
innerRect.left() - rect.left(),
|
||||||
|
innerRect.top() - rect.top(),
|
||||||
|
rect.right() - innerRect.right(),
|
||||||
|
rect.bottom() - innerRect.bottom() );
|
||||||
|
}
|
||||||
|
|
||||||
inline bool qskFuzzyCompare( qreal value1, qreal value2 )
|
inline bool qskFuzzyCompare( qreal value1, qreal value2 )
|
||||||
{
|
{
|
||||||
if ( qFuzzyIsNull( value1 ) )
|
if ( qFuzzyIsNull( value1 ) )
|
||||||
|
@ -47,13 +56,7 @@ inline bool qskFuzzyCompare( qreal value1, qreal value2 )
|
||||||
return qFuzzyCompare( value1, value2 );
|
return qFuzzyCompare( value1, value2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QMarginsF qskMargins( const QRectF& rect, const QRectF& innerRect )
|
QSK_EXPORT qreal qskFuzzyFloor( qreal value, qreal stepSize );
|
||||||
{
|
QSK_EXPORT qreal qskFuzzyCeil( qreal value, qreal stepSize );
|
||||||
return QMarginsF(
|
|
||||||
innerRect.left() - rect.left(),
|
|
||||||
innerRect.top() - rect.top(),
|
|
||||||
rect.right() - innerRect.right(),
|
|
||||||
rect.bottom() - innerRect.bottom() );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue