[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] BUG: pygame.Rect collidepoint() flawed



My bad. I didn't realize the last 2 params were width and height and
not the coordinates of the bottom right corner.
Sorry about the false alert!

Thanks for the prompt response.
- Guillaume Rava.

On 4/20/07, James Paige <Bob@xxxxxxxxxxxxxxxxxxx> wrote:
On Fri, Apr 20, 2007 at 03:16:19PM -0700, Guillaume Rava wrote:
> Hello,
>
> It seems Rect.collidepoint(x,y) works fine as long as the Rect's top
> and left values are set to zero. When the Rect object is offset from
> zero, collidepoint returns 1 when (x,y) is outside of the Rect.
> Example:
>
> >>>import pygame
> >>>r = pygame.Rect(10,10,110,110)
> >>>r.collidepoint(0,0) # GOOD
> 0
> >>>r.collidepoint(10,10) # GOOD
> 1
> >>>r.collidepoint(110,110) # BAD
> 1
> >>>r.collidepoint(119,119) # BAD
> 1
> >>>r.collidepoint(120,120) # GOOD
> 0

You misunderstand intended rectangle behaviour.

The third and fourth arguments to pygame.Rect(10,10,110,110) are the
width and height, NOT the bottom right corner.

Furthermore, moving corner points does not resize the rectangle. Moving
corner points (even bottom right) moves the whole rectangle.

---
James Paige