diff --git a/docs-mini/README.protocol b/docs-mini/README.protocol index e106f5f80..80a7163c6 100644 --- a/docs-mini/README.protocol +++ b/docs-mini/README.protocol @@ -144,7 +144,7 @@ For input chunks there exist some more options: an optional upper limit for the input value to be clamped to. If equals no limit is applied. (default: 0) 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) diff --git a/src/Network/generic.hxx b/src/Network/generic.hxx index 0b27248f5..55f0ca8a5 100644 --- a/src/Network/generic.hxx +++ b/src/Network/generic.hxx @@ -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::normalizePeriodic(prot.min, prot.max, new_val); else - new_val = std::min(prot.max, std::max(prot.min, new_val)); + new_val = SGMisc::clip(new_val, prot.min, prot.max); } setValue(prot.prop, new_val);