Skip to content

Commit

Permalink
STYLE: Remove == true from Boolean expressions
Browse files Browse the repository at this point in the history
Following C++ Core Guidelines, February 15, 2024, "Don’t add redundant `==` or
`!=` to conditions",
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es87-dont-add-redundant--or--to-conditions
  • Loading branch information
N-Dekker authored and dzenanz committed Mar 12, 2024
1 parent c9f4367 commit e7a60b6
Show file tree
Hide file tree
Showing 55 changed files with 117 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkObjectFactoryBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SynchronizeList(FactoryListType & output, FactoryListType & input, bool internal
}
if (pos == -1)
{
if (internal == true)
if (internal)
{
itk::ObjectFactoryBase::RegisterFactoryInternal(factory);
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/src/itkTBBMultiThreader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ struct TBBImageRegionSplitter : public itk::ImageIORegion
{
// The following if statement is primarily used to ensure use of
// is_splittable_in_proportion to avoid unused variable warning.
if (TBBImageRegionSplitter::is_splittable_in_proportion == true)
if (TBBImageRegionSplitter::is_splittable_in_proportion)
{
*this = region; // most things will be the same
for (int d = static_cast<int>(this->GetImageDimension()) - 1; d >= 0;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkBooleanStdVectorGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ static_assert(
ValueType{ false } == false,
"The value type of BooleanStdVectorType should be allowed as a conditional expression, evaluating to false.");
static_assert(
ValueType{ true } == true,
ValueType{ true },
"The value type of BooleanStdVectorType should be allowed as a conditional expression, evaluating to true.");
static_assert(bool{ ValueType{ false } } == false,
"The value type of BooleanStdVectorType should support a lossless round-trip from bool value false.");
static_assert(bool{ ValueType{ true } } == true,
static_assert(bool{ ValueType{ true } },
"The value type of BooleanStdVectorType should support a lossless round-trip from bool value true.");
static_assert(std::is_same_v<decltype(*itk::BooleanStdVectorType{}.data()), ValueType &>,
"BooleanStdVectorType should have a valid data() member function (unlike std::vector<bool>).");
Expand Down
11 changes: 5 additions & 6 deletions Modules/Core/Common/test/itkMathTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ TestIntegersAreSame(const T1 & v1, const T2 & v2)
std::cout << v2 << std::endl;
testPassStatus = EXIT_FAILURE;
}
if (itk::Math::AlmostEquals(v2, v1) == true)
if (itk::Math::AlmostEquals(v2, v1))
{
std::cout << "Error in "
<< "itk::Math::AlmostEquals(v2, v1) " << std::endl;
std::cout << __FILE__ << ' ' << __LINE__ << ' ' << v2 << " == " << v1 << std::endl;
testPassStatus = EXIT_FAILURE;
}
if (itk::Math::AlmostEquals(v1, v2) == true)
if (itk::Math::AlmostEquals(v1, v2))
{
std::cout << "Error in "
<< "itk::Math::AlmostEquals(v1, v2) " << std::endl;
Expand Down Expand Up @@ -606,22 +606,21 @@ main(int, char *[])
constexpr double d = 1.01;

// Test AlmostEquals()
if (itk::Math::AlmostEquals(f, d) == true || itk::Math::AlmostEquals(d, f) == true)
if (itk::Math::AlmostEquals(f, d) || itk::Math::AlmostEquals(d, f))
{
std::cout << __FILE__ << ' ' << __LINE__ << ' ' << f << " == " << d << std::endl;
testPassStatus = EXIT_FAILURE;
}
if (itk::Math::AlmostEquals(f, sc) == false || itk::Math::AlmostEquals(sc, f) == false ||
itk::Math::AlmostEquals(1.0, 1.0f) == false || itk::Math::AlmostEquals(1.1, 1.1f) == false ||
itk::Math::AlmostEquals(1, 1.0) == false || itk::Math::AlmostEquals(2.0, 1.0) == true ||
itk::Math::AlmostEquals(1, 2) == true)
itk::Math::AlmostEquals(1, 1.0) == false || itk::Math::AlmostEquals(2.0, 1.0) || itk::Math::AlmostEquals(1, 2))
{
std::cout << __FILE__ << ' ' << __LINE__ << ' ' << f << " == " << d << std::endl;
testPassStatus = EXIT_FAILURE;
}

// Test ExactlyEquals() it should detect normal inequalities
if (itk::Math::ExactlyEquals(f, d) == true || itk::Math::ExactlyEquals(d, f) == true)
if (itk::Math::ExactlyEquals(f, d) || itk::Math::ExactlyEquals(d, f))
{
std::cout << __FILE__ << ' ' << __LINE__ << ' ' << f << " == " << d << std::endl;
testPassStatus = EXIT_FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/test/itkMetaDataDictionaryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ itkMetaDataDictionaryTest(int, char *[])
{
float tempfloat = 0.0;
const bool IsValidReturn = itk::ExposeMetaData<float>(MyDictionary, "ASimpleFloatInitalized", tempfloat);
if (IsValidReturn == true)
if (IsValidReturn)
{
std::cout << tempfloat << std::endl;
}
Expand Down Expand Up @@ -158,7 +158,7 @@ itkMetaDataDictionaryTest(int, char *[])
std::cerr << "Failed to erase ASimpleFloatChanged" << std::endl;
return EXIT_FAILURE;
}
if (MyDictionary.Erase("itk") == true)
if (MyDictionary.Erase("itk"))
{
std::cerr << "Failed erase itk" << std::endl;
return EXIT_FAILURE;
Expand Down
28 changes: 14 additions & 14 deletions Modules/Core/Common/test/itkMetaProgrammingLibraryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ itkMetaProgrammingLibraryTest(int, char *[])
using namespace itk::mpl;

// Or between constants
static_assert(OrC<true, true, true>::Value == true, "Unit test failed");
static_assert(OrC<true, true, false>::Value == true, "Unit test failed");
static_assert(OrC<true, false, true>::Value == true, "Unit test failed");
static_assert(OrC<true, false, false>::Value == true, "Unit test failed");
static_assert(OrC<false, true, true>::Value == true, "Unit test failed");
static_assert(OrC<false, true, false>::Value == true, "Unit test failed");
static_assert(OrC<false, false, true>::Value == true, "Unit test failed");
static_assert(OrC<true, true, true>::Value, "Unit test failed");
static_assert(OrC<true, true, false>::Value, "Unit test failed");
static_assert(OrC<true, false, true>::Value, "Unit test failed");
static_assert(OrC<true, false, false>::Value, "Unit test failed");
static_assert(OrC<false, true, true>::Value, "Unit test failed");
static_assert(OrC<false, true, false>::Value, "Unit test failed");
static_assert(OrC<false, false, true>::Value, "Unit test failed");
static_assert(OrC<false, false, false>::Value == false, "Unit test failed");

static_assert(OrC<true, true>::Value == true, "Unit test failed");
static_assert(OrC<true, false>::Value == true, "Unit test failed");
static_assert(OrC<false, true>::Value == true, "Unit test failed");
static_assert(OrC<true, true>::Value, "Unit test failed");
static_assert(OrC<true, false>::Value, "Unit test failed");
static_assert(OrC<false, true>::Value, "Unit test failed");
static_assert(OrC<false, false>::Value == false, "Unit test failed");

// Or between types
Expand All @@ -57,7 +57,7 @@ itkMetaProgrammingLibraryTest(int, char *[])
static_assert(std::is_same_v<Or<FalseType, FalseType>::Type, FalseType>, "Unit test failed");

// And between constants
static_assert(AndC<true, true>::Value == true, "Unit test failed");
static_assert(AndC<true, true>::Value, "Unit test failed");
static_assert(AndC<true, false>::Value == false, "Unit test failed");
static_assert(AndC<false, true>::Value == false, "Unit test failed");
static_assert(AndC<false, false>::Value == false, "Unit test failed");
Expand All @@ -70,8 +70,8 @@ itkMetaProgrammingLibraryTest(int, char *[])

// Xor between constants
static_assert(XorC<true, true>::Value == false, "Unit test failed");
static_assert(XorC<true, false>::Value == true, "Unit test failed");
static_assert(XorC<false, true>::Value == true, "Unit test failed");
static_assert(XorC<true, false>::Value, "Unit test failed");
static_assert(XorC<false, true>::Value, "Unit test failed");
static_assert(XorC<false, false>::Value == false, "Unit test failed");

// Xor between types
Expand All @@ -82,7 +82,7 @@ itkMetaProgrammingLibraryTest(int, char *[])

// Not between constants
static_assert(NotC<true>::Value == false, "Unit test failed");
static_assert(NotC<false>::Value == true, "Unit test failed");
static_assert(NotC<false>::Value, "Unit test failed");

// Not between types
static_assert(std::is_same_v<Not<TrueType>::Type, FalseType>, "Unit test failed");
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkTimeStampTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ itkTimeStampTest(int, char *[])
// been used
const itk::ModifiedTimeType index = helper.timestamps[k].GetMTime() - min_mtime;

if (istimestamped[index] == true)
if (istimestamped[index])
{
iter_success = false;
std::cerr << helper.timestamps[k].GetMTime() << " was used twice as a timestamp!" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/test/itkXMLFileOutputWindowTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ itkXMLFileOutputWindowTest(int argc, char * argv[])
const std::string test3Message{ status ? "TEST THREE PASSED" : "TEST THREE FAILED" };
std::cout << test3Message << "\n\n" << std::endl;

return (status == true) ? EXIT_SUCCESS : EXIT_FAILURE;
return status ? EXIT_SUCCESS : EXIT_FAILURE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ template <typename TInputImageType, typename TSparseOutputImageType>
auto
FiniteDifferenceSparseImageFilter<TInputImageType, TSparseOutputImageType>::CalculateChange() -> TimeStepType
{
if (m_PrecomputeFlag == true)
if (m_PrecomputeFlag)
{
this->PrecalculateChange();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ GaussianBlurImageFunction<TInputImage, TOutput>::RecomputeGaussianKernel()
gaussianOperator.SetMaximumError(m_MaximumError[direction]);
gaussianOperator.SetMaximumKernelWidth(m_MaximumKernelWidth);

if ((m_UseImageSpacing == true) && (this->GetInputImage()))
if (m_UseImageSpacing && (this->GetInputImage()))
{
if (this->GetInputImage()->GetSpacing()[direction] == 0.0)
{
Expand Down Expand Up @@ -371,7 +371,7 @@ GaussianBlurImageFunction<TInputImage, TOutput>::RecomputeContinuousGaussianKern
{
typename GaussianFunctionType::InputType pt;
pt[0] = gaussianNeighborhood.GetOffset(i)[direction] - offset[direction];
if ((m_UseImageSpacing == true) && (this->GetInputImage()))
if (m_UseImageSpacing && (this->GetInputImage()))
{
if (this->GetInputImage()->GetSpacing()[direction] == 0.0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ template <typename TMesh, typename TQEType>
TQEType *
QuadEdgeMeshEulerOperatorJoinVertexFunction<TMesh, TQEType>::ProcessIsolatedQuadEdge(QEType * e)
{
QEType * temp = (e->IsIsolated() == true) ? e->GetSym() : e;
QEType * temp = (e->IsIsolated()) ? e->GetSym() : e;
QEType * rebuildEdge = temp->GetOprev();

m_OldPointID = temp->GetSym()->GetOrigin();
Expand Down Expand Up @@ -296,7 +296,7 @@ QuadEdgeMeshEulerOperatorJoinVertexFunction<TMesh, TQEType>::IsFaceIsolated(QETy
// turn around the face (left or right one) while edges are on the border
// and push them into a stack (which will be used to delete properly all
// elements )
QEType * temp = (iWasLeftFace == true) ? e : e_sym;
QEType * temp = iWasLeftFace ? e : e_sym;
QEType * e_it = temp;

oToBeDeleted.push(e_it);
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/QuadEdgeMesh/test/itkQuadEdgeTest1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ itkQuadEdgeTest1(int, char *[])
quadEdge1->SetOnext(nullptr);
quadEdge1c->IsEdgeInOnextRing(nullptr);

if (quadEdge1c->IsEdgeInOnextRing(quadEdge6) == true)
if (quadEdge1c->IsEdgeInOnextRing(quadEdge6))
{
std::cerr << "Error in IsEdgeInOnextRing() A" << std::endl;
return EXIT_FAILURE;
Expand All @@ -1249,7 +1249,7 @@ itkQuadEdgeTest1(int, char *[])
quadEdge4->SetOnext(quadEdge5);
quadEdge5->SetOnext(quadEdge1);

if (quadEdge1c->IsEdgeInOnextRing(quadEdge6) == true)
if (quadEdge1c->IsEdgeInOnextRing(quadEdge6))
{
std::cerr << "Error in IsEdgeInOnextRing() B" << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -1327,7 +1327,7 @@ itkQuadEdgeTest1(int, char *[])
#ifndef NDEBUG
quadEdgeA1c->IsLnextGivenSizeCyclic(3); // testing null case

if (quadEdgeA1c->IsLnextGivenSizeCyclic(3) == true)
if (quadEdgeA1c->IsLnextGivenSizeCyclic(3))
{
std::cerr << "Error in IsLnextGivenSizeCyclic() A" << std::endl;
return EXIT_FAILURE;
Expand Down Expand Up @@ -1425,7 +1425,7 @@ itkQuadEdgeTest1(int, char *[])
}

// Check a wrong period on purpose
if (quadEdgeA1c->IsLnextGivenSizeCyclic(4) == true)
if (quadEdgeA1c->IsLnextGivenSizeCyclic(4))
{
std::cerr << "Error in IsLnextGivenSizeCyclic() C" << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ BSplineTransformInitializer<TTransform, TImage>::InitializeTransform() const
this->m_Transform->SetTransformDomainOrigin(transformDomainOrigin);
this->m_Transform->SetTransformDomainPhysicalDimensions(transformDomainPhysicalDimensions);
this->m_Transform->SetTransformDomainDirection(transformDomainDirection);
if (this->m_SetTransformDomainMeshSizeViaInitializer == true)
if (this->m_SetTransformDomainMeshSizeViaInitializer)
{
this->m_Transform->SetTransformDomainMeshSize(this->m_TransformDomainMeshSize);
}
Expand All @@ -254,7 +254,7 @@ BSplineTransformInitializer<TTransform, TImage>::PrintSelf(std::ostream & os, In

itkPrintSelfObjectMacro(Transform);

if (this->m_SetTransformDomainMeshSizeViaInitializer == true)
if (this->m_SetTransformDomainMeshSizeViaInitializer)
{
os << indent << "Transform domain mesh size: " << this->m_TransformDomainMeshSize << std::endl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ itkSplineKernelTransformTest(int, char *[])
source2Dit++;
target2Dit++;
}
if (tps2D->IsLinear() == true) // NOTE TPS is never linear!
if (tps2D->IsLinear()) // NOTE TPS is never linear!
{
std::cout << "ERROR: 2D TPS reports as being a linear transform." << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ template <typename TInputImage, typename TOutputImage>
void
ScalarToRGBColormapImageFilter<TInputImage, TOutputImage>::BeforeThreadedGenerateData()
{
if (this->m_UseInputImageExtremaForScaling == true)
if (this->m_UseInputImageExtremaForScaling)
{
ImageRegionConstIterator<InputImageType> It(this->GetInput(), this->GetInput()->GetRequestedRegion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ DisplacementFieldJacobianDeterminantFilter<TInputImage, TRealType, TOutputImage>

// Only reset the weights if they were previously set to the image spacing,
// otherwise, the user may have provided their own weightings.
if (f == false && m_UseImageSpacing == true)
if (f == false && m_UseImageSpacing)
{
for (unsigned int i = 0; i < ImageDimension; ++i)
{
Expand Down Expand Up @@ -145,7 +145,7 @@ DisplacementFieldJacobianDeterminantFilter<TInputImage, TRealType, TOutputImage>
// Set the weights on the derivatives.
// Are we using image spacing in the calculations? If so we must update now
// in case our input image has changed.
if (m_UseImageSpacing == true)
if (m_UseImageSpacing)
{
for (unsigned int i = 0; i < ImageDimension; ++i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ itkSignedDanielssonDistanceMapImageFilterTest11(int, char *[])
return EXIT_FAILURE;
}

if (filter2D->GetSquaredDistance() == true)
if (filter2D->GetSquaredDistance())
{
std::cerr << "filter2D->GetSquaredDistance() == true & it should not" << std::endl;
return EXIT_FAILURE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ itkSignedMaurerDistanceMapImageFilterTest11(int, char *[])
return EXIT_FAILURE;
}

if (filter2D->GetSquaredDistance() == true)
if (filter2D->GetSquaredDistance())
{
std::cerr << "filter2D->GetSquaredDistance() == true and it should not be" << std::endl;
return EXIT_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Filtering/FFT/src/itkFFTWGlobalConfiguration.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ FFTWGlobalConfiguration::SetReadWisdomCache(const bool v)
{
itkInitGlobalsMacro(PimplGlobals);
GetInstance()->m_ReadWisdomCache = v;
if (v == true)
if (v)
{
ImportDefaultWisdomFile();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ GPUDiscreteGaussianImageFilter<TInputImage, TOutputImage>::GPUGenerateData()

// Set up the operator for this dimension
oper[reverse_i].SetDirection(i);
if (this->GetUseImageSpacing() == true)
if (this->GetUseImageSpacing())
{
if (localInput->GetSpacing()[i] == 0.0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ STAPLEImageFilter<TInputImage, TOutputImage>::GenerateData()
flag = true;
}

if (flag == true)
if (flag)
{
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ DerivativeImageFilter<TInputImage, TOutputImage>::GenerateData()
oper.CreateDirectional();
oper.FlipAxes();

if (m_UseImageSpacing == true)
if (m_UseImageSpacing)
{
if (this->GetInput()->GetSpacing()[m_Direction] == 0.0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ DiscreteGaussianDerivativeImageFilter<TInputImage, TOutputImage>::GenerateInputR
// Determine the size of the operator in this dimension. Note that the
// Gaussian is built as a 1D operator in each of the specified directions.
oper.SetDirection(i);
if (m_UseImageSpacing == true)
if (m_UseImageSpacing)
{
oper.SetSpacing(this->GetInput()->GetSpacing()[i]);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ DiscreteGaussianDerivativeImageFilter<TInputImage, TOutputImage>::GenerateData()
// Set up the operator for this dimension
oper[reverse_i].SetDirection(i);
oper[reverse_i].SetOrder(m_Order[i]);
if (m_UseImageSpacing == true)
if (m_UseImageSpacing)
{
// convert the variance from physical units to pixels
double s = localInput->GetSpacing()[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class itkFrequencyFFTLayoutImageRegionIteratorWithIndexTester
if (it.GetIndex() == firstNegativeIndex)
{
// abs value should be equal to largest freq for odd images
if (m_ImageIsOdd == true && m_LargestFrequency != it.GetFrequency() && -m_LargestFrequency != it.GetFrequency())
if (m_ImageIsOdd && m_LargestFrequency != it.GetFrequency() && -m_LargestFrequency != it.GetFrequency())
{
std::cout << " Frequency value is wrong." << it.GetFrequency() << " should be: " << m_LargestFrequency
<< std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ScalarToRGBPixelFunctor<TScalar>::operator()(const TScalar & v) const -> RGBPixe
TScalar buf = v;
const auto * bytes = reinterpret_cast<const unsigned char *>(&buf);

if (this->m_UseMSBForHashing == true)
if (this->m_UseMSBForHashing)
{ // swap bytes
// always swap regardless of system endianness
if (ByteSwapper<TScalar>::SystemIsBigEndian())
Expand Down
Loading

0 comments on commit e7a60b6

Please sign in to comment.