Modular arithmetic

I’ve been working with modular arithmetic these days, and it has been a pain in the neck!

Modular arithmetic consists on defining addition, subtraction, distances, in a circular range of numbers (0 to 12) in clocks for example. The main issue is that there is no greater than or smaller than, just directions!

I would like to suggest support for this feature, as it is quite recurrent when working with circular ranges such as angles.

As a code base I can place my code in an addon ofxMod or similar, but it would be more useful if integrated in OF as a pull request.

If there are enough interested people I will start working on it :smile:

we have something similar in ofWrap:


should give the correct result and there’s also ofAngleDifference and ofLerpAngle but surely having specific arithmetic operations could be useful