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

Re: [pygame] rect.collidedict() and rect.collidedictall() patch



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.
>
>