Skip to content

Commit

Permalink
STYLE: Reduce indentation else after return
Browse files Browse the repository at this point in the history
    Reduce indentation where possible and where it makes understanding code easier.
    Early exit is one of the suggested enforcements of that. Please do not use else
    or else if after something that interrupts control flow - like return, break,
    continue, throw.

    clang-tidy readability-else-after-return
  • Loading branch information
hjmjohnson committed Dec 22, 2024
1 parent a635c12 commit 1980927
Show file tree
Hide file tree
Showing 395 changed files with 2,671 additions and 3,783 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ class RescaleDynamicRangeFunctor
{
return static_cast<OutputPixelType>(255);
}
else
{
return itk::Math::Round<OutputPixelType>(-(30.0 * std::log(A)));
}
return itk::Math::Round<OutputPixelType>(-(30.0 * std::log(A)));
}
else
{
Expand Down
6 changes: 2 additions & 4 deletions Examples/Statistics/WeightedSampleStatistics.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ class ExampleWeightFunction
{
return 0.5;
}
else
{
return 0.01;
}

return 0.01;
}

protected:
Expand Down
6 changes: 2 additions & 4 deletions Modules/Bridge/VTK/src/itkVTKImageExportBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ VTKImageExportBase::PipelineModifiedCallback()
m_LastPipelineMTime = pipelineMTime;
return 1;
}
else
{
return 0;
}

return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
{
return TRealValueType{ 0.5 };
}
else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
{
return TRealValueType{ 1.0 };
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
{
return (TRealValueType{ -2.0 } * u);
}
else if ((u >= TRealValueType{ 0.5 }) && (u < TRealValueType{ 1.5 }))
if ((u >= TRealValueType{ 0.5 }) && (u < TRealValueType{ 1.5 }))
{
return (TRealValueType{ -1.5 } + u);
}
Expand All @@ -161,7 +161,7 @@ class ITK_TEMPLATE_EXPORT BSplineDerivativeKernelFunction : public KernelFunctio
{
return (TRealValueType{ -2.0 } * u + TRealValueType{ 1.5 } * u * u);
}
else if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
if ((u > TRealValueType{ -1.0 }) && (u < TRealValueType{ 0.0 }))
{
return (TRealValueType{ -2.0 } * u - TRealValueType{ 1.5 } * u * u);
}
Expand Down
12 changes: 5 additions & 7 deletions Modules/Core/Common/include/itkBSplineKernelFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
{
return TRealValueType{ 1.0 };
}
else if (Math::ExactlyEquals(absValue, TRealValueType{ 0.5 }))
if (Math::ExactlyEquals(absValue, TRealValueType{ 0.5 }))
{
return TRealValueType{ 0.5 };
}
Expand All @@ -122,10 +122,8 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
{
return TRealValueType{ 1.0 } - absValue;
}
else
{
return TRealValueType{ 0.0 };
}

return TRealValueType{ 0.0 };
}

/** Second order spline. */
Expand All @@ -138,7 +136,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
const TRealValueType sqrValue = itk::Math::sqr(absValue);
return TRealValueType{ 0.75 } - sqrValue;
}
else if (absValue < TRealValueType{ 1.5 })
if (absValue < TRealValueType{ 1.5 })
{
const TRealValueType sqrValue = itk::Math::sqr(absValue);
// NOTE: 1.0/8.0 == 0.125
Expand All @@ -162,7 +160,7 @@ class ITK_TEMPLATE_EXPORT BSplineKernelFunction : public KernelFunctionBase<TRea
return (TRealValueType{ 4.0 } - TRealValueType{ 6.0 } * sqrValue + TRealValueType{ 3.0 } * sqrValue * absValue) /
TRealValueType{ 6.0 };
}
else if (absValue < TRealValueType{ 2.0 })
if (absValue < TRealValueType{ 2.0 })
{
const TRealValueType sqrValue = itk::Math::sqr(absValue);
return (TRealValueType{ 8.0 } - TRealValueType{ 12.0 } * absValue + TRealValueType{ 6.0 } * sqrValue -
Expand Down
16 changes: 6 additions & 10 deletions Modules/Core/Common/include/itkColorTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,10 @@ ColorTable<TComponent>::GetColor(unsigned int c)
{
return m_Color[c];
}
else
{
RGBPixel<TComponent> pixel;
pixel.Set(0, 0, 0);
return pixel;
}

RGBPixel<TComponent> pixel;
pixel.Set(0, 0, 0);
return pixel;
}

template <typename TComponent>
Expand Down Expand Up @@ -329,10 +327,8 @@ ColorTable<TComponent>::GetColorName(unsigned int c)
{
return m_ColorName[c];
}
else
{
return "";
}

return "";
}

template <typename TComponent>
Expand Down
28 changes: 13 additions & 15 deletions Modules/Core/Common/include/itkConstNeighborhoodIterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::IndexInBounds(const Neigh
{
return true;
}
else if (this->InBounds()) // Is this whole neighborhood in bounds?
if (this->InBounds()) // Is this whole neighborhood in bounds?
{
return true;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::IndexInBounds(const Neigh
{
return true;
}
else if (this->InBounds()) // Is this whole neighborhood in bounds?
if (this->InBounds()) // Is this whole neighborhood in bounds?
{
return true;
}
Expand Down Expand Up @@ -162,21 +162,19 @@ ConstNeighborhoodIterator<TImage, TBoundaryCondition>::GetPixel(NeighborIndexTyp
IsInBounds = true;
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
}

OffsetType offset;
OffsetType internalIndex;
const bool flag = this->IndexInBounds(n, internalIndex, offset);
if (flag)
{
IsInBounds = true;
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
}
else
{
OffsetType offset;
OffsetType internalIndex;
const bool flag = this->IndexInBounds(n, internalIndex, offset);
if (flag)
{
IsInBounds = true;
return (m_NeighborhoodAccessorFunctor.Get(this->operator[](n)));
}
else
{
IsInBounds = false;
return (m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, this->m_BoundaryCondition));
}
IsInBounds = false;
return (m_NeighborhoodAccessorFunctor.BoundaryCondition(internalIndex, offset, this, this->m_BoundaryCondition));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ConstNeighborhoodIteratorWithOnlyIndex<TImage>::IndexInBounds(const NeighborInde
{
return true;
}
else if (this->InBounds()) // Is this whole neighborhood in bounds?
if (this->InBounds()) // Is this whole neighborhood in bounds?
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ class ITK_TEMPLATE_EXPORT ConstShapedNeighborhoodIterator : private Neighborhood
{
return true;
}
else
{
return false;
}

return false;
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,17 @@ ConstShapedNeighborhoodIterator<TImage, TBoundaryCondition>::DeactivateIndex(Nei
{
return;
}
else

while (n != *it)
{
while (n != *it)
++it;
if (it == m_ActiveIndexList.end())
{
++it;
if (it == m_ActiveIndexList.end())
{
return;
}
return;
}
m_ActiveIndexList.erase(it);
}
m_ActiveIndexList.erase(it);


// Did we just deactivate the index at the center of the neighborhood?
if (n == this->GetCenterNeighborhoodIndex())
Expand Down
12 changes: 4 additions & 8 deletions Modules/Core/Common/include/itkEquivalencyTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ class ITKCommon_EXPORT EquivalencyTable : public DataObject
{
return a;
}
else
{
return result->second;
}

return result->second;
}

/** Lookup an equivalency in the table by recursing through all
Expand All @@ -120,10 +118,8 @@ class ITKCommon_EXPORT EquivalencyTable : public DataObject
{
return false;
}
else
{
return true;
}

return true;
}

/** Erases the entry with key a. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ FiniteCylinderSpatialFunction<VDimension, TInput>::Evaluate(const InputType & po
{
return 1;
}
else
{
return 0;
}

return 0;
}

template <unsigned int VDimension, typename TInput>
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkFrustumSpatialFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FrustumSpatialFunction<VDimension, TInput>::Evaluate(const InputType & position)

return 1;
}
else if (m_RotationPlane == RotationPlaneEnum::RotateInYZPlane)
if (m_RotationPlane == RotationPlaneEnum::RotateInYZPlane)
{
const double dx = relativePosition[0];
const double dy = relativePosition[1];
Expand Down
54 changes: 25 additions & 29 deletions Modules/Core/Common/include/itkGaussianDerivativeOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ GaussianDerivativeOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI1(dou
{
return -accumulator;
}
else
{
return accumulator;
}

return accumulator;
}

template <typename TPixel, unsigned int VDimension, typename TAllocator>
Expand All @@ -242,37 +240,35 @@ GaussianDerivativeOperator<TPixel, VDimension, TAllocator>::ModifiedBesselI(int
{
return 0.0;
}
else

const double toy = 2.0 / itk::Math::abs(y);
double qip = accumulator = 0.0;
double qi = 1.0;
for (int j = 2 * (n + static_cast<int>(DIGITS * std::sqrt(static_cast<double>(n)))); j > 0; j--)
{
const double toy = 2.0 / itk::Math::abs(y);
double qip = accumulator = 0.0;
double qi = 1.0;
for (int j = 2 * (n + static_cast<int>(DIGITS * std::sqrt(static_cast<double>(n)))); j > 0; j--)
const double qim = qip + j * toy * qi;
qip = qi;
qi = qim;
if (itk::Math::abs(qi) > 1.0e10)
{
const double qim = qip + j * toy * qi;
qip = qi;
qi = qim;
if (itk::Math::abs(qi) > 1.0e10)
{
accumulator *= 1.0e-10;
qi *= 1.0e-10;
qip *= 1.0e-10;
}
if (j == n)
{
accumulator = qip;
}
accumulator *= 1.0e-10;
qi *= 1.0e-10;
qip *= 1.0e-10;
}
accumulator *= ModifiedBesselI0(y) / qi;
if (y < 0.0 && (n & 1))
if (j == n)
{
return -accumulator;
}
else
{
return accumulator;
accumulator = qip;
}
}
accumulator *= ModifiedBesselI0(y) / qi;
if (y < 0.0 && (n & 1))
{
return -accumulator;
}
else
{
return accumulator;
}
}

template <typename TPixel, unsigned int VDimension, typename TAllocator>
Expand Down
Loading

0 comments on commit 1980927

Please sign in to comment.