scale engine: Try harder to find a proper step size

If the maxSteps don't fit into the interval, we immediately returned
a base value. However, we could try more often with less steps before
falling back to that base value, giving better results when the
original steps value doesnt' fit.
This commit is contained in:
Peter Hartmann 2023-06-29 13:37:16 +02:00
parent 3e00ae4c2a
commit 22cd533a07
1 changed files with 16 additions and 10 deletions

View File

@ -102,23 +102,29 @@ namespace
{ {
double minorStepSize( double intervalSize, int maxSteps ) double minorStepSize( double intervalSize, int maxSteps )
{ {
const double minStep = divideInterval( intervalSize, maxSteps ); int steps = maxSteps;
if ( minStep != 0.0 ) while( steps > 0 )
{ {
// # ticks per interval const double minStep = divideInterval( intervalSize, steps );
const int numTicks = qCeil( qAbs( intervalSize / minStep ) ) - 1;
// Do the minor steps fit into the interval? if ( minStep != 0.0 )
if ( fuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ),
qAbs( intervalSize ), intervalSize ) > 0 )
{ {
// The minor steps doesn't fit into the interval // # ticks per interval
return 0.5 * intervalSize; const int numTicks = qCeil( qAbs( intervalSize / minStep ) ) - 1;
// Do the minor steps fit into the interval?
if ( fuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ),
qAbs( intervalSize ), intervalSize ) <= 0 )
{
return minStep;
}
} }
steps--;
} }
return minStep; return 0.5 * intervalSize;
} }
} }