[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Rect.union and rectangle positions
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Rect.union and rectangle positions
- From: "Brian Fisher" <brian@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 2 Dec 2006 09:42:53 -0800
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 02 Dec 2006 12:50:22 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=kf2HWWpaJN6qulvvOLSxGpxKx43IE2hywfx+trS8+h34DpyJ38WaxjvuKLY3IkcLbslXRKO85d8Fnv4WaGMVVEc+gekJUpQq254GGS0/LEGE8Tz1wBQWC8HD0hq0h9q4cxCQcO9Ly+fE7Sd8LCHT5qgqT5SpcCGAidzRyYL+6QU=
- In-reply-to: <4570B607.4739.124DC45@len-l.telus.net>
- References: <4570B607.4739.124DC45@len-l.telus.net>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
It seems to consider left and top just fine to me and seems to be a
proper union exactly like I'd expect. Have you had problems with it?
attached is a quick test I used.
On 12/1/06, Lenard Lindstrom <len-l@xxxxxxxxx> wrote:
Does Rect.union ignore rectangle positions? That is, does it only
return a rectangle whose width and height is the maximum of the
widths and heights of the two compared rectangles rather than a
rectangle that will actually cover the two rectangles as they are
positioned?
Lenard Lindstrom
<len-l@xxxxxxxxx>
import pygame
import sys
import random
def main():
pygame.init()
screen = pygame.display.set_mode((640, 480))
rect1 = pygame.Rect(200,190,40,40)
rect2 = pygame.Rect(320,330,40,10)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
screen.fill((0,0,0))
pygame.draw.rect(screen, (255,0,255), rect1)
pygame.draw.rect(screen, (255,255,0), rect2)
union_rect = rect1.union(rect2)
pygame.draw.rect(screen, (255,255,255), union_rect, 1)
pygame.display.flip()
if __name__ == '__main__':
main()