From 82a08d2032daf929b5b8b73812b1100946e9cbe2 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 16 Feb 2023 08:51:21 -0600 Subject: [PATCH] order ImageDraw.rounded_rectangle() points --- Tests/test_imagedraw.py | 16 ++++++++++++++++ src/PIL/ImageDraw.py | 1 + 2 files changed, 17 insertions(+) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index d4723c924..b3f03898b 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -735,6 +735,22 @@ def test_rounded_rectangle(xy): assert_image_equal_tofile(im, "Tests/images/imagedraw_rounded_rectangle.png") +@pytest.mark.parametrize( + "xy", + ((10, 20, 190, 180), (190, 20, 10, 180), (190, 180, 10, 20), (10, 180, 190, 20)), +) +def test_rounded_rectangle_unordered_points(xy): + # Arrange + im = Image.new("RGB", (200, 200)) + draw = ImageDraw.Draw(im) + + # Act + draw.rounded_rectangle(xy, 30, fill="red", outline="green", width=5) + + # Assert + assert_image_equal_tofile(im, "Tests/images/imagedraw_rounded_rectangle.png") + + @pytest.mark.parametrize( "xy, radius, type", [ diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 163828d31..733608f6b 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -301,6 +301,7 @@ class ImageDraw: (x0, y0), (x1, y1) = xy else: x0, y0, x1, y1 = xy + x0, y0, x1, y1 = min(x0, x1), min(y0, y1), max(x0, x1), max(y0, y1) d = radius * 2