Skip to content
Permalink
Browse files

(q)ceil -> std::ceil

  • Loading branch information
nyalldawson committed Aug 24, 2017
1 parent 249b505 commit 7c5aa050d1c9106124d6ada81929fb083c88e842
@@ -47,10 +47,10 @@ class QgsPointCompare
if ( mTolerance <= 0 )
return p1.x() == p2.x() ? p1.y() < p2.y() : p1.x() < p2.x();

double tx1 = ceil( p1.x() / mTolerance );
double tx2 = ceil( p2.x() / mTolerance );
double tx1 = std::ceil( p1.x() / mTolerance );
double tx2 = std::ceil( p2.x() / mTolerance );
if ( tx1 == tx2 )
return ceil( p1.y() / mTolerance ) < ceil( p2.y() / mTolerance );
return ceil( p1.y() / mTolerance ) < std::ceil( p2.y() / mTolerance );
return tx1 < tx2;
}

@@ -33,7 +33,7 @@ static double ceil_with_tolerance( double value )
if ( std::fabs( value - std::round( value ) ) < 1e-6 )
return std::round( value );
else
return qCeil( value );
return std::ceil( value );
}

static double floor_with_tolerance( double value )
@@ -87,8 +87,8 @@ QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::prepare()
if ( mBounds.isNull() )
return InvalidParameters;

int rows = qMax( ceil( mBounds.height() / mPixelSize ) + 1, 1.0 );
int cols = qMax( ceil( mBounds.width() / mPixelSize ) + 1, 1.0 );
int rows = qMax( std::ceil( mBounds.height() / mPixelSize ) + 1, 1.0 );
int cols = qMax( std::ceil( mBounds.width() / mPixelSize ) + 1, 1.0 );

if ( !createEmptyLayer( driver, mBounds, rows, cols ) )
return FileCreationError;
@@ -865,7 +865,7 @@ static QVariant fcnFloor( const QVariantList &values, const QgsExpressionContext
static QVariant fcnCeil( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
{
double x = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );
return QVariant( ceil( x ) );
return QVariant( std::ceil( x ) );
}

static QVariant fcnToInt( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent )
@@ -2705,12 +2705,12 @@ int QgsGeos::geomDigits( const GEOSGeometry *geom )
GEOSCoordSeq_getX_r( geosinit.ctxt, bBoxCoordSeq, i, &t );

int digits;
digits = ceil( log10( std::fabs( t ) ) );
digits = std::ceil( log10( std::fabs( t ) ) );
if ( digits > maxDigits )
maxDigits = digits;

GEOSCoordSeq_getY_r( geosinit.ctxt, bBoxCoordSeq, i, &t );
digits = ceil( log10( std::fabs( t ) ) );
digits = std::ceil( log10( std::fabs( t ) ) );
if ( digits > maxDigits )
maxDigits = digits;
}
@@ -305,7 +305,7 @@ QString QgsRectangle::toString( int precision ) const
precision = 0;
if ( ( width() < 10 || height() < 10 ) && ( width() > 0 && height() > 0 ) )
{
precision = static_cast<int>( ceil( -1.0 * log10( qMin( width(), height() ) ) ) ) + 1;
precision = static_cast<int>( std::ceil( -1.0 * log10( qMin( width(), height() ) ) ) ) + 1;
// sanity check
if ( precision > 20 )
precision = 20;
@@ -1460,8 +1460,8 @@ int FeaturePart::createCandidatesForPolygon( QList< LabelPosition *> &lPos, Poin
px0 = box->width / 2.0;
py0 = box->length / 2.0;

px0 -= ceil( px0 / dx ) * dx;
py0 -= ceil( py0 / dy ) * dy;
px0 -= std::ceil( px0 / dx ) * dx;
py0 -= std::ceil( py0 / dy ) * dy;

for ( px = px0; px <= box->width; px += dx )
{
@@ -427,7 +427,7 @@ void Layer::chopFeaturesAtRepeatDistance()
double chopInterval = fpart->repeatDistance();
if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
{
chopInterval *= ceil( fpart->getLabelWidth() / fpart->repeatDistance() );
chopInterval *= std::ceil( fpart->getLabelWidth() / fpart->repeatDistance() );

double bmin[2], bmax[2];
fpart->getBoundingBox( bmin, bmax );
@@ -353,8 +353,8 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
// TODO: how to effectively and precisely reproject bounding box?
const int nPoints = 1000;
double d = sqrt( ( rect.width() * rect.height() ) / std::pow( sqrt( static_cast< double >( nPoints ) ) - 1, 2.0 ) );
int nXPoints = static_cast< int >( ceil( rect.width() / d ) ) + 1;
int nYPoints = static_cast< int >( ceil( rect.height() / d ) ) + 1;
int nXPoints = static_cast< int >( std::ceil( rect.width() / d ) ) + 1;
int nYPoints = static_cast< int >( std::ceil( rect.height() / d ) ) + 1;

QgsRectangle bb_rect;
bb_rect.setMinimal();
@@ -45,7 +45,7 @@ int QgsCoordinateUtils::calculateCoordinatePrecision( double mapUnitsPerPixel, c
// having enough decimal places to show the difference in position between adjacent pixels.
// Also avoid taking the log of 0.
if ( !qgsDoubleNear( mapUnitsPerPixel, 0.0 ) )
dp = static_cast<int>( ceil( -1.0 * log10( mapUnitsPerPixel ) ) );
dp = static_cast<int>( std::ceil( -1.0 * log10( mapUnitsPerPixel ) ) );
}
else
{
@@ -270,7 +270,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
{
double s = std::pow( 10, d->precision );
double d = v.toDouble() * s;
v = QVariant( ( d < 0 ? ceil( d - 0.5 ) : floor( d + 0.5 ) ) / s );
v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : floor( d + 0.5 ) ) / s );
return true;
}

@@ -408,7 +408,7 @@ QgsPalettedRasterRenderer::ClassData QgsPalettedRasterRenderer::classDataFromRas
double min = stats.minimumValue;
double max = stats.maximumValue;
// need count of every individual value
int bins = ceil( max - min ) + 1;
int bins = std::ceil( max - min ) + 1;
if ( bins <= 0 )
return ClassData();

@@ -123,14 +123,14 @@ QgsRasterBlock *QgsRasterDataProvider::block( int bandNo, QgsRectangle const &b
{
int col = floor( ( tmpExtent.xMinimum() - extent().xMinimum() ) / providerXRes );
tmpExtent.setXMinimum( extent().xMinimum() + col * providerXRes );
col = ceil( ( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes );
col = std::ceil( ( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes );
tmpExtent.setXMaximum( extent().xMinimum() + col * providerXRes );
}
if ( tmpYRes > yRes )
{
int row = floor( ( extent().yMaximum() - tmpExtent.yMaximum() ) / providerYRes );
tmpExtent.setYMaximum( extent().yMaximum() - row * providerYRes );
row = ceil( ( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
row = std::ceil( ( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes );
}
int tmpWidth = std::round( tmpExtent.width() / tmpXRes );
@@ -357,7 +357,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &histogram,
mySrcDataType == Qgis::UInt16 || mySrcDataType == Qgis::UInt32 ) )
{
if ( myBinCount > histogram.maximum - histogram.minimum + 1 )
myBinCount = int( ceil( histogram.maximum - histogram.minimum + 1 ) );
myBinCount = int( std::ceil( histogram.maximum - histogram.minimum + 1 ) );
}
}
}
@@ -530,7 +530,7 @@ void QgsRasterInterface::cumulativeCut( int bandNo,
return;

// for byte bands make sure bin count == actual range
int myBinCount = ( mySrcDataType == Qgis::Byte ) ? int( ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
int myBinCount = ( mySrcDataType == Qgis::Byte ) ? int( std::ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
QgsRasterHistogram myHistogram = histogram( bandNo, myBinCount, stats.minimumValue, stats.maximumValue, extent, sampleSize );
//QgsRasterHistogram myHistogram = histogram( bandNo, 0, std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), extent, sampleSize );

@@ -568,7 +568,7 @@ void QgsRasterInterface::cumulativeCut( int bandNo,
if ( lowerValue != std::numeric_limits<double>::quiet_NaN() )
lowerValue = floor( lowerValue );
if ( upperValue != std::numeric_limits<double>::quiet_NaN() )
upperValue = ceil( upperValue );
upperValue = std::ceil( upperValue );
}
}

@@ -134,8 +134,8 @@ QgsRasterLayerRenderer::QgsRasterLayerRenderer( QgsRasterLayer *layer, QgsRender
// the provider anyway
mRasterViewPort->mTopLeftPoint.setX( floor( mRasterViewPort->mTopLeftPoint.x() ) );
mRasterViewPort->mTopLeftPoint.setY( floor( mRasterViewPort->mTopLeftPoint.y() ) );
mRasterViewPort->mBottomRightPoint.setX( ceil( mRasterViewPort->mBottomRightPoint.x() ) );
mRasterViewPort->mBottomRightPoint.setY( ceil( mRasterViewPort->mBottomRightPoint.y() ) );
mRasterViewPort->mBottomRightPoint.setX( std::ceil( mRasterViewPort->mBottomRightPoint.x() ) );
mRasterViewPort->mBottomRightPoint.setY( std::ceil( mRasterViewPort->mBottomRightPoint.y() ) );
// recalc myRasterExtent to aligned values
myRasterExtent.set(
mapToPixel.toMapCoordinatesF( mRasterViewPort->mTopLeftPoint.x(),
@@ -259,7 +259,7 @@ void ProjectorData::calcSrcExtent()
double x = mExtent.xMinimum() + col * mMaxSrcXRes;
mSrcExtent.setXMinimum( x );

col = ceil( ( mSrcExtent.xMaximum() - mExtent.xMinimum() ) / mMaxSrcXRes );
col = std::ceil( ( mSrcExtent.xMaximum() - mExtent.xMinimum() ) / mMaxSrcXRes );
x = mExtent.xMinimum() + col * mMaxSrcXRes;
mSrcExtent.setXMaximum( x );
}
@@ -269,7 +269,7 @@ void ProjectorData::calcSrcExtent()
double y = mExtent.yMaximum() - row * mMaxSrcYRes;
mSrcExtent.setYMaximum( y );

row = ceil( ( mExtent.yMaximum() - mSrcExtent.yMinimum() ) / mMaxSrcYRes );
row = std::ceil( ( mExtent.yMaximum() - mSrcExtent.yMinimum() ) / mMaxSrcYRes );
y = mExtent.yMaximum() - row * mMaxSrcYRes;
mSrcExtent.setYMinimum( y );
}
@@ -2617,7 +2617,7 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolRenderContext &

// Add buffer based on bleed but keep precisely the height/width ratio (angle)
// thus we add integer multiplications of width and height covering the bleed
int bufferMulti = qMax( qCeil( outputPixelBleed / width ), qCeil( outputPixelBleed / width ) );
int bufferMulti = qMax( std::ceil( outputPixelBleed / width ), std::ceil( outputPixelBleed / width ) );

// Always buffer at least once so that center of line marker in upper right corner
// does not fall outside due to representation error
@@ -3948,7 +3948,7 @@ QList<double> QgsSymbolLayerUtils::prettyBreaks( double minimum, double maximum,
}
// Maybe used to correct for the epsilon here??
int start = floor( minimum / unit + 1e-07 );
int end = ceil( maximum / unit - 1e-07 );
int end = std::ceil( maximum / unit - 1e-07 );

// Extend the range out beyond the data. Does this ever happen??
while ( start * unit > minimum + ( 1e-07 * unit ) )
@@ -240,7 +240,7 @@ void QgsColorSwatchGrid::focusOutEvent( QFocusEvent *event )

int QgsColorSwatchGrid::calculateHeight() const
{
int numberRows = ceil( ( double )mColors.length() / NUMBER_COLORS_PER_ROW );
int numberRows = std::ceil( ( double )mColors.length() / NUMBER_COLORS_PER_ROW );
return numberRows * ( mSwatchSize ) + ( numberRows - 1 ) * mSwatchSpacing + mSwatchMargin + mLabelHeight + 0.5 * mLabelMargin + mSwatchMargin;
}

@@ -1565,7 +1565,7 @@ void QgsColorPreviewWidget::drawColor( const QColor &color, QRect rect, QPainter
opaqueColor.setAlpha( 255 );
QBrush opaqueBrush = QBrush( opaqueColor );
painter.setBrush( opaqueBrush );
painter.drawRect( rect.left(), rect.top(), ceil( rect.width() / 2.0 ), rect.height() );
painter.drawRect( rect.left(), rect.top(), std::ceil( rect.width() / 2.0 ), rect.height() );
}
else
{
@@ -90,14 +90,14 @@ void QgsDial::update()
if ( minimum() != 0 )
QDial::setMinimum( 0 );

int max = qCeil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
if ( maximum() != max )
QDial::setMaximum( max );

if ( singleStep() != 1 )
QDial::setSingleStep( 1 );

QDial::setValue( qCeil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
QDial::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
}

connect( this, static_cast < void ( QDial::* )( int ) > ( &QDial::valueChanged ), this, &QgsDial::onValueChanged );
@@ -95,14 +95,14 @@ void QgsSlider::update()
if ( minimum() != 0 )
QSlider::setMinimum( 0 );

int max = qCeil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
if ( maximum() != max )
QSlider::setMaximum( max );

if ( singleStep() != 1 )
QSlider::setSingleStep( 1 );

QSlider::setValue( qCeil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
QSlider::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
}

connect( this, &QSlider::valueChanged, this, &QgsSlider::onValueChanged );
@@ -805,7 +805,7 @@ void QgsGeorefPluginGui::updateMouseCoordinatePrecision()
// to show the difference in position between adjacent pixels.
// Also avoid taking the log of 0.
if ( mCanvas->mapUnitsPerPixel() != 0.0 )
dp = static_cast<int>( ceil( -1.0 * log10( mCanvas->mapUnitsPerPixel() ) ) );
dp = static_cast<int>( std::ceil( -1.0 * log10( mCanvas->mapUnitsPerPixel() ) ) );
}
else
dp = QgsProject::instance()->readNumEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DecimalPlaces" ) );
@@ -289,8 +289,8 @@ void QgsAmsProvider::draw( const QgsRectangle &viewExtent, int pixelWidth, int p
// tile_y = oy - j * (resolution * tileHeight)
int ixStart = qFloor( ( viewExtent.xMinimum() - ox ) / ( tileWidth * resolution ) );
int iyStart = qFloor( ( oy - viewExtent.yMaximum() ) / ( tileHeight * resolution ) );
int ixEnd = qCeil( ( viewExtent.xMaximum() - ox ) / ( tileWidth * resolution ) );
int iyEnd = qCeil( ( oy - viewExtent.yMinimum() ) / ( tileHeight * resolution ) );
int ixEnd = std::ceil( ( viewExtent.xMaximum() - ox ) / ( tileWidth * resolution ) );
int iyEnd = std::ceil( ( oy - viewExtent.yMinimum() ) / ( tileHeight * resolution ) );
double imX = ( viewExtent.xMinimum() - ox ) / resolution;
double imY = ( oy - viewExtent.yMaximum() ) / resolution;

@@ -1286,8 +1286,8 @@ void QgsWmsCapabilities::parseTileSetProfile( QDomElement const &e )
double r = rS.toDouble();
m.identifier = QString::number( i );
Q_ASSERT( l.boundingBoxes.size() == 1 );
m.matrixWidth = ceil( l.boundingBoxes.at( 0 ).box.width() / m.tileWidth / r );
m.matrixHeight = ceil( l.boundingBoxes.at( 0 ).box.height() / m.tileHeight / r );
m.matrixWidth = std::ceil( l.boundingBoxes.at( 0 ).box.width() / m.tileWidth / r );
m.matrixHeight = std::ceil( l.boundingBoxes.at( 0 ).box.height() / m.tileHeight / r );
m.topLeft = QgsPointXY( l.boundingBoxes.at( 0 ).box.xMinimum(), l.boundingBoxes.at( 0 ).box.yMinimum() + m.matrixHeight * m.tileHeight * r );
m.tres = r;
ms.tileMatrices.insert( r, m );
@@ -659,8 +659,8 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, in
tempTm->topLeft = QgsPointXY( mLayerExtent.xMinimum(), mLayerExtent.yMaximum() );
tempTm->tileWidth = mSettings.mMaxWidth;
tempTm->tileHeight = mSettings.mMaxHeight;
tempTm->matrixWidth = ceil( mLayerExtent.width() / mSettings.mMaxWidth / vres );
tempTm->matrixHeight = ceil( mLayerExtent.height() / mSettings.mMaxHeight / vres );
tempTm->matrixWidth = std::ceil( mLayerExtent.width() / mSettings.mMaxWidth / vres );
tempTm->matrixHeight = std::ceil( mLayerExtent.height() / mSettings.mMaxHeight / vres );
tempTm->tres = vres;
tm = tempTm.get();

@@ -2275,7 +2275,7 @@ QString QgsWmsProvider::metadata()
if ( mLayerExtent.yMaximum() > r.yMaximum() )
{
metadata += QStringLiteral( "<td title=\"%1<br>%2\"><font color=\"red\">%3</font></td>" )
.arg( tr( "%n missing row(s)", nullptr, ( int ) ceil( ( mLayerExtent.yMaximum() - r.yMaximum() ) / th ) ),
.arg( tr( "%n missing row(s)", nullptr, ( int ) std::ceil( ( mLayerExtent.yMaximum() - r.yMaximum() ) / th ) ),
tr( "Layer's upper bound: %1" ).arg( mLayerExtent.yMaximum(), 0, 'f' ) )
.arg( r.yMaximum(), 0, 'f' );
}
@@ -2288,7 +2288,7 @@ QString QgsWmsProvider::metadata()
if ( mLayerExtent.xMinimum() < r.xMinimum() )
{
metadata += QStringLiteral( "<td title=\"%1<br>%2\"><font color=\"red\">%3</font></td>" )
.arg( tr( "%n missing column(s)", nullptr, ( int ) ceil( ( r.xMinimum() - mLayerExtent.xMinimum() ) / tw ) ),
.arg( tr( "%n missing column(s)", nullptr, ( int ) std::ceil( ( r.xMinimum() - mLayerExtent.xMinimum() ) / tw ) ),
tr( "Layer's left bound: %1" ).arg( mLayerExtent.xMinimum(), 0, 'f' ) )
.arg( r.xMinimum(), 0, 'f' );
}
@@ -2301,7 +2301,7 @@ QString QgsWmsProvider::metadata()
if ( mLayerExtent.yMaximum() > r.yMaximum() )
{
metadata += QStringLiteral( "<td title=\"%1<br>%2\"><font color=\"red\">%3</font></td>" )
.arg( tr( "%n missing row(s)", nullptr, ( int ) ceil( ( mLayerExtent.yMaximum() - r.yMaximum() ) / th ) ),
.arg( tr( "%n missing row(s)", nullptr, ( int ) std::ceil( ( mLayerExtent.yMaximum() - r.yMaximum() ) / th ) ),
tr( "Layer's lower bound: %1" ).arg( mLayerExtent.yMaximum(), 0, 'f' ) )
.arg( r.yMaximum(), 0, 'f' );
}
@@ -2314,7 +2314,7 @@ QString QgsWmsProvider::metadata()
if ( mLayerExtent.xMaximum() > r.xMaximum() )
{
metadata += QStringLiteral( "<td title=\"%1<br>%2\"><font color=\"red\">%3</font></td>" )
.arg( tr( "%n missing column(s)", nullptr, ( int ) ceil( ( mLayerExtent.xMaximum() - r.xMaximum() ) / tw ) ),
.arg( tr( "%n missing column(s)", nullptr, ( int ) std::ceil( ( mLayerExtent.xMaximum() - r.xMaximum() ) / tw ) ),
tr( "Layer's right bound: %1" ).arg( mLayerExtent.xMaximum(), 0, 'f' ) )
.arg( r.xMaximum(), 0, 'f' );
}
@@ -4044,7 +4044,7 @@ static QString formatDouble( double x )
{
if ( x == 0.0 )
return QStringLiteral( "0" );
const int numberOfDecimals = qMax( 0, 19 - static_cast<int>( ceil( log10( std::fabs( x ) ) ) ) );
const int numberOfDecimals = qMax( 0, 19 - static_cast<int>( std::ceil( log10( std::fabs( x ) ) ) ) );
return qgsDoubleToString( x, numberOfDecimals );
}

@@ -248,7 +248,7 @@ int TestZipLayer::getLayerTransparency( const QString &myFileName, const QString
QgsRasterLayer *layer = dynamic_cast<QgsRasterLayer *>( myLayer );
if ( layer && layer->renderer() )
{
myTransparency = ceil( layer->renderer()->opacity() * 255 );
myTransparency = std::ceil( layer->renderer()->opacity() * 255 );
}
}
}

0 comments on commit 7c5aa05

Please sign in to comment.
You can’t perform that action at this time.