[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] Re: Rectangles, question about bottom and right



owner-pygame-users@seul.org wrote:

> List,
>
> I've noticed that the Rect.bottom and Rect.right attributes do not
> give me the values I expect them to.  (Which could be because I'm
> not expecting the right thing :)
>
> For example:
>
>>>>r = Rect(0,0,1,1)
>>>>r.bottom
>>>
> 1
>
>>>>r.right
>>>
> 1
>
> It seems to me that for a rectangle with the width of one, r.right
> should be the same value as r.left.
>
> Thus, I'd propose that these are the correct values...
> r.right = r.left + r.width - 1
> r.bottom = r.top + r.height - 1
>
> In interval terms, the problem I see is that a Rect covers the area of
> [top,bottom) x [left,right) as opposed to [top,bottom] x [left,right]
>
> Any thoughts?


argh, the tricky issues of the bottomright edge of the rectangle. basically
all rectangle issues are inclusive on the top left edge and exclusive on
the bottom-right edges. this is pretty much as you've figured out. this is
how SDL handles it's rectangle arguments, and i've carried it over to
pygame as well.

obviously there are pros and cons to this method. i thought about it for
awhile when writing pygame, and i think it is the best way to handle
things. from my perspective this makes the rectangles easy to deal with in
my 'human terms'. for example, width and height are always the number of
pixels to draw across, and "right - left == width" and "left + width ==
right". these examples become false if we change the value of the right edge.

this also makes it easy in graphics terms to line objects up next to each
other (which is usually preferred in graphics, as opposed to overlapping by
a single pixel). so you can say rect2.left = rect1.right and you will get
two rectangles that line up right next to each other.

i've done some looking around, and this sort of rectangle format seems
pretty popular. it is used be several other graphic libraries as well. in
fact, i haven't looked hard, but i haven't seen anything else use a
different meaning for the rectangles? i am curious to find one though and
see how it works.

anyways, for the most part all these rectangles "make sense to me", but
occasionally i can get on the wrong side of the fence and see things from
the other side, then i get confused, heh.







____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org