From 6bfba4064bdc025782930549f7edf41985fc197d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 27 Aug 2011 23:30:44 +0200 Subject: [PATCH] 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. --- code/math.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code/math.h b/code/math.h index 716767d..e972c2e 100644 --- a/code/math.h +++ b/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) { if (*in < low) - *in = high; + *in += high - low; if (*in > high) - *in = low; + *in -= high - low; } static inline void wrapInt(int *in, int low, int high) { if (*in < low) - *in = high; + *in += high - low; if (*in > high) - *in = low; + *in -= high - low; } static inline void wrapFloat(float *in, float low, float high) { if (*in < low) - *in = high; + *in += high - low; if (*in > high) - *in = low; + *in -= high - low; } static inline int rrand(int min, int max)