X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2FSGExpression.hxx;h=420a9045ce001926310942e49e4ffbdaa21b2327;hb=c82df0590dd46347e2f1d0dca4cc3712f67f3654;hp=1589aab1ce95a4ae9bc8b809eb2b19e22b6dc390;hpb=59ef7d8fd12da6a2651fd915f0bcefaedc0d7c28;p=simgear.git diff --git a/simgear/structure/SGExpression.hxx b/simgear/structure/SGExpression.hxx index 1589aab1..420a9045 100644 --- a/simgear/structure/SGExpression.hxx +++ b/simgear/structure/SGExpression.hxx @@ -122,6 +122,9 @@ public: T getValue(const simgear::expression::Binding* binding = 0) const { T value; eval(value, binding); return value; } + double getDoubleValue(const simgear::expression::Binding* binding = 0) const + { T value; eval(value, binding); return value; } + virtual bool isConst() const { return false; } virtual SGExpression* simplify(); virtual simgear::expression::Type getType() const @@ -319,7 +322,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = acos(SGMisc::clip(getOperand()->getValue(b), -1, 1)); } + { value = acos((double)SGMisc::clip(getOperand()->getValue(b), -1, 1)); } using SGUnaryExpression::getOperand; }; @@ -332,7 +335,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = asin(SGMisc::clip(getOperand()->getValue(b), -1, 1)); } + { value = asin((double)SGMisc::clip(getOperand()->getValue(b), -1, 1)); } using SGUnaryExpression::getOperand; }; @@ -345,7 +348,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = atan(getOperand()->getValue(b)); } + { value = atan(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -358,7 +361,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = ceil(getOperand()->getValue(b)); } + { value = ceil(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -371,7 +374,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = cos(getOperand()->getValue(b)); } + { value = cos(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -384,7 +387,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = cosh(getOperand()->getValue(b)); } + { value = cosh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -397,7 +400,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = exp(getOperand()->getValue(b)); } + { value = exp(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -410,7 +413,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = floor(getOperand()->getValue(b)); } + { value = floor(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -423,7 +426,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = log(getOperand()->getValue(b)); } + { value = log(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -436,7 +439,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = log10(getOperand()->getValue(b)); } + { value = log10(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -449,7 +452,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sin(getOperand()->getValue(b)); } + { value = sin(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -462,7 +465,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sinh(getOperand()->getValue(b)); } + { value = sinh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -488,7 +491,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = sqrt(getOperand()->getValue(b)); } + { value = sqrt(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -501,7 +504,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = tan(getOperand()->getValue(b)); } + { value = tan(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -514,7 +517,7 @@ public: { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = tanh(getOperand()->getValue(b)); } + { value = tanh(getOperand()->getDoubleValue(b)); } using SGUnaryExpression::getOperand; }; @@ -662,24 +665,16 @@ 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; - } + if( _step <= SGLimits::min() ) return property; + + // apply stepping of input value + T modprop = floor(property/_step)*_step; + + // calculate scroll amount (for odometer like movement) + T remainder = property <= SGLimits::min() ? -fmod(property,_step) : (_step - fmod(property,_step)); + if( remainder > SGLimits::min() && remainder < _scroll ) + modprop += (_scroll - remainder) / _scroll * _step; + return modprop; } @@ -731,7 +726,7 @@ public: : SGBinaryExpression(expr0, expr1) { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = atan2(getOperand(0)->getValue(b), getOperand(1)->getValue(b)); } + { value = atan2(getOperand(0)->getDoubleValue(b), getOperand(1)->getDoubleValue(b)); } using SGBinaryExpression::getOperand; }; @@ -771,7 +766,7 @@ public: : SGBinaryExpression(expr0, expr1) { } virtual void eval(T& value, const simgear::expression::Binding* b) const - { value = pow(getOperand(0)->getValue(b), getOperand(1)->getValue(b)); } + { value = pow(getOperand(0)->getDoubleValue(b), getOperand(1)->getDoubleValue(b)); } using SGBinaryExpression::getOperand; }; @@ -794,6 +789,25 @@ public: using SGNaryExpression::getOperand; }; +template +class SGDifferenceExpression : public SGNaryExpression { +public: + SGDifferenceExpression() + { } + SGDifferenceExpression(SGExpression* expr0, SGExpression* expr1) + : SGNaryExpression(expr0, expr1) + { } + virtual void eval(T& value, const simgear::expression::Binding* b) const + { + value = getOperand(0)->getValue(b); + unsigned sz = SGNaryExpression::getNumOperands(); + for (unsigned i = 1; i < sz; ++i) + value -= getOperand(i)->getValue(b); + } + using SGNaryExpression::getValue; + using SGNaryExpression::getOperand; +}; + template class SGProductExpression : public SGNaryExpression { public: @@ -1202,7 +1216,7 @@ namespace simgear void eval(bool& value, const expression::Binding* b) const { value = false; - for (int i = 0; i < getNumOperands(); ++i) { + for (int i = 0; i < (int)getNumOperands(); ++i) { value = value || getOperand(i)->getValue(b); if (value) return; @@ -1216,7 +1230,7 @@ namespace simgear void eval(bool& value, const expression::Binding* b) const { value = true; - for (int i = 0; i < getNumOperands(); ++i) { + for (int i = 0; i < (int)getNumOperands(); ++i) { value = value && getOperand(i)->getValue(b); if (!value) return; @@ -1234,7 +1248,7 @@ namespace simgear ConvertExpression() {} ConvertExpression(::SGExpression* expr0) { - addOperand(expr0); + this->addOperand(expr0); } virtual void eval(T& value, const simgear::expression::Binding* b) const {