Repository: python-pillow/Pillow

Issue:
Bug with line joints
### What did you do?

When I use the `joint='curve'` attribute on the line method with a sequence of numeric value, I get an error.

### What did you expect to happen?

[The documentation say](https://pillow.readthedocs.io/en/stable/reference/ImageDraw.html#PIL.ImageDraw.PIL.ImageDraw.ImageDraw.line) that you can pass *Sequence of either 2-tuples or numeric values*.

So, this should work:
```pycon
>>> from PIL import Image, ImageDraw
>>> im = Image.new('RGB', (800, 600))
>>> draw = ImageDraw.Draw(im)
>>> draw.line((400, 200, 300, 280, 100, 280), 0, 50, joint='curve')
```


### What actually happened?

 *Sequence of 2-tuples*  and `joint='curve'` works fine :

```pycon
>>> draw.line(((400, 200), (300, 280), (100, 280)), 0, 50, joint='curve')
```

*Sequence of numeric values*, but no `joint='curve'` works fine : 

```pycon
>>> draw.line((400,200,300,280,100,280), 0, 50)
```

*Sequence of numeric values*   and `joint='curve'` doesn't work :
```pycon
>>> draw.line((400,200,300,280,100,280), 0, 50, joint='curve')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/leon/virtualenvs/ogn/lib/python3.5/site-packages/PIL/ImageDraw.py", line 165, in line
    for start, end in ((xy[i-1], point), (point, xy[i+1]))
  File "/home/leon/virtualenvs/ogn/lib/python3.5/site-packages/PIL/ImageDraw.py", line 165, in <listcomp>
    for start, end in ((xy[i-1], point), (point, xy[i+1]))
TypeError: 'int' object is not subscriptable
```

### What are your OS, Python and Pillow versions?

* OS: Debian Linux
* Python: 3.5.3
* Pillow: '5.4.1'



Discussion:
Thanks for reporting this bug. I've created PR #4580 to resolve it.

Resolving patch:
diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py
--- a/src/PIL/ImageDraw.py
+++ b/src/PIL/ImageDraw.py
@@ -156,6 +156,8 @@ def line(self, xy, fill=None, width=0, joint=None):
         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 = [


Test patch:
diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py
--- a/Tests/test_imagedraw.py
+++ b/Tests/test_imagedraw.py
@@ -873,28 +873,93 @@ def test_wide_line_dot():
     assert_image_similar(im, Image.open(expected), 1)
 
 
-def test_line_joint():
+@pytest.mark.parametrize(
+    "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),
+        ],
+        (
+            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,
+        ],
+    ],
+)
+def test_line_joint(xy):
     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")
 
     # Assert