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

Re: [pygame] issue with pygame.rect.inflate_ip()



On 04/02/12 07:12 AM, david BERTRAND wrote:
Hi,

I'm new here but I'm working whith pygame (1.9.2) since few month.
When I use inflate() or inflate_ip, the resulting size and the new rect.center are never as expected.

reading the sources (1.9.1, rect.c), I found :

self->r.x -= x / 2;
self->r.y -= y / 2;
self->r.w += x;
self->r.h += y;

if (r.w, r.h) is the size of the rect this is correct.
But it woks like if (r.w, r.h)  represents the rect.bottomright corner.
Andin this case, it seems better to write something like :

self->r.x -= x / 2;
self->r.y -= y / 2;
self->r.w += x / 2;
self->r.h += y / 2;

Please, excuse me if I am wrong : I am not a great C reader.

Hi David,

A rectangle is stored as the position of the top-left corner (r.x, r.y), and the size (r.w, r.h). It is the same with rectangles in Python: Rect(left, top, width, height).

Lenard Lindstrom