Navigation Menu

Skip to content

Commit

Permalink
Fix potential 0 argument for std::log10
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 18, 2023
1 parent 4ebcad5 commit 1fe0863
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/app/georeferencer/qgsresidualplotitem.cpp
Expand Up @@ -112,28 +112,31 @@ void QgsResidualPlotItem::paint( QPainter *painter, const QStyleOptionGraphicsIt
}

//draw scale bar
double initialScaleBarWidth = rect().width() / 5;
double initialScaleBarWidth = 0;
double scaleBarWidthUnits = rect().width() / 5 / minMMPixelRatio;

//a simple method to round to next nice number
int nDecPlaces;
if ( scaleBarWidthUnits < 1 )
if ( scaleBarWidthUnits <= 0 )
{
initialScaleBarWidth = rect().width() / 5;
}
else if ( scaleBarWidthUnits < 1 )
{
nDecPlaces = -std::floor( std::log10( scaleBarWidthUnits ) );
scaleBarWidthUnits *= std::pow( 10.0, nDecPlaces );
scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
scaleBarWidthUnits /= std::pow( 10.0, nDecPlaces );
initialScaleBarWidth = scaleBarWidthUnits * minMMPixelRatio;
}
else
else if ( scaleBarWidthUnits > 0 )
{
nDecPlaces = static_cast<int>( std::log10( scaleBarWidthUnits ) );
scaleBarWidthUnits /= std::pow( 10.0, nDecPlaces );
scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
scaleBarWidthUnits *= std::pow( 10.0, nDecPlaces );
initialScaleBarWidth = scaleBarWidthUnits * minMMPixelRatio;
}
initialScaleBarWidth = scaleBarWidthUnits * minMMPixelRatio;



painter->setPen( QColor( 0, 0, 0 ) );
painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5 + initialScaleBarWidth, rect().height() - 5 ) );
Expand Down

0 comments on commit 1fe0863

Please sign in to comment.