1
0
Fork 0

Use simgear functions for clip and wrap around.

This commit is contained in:
Thomas Geymayer 2012-02-14 14:41:53 +01:00 committed by ThorstenB
parent ccf15ac97e
commit dd3afd4c4e
2 changed files with 3 additions and 12 deletions

View file

@ -144,7 +144,7 @@ For input chunks there exist some more options:
<max> an optional upper limit for the input value to be clamped to. If
<min> equals <max> no limit is applied. (default: 0)
<wrap> instead of clamping to minimum and maximum limits, wrap values
around. (default: false)
around. Values will be in [min, max[ (default: false)
(Usefull for eg. heading selector to start again with 1 for
values higher than 360)

View file

@ -113,18 +113,9 @@ private:
if( prot.max > prot.min )
{
if( prot.wrap )
{
T range = prot.max - prot.min + 1;
if( range > 0 )
{
while( new_val < prot.min )
new_val += range;
while( new_val > prot.max )
new_val -= range;
}
}
new_val = SGMisc<double>::normalizePeriodic(prot.min, prot.max, new_val);
else
new_val = std::min<T>(prot.max, std::max<T>(prot.min, new_val));
new_val = SGMisc<T>::clip(new_val, prot.min, prot.max);
}
setValue(prot.prop, new_val);