kivy / cymunk

Cython port of Pymunk
http://readthedocs.org/docs/cymunk/en/latest/
MIT License
45 stars 29 forks source link

Polygon Get Vertices Issue #17

Closed pearsonkyle closed 10 years ago

pearsonkyle commented 10 years ago

Hi,

I wasn't able to properly retrieve the vertices for a polygon shape due to some operations not being supported by the cpVect class (or Vec2d), so I hacked in a solution (check shape.pxi and core.pxi). Before you test my build please run the kivy_demo.py in the examples folder to see if your build will work, hopefully it should raise some errors and then test my new build.

Thank you for you time, I'm happy to answer any questions.

The issue was that the Vec2d '+' operator didn't want to work in my cymunk build (possibly because my cymunk build was older?) Also when trying to rotate the vectors to get the proper vertices there was no cpvrotate function.

Kovak commented 10 years ago

Hello,

First of all, thanks for finding this issue and taking a shot at fixing it!

Could you try the chipmunk6.2 branch. I have fixed get_vertices in this branch.

To give some explanation as to why I did not go in the same direction as this PR:

  1. In core.pxi, rotate is meant to rotate that vector in place. Adding the return of a list of the float values changes what this function does as no return was previously in the api. In addition, this is unnecessary as you could always read the values of the Vec2d to find out what the new vector is.
  2. The old get_vertices loop was sort of silly because it bothered to type out the structure of the loop for Cython but then interacted with the python version of the objects. I have changed this to perform as much of the calculation as possible using chipmunks native c functions and to write out the points to Vec2d's afterwards. This ensures less work is done in Python, and makes the code much simpler, and that the return type of Vec2d is consistent with the rest of the api rather than converting to tuples.
pearsonkyle commented 10 years ago

Hey,

Thanks for the fix! Everything is working just fine now.