Skip to content

Commit c1f503e

Browse files
committed
Updated docs, tests and code.
1 parent 00abf9e commit c1f503e

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

docs/reST/ref/geometry.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,15 @@
285285
286286
.. method:: contains
287287

288-
| :sl:`test if a shape or point is inside the circle`
288+
| :sl:`check if a shape or point is inside the circle`
289289
| :sg:`contains(circle, /) -> bool`
290290
| :sg:`contains(rect, /) -> bool`
291291
| :sg:`contains((x, y), /) -> bool`
292292
| :sg:`contains(vector2, /) -> bool`
293293
294-
The `contains` method tests whether a given shape or point is completely contained
295-
within a `Circle` object. The function takes a single argument which can be a `Circle`,
296-
`Rect`, `FRect`, or a point.
297-
It returns `True` if the shape or point is completely contained, and `False` otherwise.
298-
294+
Checks whether a given shape or point is completely contained within the `Circle`.
295+
Takes a single argument which can be a `Circle`, `Rect`, `FRect`, or a point.
296+
Returns `True` if the shape or point is completely contained, and `False` otherwise.
299297

300298
.. note::
301299
The shape argument must be an actual shape object (`Circle`, `Rect`, or `FRect`).

src_c/circle.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,18 @@ pg_circle_contains(pgCircleObject *self, PyObject *arg)
380380

381381
if (pgCircle_Check(arg)) {
382382
pgCircleBase *temp = &pgCircle_AsCircle(arg);
383-
if (temp == scirc) {
384-
/*a circle is always contained within itself*/
383+
/*a circle is always contained within itself*/
384+
if (temp == scirc)
385385
Py_RETURN_TRUE;
386-
}
387386
/* a bigger circle can't be contained within a smaller circle */
388-
if (temp->r > scirc->r) {
387+
if (temp->r > scirc->r)
389388
Py_RETURN_FALSE;
390-
}
391389

392-
double dx = temp->x - scirc->x;
393-
double dy = temp->y - scirc->y;
394-
double distance = sqrt(dx * dx + dy * dy);
390+
const double dx = temp->x - scirc->x;
391+
const double dy = temp->y - scirc->y;
392+
const double dr = temp->r - scirc->r;
395393

396-
result = distance + temp->r <= scirc->r;
394+
result = (dx * dx + dy * dy) <= (dr * dr);
397395
}
398396
else if (pgRect_Check(arg)) {
399397
SDL_Rect *temp = &pgRect_AsRect(arg);

src_c/doc/geometry_doc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#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"
1616
#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"
1717
#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"
18-
#define DOC_CIRCLE_CONTAINS "contains(circle, /) -> bool\ncontains(rect, /) -> bool\ncontains((x, y), /) -> bool\ncontains(vector2, /) -> bool\ntest if a shape or point is inside the circle"
18+
#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"
1919
#define DOC_CIRCLE_UPDATE "update((x, y), radius, /) -> None\nupdate(x, y, radius, /) -> None\nupdates the circle position and radius"
2020
#define DOC_CIRCLE_ROTATE "rotate(angle, rotation_point=Circle.center, /) -> Circle\nrotate(angle, /) -> Circle\nrotates the circle"
2121
#define DOC_CIRCLE_ROTATEIP "rotate_ip(angle, rotation_point=Circle.center, /) -> None\nrotate_ip(angle, /) -> None\nrotates the circle in place"

test/geometry_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,10 @@ def test_contains_circle(self):
11991199
# intersecting circle
12001200
self.assertFalse(c.contains(c4))
12011201

1202+
# bigger circle not contained in smaller circle
1203+
self.assertFalse(c2.contains(c))
1204+
self.assertFalse(c3.contains(c4))
1205+
12021206
def test_contains_point(self):
12031207
"""Ensures that the contains method correctly determines if a point is
12041208
contained within the circle"""

0 commit comments

Comments
 (0)