Rect::colliderect bug

Issue #215 closed
Former user created an issue

colliderect() sometimes returns 0 where it should clearly return 1. A few tests suggest that this is due to careless rounding down.

Example of intersecting rectangles for which colliderect() returns 0:

>>> r1 = Rect((0.1,0),(10,10))
>>> r2 = Rect((10,0),(10,10))
>>> r1.colliderect(r2)
>>> r2.colliderect(r1)

And similarly in the y direction.

Comments (8)

  1. Jason Marshall

    Sorry, no. The values that are passed to pygame.Rect are converted to integers. In your example, r1 would be equal to Rect((0, 0), (10, 10)).

  2. Jason Marshall

    The most common use cases for the Rect class involve use with (non-OpenGL) 2D raster graphics, for which float values would not make sense. That's why Rect coerces floats to integers.

  3. Denis B

    Agree, did not read Rect documentation carefully. Though I think such a central remark could have been made more visible in the class documentation.

  4. Log in to comment