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

Re: [pygame] BUG? rect __eq__



Hi,

thanks for the notes.


Yes I agree the current behaviour is more useful, and probably more expected.

Note that all of these are true:
Rect(0,0,10,10) == [0,0,10,10]
[0,0,10,10] == [0,0,10,10]
Rect(0,0,10,10) == (0,0,10,10)

However:
(0,0,10,10) != [0,0,10,10]

The rect uses a compare function, where it sees if the other object is
a rect like, then compares to it.

It definitely does need documenting.

I'm not sure if a UserRect style class is useful or not.

Cheers,


On 6/6/06, Sami Hangaslammi <sami.hangaslammi@xxxxxxxxx> wrote:
On 6/6/06, Rene Dudfield <renesd@xxxxxxxxx> wrote:
> Could this behaviour be improved at all?

I think the current behaviour is desireable in almost all real use
cases. IMHO, Rect should be just a collection of values, so it's
logical that rect(0,0,10,10) == rect(0,0,10,10) even if the object
instances are different. I think it is enough to document this
behaviour, so that those who inherit from Rect don't get any
surprises.

Another option is to provide another Rect class solely meant for
inheritance where you add logic to the object (in which case the
object identity usually becomes important). Then it's just a matter of
picking a good name for it. RectObject? RectBase? UserRect? I dunno.

--
Sami Hangaslammi