2021-11-19 17:22:09 +01:00
|
|
|
#pragma once
|
|
|
|
|
2021-11-16 22:04:22 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
static inline float bellCurveApproximation(float x, float inverseWidth)
|
|
|
|
{
|
|
|
|
if (x < 0)
|
|
|
|
x = -x;
|
|
|
|
|
|
|
|
const auto nx = x * inverseWidth * 4;
|
|
|
|
if (nx > 2)
|
|
|
|
return 0.0f;
|
|
|
|
|
|
|
|
const auto x2 = nx * nx;
|
|
|
|
const auto x3 = x2 * nx;
|
|
|
|
const auto res = 1.0f + 0.27606958941084f * x3 - 0.80213917882168f * x2;
|
|
|
|
|
|
|
|
return res < 0.0f ? 0.0f : res;
|
2021-12-20 20:41:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Function start at 0 (x=0) and goes smoothly up to 1 and arrives 1 at x=width
|
|
|
|
// inverse width has to be 1 / width (should be cached outside)
|
|
|
|
static inline float stepFunction(float x, float width, float inverseWidth)
|
|
|
|
{
|
|
|
|
if (x < 0.0f)
|
|
|
|
return 0.0f;
|
|
|
|
if (x >= width)
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
auto bellInvWidth = inverseWidth * 0.5f;
|
|
|
|
auto nx = (-x + width) * bellInvWidth * 4;
|
|
|
|
auto x2 = nx * nx;
|
|
|
|
auto x3 = x2 * nx;
|
|
|
|
return 1 + 0.2760695894 * x3 - 0.8021391 * x2;
|
2021-11-16 22:04:22 +01:00
|
|
|
}
|