Skip to content

Commit

Permalink
Merge pull request pygame-community#2952 from zoldalma999/use-static-…
Browse files Browse the repository at this point in the history
…inline

Use static inline instead of inline
  • Loading branch information
damusss authored Jun 30, 2024
2 parents 778d471 + 4879429 commit c6c7d20
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
36 changes: 0 additions & 36 deletions src_c/geometry_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,39 +146,3 @@ pgCircle_FromObjectFastcall(PyObject *const *args, Py_ssize_t nargs,
return 0;
}
}

/* === Collision Functions === */

inline int
pgCollision_CirclePoint(pgCircleBase *circle, double Cx, double Cy)
{
double dx = circle->x - Cx;
double dy = circle->y - Cy;
return dx * dx + dy * dy <= circle->r * circle->r;
}

inline int
pgCollision_CircleCircle(pgCircleBase *A, pgCircleBase *B)
{
double dx, dy;
double sum_radii;

dx = A->x - B->x;
dy = A->y - B->y;
sum_radii = A->r + B->r;

return dx * dx + dy * dy <= sum_radii * sum_radii;
}

inline int
pgCollision_RectCircle(double rx, double ry, double rw, double rh,
pgCircleBase *circle)
{
const double cx = circle->x, cy = circle->y;
const double r_bottom = ry + rh, r_right = rx + rw;

const double test_x = (cx < rx) ? rx : ((cx > r_right) ? r_right : cx);
const double test_y = (cy < ry) ? ry : ((cy > r_bottom) ? r_bottom : cy);

return pgCollision_CirclePoint(circle, test_x, test_y);
}
38 changes: 31 additions & 7 deletions src_c/geometry_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,38 @@ pgCircle_FromObjectFastcall(PyObject *const *args, Py_ssize_t nargs,

/* === Collision Functions === */

inline int
pgCollision_CirclePoint(pgCircleBase *circle, double Cx, double Cy);
static inline int
pgCollision_CirclePoint(pgCircleBase *circle, double Cx, double Cy)
{
double dx = circle->x - Cx;
double dy = circle->y - Cy;
return dx * dx + dy * dy <= circle->r * circle->r;
}

static inline int
pgCollision_CircleCircle(pgCircleBase *A, pgCircleBase *B)
{
double dx, dy;
double sum_radii;

dx = A->x - B->x;
dy = A->y - B->y;
sum_radii = A->r + B->r;

return dx * dx + dy * dy <= sum_radii * sum_radii;
}

static inline int
pgCollision_RectCircle(double rx, double ry, double rw, double rh,
pgCircleBase *circle)
{
const double cx = circle->x, cy = circle->y;
const double r_bottom = ry + rh, r_right = rx + rw;

inline int
pgCollision_CircleCircle(pgCircleBase *A, pgCircleBase *B);
const double test_x = (cx < rx) ? rx : ((cx > r_right) ? r_right : cx);
const double test_y = (cy < ry) ? ry : ((cy > r_bottom) ? r_bottom : cy);

inline int
pgCollision_RectCircle(double rx, double ry, double rw, double rh,
pgCircleBase *circle);
return pgCollision_CirclePoint(circle, test_x, test_y);
}

#endif // PYGAME_CE_GEOMETRY_COMMON_H
4 changes: 2 additions & 2 deletions src_c/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -4192,13 +4192,13 @@ vector_elementwise(pgVector *vec, PyObject *_null)
return (PyObject *)proxy;
}

inline double
static inline double
lerp(double a, double b, double v)
{
return a + (b - a) * v;
}

inline double
static inline double
invlerp(double a, double b, double v)
{
return (v - a) / (b - a);
Expand Down

0 comments on commit c6c7d20

Please sign in to comment.