Make wrap() functions really wrap.
Before, if a value was over one of the limits, it would be set to the other limit. For most usecases, that was fine, however for the starfield this would cause stars to become aligned to each other after a while.
This commit is contained in:
parent
1abf5d8c67
commit
6bfba4064b
12
code/math.h
12
code/math.h
|
@ -73,25 +73,25 @@ static inline void limitFloat(float *in, float low, float high)
|
||||||
static inline void wrapChar(signed char *in, signed char low, signed char high)
|
static inline void wrapChar(signed char *in, signed char low, signed char high)
|
||||||
{
|
{
|
||||||
if (*in < low)
|
if (*in < low)
|
||||||
*in = high;
|
*in += high - low;
|
||||||
if (*in > high)
|
if (*in > high)
|
||||||
*in = low;
|
*in -= high - low;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void wrapInt(int *in, int low, int high)
|
static inline void wrapInt(int *in, int low, int high)
|
||||||
{
|
{
|
||||||
if (*in < low)
|
if (*in < low)
|
||||||
*in = high;
|
*in += high - low;
|
||||||
if (*in > high)
|
if (*in > high)
|
||||||
*in = low;
|
*in -= high - low;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void wrapFloat(float *in, float low, float high)
|
static inline void wrapFloat(float *in, float low, float high)
|
||||||
{
|
{
|
||||||
if (*in < low)
|
if (*in < low)
|
||||||
*in = high;
|
*in += high - low;
|
||||||
if (*in > high)
|
if (*in > high)
|
||||||
*in = low;
|
*in -= high - low;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int rrand(int min, int max)
|
static inline int rrand(int min, int max)
|
||||||
|
|
Loading…
Reference in New Issue