Skip to content

Commit 73a0427

Browse files
committed
corrected two comments and reduced indentation levels
1 parent f072a37 commit 73a0427

File tree

2 files changed

+48
-46
lines changed

2 files changed

+48
-46
lines changed

src_c/circle.c

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,13 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
613613
if (PySequence_FAST_CHECK(arg)) {
614614
PyObject **items = PySequence_Fast_ITEMS(arg);
615615
for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) {
616-
colliding = _pg_circle_collideswith(scirc, items[i]);
617-
if (colliding == 1) {
618-
return PyLong_FromSsize_t(i);
619-
}
620-
else if (colliding == -1) {
616+
if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) {
617+
/*invalid shape*/
621618
return NULL;
622619
}
620+
if (colliding) {
621+
return PyLong_FromSsize_t(i);
622+
}
623623
}
624624
return PyLong_FromLong(-1);
625625
}
@@ -631,15 +631,16 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg)
631631
return NULL;
632632
}
633633

634-
colliding = _pg_circle_collideswith(scirc, obj);
634+
if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) {
635+
/*invalid shape*/
636+
Py_DECREF(obj);
637+
return NULL;
638+
}
635639
Py_DECREF(obj);
636640

637-
if (colliding == 1) {
641+
if (colliding) {
638642
return PyLong_FromSsize_t(i);
639643
}
640-
else if (colliding == -1) {
641-
return NULL;
642-
}
643644
}
644645

645646
return PyLong_FromLong(-1);
@@ -667,27 +668,28 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
667668
PyObject **items = PySequence_Fast_ITEMS(arg);
668669

669670
for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) {
670-
colliding = _pg_circle_collideswith(scirc, items[i]);
671-
672-
if (colliding == 1) {
673-
PyObject *num = PyLong_FromSsize_t(i);
674-
if (!num) {
675-
Py_DECREF(ret);
676-
return NULL;
677-
}
678-
679-
if (PyList_Append(ret, num)) {
680-
Py_DECREF(num);
681-
Py_DECREF(ret);
682-
return NULL;
683-
}
684-
Py_DECREF(num);
671+
if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) {
672+
/*invalid shape*/
673+
Py_DECREF(ret);
674+
return NULL;
685675
}
686-
/*invalid shape*/
687-
else if (colliding == -1) {
676+
677+
if (!colliding) {
678+
continue;
679+
}
680+
681+
PyObject *num = PyLong_FromSsize_t(i);
682+
if (!num) {
688683
Py_DECREF(ret);
689684
return NULL;
690685
}
686+
687+
if (PyList_Append(ret, num)) {
688+
Py_DECREF(num);
689+
Py_DECREF(ret);
690+
return NULL;
691+
}
692+
Py_DECREF(num);
691693
}
692694

693695
return ret;
@@ -701,28 +703,30 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
701703
return NULL;
702704
}
703705

704-
colliding = _pg_circle_collideswith(scirc, obj);
706+
if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) {
707+
/*invalid shape*/
708+
Py_DECREF(ret);
709+
Py_DECREF(obj);
710+
return NULL;
711+
}
705712
Py_DECREF(obj);
706713

707-
if (colliding == 1) {
708-
PyObject *num = PyLong_FromSsize_t(i);
709-
if (!num) {
710-
Py_DECREF(ret);
711-
return NULL;
712-
}
714+
if (!colliding) {
715+
continue;
716+
}
713717

714-
if (PyList_Append(ret, num)) {
715-
Py_DECREF(num);
716-
Py_DECREF(ret);
717-
return NULL;
718-
}
719-
Py_DECREF(num);
718+
PyObject *num = PyLong_FromSsize_t(i);
719+
if (!num) {
720+
Py_DECREF(ret);
721+
return NULL;
720722
}
721-
/*invalid shape*/
722-
else if (colliding == -1) {
723+
724+
if (PyList_Append(ret, num)) {
725+
Py_DECREF(num);
723726
Py_DECREF(ret);
724727
return NULL;
725728
}
729+
Py_DECREF(num);
726730
}
727731

728732
return ret;

test/test_circle.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,7 @@ def test_collidelist_return_type(self):
14121412
self.assertIsInstance(c.collidelist([object]), int)
14131413

14141414
def test_collidelist(self):
1415-
"""Ensures that the collidelist method correctly determines if a circle is
1416-
contained within the circle"""
1415+
"""Ensures that the collidelist method works correctly"""
14171416
c = Circle(10, 10, 4)
14181417

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

14691468
def test_collidelistall(self):
1470-
"""Ensures that the collidelistall method correctly determines if a circle is
1471-
contained within the circle"""
1469+
"""Ensures that the collidelistall method works correctly"""
14721470
c = Circle(10, 10, 4)
14731471

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

0 commit comments

Comments
 (0)