From fe8320410f1e81458ccc05f01e9b9d91f20308ab Mon Sep 17 00:00:00 2001 From: Damus666 Date: Mon, 27 May 2024 21:59:09 +0200 Subject: [PATCH 1/7] Port API --- buildconfig/stubs/pygame/geometry.pyi | 3 + docs/reST/ref/geometry.rst | 46 ++++++++ src_c/circle.c | 163 ++++++++++++++++++++++++-- src_c/doc/geometry_doc.h | 2 + test/geometry_test.py | 92 +++++++++++++++ 5 files changed, 299 insertions(+), 7 deletions(-) diff --git a/buildconfig/stubs/pygame/geometry.pyi b/buildconfig/stubs/pygame/geometry.pyi index fb7c8de850..1eabbfdcce 100644 --- a/buildconfig/stubs/pygame/geometry.pyi +++ b/buildconfig/stubs/pygame/geometry.pyi @@ -5,6 +5,7 @@ from typing import ( Protocol, Tuple, Sequence, + List, ) from pygame import Rect, FRect @@ -94,6 +95,8 @@ class Circle: @overload def colliderect(self, topleft: Coordinate, size: Coordinate, /) -> bool: ... def collideswith(self, other: _CanBeCollided, /) -> bool: ... + def collidelist(self, colliders: Sequence[_CanBeCollided], /) -> int: ... + def collidelistall(self, colliders: Sequence[_CanBeCollided], /) -> List[int]: ... def contains(self, shape: _CanBeCollided) -> bool: ... @overload def update(self, circle: _CircleValue, /) -> None: ... diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index 8d3fa7cfd0..ba9cf2778a 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -283,6 +283,52 @@ .. ## Circle.collideswith ## + .. method:: collidelist + + | :sl:`test if a list of objects collide with the circle` + | :sg:`collidelist(colliders) -> int` + + The `collidelist` method tests whether a given list of shapes or points collides + (overlaps) with this `Circle` object. The function takes in a single argument, which + must be a list of `Line`, `Circle`, `Rect`, `Polygon`, tuple or list containing the + x and y coordinates of a point, or `Vector2` objects. The function returns the index + of the first shape or point in the list that collides with the `Circle` object, or + -1 if there is no collision. + + .. note:: + It is important to note that the shapes must be actual shape objects, such as + `Line`, `Circle`, `Polygon`, or `Rect` instances. It is not possible to pass a tuple + or list of coordinates representing the shape as an argument(except for a point), + because the type of shape represented by the coordinates cannot be determined. + For example, a tuple with the format (a, b, c, d) could represent either a `Line` + or a `Rect` object, and there is no way to determine which is which without + explicitly passing a `Line` or `Rect` object as an argument. + + .. ## Circle.collidelist ## + + .. method:: collidelistall + + | :sl:`test if all objects in a list collide with the circle` + | :sg:`collidelistall(colliders) -> list` + + The `collidelistall` method tests whether a given list of shapes or points collides + (overlaps) with this `Circle` object. The function takes in a single argument, which + must be a list of `Line`, `Circle`, `Rect`, `Polygon`, tuple or list containing the + x and y coordinates of a point, or `Vector2` objects. The function returns a list + containing the indices of all the shapes or points in the list that collide with + the `Circle` object, or an empty list if there is no collision. + + .. note:: + It is important to note that the shapes must be actual shape objects, such as + `Line`, `Circle`, `Polygon`, or `Rect` instances. It is not possible to pass a tuple + or list of coordinates representing the shape as an argument(except for a point), + because the type of shape represented by the coordinates cannot be determined. + For example, a tuple with the format (a, b, c, d) could represent either a `Line` + or a `Rect` object, and there is no way to determine which is which without + explicitly passing a `Line` or `Rect` object as an argument. + + .. ## Circle.collidelistall ## + .. method:: contains | :sl:`check if a shape or point is inside the circle` diff --git a/src_c/circle.c b/src_c/circle.c index 63df177084..1ad7fe66c0 100644 --- a/src_c/circle.c +++ b/src_c/circle.c @@ -311,11 +311,10 @@ pg_circle_rotate_ip(pgCircleObject *self, PyObject *const *args, Py_RETURN_NONE; } -static PyObject * -pg_circle_collideswith(pgCircleObject *self, PyObject *arg) +static inline int +_pg_circle_collideswith(pgCircleBase *scirc, PyObject *arg) { int result = 0; - pgCircleBase *scirc = &self->circle; if (pgCircle_Check(arg)) { result = pgCollision_CircleCircle(&pgCircle_AsCircle(arg), scirc); } @@ -334,21 +333,167 @@ pg_circle_collideswith(pgCircleObject *self, PyObject *arg) else if (PySequence_Check(arg)) { double x, y; if (!pg_TwoDoublesFromObj(arg, &x, &y)) { - return RAISE( + PyErr_SetString( PyExc_TypeError, "Invalid point argument, must be a sequence of two numbers"); } result = pgCollision_CirclePoint(scirc, x, y); } else { - return RAISE(PyExc_TypeError, - "Invalid shape argument, must be a Circle, Rect / FRect, " - "Line, Polygon or a sequence of two numbers"); + PyErr_SetString( + PyExc_TypeError, + "Invalid point argument, must be a sequence of 2 numbers"); + return -1; + } + + return result; +} + +static PyObject * +pg_circle_collideswith(pgCircleObject *self, PyObject *arg) +{ + int result = _pg_circle_collideswith(&self->circle, arg); + if (result == -1) { + return NULL; } return PyBool_FromLong(result); } +static PyObject * +pg_circle_collidelist(pgCircleObject *self, PyObject *arg) +{ + Py_ssize_t i; + pgCircleBase *scirc = &self->circle; + int colliding; + + if (!PySequence_Check(arg)) { + return RAISE(PyExc_TypeError, "Argument must be a sequence"); + } + + /* fast path */ + if (pgSequenceFast_Check(arg)) { + PyObject **items = PySequence_Fast_ITEMS(arg); + for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) { + if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) { + /*invalid shape*/ + return NULL; + } + if (colliding) { + return PyLong_FromSsize_t(i); + } + } + return PyLong_FromLong(-1); + } + + /* general sequence path */ + for (i = 0; i < PySequence_Length(arg); i++) { + PyObject *obj = PySequence_GetItem(arg, i); + if (!obj) { + return NULL; + } + + if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) { + /*invalid shape*/ + Py_DECREF(obj); + return NULL; + } + Py_DECREF(obj); + + if (colliding) { + return PyLong_FromSsize_t(i); + } + } + + return PyLong_FromLong(-1); +} + +static PyObject * +pg_circle_collidelistall(pgCircleObject *self, PyObject *arg) +{ + PyObject *ret; + Py_ssize_t i; + pgCircleBase *scirc = &self->circle; + int colliding; + + if (!PySequence_Check(arg)) { + return RAISE(PyExc_TypeError, "Argument must be a sequence"); + } + + ret = PyList_New(0); + if (!ret) { + return NULL; + } + + /* fast path */ + if (pgSequenceFast_Check(arg)) { + PyObject **items = PySequence_Fast_ITEMS(arg); + + for (i = 0; i < PySequence_Fast_GET_SIZE(arg); i++) { + if ((colliding = _pg_circle_collideswith(scirc, items[i])) == -1) { + /*invalid shape*/ + Py_DECREF(ret); + return NULL; + } + + 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; + } + + /* general sequence path */ + for (i = 0; i < PySequence_Length(arg); i++) { + PyObject *obj = PySequence_GetItem(arg, i); + if (!obj) { + Py_DECREF(ret); + return NULL; + } + + if ((colliding = _pg_circle_collideswith(scirc, obj)) == -1) { + /*invalid shape*/ + Py_DECREF(ret); + Py_DECREF(obj); + return NULL; + } + Py_DECREF(obj); + + 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; +} + static PyObject * pg_circle_as_rect(pgCircleObject *self, PyObject *_null) { @@ -438,6 +583,10 @@ static struct PyMethodDef pg_circle_methods[] = { DOC_CIRCLE_UPDATE}, {"collideswith", (PyCFunction)pg_circle_collideswith, METH_O, DOC_CIRCLE_COLLIDESWITH}, + {"collidelist", (PyCFunction)pg_circle_collidelist, METH_O, + DOC_CIRCLE_COLLIDELIST}, + {"collidelistall", (PyCFunction)pg_circle_collidelistall, METH_O, + DOC_CIRCLE_COLLIDELISTALL}, {"as_rect", (PyCFunction)pg_circle_as_rect, METH_NOARGS, DOC_CIRCLE_ASRECT}, {"as_frect", (PyCFunction)pg_circle_as_frect, METH_NOARGS, diff --git a/src_c/doc/geometry_doc.h b/src_c/doc/geometry_doc.h index 960714ff73..92b300d368 100644 --- a/src_c/doc/geometry_doc.h +++ b/src_c/doc/geometry_doc.h @@ -15,6 +15,8 @@ #define DOC_CIRCLE_MOVEIP "move_ip((x, y), /) -> None\nmove_ip(x, y, /) -> None\nmove_ip(vector2, /) -> None\nmoves the circle by a given amount, in place" #define DOC_CIRCLE_COLLIDERECT "colliderect(rect, /) -> bool\ncolliderect((x, y, width, height), /) -> bool\ncolliderect(x, y, width, height, /) -> bool\ncolliderect((x, y), (width, height), /) -> bool\nchecks if a rectangle intersects the circle" #define DOC_CIRCLE_COLLIDESWITH "collideswith(circle, /) -> bool\ncollideswith(rect, /) -> bool\ncollideswith((x, y), /) -> bool\ncollideswith(vector2, /) -> bool\ncheck if a shape or point collides with the circle" +#define DOC_CIRCLE_COLLIDELIST "collidelist(colliders) -> int\ntest if a list of objects collide with the circle" +#define DOC_CIRCLE_COLLIDELISTALL "collidelistall(colliders) -> list\ntest if all objects in a list collide with the circle" #define DOC_CIRCLE_CONTAINS "contains(circle, /) -> bool\ncontains(rect, /) -> bool\ncontains((x, y), /) -> bool\ncontains(vector2, /) -> bool\ncheck if a shape or point is inside the circle" #define DOC_CIRCLE_UPDATE "update((x, y), radius, /) -> None\nupdate(x, y, radius, /) -> None\nupdates the circle position and radius" #define DOC_CIRCLE_ROTATE "rotate(angle, rotation_point=Circle.center, /) -> Circle\nrotate(angle, /) -> Circle\nrotates the circle" diff --git a/test/geometry_test.py b/test/geometry_test.py index b69b316908..df6aadfc58 100644 --- a/test/geometry_test.py +++ b/test/geometry_test.py @@ -675,6 +675,98 @@ def test_collideswith(self): self.assertTrue(c.collideswith(p)) self.assertFalse(c.collideswith(p2)) + def test_collidelist_argtype(self): + """Tests if the function correctly handles incorrect types as parameters""" + + invalid_types = (None, "1", (1,), 1, (1, 2, 3), True, False) + + c = Circle(10, 10, 4) + + for value in invalid_types: + with self.assertRaises(TypeError): + c.collidelist(value) + + def test_collidelist_argnum(self): + """Tests if the function correctly handles incorrect number of parameters""" + c = Circle(10, 10, 4) + + circles = [(Circle(10, 10, 4), Circle(10, 10, 4))] + + with self.assertRaises(TypeError): + c.collidelist() + + with self.assertRaises(TypeError): + c.collidelist(circles, 1) + + def test_collidelist_return_type(self): + """Tests if the function returns the correct type""" + c = Circle(10, 10, 4) + + objects = [ + Circle(10, 10, 4), + Rect(10, 10, 4, 4), + ] + + for object in objects: + self.assertIsInstance(c.collidelist([object]), int) + + def test_collidelist(self): + """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)] + rects = [Rect(1000, 1000, 4, 4), Rect(1000, 200, 5, 5), Rect(5, 10, 7, 3)] + expected = [1, 2] + + for objects, expected in zip([circles, rects], expected): + self.assertEqual(c.collidelist(objects), expected) + + def test_collidelistall_argtype(self): + """Tests if the function correctly handles incorrect types as parameters""" + + invalid_types = (None, "1", (1,), 1, (1, 2, 3), True, False) + + c = Circle(10, 10, 4) + + for value in invalid_types: + with self.assertRaises(TypeError): + c.collidelistall(value) + + def test_collidelistall_argnum(self): + """Tests if the function correctly handles incorrect number of parameters""" + c = Circle(10, 10, 4) + + circles = [(Circle(10, 10, 4), Circle(10, 10, 4))] + + with self.assertRaises(TypeError): + c.collidelistall() + + with self.assertRaises(TypeError): + c.collidelistall(circles, 1) + + def test_collidelistall_return_type(self): + """Tests if the function returns the correct type""" + c = Circle(10, 10, 4) + + objects = [ + Circle(10, 10, 4), + Rect(10, 10, 4, 4), + ] + + for object in objects: + self.assertIsInstance(c.collidelistall([object]), list) + + def test_collidelistall(self): + """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)] + rects = [Rect(1000, 1000, 4, 4), Rect(1000, 200, 5, 5), Rect(5, 10, 7, 3)] + expected = [[1, 2], [2]] + + for objects, expected in zip([circles, rects], expected): + self.assertEqual(c.collidelistall(objects), expected) + def test_update(self): """Ensures that updating the circle position and dimension correctly updates position and dimension""" From 767ec01d4c2c554906342d0d85812819e2225230 Mon Sep 17 00:00:00 2001 From: Damus666 Date: Mon, 27 May 2024 22:16:35 +0200 Subject: [PATCH 2/7] Fix return --- src_c/circle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src_c/circle.c b/src_c/circle.c index 1ad7fe66c0..efe397313f 100644 --- a/src_c/circle.c +++ b/src_c/circle.c @@ -311,7 +311,7 @@ pg_circle_rotate_ip(pgCircleObject *self, PyObject *const *args, Py_RETURN_NONE; } -static inline int +static PG_FORCEINLINE int _pg_circle_collideswith(pgCircleBase *scirc, PyObject *arg) { int result = 0; @@ -336,6 +336,7 @@ _pg_circle_collideswith(pgCircleBase *scirc, PyObject *arg) PyErr_SetString( PyExc_TypeError, "Invalid point argument, must be a sequence of two numbers"); + return -1; } result = pgCollision_CirclePoint(scirc, x, y); } From e68f97420ffbb714014b052ef05113e784d12a68 Mon Sep 17 00:00:00 2001 From: Damus666 Date: Mon, 27 May 2024 23:06:09 +0200 Subject: [PATCH 3/7] Add versionadded --- docs/reST/ref/geometry.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index ba9cf2778a..512e0188ad 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -304,6 +304,8 @@ or a `Rect` object, and there is no way to determine which is which without explicitly passing a `Line` or `Rect` object as an argument. + .. versionadded:: 2.5.0 + .. ## Circle.collidelist ## .. method:: collidelistall @@ -327,6 +329,8 @@ or a `Rect` object, and there is no way to determine which is which without explicitly passing a `Line` or `Rect` object as an argument. + .. versionadded:: 2.5.0 + .. ## Circle.collidelistall ## .. method:: contains From 9643c4306fe2935300917157480dd437ed3f2653 Mon Sep 17 00:00:00 2001 From: Damus666 Date: Tue, 28 May 2024 14:08:49 +0200 Subject: [PATCH 4/7] Fix docs and code --- docs/reST/ref/geometry.rst | 28 ++++++++++------------------ src_c/circle.c | 4 ++-- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index 512e0188ad..5277c5a501 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -290,19 +290,15 @@ The `collidelist` method tests whether a given list of shapes or points collides (overlaps) with this `Circle` object. The function takes in a single argument, which - must be a list of `Line`, `Circle`, `Rect`, `Polygon`, tuple or list containing the - x and y coordinates of a point, or `Vector2` objects. The function returns the index + must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns the index of the first shape or point in the list that collides with the `Circle` object, or -1 if there is no collision. .. note:: - It is important to note that the shapes must be actual shape objects, such as - `Line`, `Circle`, `Polygon`, or `Rect` instances. It is not possible to pass a tuple - or list of coordinates representing the shape as an argument(except for a point), - because the type of shape represented by the coordinates cannot be determined. - For example, a tuple with the format (a, b, c, d) could represent either a `Line` - or a `Rect` object, and there is no way to determine which is which without - explicitly passing a `Line` or `Rect` object as an argument. + The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` + instances. It is not possible to pass a tuple or list of coordinates representing + the shape as an argument (except for a point), because the shape type can't be + determined from the coordinates alone. .. versionadded:: 2.5.0 @@ -315,19 +311,15 @@ The `collidelistall` method tests whether a given list of shapes or points collides (overlaps) with this `Circle` object. The function takes in a single argument, which - must be a list of `Line`, `Circle`, `Rect`, `Polygon`, tuple or list containing the - x and y coordinates of a point, or `Vector2` objects. The function returns a list + must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns a list containing the indices of all the shapes or points in the list that collide with the `Circle` object, or an empty list if there is no collision. .. note:: - It is important to note that the shapes must be actual shape objects, such as - `Line`, `Circle`, `Polygon`, or `Rect` instances. It is not possible to pass a tuple - or list of coordinates representing the shape as an argument(except for a point), - because the type of shape represented by the coordinates cannot be determined. - For example, a tuple with the format (a, b, c, d) could represent either a `Line` - or a `Rect` object, and there is no way to determine which is which without - explicitly passing a `Line` or `Rect` object as an argument. + The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` + instances. It is not possible to pass a tuple or list of coordinates representing + the shape as an argument (except for a point), because the shape type can't be + determined from the coordinates alone. .. versionadded:: 2.5.0 diff --git a/src_c/circle.c b/src_c/circle.c index efe397313f..1cadecaf15 100644 --- a/src_c/circle.c +++ b/src_c/circle.c @@ -389,7 +389,7 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg) /* general sequence path */ for (i = 0; i < PySequence_Length(arg); i++) { - PyObject *obj = PySequence_GetItem(arg, i); + PyObject *obj = PySequence_ITEM(arg, i); if (!obj) { return NULL; } @@ -460,7 +460,7 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg) /* general sequence path */ for (i = 0; i < PySequence_Length(arg); i++) { - PyObject *obj = PySequence_GetItem(arg, i); + PyObject *obj = PySequence_ITEM(arg, i); if (!obj) { Py_DECREF(ret); return NULL; From cbafc0254a0b790f72a71dedd3d5979d23d9dae6 Mon Sep 17 00:00:00 2001 From: Damus666 Date: Sun, 2 Jun 2024 10:58:35 +0200 Subject: [PATCH 5/7] Modify exc msg and add points to tests --- src_c/circle.c | 2 +- test/geometry_test.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src_c/circle.c b/src_c/circle.c index 1cadecaf15..2356a23e49 100644 --- a/src_c/circle.c +++ b/src_c/circle.c @@ -369,7 +369,7 @@ pg_circle_collidelist(pgCircleObject *self, PyObject *arg) int colliding; if (!PySequence_Check(arg)) { - return RAISE(PyExc_TypeError, "Argument must be a sequence"); + return RAISE(PyExc_TypeError, "colliders argument must be a sequence"); } /* fast path */ diff --git a/test/geometry_test.py b/test/geometry_test.py index df6aadfc58..69884a7f37 100644 --- a/test/geometry_test.py +++ b/test/geometry_test.py @@ -716,9 +716,10 @@ def test_collidelist(self): circles = [Circle(1000, 1000, 2), Circle(5, 10, 5), Circle(16, 10, 7)] rects = [Rect(1000, 1000, 4, 4), Rect(1000, 200, 5, 5), Rect(5, 10, 7, 3)] - expected = [1, 2] + points = [(-10, -10), Vector2(1, 1), Vector2(10, -20), (10, 10)] + expected = [1, 2, 3] - for objects, expected in zip([circles, rects], expected): + for objects, expected in zip([circles, rects, points], expected): self.assertEqual(c.collidelist(objects), expected) def test_collidelistall_argtype(self): @@ -751,6 +752,8 @@ def test_collidelistall_return_type(self): objects = [ Circle(10, 10, 4), Rect(10, 10, 4, 4), + (10, 10), + Vector2(9, 9), ] for object in objects: @@ -762,9 +765,10 @@ def test_collidelistall(self): circles = [Circle(1000, 1000, 2), Circle(5, 10, 5), Circle(16, 10, 7)] rects = [Rect(1000, 1000, 4, 4), Rect(1000, 200, 5, 5), Rect(5, 10, 7, 3)] - expected = [[1, 2], [2]] + points = [Vector2(-10, -10), (8, 8), (10, -20), Vector2(10, 10)] + expected = [[1, 2], [2], [1, 3]] - for objects, expected in zip([circles, rects], expected): + for objects, expected in zip([circles, rects, points], expected): self.assertEqual(c.collidelistall(objects), expected) def test_update(self): From 0bbd797d648fac867b96f0bc8cfeaa3f90c25510 Mon Sep 17 00:00:00 2001 From: Damus666 Date: Sun, 15 Sep 2024 16:14:48 +0200 Subject: [PATCH 6/7] Update versionadded --- docs/reST/ref/geometry.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index 9e62f2ae96..2622f179e0 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -234,7 +234,7 @@ the shape as an argument (except for a point), because the shape type can't be determined from the coordinates alone. - .. versionadded:: 2.5.0 + .. versionadded:: 2.5.2 .. ## Circle.collidelist ## @@ -255,7 +255,7 @@ the shape as an argument (except for a point), because the shape type can't be determined from the coordinates alone. - .. versionadded:: 2.5.0 + .. versionadded:: 2.5.2 .. ## Circle.collidelistall ## From 8378687f31588635697d28cce1559348473826b9 Mon Sep 17 00:00:00 2001 From: Damiano <97639432+damusss@users.noreply.github.com> Date: Sat, 28 Sep 2024 20:41:36 +0200 Subject: [PATCH 7/7] Fix docs indentation --- docs/reST/ref/geometry.rst | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/reST/ref/geometry.rst b/docs/reST/ref/geometry.rst index 811940d80a..2186651313 100644 --- a/docs/reST/ref/geometry.rst +++ b/docs/reST/ref/geometry.rst @@ -194,7 +194,7 @@ x, y coordinates and width, height as its argument. .. versionadded:: 2.4.0 - + .. ## Circle.colliderect ## .. method:: collideswith @@ -217,47 +217,47 @@ .. ## Circle.collideswith ## - .. method:: collidelist + .. method:: collidelist - | :sl:`test if a list of objects collide with the circle` - | :sg:`collidelist(colliders) -> int` + | :sl:`test if a list of objects collide with the circle` + | :sg:`collidelist(colliders) -> int` - The `collidelist` method tests whether a given list of shapes or points collides - (overlaps) with this `Circle` object. The function takes in a single argument, which - must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns the index - of the first shape or point in the list that collides with the `Circle` object, or - -1 if there is no collision. + The `collidelist` method tests whether a given list of shapes or points collides + (overlaps) with this `Circle` object. The function takes in a single argument, which + must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns the index + of the first shape or point in the list that collides with the `Circle` object, or + -1 if there is no collision. - .. note:: - The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` - instances. It is not possible to pass a tuple or list of coordinates representing - the shape as an argument (except for a point), because the shape type can't be - determined from the coordinates alone. + .. note:: + The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` + instances. It is not possible to pass a tuple or list of coordinates representing + the shape as an argument (except for a point), because the shape type can't be + determined from the coordinates alone. - .. versionadded:: 2.5.2 + .. versionadded:: 2.5.2 - .. ## Circle.collidelist ## + .. ## Circle.collidelist ## - .. method:: collidelistall + .. method:: collidelistall - | :sl:`test if all objects in a list collide with the circle` - | :sg:`collidelistall(colliders) -> list` + | :sl:`test if all objects in a list collide with the circle` + | :sg:`collidelistall(colliders) -> list` - The `collidelistall` method tests whether a given list of shapes or points collides - (overlaps) with this `Circle` object. The function takes in a single argument, which - must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns a list - containing the indices of all the shapes or points in the list that collide with - the `Circle` object, or an empty list if there is no collision. + The `collidelistall` method tests whether a given list of shapes or points collides + (overlaps) with this `Circle` object. The function takes in a single argument, which + must be a list of `Circle`, `Rect`, `FRect`, or a point. The function returns a list + containing the indices of all the shapes or points in the list that collide with + the `Circle` object, or an empty list if there is no collision. - .. note:: - The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` - instances. It is not possible to pass a tuple or list of coordinates representing - the shape as an argument (except for a point), because the shape type can't be - determined from the coordinates alone. + .. note:: + The shapes must be actual shape objects, such as `Circle`, `Rect` or `FRect` + instances. It is not possible to pass a tuple or list of coordinates representing + the shape as an argument (except for a point), because the shape type can't be + determined from the coordinates alone. - .. versionadded:: 2.5.2 + .. versionadded:: 2.5.2 - .. ## Circle.collidelistall ## + .. ## Circle.collidelistall ## .. method:: contains