Skip to content

Commit 00abf9e

Browse files
committed
address issue with circle case
1 parent 4d2e563 commit 00abf9e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src_c/circle.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,16 @@ pg_circle_contains(pgCircleObject *self, PyObject *arg)
384384
/*a circle is always contained within itself*/
385385
Py_RETURN_TRUE;
386386
}
387-
double dx, dy, dr;
387+
/* a bigger circle can't be contained within a smaller circle */
388+
if (temp->r > scirc->r) {
389+
Py_RETURN_FALSE;
390+
}
388391

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

393-
result = (dx * dx + dy * dy) <= (dr * dr);
396+
result = distance + temp->r <= scirc->r;
394397
}
395398
else if (pgRect_Check(arg)) {
396399
SDL_Rect *temp = &pgRect_AsRect(arg);

0 commit comments

Comments
 (0)