6#include "QskIntervalF.h"
7#include "QskFunctions.h"
13static void qskRegisterIntervalF()
15 qRegisterMetaType< QskIntervalF >();
17#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
18 QMetaType::registerEqualsComparator< QskIntervalF >();
22Q_CONSTRUCTOR_FUNCTION( qskRegisterIntervalF )
27 const qreal lowerBound = intv1.lowerBound()
28 + progress * ( intv2.lowerBound() - intv1.lowerBound() );
30 const qreal upperBound = intv1.upperBound()
31 + progress * ( intv2.upperBound() - intv1.upperBound() );
39 return qskInterpolated( *
this, to, progress );
42QVariant QskIntervalF::interpolate(
45 return QVariant::fromValue( qskInterpolated( intv1, intv2, progress ) );
48void QskIntervalF::unite(
const QskIntervalF& other )
noexcept
52 if ( other.isValid() )
54 if ( other.m_lowerBound < m_lowerBound )
56 m_lowerBound = other.m_lowerBound;
58 else if ( other.m_upperBound > m_upperBound )
60 m_upperBound = other.m_upperBound;
66 if ( other.isValid() )
68 m_lowerBound = other.m_lowerBound;
69 m_upperBound = other.m_upperBound;
78 if ( other.isValid() )
80 const auto min = std::min( m_lowerBound, other.m_lowerBound );
81 const auto max = std::max( m_upperBound, other.m_upperBound );
88 if ( other.isValid() )
100 if ( !other.isValid() )
103 if ( m_lowerBound <= other.m_lowerBound )
105 if ( m_upperBound < other.m_lowerBound )
108 const qreal max = std::min( m_upperBound, other.m_upperBound );
113 if ( other.m_upperBound < m_lowerBound )
116 const qreal max = std::min( m_upperBound, other.m_upperBound );
121bool QskIntervalF::intersects(
const QskIntervalF& other )
const noexcept
123 if ( !isValid() || !other.isValid() )
126 if ( m_lowerBound <= other.m_lowerBound )
127 return m_upperBound >= other.m_lowerBound;
129 return m_lowerBound <= other.m_upperBound;
132void QskIntervalF::extend( qreal value )
noexcept
136 m_lowerBound = value;
137 m_upperBound = value;
139 else if ( value < m_lowerBound )
141 m_lowerBound = value;
143 else if ( value >= m_upperBound )
145 m_upperBound = value;
149QskIntervalF QskIntervalF::extended( qreal value )
const noexcept
154 const qreal lower = std::min( value, m_lowerBound );
155 const qreal upper = std::max( value, m_upperBound );
160void QskIntervalF::spanFromLowerBound( qreal value )
noexcept
164 m_lowerBound = value;
165 m_upperBound = value;
169 m_lowerBound = value;
170 if ( m_lowerBound > m_upperBound )
171 m_upperBound = m_lowerBound;
175void QskIntervalF::spanFromUpperBound( qreal value )
noexcept
179 m_lowerBound = value;
180 m_upperBound = value;
184 m_upperBound = value;
185 if ( m_lowerBound > m_upperBound )
186 m_lowerBound = m_upperBound;
190QskIntervalF QskIntervalF::fuzzyAligned( qreal stepSize )
const
192 auto v1 = m_lowerBound;
193 auto v2 = m_upperBound;
195 const auto max = std::numeric_limits< qreal >::max();
197 if ( -max + stepSize <= v1 )
199 const auto v = qskFuzzyFloor( v1, stepSize );
200 if ( !qskFuzzyCompare( v1, v ) )
204 if ( max - stepSize >= v2 )
206 const auto v = qskFuzzyCeil( v2, stepSize );
207 if ( !qskFuzzyCompare( v2, v ) )
214bool QskIntervalF::fuzzyContains( qreal value )
const
219 if ( ( value < m_lowerBound ) && !qskFuzzyCompare( value, m_lowerBound ) )
222 if ( ( value > m_upperBound ) && !qskFuzzyCompare( value, m_upperBound ) )
228bool QskIntervalF::fuzzyContains(
const QskIntervalF& interval )
const
230 if ( !isValid() || !interval.isValid() )
233 if ( ( interval.m_lowerBound < m_lowerBound )
234 && !qskFuzzyCompare( interval.m_lowerBound, m_lowerBound ) )
239 if ( ( interval.m_upperBound > m_upperBound )
240 && !qskFuzzyCompare( interval.m_upperBound, m_upperBound ) )
248bool QskIntervalF::fuzzyIsBoundary( qreal value )
const
250 return qskFuzzyCompare( value, m_lowerBound )
251 || qskFuzzyCompare( value, m_upperBound );
254QRectF QskIntervalF::toRect(
const QskIntervalF& intervalX,
257 return QRectF( intervalX.lowerBound(), intervalY.lowerBound(),
258 intervalX.length(), intervalY.length() ).normalized();
261#ifndef QT_NO_DEBUG_STREAM
265QDebug operator<<( QDebug debug,
const QskIntervalF& interval )
267 debug.nospace() <<
"QskIntervalF("
268 << interval.lowerBound() <<
"," << interval.upperBound() <<
")";
270 return debug.space();
275#include "moc_QskIntervalF.cpp"