vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

rotate number goes up and down indefinitely #30

Closed italomaia closed 10 years ago

italomaia commented 10 years ago

I just noticed polygon:rotate could make my polygon rotation number to go beyong math.py * 2 and there is no documented way to sanitize it. Messing around with _rotation, which is probably a bad idea, does the trick.

My suggestion here is to create a way to allow the developer to sanitize the rotation by himself or do it internally. Don't know if this could be a issue for other projects, but thought it would be worth mentioning.

vrld commented 10 years ago

"Unsanitized" rotation is not a problem, since functions operating on angles are usually periodic and therefore accept angles beyond the range [0:2π]. More importantly, it is also wanted, since this way you can count the number of turns by dividing by 2π. Likewise, you can also determine the direction of turns by looking at the sign of shape:rotation().

However, if you absolutely want to keep rotation in the range [0:2π], you can do the following:

shape:setRotation(shape:rotation() % (2*math.pi))