Skip to content
Permalink
Browse files
Simplify boolean expressions
By applying clang-tidy readability-simplify-boolean-expr fixit
  • Loading branch information
nyalldawson committed Sep 11, 2017
1 parent 7afec4b commit b468ab3
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 210 deletions.
@@ -657,9 +657,7 @@ bool DualEdgeTriangulation::calcNormal( double x, double y, Vector3D *result )
{
if ( result && mTriangleInterpolator )
{
if ( !mTriangleInterpolator->calcNormVec( x, y, result ) )
{return false;}
return true;
return mTriangleInterpolator->calcNormVec( x, y, result );
}
else
{
@@ -672,9 +670,7 @@ bool DualEdgeTriangulation::calcPoint( double x, double y, QgsPoint *result )
{
if ( result && mTriangleInterpolator )
{
if ( !mTriangleInterpolator->calcPoint( x, y, result ) )
{return false;}
return true;
return mTriangleInterpolator->calcPoint( x, y, result );
}
else
{
@@ -1737,14 +1733,7 @@ void DualEdgeTriangulation::ruppertRefinement()
bool twoforcededges;//flag to decide, if edges should be added to the maps. Do not add them if true


if ( ( mHalfEdge[i]->getForced() || edgeOnConvexHull( i ) ) && ( mHalfEdge[mHalfEdge[i]->getNext()]->getForced() || edgeOnConvexHull( mHalfEdge[i]->getNext() ) ) )
{
twoforcededges = true;
}
else
{
twoforcededges = false;
}
twoforcededges = ( mHalfEdge[i]->getForced() || edgeOnConvexHull( i ) ) && ( mHalfEdge[mHalfEdge[i]->getNext()]->getForced() || edgeOnConvexHull( mHalfEdge[i]->getNext() ) );

if ( angle < mintol && !twoforcededges )
{
@@ -2063,32 +2052,11 @@ void DualEdgeTriangulation::ruppertRefinement()



if ( ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) && ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) )
{
twoforcededges1 = true;
}
else
{
twoforcededges1 = false;
}
twoforcededges1 = ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) && ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) );

if ( ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) && ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) )
{
twoforcededges2 = true;
}
else
{
twoforcededges2 = false;
}
twoforcededges2 = ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) && ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) );

if ( ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) && ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) )
{
twoforcededges3 = true;
}
else
{
twoforcededges3 = false;
}
twoforcededges3 = ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) && ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) );


//update the settings related to ed1
@@ -2276,32 +2244,11 @@ void DualEdgeTriangulation::ruppertRefinement()
//todo: put all three edges on the dontexamine list if two edges are forced or convex hull edges
bool twoforcededges1, twoforcededges2, twoforcededges3;

if ( ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) && ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) )
{
twoforcededges1 = true;
}
else
{
twoforcededges1 = false;
}
twoforcededges1 = ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) && ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) );

if ( ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) && ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) )
{
twoforcededges2 = true;
}
else
{
twoforcededges2 = false;
}
twoforcededges2 = ( mHalfEdge[ed2]->getForced() || edgeOnConvexHull( ed2 ) ) && ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) );

if ( ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) && ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) ) )
{
twoforcededges3 = true;
}
else
{
twoforcededges3 = false;
}
twoforcededges3 = ( mHalfEdge[ed3]->getForced() || edgeOnConvexHull( ed3 ) ) && ( mHalfEdge[ed1]->getForced() || edgeOnConvexHull( ed1 ) );


//update the settings related to ed1
@@ -413,9 +413,5 @@ bool QgsRasterMatrix::twoArgumentOperation( TwoArgOperator op, const QgsRasterMa

bool QgsRasterMatrix::testPowerValidity( double base, double power ) const
{
if ( ( base == 0 && power < 0 ) || ( base < 0 && ( power - std::floor( power ) ) > 0 ) )
{
return false;
}
return true;
return !( ( base == 0 && power < 0 ) || ( base < 0 && ( power - std::floor( power ) ) > 0 ) );
}
@@ -79,10 +79,7 @@ bool QgsSnapIndex::SegmentSnapItem::getIntersection( const QgsPoint &p1, const Q
return false;

double lambdaw = QgsVector( inter.x() - q1.x(), inter.y() - q1.y() ) * w;
if ( lambdaw < 0. + 1E-8 || lambdaw >= wl - 1E-8 )
return false;

return true;
return !( lambdaw < 0. + 1E-8 || lambdaw >= wl - 1E-8 );
}

bool QgsSnapIndex::SegmentSnapItem::getProjection( const QgsPoint &p, QgsPoint &pProj )
@@ -495,11 +495,7 @@ void QgsZonalStatistics::statisticsFromPreciseIntersection( const QgsGeometry &p

bool QgsZonalStatistics::validPixel( float value ) const
{
if ( value == mInputNodataValue || std::isnan( value ) )
{
return false;
}
return true;
return !( value == mInputNodataValue || std::isnan( value ) );
}

QString QgsZonalStatistics::getUniqueFieldName( const QString &fieldName, const QList<QgsField> &newFields )
@@ -79,7 +79,7 @@ QMap<QString, QVariant> QgisAppStyleSheet::defaultOptions()
QgsDebugMsg( QString( "fontFamily: %1" ).arg( fontFamily ) );
opts.insert( QStringLiteral( "fontFamily" ), QVariant( fontFamily ) );

bool gbxCustom = ( mMacStyle ? true : false );
bool gbxCustom = ( mMacStyle );
opts.insert( QStringLiteral( "groupBoxCustom" ), settings.value( QStringLiteral( "groupBoxCustom" ), QVariant( gbxCustom ) ) );

settings.endGroup(); // "qgis/stylesheet"
@@ -194,16 +194,16 @@ void QgisAppStyleSheet::setActiveValues()
mStyle = qApp->style()->objectName(); // active style name (lowercase)
QgsDebugMsg( QString( "Style name: %1" ).arg( mStyle ) );

mMotifStyle = mStyle.contains( QLatin1String( "motif" ) ) ? true : false; // motif
mCdeStyle = mStyle.contains( QLatin1String( "cde" ) ) ? true : false; // cde
mPlastqStyle = mStyle.contains( QLatin1String( "plastique" ) ) ? true : false; // plastique
mCleanLkStyle = mStyle.contains( QLatin1String( "cleanlooks" ) ) ? true : false; // cleanlooks
mGtkStyle = mStyle.contains( QLatin1String( "gtk" ) ) ? true : false; // gtk+
mWinStyle = mStyle.contains( QLatin1String( "windows" ) ) ? true : false; // windows
mWinXpStyle = mStyle.contains( QLatin1String( "windowsxp" ) ) ? true : false; // windowsxp
mWinVistaStyle = mStyle.contains( QLatin1String( "windowsvista" ) ) ? true : false; // windowsvista
mMacStyle = mStyle.contains( QLatin1String( "macintosh" ) ) ? true : false; // macintosh (aqua)
mOxyStyle = mStyle.contains( QLatin1String( "oxygen" ) ) ? true : false; // oxygen
mMotifStyle = mStyle.contains( QLatin1String( "motif" ) ); // motif
mCdeStyle = mStyle.contains( QLatin1String( "cde" ) ); // cde
mPlastqStyle = mStyle.contains( QLatin1String( "plastique" ) ); // plastique
mCleanLkStyle = mStyle.contains( QLatin1String( "cleanlooks" ) ); // cleanlooks
mGtkStyle = mStyle.contains( QLatin1String( "gtk" ) ); // gtk+
mWinStyle = mStyle.contains( QLatin1String( "windows" ) ); // windows
mWinXpStyle = mStyle.contains( QLatin1String( "windowsxp" ) ); // windowsxp
mWinVistaStyle = mStyle.contains( QLatin1String( "windowsvista" ) ); // windowsvista
mMacStyle = mStyle.contains( QLatin1String( "macintosh" ) ); // macintosh (aqua)
mOxyStyle = mStyle.contains( QLatin1String( "oxygen" ) ); // oxygen

mDefaultFont = qApp->font(); // save before it is changed in any way

@@ -121,7 +121,7 @@ bool QgsCustomizationDialog::itemChecked( const QString &path )
QTreeWidgetItem *myItem = item( path );
if ( !myItem )
return true;
return myItem->checkState( 0 ) == Qt::Checked ? true : false;
return myItem->checkState( 0 ) == Qt::Checked;
}

void QgsCustomizationDialog::setItemChecked( const QString &path, bool on )
@@ -159,7 +159,7 @@ void QgsCustomizationDialog::itemToSettings( const QString &path, QTreeWidgetIte
return; // object is not identifiable

QString myPath = path + '/' + objectName;
bool on = item->checkState( 0 ) == Qt::Checked ? true : false;
bool on = item->checkState( 0 ) == Qt::Checked;
settings->setValue( myPath, on );

for ( int i = 0; i < item->childCount(); ++i )
@@ -753,11 +753,9 @@ bool QgsDecorationGrid::isDirty()
{
// checks if stored map units is undefined or different from canvas map units
// or if interval is 0
if ( mMapUnits == QgsUnitTypes::DistanceUnknownUnit ||
mMapUnits != QgisApp::instance()->mapCanvas()->mapSettings().mapUnits() ||
qgsDoubleNear( mGridIntervalX, 0.0 ) || qgsDoubleNear( mGridIntervalY, 0.0 ) )
return true;
return false;
return mMapUnits == QgsUnitTypes::DistanceUnknownUnit ||
mMapUnits != QgisApp::instance()->mapCanvas()->mapSettings().mapUnits() ||
qgsDoubleNear( mGridIntervalX, 0.0 ) || qgsDoubleNear( mGridIntervalY, 0.0 );
}

void QgsDecorationGrid::setDirty( bool dirty )
@@ -473,8 +473,5 @@ bool QgsMapToolPinLabels::pinUnpinCurrentDiagram( bool pin )
vlayer->endEditCommand();
}

if ( writeFailed )
return false;

return true;
return !writeFailed;
}
@@ -71,7 +71,6 @@ void QgsMapToolRotateLabel::canvasPressEvent( QgsMapMouseEvent *e )
return;
}

if ( true )
{
mCurrentMouseAzimuth = convertAzimuth( mRotationPoint.azimuth( toMapCoordinates( e->pos() ) ) );

@@ -157,7 +157,7 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
if ( labChanged || diagChanged )
{
// TODO: highlight features (maybe with QTimer?)
labelChanged = labelChanged || true;
labelChanged = true;
}
}
}
@@ -173,7 +173,7 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
mCurrentLabel.pos = pos;

if ( showHide( vlayer, false ) )
labelChanged = labelChanged || true;
labelChanged = true;
}
}
}
@@ -955,16 +955,16 @@ bool QgsComposition::readXml( const QDomElement &compositionElem, const QDomDocu
}

//snapping
mSnapToGrid = compositionElem.attribute( QStringLiteral( "snapping" ), QStringLiteral( "0" ) ).toInt() == 0 ? false : true;
mGridVisible = compositionElem.attribute( QStringLiteral( "gridVisible" ), QStringLiteral( "0" ) ).toInt() == 0 ? false : true;
mSnapToGrid = compositionElem.attribute( QStringLiteral( "snapping" ), QStringLiteral( "0" ) ).toInt() != 0;
mGridVisible = compositionElem.attribute( QStringLiteral( "gridVisible" ), QStringLiteral( "0" ) ).toInt() != 0;

mSnapGridResolution = compositionElem.attribute( QStringLiteral( "snapGridResolution" ) ).toDouble();
mSnapGridOffsetX = compositionElem.attribute( QStringLiteral( "snapGridOffsetX" ) ).toDouble();
mSnapGridOffsetY = compositionElem.attribute( QStringLiteral( "snapGridOffsetY" ) ).toDouble();

mAlignmentSnap = compositionElem.attribute( QStringLiteral( "alignmentSnap" ), QStringLiteral( "1" ) ).toInt() == 0 ? false : true;
mGuidesVisible = compositionElem.attribute( QStringLiteral( "guidesVisible" ), QStringLiteral( "1" ) ).toInt() == 0 ? false : true;
mSmartGuides = compositionElem.attribute( QStringLiteral( "smartGuides" ), QStringLiteral( "1" ) ).toInt() == 0 ? false : true;
mAlignmentSnap = compositionElem.attribute( QStringLiteral( "alignmentSnap" ), QStringLiteral( "1" ) ).toInt() != 0;
mGuidesVisible = compositionElem.attribute( QStringLiteral( "guidesVisible" ), QStringLiteral( "1" ) ).toInt() != 0;
mSmartGuides = compositionElem.attribute( QStringLiteral( "smartGuides" ), QStringLiteral( "1" ) ).toInt() != 0;
mSnapTolerance = compositionElem.attribute( QStringLiteral( "snapTolerancePixels" ), QStringLiteral( "10" ) ).toInt();

mResizeToContentsMarginTop = compositionElem.attribute( QStringLiteral( "resizeToContentsMarginTop" ), QStringLiteral( "0" ) ).toDouble();
@@ -1347,10 +1347,7 @@ bool QgsExpressionNodeCondition::needsGeometry() const
return true;
}

if ( mElseExp && mElseExp->needsGeometry() )
return true;

return false;
return mElseExp && mElseExp->needsGeometry();
}

QgsExpressionNode *QgsExpressionNodeCondition::clone() const
@@ -92,10 +92,7 @@ bool QgsBox3d::intersects( const QgsBox3d &other ) const

double z1 = ( mZmin > other.mZmin ? mZmin : other.mZmin );
double z2 = ( mZmax < other.mZmax ? mZmax : other.mZmax );
if ( z1 > z2 )
return false;

return true;
return z1 <= z2;
}

bool QgsBox3d::contains( const QgsBox3d &other ) const
@@ -360,10 +360,7 @@ bool QgsGeometryUtils::segmentIntersection( const QgsPoint &p1, const QgsPoint &
return false;

double lambdaw = QgsVector( inter.x() - q1.x(), inter.y() - q1.y() ) * w;
if ( lambdaw < 0. + tolerance || lambdaw >= wl - tolerance )
return false;

return true;
return !( lambdaw < 0. + tolerance || lambdaw >= wl - tolerance );
}

QList<QgsGeometryUtils::SelfIntersection> QgsGeometryUtils::getSelfIntersections( const QgsAbstractGeometry *geom, int part, int ring, double tolerance )
@@ -173,9 +173,7 @@ bool QgsRectangle::intersects( const QgsRectangle &rect ) const
return false;
double y1 = ( mYmin > rect.mYmin ? mYmin : rect.mYmin );
double y2 = ( mYmax < rect.mYmax ? mYmax : rect.mYmax );
if ( y1 > y2 )
return false;
return true;
return y1 <= y2;
}

bool QgsRectangle::contains( const QgsRectangle &rect ) const
@@ -541,12 +541,7 @@ double QgsTriangle::inscribedRadius() const

bool QgsTriangle::validateGeom( const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &p3 )
{
if ( ( ( p1 == p2 ) || ( p1 == p3 ) || ( p2 == p3 ) ) || qgsDoubleNear( QgsGeometryUtils::leftOfLine( p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y() ), 0.0 ) )
{
return false;
}

return true;
return !( ( ( p1 == p2 ) || ( p1 == p3 ) || ( p2 == p3 ) ) || qgsDoubleNear( QgsGeometryUtils::leftOfLine( p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y() ), 0.0 ) );
}

QgsCircle QgsTriangle::inscribedCircle() const
@@ -166,10 +166,7 @@ bool FeaturePart::hasSameLabelFeatureAs( FeaturePart *part ) const

// any part of joined features are also treated as having the same label feature
int connectedFeatureId = mLF->layer()->connectedFeatureId( mLF->id() );
if ( connectedFeatureId >= 0 && connectedFeatureId == mLF->layer()->connectedFeatureId( part->featureId() ) )
return true;

return false;
return connectedFeatureId >= 0 && connectedFeatureId == mLF->layer()->connectedFeatureId( part->featureId() );
}

LabelPosition::Quadrant FeaturePart::quadrantFromOffset() const
@@ -1158,10 +1158,7 @@ bool QgsProcessingParameterExtent::checkValueIsAcceptable( const QVariant &input
}

// try as layer extent
if ( QgsProcessingUtils::mapLayerFromString( input.toString(), *context ) )
return true;

return false;
return QgsProcessingUtils::mapLayerFromString( input.toString(), *context );
}

QString QgsProcessingParameterExtent::valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const
@@ -1649,10 +1646,7 @@ bool QgsProcessingParameterNumber::checkValueIsAcceptable( const QVariant &input
if ( !ok )
return mFlags & FlagOptional;

if ( res < mMin || res > mMax )
return false;

return true;
return !( res < mMin || res > mMax );
}

QString QgsProcessingParameterNumber::valueAsPythonString( const QVariant &value, QgsProcessingContext & ) const
@@ -53,9 +53,7 @@ bool QgsMapToPixelSimplifier::equalSnapToGrid( double x1, double y1, double x2,

int grid_y1 = std::round( ( y1 - gridOriginY ) * gridInverseSizeXY );
int grid_y2 = std::round( ( y2 - gridOriginY ) * gridInverseSizeXY );
if ( grid_y1 != grid_y2 ) return false;

return true;
return grid_y1 == grid_y2;
}

//////////////////////////////////////////////////////////////////////////////////////////////
@@ -92,10 +92,7 @@ bool QgsSnappingUtils::isIndexPrepared( QgsVectorLayer *vl, const QgsRectangle &

QgsRectangle aoi( areaOfInterest );
aoi.scale( 0.999 );
if ( ( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ) )
return true;

return false; // the index - even if it exists - is not suitable
return ( mStrategy == IndexHybrid || mStrategy == IndexExtent ) && loc->hasIndex() && ( !loc->extent() || loc->extent()->contains( aoi ) ); // the index - even if it exists - is not suitable
}


0 comments on commit b468ab3

Please sign in to comment.