Skip to content
Permalink
Browse files

Make FindBestFrameNumberForFramestart a lot faster

  • Loading branch information
rduivenvoorde authored and nyalldawson committed Feb 12, 2021
1 parent f5d9154 commit 80251ac97d8249d47727d65a97d3ffea5e7808db
@@ -188,7 +188,7 @@ Sets whether the animation should ``loop`` after hitting the end or start frame.
.. seealso:: :py:func:`isLooping`
%End

long findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const;
long long findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const;
%Docstring
Returns the best suited frame number for the specified datetime, based on the start of the corresponding temporal range.
%End
@@ -312,11 +312,14 @@ QgsTemporalNavigationObject::AnimationState QgsTemporalNavigationObject::animati
return mPlayBackMode;
}

long QgsTemporalNavigationObject::findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const
long long QgsTemporalNavigationObject::findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const
{
long bestFrame = 0;
QgsDateTimeRange testFrame = QgsDateTimeRange( frameStart, frameStart ); // creatng an 'instant' Range here
for ( long i = 0; i < totalFrameCount(); ++i )
long long bestFrame = 0;
QgsDateTimeRange testFrame = QgsDateTimeRange( frameStart, frameStart ); // creating an 'instant' Range here
// earlier we looped from frame 0 till totalFrameCount() here, but this loop grew gigantic if you switched to for example milliseconds
// that is why now we calculate a rough framestart here
long long roughFrameStart = std::floor( ( frameStart - mTemporalExtents.begin() ).seconds() / mFrameDuration.seconds() );
for ( long long i = roughFrameStart; i < totalFrameCount(); ++i )
{
QgsDateTimeRange range = dateTimeRangeForFrameNumber( i );
if ( range.overlaps( testFrame ) )
@@ -206,7 +206,7 @@ class CORE_EXPORT QgsTemporalNavigationObject : public QgsTemporalController, pu
/**
* Returns the best suited frame number for the specified datetime, based on the start of the corresponding temporal range.
*/
long findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const;
long long findBestFrameNumberForFrameStart( const QDateTime &frameStart ) const;

QgsExpressionContextScope *createExpressionContextScope() const override SIP_FACTORY;

0 comments on commit 80251ac

Please sign in to comment.