Skip to content

Commit

Permalink
corrected two comments and reduced indentation levels
Browse files Browse the repository at this point in the history
  • Loading branch information
itzpr3d4t0r committed May 27, 2024
1 parent f072a37 commit 73a0427
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
88 changes: 46 additions & 42 deletions src_c/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
if (PySequence_FAST_CHECK(arg)) {
PyObject **items = PySequence_Fast_ITEMS(arg);
for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) {
colliding = _pg_circle_collideswith(scirc, items[i]);
if (colliding == 1) {
return PyLong_FromSsize_t(i);
}
else if (colliding == -1) {
if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) {
/*invalid shape*/
return NULL;
}
if (colliding) {
return PyLong_FromSsize_t(i);
}
}
return PyLong_FromLong(-1);
}
Expand All @@ -631,15 +631,16 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
return NULL;
}

colliding = _pg_circle_collideswith(scirc, obj);
if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) {
/*invalid shape*/
Py_DECREF(obj);
return NULL;
}
Py_DECREF(obj);

if (colliding == 1) {
if (colliding) {
return PyLong_FromSsize_t(i);
}
else if (colliding == -1) {
return NULL;
}
}

return PyLong_FromLong(-1);
Expand Down Expand Up @@ -667,27 +668,28 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
PyObject **items = PySequence_Fast_ITEMS(arg);

for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) {
colliding = _pg_circle_collideswith(scirc, items[i]);

if (colliding == 1) {
PyObject *num = PyLong_FromSsize_t(i);
if (!num) {
Py_DECREF(ret);
return NULL;
}

if (PyList_Append(ret, num)) {
Py_DECREF(num);
Py_DECREF(ret);
return NULL;
}
Py_DECREF(num);
if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) {
/*invalid shape*/
Py_DECREF(ret);
return NULL;
}
/*invalid shape*/
else if (colliding == -1) {

if (!colliding) {
continue;
}

PyObject *num = PyLong_FromSsize_t(i);
if (!num) {
Py_DECREF(ret);
return NULL;
}

if (PyList_Append(ret, num)) {
Py_DECREF(num);
Py_DECREF(ret);
return NULL;
}
Py_DECREF(num);
}

return ret;
Expand All @@ -701,28 +703,30 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
return NULL;
}

colliding = _pg_circle_collideswith(scirc, obj);
if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) {
/*invalid shape*/
Py_DECREF(ret);
Py_DECREF(obj);
return NULL;
}
Py_DECREF(obj);

if (colliding == 1) {
PyObject *num = PyLong_FromSsize_t(i);
if (!num) {
Py_DECREF(ret);
return NULL;
}
if (!colliding) {
continue;
}

if (PyList_Append(ret, num)) {
Py_DECREF(num);
Py_DECREF(ret);
return NULL;
}
Py_DECREF(num);
PyObject *num = PyLong_FromSsize_t(i);
if (!num) {
Py_DECREF(ret);
return NULL;
}
/*invalid shape*/
else if (colliding == -1) {

if (PyList_Append(ret, num)) {
Py_DECREF(num);
Py_DECREF(ret);
return NULL;
}
Py_DECREF(num);
}

return ret;
Expand Down
6 changes: 2 additions & 4 deletions test/test_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,7 @@ def test_collidelist_return_type(self):
self.assertIsInstance(c.collidelist([object]), int)

def test_collidelist(self):
"""Ensures that the collidelist method correctly determines if a circle is
contained within the circle"""
"""Ensures that the collidelist method works correctly"""
c = Circle(10, 10, 4)

circles = [Circle(1000, 1000, 2), Circle(5, 10, 5), Circle(16, 10, 7)]
Expand Down Expand Up @@ -1467,8 +1466,7 @@ def test_collidelistall_return_type(self):
self.assertIsInstance(c.collidelistall([object]), list)

def test_collidelistall(self):
"""Ensures that the collidelistall method correctly determines if a circle is
contained within the circle"""
"""Ensures that the collidelistall method works correctly"""
c = Circle(10, 10, 4)

circles = [Circle(1000, 1000, 2), Circle(5, 10, 5), Circle(16, 10, 7)]
Expand Down

0 comments on commit 73a0427

Please sign in to comment.