[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] rect.collidedict() and rect.collidedictall() patch
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] rect.collidedict() and rect.collidedictall() patch
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Sun, 26 Aug 2007 14:31:19 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Sun, 26 Aug 2007 00:31:27 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gd3wj4A1hz2A0xPsjWVLhIIRhIWoN4TixciW8fI5PRuSri1fp39Lryul+4x/adtBP9+ILZcODv30zyhCoZdlecFueK1veSpsKCa/wrfQY/klN4Ec7CmZjYFxR8g4dYzdzc4FZNTHInjZWRmWNNDtmfAHTPrudrshAZ4GIhjmzn0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qkqzU5pXOroGU37c3XXFdpADcoqhZPA4xOBBMvhh7DBjpG65sYDovUGUTVSGf3idaELNqp9QiC2ao5Y2dz8JH0FGwg4YGx6dVzTTGl9BGZzd2Q8S8dzWhBc88K3zcptYzNEwueRqFpS9OaRnO2fXa0ezPC2MDEi7kjeqdGS6K+U=
- In-reply-to: <46D03814.9020304@xxxxxxxxxx>
- References: <46D03814.9020304@xxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi,
I think tuples are hashable though? Like (0,0,10,10) etc.
If we change it then it's breaking the API a bit... but maybe no one
used collidedictall anyway?
On 8/26/07, DR0ID <dr0id@xxxxxxxxxx> wrote:
> Hi
>
> since a dictionary with rectstyle keys is not possible (because rects
> are not hashable), the source did not make sense to check if the keys
> where rectstyle objects. It should be the values that must be a
> rectstyle. Patch changes exactly that.
>
> Documentation of collidedictall() updated to say that a empty list [] is
> returned if no collision is found (not a empty dictioniary).
>
>
> ~DR0ID
>
> Index: src/rect.c
> ===================================================================
> --- src/rect.c (revision 1047)
> +++ src/rect.c (working copy)
> @@ -500,14 +500,14 @@
> return NULL;
> if (!PyDict_Check (dict))
> return RAISE (PyExc_TypeError,
> - "Argument must be a dict with rectstyle keys.");
> + "Argument must be a dict with rectstyle values (1).");
>
> while (PyDict_Next (dict, &loop, &key, &val))
> {
> - if (!(argrect = GameRect_FromObject (key, &temp)))
> + if (!(argrect = GameRect_FromObject (val, &temp)))
> {
> RAISE (PyExc_TypeError,
> - "Argument must be a dict with rectstyle keys.");
> + "Argument must be a dict with rectstyle values (2).");
> break;
> }
> if (DoRectsIntersect (&self->r, argrect))
> @@ -535,7 +535,7 @@
> return NULL;
> if (!PyDict_Check (dict))
> return RAISE (PyExc_TypeError,
> - "Argument must be a dict with rectstyle keys.");
> + "Argument must be a dict with rectstyle values (1).");
>
> ret = PyList_New (0);
> if(!ret)
> @@ -543,11 +543,11 @@
>
> while (PyDict_Next (dict, &loop, &key, &val))
> {
> - if (!(argrect = GameRect_FromObject (key, &temp)))
> + if (!(argrect = GameRect_FromObject (val, &temp)))
> {
> Py_DECREF (ret);
> return RAISE (PyExc_TypeError,
> - "Argument must be a dict with rectstyle keys.");
> + "Argument must be a dict with rectstyle values (2).");
> }
>
> if (DoRectsIntersect (&self->r, argrect))
> Index: src/rect.doc
> ===================================================================
> --- src/rect.doc (revision 1047)
> +++ src/rect.doc (working copy)
> @@ -264,7 +264,7 @@
> Rect.collidedictall(dict): return [(key, value), ...]
>
> Returns a list of all the key and value pairs that intersect with the
> -Rect. If no collisions are found an empty dictionary is returned.
> +Rect. If no collisions are found an empty list is returned.
>
> Rect objects are not hashable and cannot be used as keys in a dictionary,
> only as values.
>
>