Skip to content

Commit

Permalink
remove excess rotate function
Browse files Browse the repository at this point in the history
  • Loading branch information
itzpr3d4t0r committed May 27, 2024
1 parent f032a65 commit 2718395
Showing 1 changed file with 0 additions and 93 deletions.
93 changes: 0 additions & 93 deletions src_c/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,99 +732,6 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
return ret;
}

static void
_pg_rotate_circle_helper(pgCircleBase *circle, double angle, double rx,
double ry)
{
if (angle == 0.0 || fmod(angle, 360.0) == 0.0) {
return;
}

double x = circle->x - rx;
double y = circle->y - ry;

const double angle_rad = DEG_TO_RAD(angle);

double cos_theta = cos(angle_rad);
double sin_theta = sin(angle_rad);

circle->x = rx + x * cos_theta - y * sin_theta;
circle->y = ry + x * sin_theta + y * cos_theta;
}

static PyObject *
pg_circle_rotate(pgCircleObject *self, PyObject *const *args, Py_ssize_t nargs)
{
if (!nargs || nargs > 2) {
return RAISE(PyExc_TypeError, "rotate requires 1 or 2 arguments");
}

pgCircleBase *circle = &self->circle;
double angle, rx, ry;

rx = circle->x;
ry = circle->y;

if (!pg_DoubleFromObj(args[0], &angle)) {
return RAISE(PyExc_TypeError,
"Invalid angle argument, must be numeric");
}

if (nargs != 2) {
return _pg_circle_subtype_new(Py_TYPE(self), circle);
}

if (!pg_TwoDoublesFromObj(args[1], &rx, &ry)) {
return RAISE(PyExc_TypeError,
"Invalid rotation point argument, must be a sequence of "
"2 numbers");
}

PyObject *circle_obj = _pg_circle_subtype_new(Py_TYPE(self), circle);
if (!circle_obj) {
return NULL;
}

_pg_rotate_circle_helper(&pgCircle_AsCircle(circle_obj), angle, rx, ry);

return circle_obj;
}

static PyObject *
pg_circle_rotate_ip(pgCircleObject *self, PyObject *const *args,
Py_ssize_t nargs)
{
if (!nargs || nargs > 2) {
return RAISE(PyExc_TypeError, "rotate requires 1 or 2 arguments");
}

pgCircleBase *circle = &self->circle;
double angle, rx, ry;

rx = circle->x;
ry = circle->y;

if (!pg_DoubleFromObj(args[0], &angle)) {
return RAISE(PyExc_TypeError,
"Invalid angle argument, must be numeric");
}

if (nargs != 2) {
/* just return None */
Py_RETURN_NONE;
}

if (!pg_TwoDoublesFromObj(args[1], &rx, &ry)) {
return RAISE(PyExc_TypeError,
"Invalid rotation point argument, must be a sequence "
"of 2 numbers");
}

_pg_rotate_circle_helper(circle, angle, rx, ry);

Py_RETURN_NONE;
}

static struct PyMethodDef pg_circle_methods[] = {
{"collidecircle", (PyCFunction)pg_circle_collidecircle, METH_FASTCALL,
NULL},
Expand Down

0 comments on commit 2718395

Please sign in to comment.