Commits

Anonymous committed 1669be9

Added PointFromObject support to some pygame2.Rect and pygame2.FRect class methods.

Comments (0)

Files changed (3)

src/base/floatrect.c

     double x, y;
 
     if (!PyArg_ParseTuple (args, "dd:move", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:move", &pos))
+            return NULL;
+        if (!FPointFromObject (pos, &x, &y))
+            return NULL;
+    }
 
     return PyFRect_New (frect->x + x, frect->y + y, frect->w, frect->h);
 }
     double x, y;
 
     if (!PyArg_ParseTuple (args, "dd:move_ip", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:move_ip", &pos))
+            return NULL;
+        if (!FPointFromObject (pos, &x, &y))
+            return NULL;
+    }
+
     frect->x = DBL_ADD_LIMIT (frect->x, x);
     frect->y = DBL_ADD_LIMIT (frect->y, y);
     Py_RETURN_NONE;
     double x, y;
 
     if (!PyArg_ParseTuple (args, "dd:inflate", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:inflate", &pos))
+            return NULL;
+        if (!FPointFromObject (pos, &x, &y))
+            return NULL;
+    }
 
     return PyFRect_New (DBL_SUB_LIMIT (frect->x, x / 2),
         DBL_SUB_LIMIT (frect->y, y / 2), DBL_ADD_LIMIT (frect->w, x),
     double x, y;
 
     if (!PyArg_ParseTuple (args, "dd:inflate_ip", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:inflate_ip", &pos))
+            return NULL;
+        if (!FPointFromObject (pos, &x, &y))
+            return NULL;
+    }
+
     frect->x = DBL_SUB_LIMIT (frect->x, x / 2);
     frect->y = DBL_SUB_LIMIT (frect->y, y / 2);
     frect->w = DBL_ADD_LIMIT (frect->w, x);
     double x, y;
 
     if (!PyArg_ParseTuple (args, "dd:collidepoint", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:collidepoint", &pos))
+            return NULL;
+        if (!FPointFromObject (pos, &x, &y))
+            return NULL;
+    }
 
     if (x >= rself->x && x < rself->x + rself->w &&
         y >= rself->y && y < rself->y + rself->h)
     pgint16 x, y;
 
     if (!PyArg_ParseTuple (args, "ii:move", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:move", &pos))
+            return NULL;
+        if (!PointFromObject (pos, (int*)&x, (int*)&y))
+            return NULL;
+    }
 
     return PyRect_New (rect->x + x, rect->y + y, rect->w, rect->h);
 }
     pgint16 x, y;
 
     if (!PyArg_ParseTuple (args, "ii:move_ip", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:move_ip", &pos))
+            return NULL;
+        if (!PointFromObject (pos, (int*)&x, (int*)&y))
+            return NULL;
+    }
     rect->x = INT16_ADD_LIMIT (rect->x, x);
     rect->y = INT16_ADD_LIMIT (rect->y, y);
     Py_RETURN_NONE;
     pgint32 w, h;
 
     if (!PyArg_ParseTuple (args, "ii:inflate", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:inflate", &pos))
+            return NULL;
+        if (!PointFromObject (pos, (int*)&x, (int*)&y))
+            return NULL;
+    }
 
     w = (pgint32)(rect->w + x);
     h = (pgint32)(rect->h + y);
     pgint32 w, h;
 
     if (!PyArg_ParseTuple (args, "ii:inflate_ip", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:inflate_ip", &pos))
+            return NULL;
+        if (!PointFromObject (pos, (int*)&x, (int*)&y))
+            return NULL;
+    }
+
     rect->x = INT16_SUB_LIMIT (rect->x, x / 2);
     rect->y = INT16_SUB_LIMIT (rect->y, y / 2);
     w = (pgint32)(rect->w + x);
     pgint32 r, b;
 
     if (!PyArg_ParseTuple (args, "ii:collidepoint", &x, &y))
-        return NULL;
+    {
+        PyObject *pos;
+        PyErr_Clear ();
+        if (!PyArg_ParseTuple (args, "O:collidepoint", &pos))
+            return NULL;
+        if (!PointFromObject (pos, (int*)&x, (int*)&y))
+            return NULL;
+    }
 
     r = rself->x + rself->w;
     b = rself->y + rself->h;

test/base_rect_test.py

         self.assertEqual( (r.centerx,r.bottom), r.midbottom )
         self.assertEqual( (r.left,r.centery), r.midleft )
         self.assertEqual( (r.right,r.centery), r.midright )
-    
 
     def testEquals( self ):
         """ check to see how the rect uses __eq__