Skip to content

Commit

Permalink
STYLE: Move static constexpr to local scope where needed
Browse files Browse the repository at this point in the history
These constant values are only used inside operator(), so move local
(static constexpr) variable of operator() instead of a member variable
of the class.
  • Loading branch information
hjmjohnson committed Dec 27, 2024
1 parent 8f5f9b1 commit 3ca7ee5
Showing 1 changed file with 21 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace itk
{
// clang-format off
namespace Function
{
/**
Expand All @@ -41,12 +42,10 @@ class ITK_TEMPLATE_EXPORT CosineWindowFunction
inline TOutput
operator()(const TInput & A) const
{
return static_cast<TOutput>(std::cos(A * m_Factor));
/** Equal to \f$ \frac{\pi}{2 m} \f$ */
static constexpr double factor = Math::pi / (2 * VRadius);
return static_cast<TOutput>(std::cos(A * factor));
}

private:
/** Equal to \f$ \frac{\pi}{2 m} \f$ */
static constexpr double m_Factor = itk::Math::pi / (2 * VRadius);
};

/**
Expand All @@ -63,12 +62,10 @@ class ITK_TEMPLATE_EXPORT HammingWindowFunction
inline TOutput
operator()(const TInput & A) const
{
return static_cast<TOutput>(0.54 + 0.46 * std::cos(A * m_Factor));
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double factor = Math::pi / VRadius;
return static_cast<TOutput>(0.54 + 0.46 * std::cos(A * factor));
}

private:
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double m_Factor = itk::Math::pi / VRadius;
};

/**
Expand All @@ -85,12 +82,10 @@ class ITK_TEMPLATE_EXPORT WelchWindowFunction
inline TOutput
operator()(const TInput & A) const
{
return static_cast<TOutput>(1.0 - A * m_Factor * A);
/** Equal to \f$ \frac{1}{m^2} \f$ */
static constexpr double factor = 1.0 / (VRadius * VRadius);
return static_cast<TOutput>(1.0 - A * factor * A);
}

private:
/** Equal to \f$ \frac{1}{m^2} \f$ */
static constexpr double m_Factor = 1.0 / (VRadius * VRadius);
};

/**
Expand All @@ -113,13 +108,11 @@ class ITK_TEMPLATE_EXPORT LanczosWindowFunction
{
return static_cast<TOutput>(1.0);
} // namespace Function
const double z = m_Factor * A;
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double factor = Math::pi / VRadius;
const double z = factor * A;
return static_cast<TOutput>(std::sin(z) / z);
} // namespace itk

private:
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double m_Factor = itk::Math::pi / VRadius;
};

/**
Expand All @@ -136,17 +129,16 @@ class ITK_TEMPLATE_EXPORT BlackmanWindowFunction
inline TOutput
operator()(const TInput & A) const
{
return static_cast<TOutput>(0.42 + 0.5 * std::cos(A * m_Factor1) + 0.08 * std::cos(A * m_Factor2));
}
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double factor1 = Math::pi / VRadius;

private:
/** Equal to \f$ \frac{\pi}{m} \f$ */
static constexpr double m_Factor1 = itk::Math::pi / VRadius;

/** Equal to \f$ \frac{2 \pi}{m} \f$ */
static constexpr double m_Factor2 = 2.0 * itk::Math::pi / VRadius;
/** Equal to \f$ \frac{2 \pi}{m} \f$ */
static constexpr double factor2 = 2.0 * Math::pi / VRadius;
return static_cast<TOutput>(0.42 + 0.5 * std::cos(A * factor1) + 0.08 * std::cos(A * factor2));
}
};
} // namespace Function
// clang-format on

/**
* \class WindowedSincInterpolateImageFunction
Expand Down Expand Up @@ -356,7 +348,7 @@ class ITK_TEMPLATE_EXPORT WindowedSincInterpolateImageFunction
inline double
Sinc(double x) const
{
const double px = itk::Math::pi * x;
const double px = Math::pi * x;

return (x == 0.0) ? 1.0 : std::sin(px) / px;
}
Expand Down

0 comments on commit 3ca7ee5

Please sign in to comment.