bastienleonard / pysfml-cython

A Python 2/3 binding for SFML 2, written with Cython
http://pysfml2-cython.readthedocs.org/
Other
68 stars 8 forks source link

Get Vector2f division operators working with Python3 #21

Closed L-P closed 12 years ago

L-P commented 12 years ago

Python3 does not use __div__ but __floordiv__ and __truediv__ so expressions like sf.Vector2f(4, 2) / 7 raised TypeError exceptions. I did not implement __floordiv__ because it does not make much sense with a vector of floats.

Time.__div__ should get the same treatment but I could not get it to work :

src/sf.cpp:9674:15: error: cannot convert ‘PyObject* {aka _object*}’ to ‘__pyx_obj_2sf_Time*’ in assignment

Did not make much sense to me.

bastienleonard commented 12 years ago

Time.__div__ should get the same treatment but I could not get it to work :

It probably just needs a cast, I'll try to add it.

bastienleonard commented 12 years ago

I have added __truediv__ in Time. I also realized that your modification relies on the first argument to be self. This doesn't work with the way Cython does arithmetic operator overloading, see http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods. So I simply duplicated the old code of __div__ in __truediv__. It also saves one runtime method call. (We could make it a C function, but then it would need to be far outside of the methods that call it.)

L-P commented 12 years ago

I had a little doubt about that, thanks.