Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rect does not support floating point coordinates #12

Open
lordmauve opened this issue Jun 4, 2015 · 6 comments
Open

Rect does not support floating point coordinates #12

lordmauve opened this issue Jun 4, 2015 · 6 comments
Labels
bug Something isn't working minor

Comments

@lordmauve
Copy link
Owner

Originally reported by: Daniel Pope (Bitbucket: lordmauve, GitHub: lordmauve)


This is confusing:

>>> from pygame import Rect
>>> Rect(1.5, 2.6, 7, 0.1)
<rect(1, 2, 7, 0)>

It is inconsistent with Python's own number types, because Python tries to minimise the distinction between integral and float types.


@lordmauve
Copy link
Owner Author

Original comment by Tim Golden (Bitbucket: TJG, GitHub: TJG):


Hmmm. I'm not clear how to proceed on this: we can easily use the Rect subclass I've just created for Issue #11 but we'd have to reimplement every operation to allow for underlying floats, and at some point we'll have to pass the rect to, eg, screen.blit, at which point pygame will presumably complain because the numbers are floats.

Or are you simply suggesting that we store (and display) floats but that all the properties (x, y, topleft etc.) return integers as at present?

@lordmauve
Copy link
Owner Author

Original comment by Daniel Pope (Bitbucket: lordmauve, GitHub: lordmauve):


I was thinking the Rect class could store and return floats and we round them to integers to pass to Pygame's APIs. Either that or pursue a fix in Pygame itself.

@lordmauve
Copy link
Owner Author

Original comment by Tim Golden (Bitbucket: TJG, GitHub: TJG):


Seems to the me that the fix in pygame would be too far-reaching and
possibly break long-standing assumptions. At best you might get away
with a FloatingRect class (or whatever). However, I'm not a pygame dev
so my intuition might well be off here.

I'll try sketching out a pgzero on the back of Issue #11 which holds
floats and see what it looks like.

@lordmauve
Copy link
Owner Author

Original comment by first last (Bitbucket: JustAMan, GitHub: JustAMan):


My guess is probably the solution might be to implement own wrapper which does all the stuff with floats but rounds the coordinates to integers when being used from PyGame point of view.

@lordmauve
Copy link
Owner Author

Original comment by Daniel Pope (Bitbucket: lordmauve, GitHub: lordmauve):


The ZRect class has been implemented to fix this. @tjg and I had a chat offline about the implications of bringing this in and the compatibility problems of doing so. We decided to hold off for the moment. ZRect is available if you need it, but it is clearly different to the default Rect objects in Pygame and Pygame Zero.

@lordmauve
Copy link
Owner Author

We should document the use of ZRect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor
Projects
None yet
Development

No branches or pull requests

1 participant