clip() function for integers (Like CLIP macro) and some slightly altered comments/variable names.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5104 4a71c877-e1ca-e34f-864e-861f7616d084
master
Dennis Schridde 2008-05-13 23:19:10 +00:00
parent 6493ff1d2d
commit be2b8a35ab
1 changed files with 25 additions and 12 deletions

View File

@ -72,29 +72,42 @@ static inline WZ_DECL_CONST float rad2degf(float x)
}
/*!
* Moves x into the range 0 - y
* Moves x into the range 0 - max
* \param x Value to clip
* \param y Upper range
* \return Value in the range 0 - y
* \param max Upper range
* \return Value in the range 0 - max
*/
static inline WZ_DECL_CONST WZ_DECL_WARN_UNUSED_RESULT int wrap(int x, int y)
static inline WZ_DECL_CONST int wrap(int x, int max)
{
while(x < 0) x += y;
while(x >= y) x -= y;
while(x < 0) x += max;
while(x >= max) x -= max;
return x;
}
/*!
* Moves x into the range 0.0f - y
* Moves x into the range 0.0f - max
* \param x Value to clip
* \param y Upper range
* \return Value in the range 0.0f - y
* \param max Upper range
* \return Value in the range 0.0f - max
*/
static inline WZ_DECL_CONST WZ_DECL_WARN_UNUSED_RESULT float wrapf(float x, float y)
static inline WZ_DECL_CONST float wrapf(float x, float max)
{
while(x < 0.0f) x += y;
while(x >= y) x -= y;
while(x < 0.0f) x += max;
while(x >= max) x -= max;
return x;
}
/*!
* Clips x to boundaries
* \param x Value to clip
* \param min Lower bound
* \param max Upper bound
*/
static inline WZ_DECL_CONST int clip(int x, int min, int max)
{
if (x < min) return min;
if (x > max) return max;
return x;
}