pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Add skew functionality to pygame.transform

Open Temmie3754 opened this issue 2 years ago • 5 comments
trafficstars

This adds a skew function to the transform module as requested by #2098 with modifications to support inputs of any 4 coordinates to map the surface to. Do note this is still a WIP so the full implementation for release has not been completed, feel free however to test out the current algorithm implementation and submit feedback on it.

Temmie3754 avatar May 04 '23 11:05 Temmie3754

Just two comments regarding this pull request:

  1. The cython files: scrolling through the diff, it seems that the changes are caused by regeneration of these files with a newer version of cython (0.29.30 -> 0.29.34). I assume that it was accidental, but if it were intentional, this should be done in a different pull request.
  2. In #2098 there is discussion regarding how this function should be named, what's the final decision?

gresm avatar May 09 '23 12:05 gresm

  1. Fixed that.
  2. I think using skew() would be most appropriate for this implementation since it doesn't perform a perspective warp operation or a transformation but rather attempts to map all horizontal lines in the original surface to new positions in the new surface by changing the angle and length of each line in the surface. I believe that a quad_transform() naming scheme would be more appropriate for a different implementation that mapped points using a transformation matrix. skew() also fits the naming scheme of the transform module better since quads are not mentioned outside of _sdl2 so using it here may bring about more confusion, especially since this does not work with the quads drawn by the _sdl2 module.

Temmie3754 avatar May 12 '23 11:05 Temmie3754

it doesn't perform a perspective warp operation or a transformation but rather attempts to map all horizontal lines in the original surface to new positions in the new surface by changing the angle and length of each line in the surface.

I do see use cases for this, but it may be redundant. Another thread involves mapping a surface to new points. This skew functionality could be achieved using that method. Although that thread hasn't seen much activity...

simplyrohan avatar May 28 '23 19:05 simplyrohan

I like the name skew, it is familiar to me for this type of operation (and is the sort of word I'd look for in a transform submodule to get this effect). Photoshop and GIMP use shear for this operation, so that is another option if others would prefer that.

I'm happy having a function like this even if you could achieve the same thing with a more complicated warping function as it is likely that users would look for something like this and might not grasp that a more complicated function could be used for the same thing.

If needed we could eventually reduce underlying code duplication by making this API call the more complicated spatial transform with some fixed parameters.

MyreMylar avatar Aug 14 '23 13:08 MyreMylar

Will probably need to write some tests for this and maybe some further changes to the docs but otherwise at this point I think it is fully functional, unless anyone else has other ideas for this PR.

Temmie3754 avatar Oct 08 '24 15:10 Temmie3754