mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-28 16:58:57 +08:00
added Calc::map and Calc::clamped_map
This commit is contained in:
parent
ef5714bb83
commit
37a966263d
|
@ -46,6 +46,16 @@ int Calc::clamp_int(int t, int min, int max)
|
|||
return t < min ? min : (t > max ? max : t);
|
||||
}
|
||||
|
||||
float Calc::map(float t, float old_min, float old_max, float new_min, float new_max)
|
||||
{
|
||||
return new_min + ((t - old_min) / (old_max - old_min)) * (new_max - new_min);
|
||||
}
|
||||
|
||||
float Calc::clamped_map(float t, float old_min, float old_max, float new_min, float new_max)
|
||||
{
|
||||
return map(Calc::clamp(t, old_min, old_max), old_min, old_max, new_min, new_max);
|
||||
}
|
||||
|
||||
int Calc::sign(int x)
|
||||
{
|
||||
return (x < 0 ? -1 : (x > 0 ? 1 : 0));
|
||||
|
@ -66,6 +76,11 @@ float Calc::abs(float x)
|
|||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
float Calc::round(float x)
|
||||
{
|
||||
return roundf(x);
|
||||
}
|
||||
|
||||
float Calc::floor(float x)
|
||||
{
|
||||
return floorf(x);
|
||||
|
|
|
@ -28,6 +28,10 @@ namespace Blah
|
|||
|
||||
int clamp_int(int t, int min, int max);
|
||||
|
||||
float map(float t, float old_min, float old_max, float new_min, float new_max);
|
||||
|
||||
float clamped_map(float t, float old_min, float old_max, float new_min, float new_max);
|
||||
|
||||
int sign(int x);
|
||||
|
||||
float sign(float x);
|
||||
|
@ -41,7 +45,9 @@ namespace Blah
|
|||
|
||||
template<class T, class U>
|
||||
T max(T a, U b) { return (T)(a > b ? a : b); }
|
||||
|
||||
|
||||
float round(float x);
|
||||
|
||||
float floor(float x);
|
||||
|
||||
float ceiling(float x);
|
||||
|
|
Loading…
Reference in New Issue
Block a user