From 4879429e51e447afc8e79f8d8464d03e35f9dbc1 Mon Sep 17 00:00:00 2001 From: zoldalma <46655437+zoldalma999@users.noreply.github.com> Date: Sun, 23 Jun 2024 10:27:54 +0200 Subject: [PATCH] Use static inline instead of inline --- src_c/geometry_common.c | 36 ------------------------------------ src_c/geometry_common.h | 38 +++++++++++++++++++++++++++++++------- src_c/math.c | 4 ++-- 3 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src_c/geometry_common.c b/src_c/geometry_common.c index 5116cc6b0d..5003dadc9c 100644 --- a/src_c/geometry_common.c +++ b/src_c/geometry_common.c @@ -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); -} diff --git a/src_c/geometry_common.h b/src_c/geometry_common.h index 124abca450..66628de282 100644 --- a/src_c/geometry_common.h +++ b/src_c/geometry_common.h @@ -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 diff --git a/src_c/math.c b/src_c/math.c index 8ed8ccae5e..51c5fd3641 100644 --- a/src_c/math.c +++ b/src_c/math.c @@ -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);