Skip to content

Commit 52c66bb

Browse files
authored
Merge pull request #4580 from radarhere/curve
Fixed drawing a jointed line with a sequence of numeric values
2 parents 57de57a + a5ef2b4 commit 52c66bb

2 files changed

Lines changed: 84 additions & 17 deletions

File tree

Tests/test_imagedraw.py

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -873,28 +873,93 @@ def test_wide_line_dot():
873873
assert_image_similar(im, Image.open(expected), 1)
874874

875875

876-
def test_line_joint():
876+
@pytest.mark.parametrize(
877+
"xy",
878+
[
879+
[
880+
(400, 280),
881+
(380, 280),
882+
(450, 280),
883+
(440, 120),
884+
(350, 200),
885+
(310, 280),
886+
(300, 280),
887+
(250, 280),
888+
(250, 200),
889+
(150, 200),
890+
(150, 260),
891+
(50, 200),
892+
(150, 50),
893+
(250, 100),
894+
],
895+
(
896+
400,
897+
280,
898+
380,
899+
280,
900+
450,
901+
280,
902+
440,
903+
120,
904+
350,
905+
200,
906+
310,
907+
280,
908+
300,
909+
280,
910+
250,
911+
280,
912+
250,
913+
200,
914+
150,
915+
200,
916+
150,
917+
260,
918+
50,
919+
200,
920+
150,
921+
50,
922+
250,
923+
100,
924+
),
925+
[
926+
400,
927+
280,
928+
380,
929+
280,
930+
450,
931+
280,
932+
440,
933+
120,
934+
350,
935+
200,
936+
310,
937+
280,
938+
300,
939+
280,
940+
250,
941+
280,
942+
250,
943+
200,
944+
150,
945+
200,
946+
150,
947+
260,
948+
50,
949+
200,
950+
150,
951+
50,
952+
250,
953+
100,
954+
],
955+
],
956+
)
957+
def test_line_joint(xy):
877958
im = Image.new("RGB", (500, 325))
878959
draw = ImageDraw.Draw(im)
879960
expected = "Tests/images/imagedraw_line_joint_curve.png"
880961

881962
# Act
882-
xy = [
883-
(400, 280),
884-
(380, 280),
885-
(450, 280),
886-
(440, 120),
887-
(350, 200),
888-
(310, 280),
889-
(300, 280),
890-
(250, 280),
891-
(250, 200),
892-
(150, 200),
893-
(150, 260),
894-
(50, 200),
895-
(150, 50),
896-
(250, 100),
897-
]
898963
draw.line(xy, GRAY, 50, "curve")
899964

900965
# Assert

src/PIL/ImageDraw.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def line(self, xy, fill=None, width=0, joint=None):
156156
if ink is not None:
157157
self.draw.draw_lines(xy, ink, width)
158158
if joint == "curve" and width > 4:
159+
if not isinstance(xy[0], (list, tuple)):
160+
xy = [tuple(xy[i : i + 2]) for i in range(0, len(xy), 2)]
159161
for i in range(1, len(xy) - 1):
160162
point = xy[i]
161163
angles = [

0 commit comments

Comments
 (0)