From 22a9a7df770565468494d6dfc71712e15d67dffd Mon Sep 17 00:00:00 2001 From: MightyJosip Date: Tue, 11 Jul 2023 12:13:23 +0200 Subject: [PATCH 1/2] Fix round rect with negative values --- src_c/draw.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src_c/draw.c b/src_c/draw.c index da3a7e9714..def09bf949 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -972,9 +972,15 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs) rect->y += rect->h; rect->h = -rect->h; } + // Ignore negative values + radius = MAX(radius, 0); + top_left_radius = MAX(top_left_radius, 0); + top_right_radius = MAX(top_right_radius, 0); + bottom_left_radius = MAX(bottom_left_radius, 0); + bottom_right_radius = MAX(bottom_right_radius, 0); if (width > rect->w / 2 || width > rect->h / 2) { - width = MAX(rect->w / 2, rect->h / 2); + width = 0; } draw_round_rect(surf, rect->x, rect->y, rect->x + rect->w - 1, @@ -2472,14 +2478,10 @@ draw_round_rect(SDL_Surface *surf, int x1, int y1, int x2, int y2, int radius, { int pts[16], i; float q_top, q_left, q_bottom, q_right, f; - if (top_left < 0) - top_left = radius; - if (top_right < 0) - top_right = radius; - if (bottom_left < 0) - bottom_left = radius; - if (bottom_right < 0) - bottom_right = radius; + if (!top_left) top_left = radius; + if (!top_right) top_right = radius; + if (!bottom_left) bottom_left = radius; + if (!bottom_right) bottom_right = radius; if ((top_left + top_right) > (x2 - x1 + 1) || (bottom_left + bottom_right) > (x2 - x1 + 1) || (top_left + bottom_left) > (y2 - y1 + 1) || From af8b7bd90592f1ddc0409f77090f3b6fb8dac162 Mon Sep 17 00:00:00 2001 From: MightyJosip Date: Tue, 11 Jul 2023 12:23:16 +0200 Subject: [PATCH 2/2] Fix round rect with negative values --- src_c/draw.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src_c/draw.c b/src_c/draw.c index def09bf949..ad72040701 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -2478,10 +2478,14 @@ draw_round_rect(SDL_Surface *surf, int x1, int y1, int x2, int y2, int radius, { int pts[16], i; float q_top, q_left, q_bottom, q_right, f; - if (!top_left) top_left = radius; - if (!top_right) top_right = radius; - if (!bottom_left) bottom_left = radius; - if (!bottom_right) bottom_right = radius; + if (!top_left) + top_left = radius; + if (!top_right) + top_right = radius; + if (!bottom_left) + bottom_left = radius; + if (!bottom_right) + bottom_right = radius; if ((top_left + top_right) > (x2 - x1 + 1) || (bottom_left + bottom_right) > (x2 - x1 + 1) || (top_left + bottom_left) > (y2 - y1 + 1) ||