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

Re: [pygame] substract rects



Pete Shinners wrote:
> Subject: Re: [pygame] substract rects
> Date: Tue, 17 Jun 2003 17:49:11 +0200

> Gerrit Holl wrote:
> >has anyone written code to substract rects yet?
> >I could do it myself but don't want to reinvent the wheel.
> >I didn't find it on the Code Repository.
> 
> there is no subtract. just as useful could be an 'add'. it seems both 
> these functions would take two rectangles and return a small list or 
> tuple of 0 to 4 rectangles.

I don't think it would return a tuple with 0 rectangles: I think a-a should
behave like .clip for two non-colliding rectangles, so that the position
is still in the rect:

Rect(10,10,10,10) - Rect(10,10,10,10) = Rect(10,10,0,0)
Remaining question is what to do on a-b if a<b: behave like
max(a,b)-min(a,b)? Return rects with negative sizes? Or raise
an Exception? I think I'm going for the last one.

I don't really see a need for an 'add' method/function. In
order to be orthogonal with 'substract', it would not be allowed
to behave like .union. But any result of a substract could be
added again using .unionall; so I don't see what an 'add' method/function
would do.

> i've always thought these would be cool, but never really had a strong 
> need for them. there's even placeholders for them in the rect.c source. :]

There may a different way to solve my problem, but here, it seems the
best way. I will likely upload by solution to the Pygame Code Repository.

yours,
Gerrit.

-- 
36. The field, garden, and house of a chieftain, of a man, or of one
subject to quit-rent, can not be sold.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/