openframeworks/openFrameworks — pull request #2205 by bilderbuchi (2013-07-09 20:33:47+00:00)
Title: Fix while loops in angle wrappers

My proposed fix for #2052.

Added a generic `ofWrap(value, from, to)` function which wraps an arbitrary float into the interval between two others.
I picked a [simpler](http://stackoverflow.com/a/5852628/599884), but not numerically totally accurate etc. algorithm. [The "better" alternative](http://stackoverflow.com/a/4635752/599884) is most probably numerical precision overkill for OF.

This now makes some strange (ab)use cases impossible (https://github.com/openframeworks/openFrameworks/issues/2052#issuecomment-20253606)

@bakercp: I left the [one remaining](https://github.com/bilderbuchi/openFrameworks/blob/f6b0413051991cb85bb2810bdc4f898f3de67c25/libs/openFrameworks/graphics/ofPolyline.cpp#L297) while loop instance in ofPolyline alone for now, because I'm not sure how you wanted to handle edge cases. since both `angleBeginRad` and `angleEndRad` will be wrapped into `[0, 2PI]`, the while loop could be replace by an if statement, except for I don't know what should happen if `angleBeginRad==2_PI` and `angleEndRad==0.0`?

One caveat: the cycle is solely determined by `to-from`, so it's possible to do `ofWrapDegrees(40, 0, M_TWOPI)`, which would still wrap into a 2PI range not 360. I could add an ofLog warning to `ofWrapDegrees()` and `ofWrapRadians()` if the cycle is not right (doing a fuzzy float comparison), but I'm not sure if it's worth the probably performance penalty, because the above use doesn't make much sense in the first place.
Opinions?