al::normalize 1:1 fix

This commit is contained in:
shibbo 2020-07-24 01:43:47 -04:00
parent 73aa9ab4db
commit 9155ed1c05

View File

@ -1,27 +1,45 @@
#include <al/util/Mathutil.h>
#include "al/util/MathUtil.h"
float normalize(signed int var, signed int min, signed int max)
namespace al
{
signed int v3;
float result;
float normalize(signed int var, signed int min, signed int max)
{
signed int v3;
float result;
if ( var <= min )
return 0.0;
if ( max - min <= 0 )
{
result = 1.0;
if ( var < min )
result = 0.0;
}
else
{
if ( var <= max )
v3 = var;
else
v3 = max;
if ( var < min )
v3 = min;
result = (v3 - min) / (max - min);
}
return result;
}
if (var <= min)
{
return 0.0f;
}
if (max - min <= 0)
{
result = 1.0f;
if (var < min)
{
result = 0.0f;
}
}
else
{
if (var <= max)
{
v3 = var;
}
else
{
v3 = max;
}
if (var < min)
{
v3 = min;
}
result = (static_cast<float>(v3 - min) / static_cast<float>(max - min));
}
return result;
}
};