From f5e9252b12890502f3c9b24d32941ab09e297523 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 24 Apr 2020 18:48:10 +1000 Subject: [PATCH] Fixed drawing a jointed line with a sequence of numeric values --- Tests/test_imagedraw.py | 108 +++++++++++++++++++++++++++++++--------- src/PIL/ImageDraw.py | 2 + 2 files changed, 87 insertions(+), 23 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index f6eabb21a..5aa9599ec 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -874,31 +874,93 @@ def test_wide_line_dot(): def test_line_joint(): - im = Image.new("RGB", (500, 325)) - draw = ImageDraw.Draw(im) - expected = "Tests/images/imagedraw_line_joint_curve.png" + for xy in [ + [ + (400, 280), + (380, 280), + (450, 280), + (440, 120), + (350, 200), + (310, 280), + (300, 280), + (250, 280), + (250, 200), + (150, 200), + (150, 260), + (50, 200), + (150, 50), + (250, 100), + ], + ( + 400, + 280, + 380, + 280, + 450, + 280, + 440, + 120, + 350, + 200, + 310, + 280, + 300, + 280, + 250, + 280, + 250, + 200, + 150, + 200, + 150, + 260, + 50, + 200, + 150, + 50, + 250, + 100, + ), + [ + 400, + 280, + 380, + 280, + 450, + 280, + 440, + 120, + 350, + 200, + 310, + 280, + 300, + 280, + 250, + 280, + 250, + 200, + 150, + 200, + 150, + 260, + 50, + 200, + 150, + 50, + 250, + 100, + ], + ]: + im = Image.new("RGB", (500, 325)) + draw = ImageDraw.Draw(im) + expected = "Tests/images/imagedraw_line_joint_curve.png" - # Act - xy = [ - (400, 280), - (380, 280), - (450, 280), - (440, 120), - (350, 200), - (310, 280), - (300, 280), - (250, 280), - (250, 200), - (150, 200), - (150, 260), - (50, 200), - (150, 50), - (250, 100), - ] - draw.line(xy, GRAY, 50, "curve") + # Act + draw.line(xy, GRAY, 50, "curve") - # Assert - assert_image_similar(im, Image.open(expected), 3) + # Assert + assert_image_similar(im, Image.open(expected), 3) def test_textsize_empty_string(): diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 7abd459f9..cbecf652d 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -156,6 +156,8 @@ class ImageDraw: if ink is not None: self.draw.draw_lines(xy, ink, width) if joint == "curve" and width > 4: + if not isinstance(xy[0], (list, tuple)): + xy = [tuple(xy[i : i + 2]) for i in range(0, len(xy), 2)] for i in range(1, len(xy) - 1): point = xy[i] angles = [