31 template <FloatType T>
32 [[nodiscard]] T
lerp(T start, T end, T ratio)
noexcept {
33 const auto interpolated = start + (end - start) * ratio;
45 template <FloatType T>
46 [[nodiscard]] T
remap(T x, T newMin, T newMax) {
48 const auto rescaled = (x * (newMax - newMin)) + newMin;
62 template <FloatType T>
63 [[nodiscard]] T
remap(T x, T srcMin, T srcMax, T newMin, T newMax) {
65 const auto normalised = (x - srcMin) / (srcMax - srcMin);
66 return remap<T>(normalised, newMin, newMax);
76 template <FloatType T>
87 template <FloatType T>
101 template <FloatType T>
103 assert(data.size() % 2 == 0);
104 std::span<std::complex<T>> complexView{
reinterpret_cast<std::complex<T>*
>(data.data()), data.size() / 2 };
116 template <FloatType T>
118 std::span<T> interleavedView{
reinterpret_cast<T*
>(data.data()), data.size() * 2 };
119 return interleavedView;
121 template <FloatType T>
122 [[nodiscard]] T
sinc(T x)
noexcept {
123 static constexpr auto epsilon{
static_cast<T
>(1e-6) };
124 if (std::abs(x) < epsilon) {
125 return static_cast<T
>(1.0);
127 const auto xPi = x * std::numbers::pi_v<T>;
128 return std::sin(xPi) / xPi;
Math helper functions and classes.
Definition marvin_Math.h:22
std::span< std::complex< T > > interleavedToComplexView(std::span< T > data)
Definition marvin_Math.h:102
std::span< T > complexViewToInterleaved(std::span< std::complex< T > > data)
Definition marvin_Math.h:117
T lerp(T start, T end, T ratio) noexcept
Definition marvin_Math.h:32
T remap(T x, T newMin, T newMax)
Definition marvin_Math.h:46
T sinc(T x) noexcept
Definition marvin_Math.h:122
POD type that represents a range of values, for classes requiring a min and a max.
Definition marvin_Range.h:21
T max
Definition marvin_Range.h:23
T min
Definition marvin_Range.h:22