From: Torsten Dreyer Date: Wed, 25 May 2011 17:14:09 +0000 (+0200) Subject: Fix bug #285 textranslate and scroll animation with negative numbers X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ca668f8a373190093738a69a5b700d6fcc086c7c;p=simgear.git Fix bug #285 textranslate and scroll animation with negative numbers rewrite SGStepExpression::apply_mods so it creates the same step for negative numbers as it does for positive numbers. --- diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index ffb9dd1d..1f599b76 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -665,24 +665,14 @@ public: private: T apply_mods(T property) const { - T modprop; - if (_step > 0) { - T scrollval = 0; - if(_scroll > 0) { - // calculate scroll amount (for odometer like movement) - T remainder = _step - fmod(fabs(property), _step); - if (remainder < _scroll) { - scrollval = (_scroll - remainder) / _scroll * _step; - } - } - // apply stepping of input value - if(property > 0) - modprop = ((floor(property/_step) * _step) + scrollval); - else - modprop = ((ceil(property/_step) * _step) + scrollval); - } else { - modprop = property; - } + // apply stepping of input value + T modprop = floor(property/_step)*_step; + + // calculate scroll amount (for odometer like movement) + T remainder = property < 0 ? -fmod(property,_step) : (_step - fmod(property,_step)); + if( remainder > 0.0 && remainder < _scroll ) + modprop += (_scroll - remainder) / _scroll * _step; + return modprop; }