diff --git a/lion/foundation/utils.h b/lion/foundation/utils.h index ac7d59c..dc83bfb 100644 --- a/lion/foundation/utils.h +++ b/lion/foundation/utils.h @@ -158,6 +158,9 @@ constexpr T smooth_step(const T &x, S eps); template constexpr T smooth_deadzone(const T &x, const T1 &lo, const T2 &hi, S eps2); +template +constexpr T smooth_antipulse(const T &x, const T1 &lo, const T2 &hi, S eps); + template constexpr std::vector linspace(T lo, T hi, std::size_t num_points); diff --git a/lion/foundation/utils.hpp b/lion/foundation/utils.hpp index 74d0a8f..916c861 100644 --- a/lion/foundation/utils.hpp +++ b/lion/foundation/utils.hpp @@ -236,7 +236,6 @@ constexpr T smooth_sign(const T &x, S eps) if constexpr (ActuallySmooth) { if constexpr (UseSmoothAbsFormula) { - return x / smooth_abs(x, eps * eps); } else { @@ -431,10 +430,10 @@ template constexpr T smooth_deadzone(const T &x, const T1 &lo, const T2 &hi, S eps2) { // - // Implements the "smooth deadzone" function, in which the output - // is zero for x in "[lo, hi]", equal to "x - lo" if x < lo, and - // equal to "x - hi" if x > hi. When template parameter "ActuallySmooth" - // is true, the deadzone's sharpness is smoothed out with parameter + // Implements the "smooth deadzone" function, whose output is zero + // for x in "[lo, hi]", equal to "x - lo" if x < lo, and equal to + // "x - hi" if x > hi. When template parameter "ActuallySmooth" is + // true, the deadzone's sharpness is smoothed out with parameter // "eps2", else, it is the strict deadzone function. // @@ -442,6 +441,21 @@ constexpr T smooth_deadzone(const T &x, const T1 &lo, const T2 &hi, S eps2) } +template +constexpr T smooth_antipulse(const T &x, const T1 &lo, const T2 &hi, S eps) +{ + // + // Implements the "smooth antipulse" function, whose output is zero + // for x in "[lo, hi]", and equal to 1 otherwise. When template + // parameter "ActuallySmooth" is true, the pulse's sharpness is + // smoothed out with parameter "eps", else, it is the strict + // antipulse function. + // + + return smooth_step(x - hi, eps) + smooth_step(lo - x, eps); +} + + template constexpr std::vector linspace(T lo, T hi, std::size_t num_points) {