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,7 +102,11 @@ namespace
{
double minorStepSize( double intervalSize, int maxSteps )
{
const double minStep = divideInterval( intervalSize, maxSteps );
int steps = maxSteps;
while( steps > 0 )
{
const double minStep = divideInterval( intervalSize, steps );
if ( minStep != 0.0 )
{
@ -111,14 +115,16 @@ namespace
// Do the minor steps fit into the interval?
if ( fuzzyCompare( ( numTicks + 1 ) * qAbs( minStep ),
qAbs( intervalSize ), intervalSize ) > 0 )
qAbs( intervalSize ), intervalSize ) <= 0 )
{
// The minor steps doesn't fit into the interval
return 0.5 * intervalSize;
return minStep;
}
}
return minStep;
steps--;
}
return 0.5 * intervalSize;
}
}