-
-
Notifications
You must be signed in to change notification settings - Fork 198
Add Circle collideswith()
#2661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
699efaf
76ea633
ebe38db
ade28da
e4b155d
1e56aa8
669c481
096b0bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,6 +388,44 @@ pg_circle_colliderect(pgCircleObject *self, PyObject *const *args, | |
return PyBool_FromLong(pgCollision_RectCircle(x, y, w, h, &self->circle)); | ||
} | ||
|
||
static PyObject * | ||
pg_circle_collideswith(pgCircleObject *self, PyObject *arg) | ||
{ | ||
int result = 0; | ||
pgCircleBase *scirc = &self->circle; | ||
if (pgCircle_Check(arg)) { | ||
result = pgCollision_CircleCircle(&pgCircle_AsCircle(arg), scirc); | ||
} | ||
else if (pgRect_Check(arg)) { | ||
SDL_Rect *argrect = &pgRect_AsRect(arg); | ||
result = pgCollision_RectCircle((double)argrect->x, (double)argrect->y, | ||
(double)argrect->w, (double)argrect->h, | ||
scirc); | ||
} | ||
else if (pgFRect_Check(arg)) { | ||
SDL_FRect *argrect = &pgFRect_AsRect(arg); | ||
result = pgCollision_RectCircle((double)argrect->x, (double)argrect->y, | ||
(double)argrect->w, (double)argrect->h, | ||
scirc); | ||
} | ||
else if (PySequence_Check(arg)) { | ||
double x, y; | ||
if (!pg_TwoDoublesFromObj(arg, &x, &y)) { | ||
return RAISE( | ||
PyExc_TypeError, | ||
"Invalid point argument, must be a sequence of 2 numbers"); | ||
} | ||
result = pgCollision_CirclePoint(scirc, x, y); | ||
} | ||
else { | ||
return RAISE(PyExc_TypeError, | ||
"Invalid shape argument, must be a CircleType, RectType, " | ||
"LineType, PolygonType or a sequence of 2 numbers"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know about this one, because the argument is an instance of those types not a type itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I changed it a bit. I've removed mentions of Line and Poly as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure Coordinate should've been used instead of a sequence of two points since we don't really have a Coordinate object, it only appears in type stubs, maybe you can change that back, as for the other shapes, maybe those could stay in the message since otherwise they'd have to be added later and that could be forgotten. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. |
||
} | ||
|
||
return PyBool_FromLong(result); | ||
} | ||
|
||
static struct PyMethodDef pg_circle_methods[] = { | ||
{"collidepoint", (PyCFunction)pg_circle_collidepoint, METH_FASTCALL, | ||
DOC_CIRCLE_COLLIDEPOINT}, | ||
|
@@ -400,6 +438,8 @@ static struct PyMethodDef pg_circle_methods[] = { | |
DOC_CIRCLE_COLLIDERECT}, | ||
{"update", (PyCFunction)pg_circle_update, METH_FASTCALL, | ||
DOC_CIRCLE_UPDATE}, | ||
{"collideswith", (PyCFunction)pg_circle_collideswith, METH_O, | ||
DOC_CIRCLE_COLLIDESWITH}, | ||
{"__copy__", (PyCFunction)pg_circle_copy, METH_NOARGS, DOC_CIRCLE_COPY}, | ||
{"copy", (PyCFunction)pg_circle_copy, METH_NOARGS, DOC_CIRCLE_COPY}, | ||
{NULL, NULL, 0, NULL}}; | ||
|
Uh oh!
There was an error while loading. Please reload this page.