From a6c8f8034e50cbd89c9badc85602654c7a1b4ac0 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 30 Aug 2020 22:03:11 +0200 Subject: [PATCH] Updated the built-in Math::clamp() argument order to behave as the C++17 std::clamp(). --- es-core/src/components/VideoVlcComponent.cpp | 3 ++- es-core/src/math/Misc.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/es-core/src/components/VideoVlcComponent.cpp b/es-core/src/components/VideoVlcComponent.cpp index 1f2c175f2..c76649c5d 100644 --- a/es-core/src/components/VideoVlcComponent.cpp +++ b/es-core/src/components/VideoVlcComponent.cpp @@ -151,7 +151,8 @@ void VideoVlcComponent::render(const Transform4x4f& parentTrans) Renderer::setMatrix(trans); 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 = Renderer::convertColor((fadeIn << 24) | (fadeIn << 16) | (fadeIn << 8) | 255); Renderer::Vertex vertices[4]; diff --git a/es-core/src/math/Misc.cpp b/es-core/src/math/Misc.cpp index 96578f31a..2442bb139 100644 --- a/es-core/src/math/Misc.cpp +++ b/es-core/src/math/Misc.cpp @@ -51,7 +51,7 @@ namespace Math 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); } @@ -63,18 +63,18 @@ namespace Math 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) { - 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)); } 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); }