Skip to content
Permalink
Browse files

Minimizing max number of steps in loop to 10

To 'handle' for the fact that there is a theoretical chance that
the roughFrameStart will overshoot and you would loop till the end
of the mTemporalExtents. Which if going from years to milliseconds could
be millions and freeze the ui

I also tested to add an 'undershoot' of 30/31, but that 'undershoot'
already freezes the ui

So my best alternative strategie is to bail out here.
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Feb 12, 2021
1 parent 80251ac commit d096ef2b87764bf1a558cb2112e066e7f8558709
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/qgstemporalnavigationobject.cpp
@@ -317,9 +317,11 @@ long long QgsTemporalNavigationObject::findBestFrameNumberForFrameStart( const Q
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
// that is why now we calculate a rough framestart here, by taking the old frameStart and calculate a rough frameNumber here:
// because of the 'fluidity' of the DateTime units (notable months and years), there seems to be a theoretical chance
// to overshoot. So in that case fail and return to startFrame (so max number of loops is just 10)
long long roughFrameStart = std::floor( ( frameStart - mTemporalExtents.begin() ).seconds() / mFrameDuration.seconds() );
for ( long long i = roughFrameStart; i < totalFrameCount(); ++i )
for ( long long i = roughFrameStart; i < roughFrameStart + 10; ++i )
{
QgsDateTimeRange range = dateTimeRangeForFrameNumber( i );
if ( range.overlaps( testFrame ) )

0 comments on commit d096ef2

Please sign in to comment.