Updated the built-in Math::clamp() argument order to behave as the C++17 std::clamp().

This commit is contained in:
Leon Styhre 2020-08-30 22:03:11 +02:00
parent cbe86909f6
commit a6c8f8034e
2 changed files with 6 additions and 5 deletions

View file

@ -151,7 +151,8 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans)
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
if (mIsPlaying && mContext.valid) { if (mIsPlaying && mContext.valid) {
const unsigned int fadeIn = (unsigned int)(Math::clamp(0.0f, mFadeIn, 1.0f) * 255.0f); // This fade in is only used by the video screensaver.
const unsigned int fadeIn = (unsigned int)(Math::clamp(mFadeIn, 0.0f, 1.0f) * 255.0f);
const unsigned int color = const unsigned int color =
Renderer::convertColor((fadeIn << 24) | (fadeIn << 16) | (fadeIn << 8) | 255); Renderer::convertColor((fadeIn << 24) | (fadeIn << 16) | (fadeIn << 8) | 255);
Renderer::Vertex vertices[4]; Renderer::Vertex vertices[4];

View file

@ -51,7 +51,7 @@ namespace Math
return (_num1 > _num2) ? _num1 : _num2; return (_num1 > _num2) ? _num1 : _num2;
} }
float clamp(const float _min, const float _max, const float _num) float clamp(const float _num, const float _min, const float _max)
{ {
return max(min(_num, _max), _min); return max(min(_num, _max), _min);
} }
@ -63,18 +63,18 @@ namespace Math
float lerp(const float _start, const float _end, const float _fraction) float lerp(const float _start, const float _end, const float _fraction)
{ {
return (_start + ((_end - _start) * clamp(0, 1, _fraction))); return (_start + ((_end - _start) * clamp(_fraction, 0, 1)));
} }
float smoothStep(const float _left, const float _right, const float _x) float smoothStep(const float _left, const float _right, const float _x)
{ {
const float x = clamp(0, 1, (_x - _left)/(_right - _left)); const float x = clamp((_x - _left)/(_right - _left), 0, 1);
return x * x * (3 - (2 * x)); return x * x * (3 - (2 * x));
} }
float smootherStep(const float _left, const float _right, const float _x) float smootherStep(const float _left, const float _right, const float _x)
{ {
const float x = clamp(0, 1, (_x - _left)/(_right - _left)); const float x = clamp((_x - _left)/(_right - _left), 0, 1);
return x * x * x * (x * ((x * 6) - 15) + 10); return x * x * x * (x * ((x * 6) - 15) + 10);
} }