Fixed drawing a jointed line with a sequence of numeric values

This commit is contained in:
Andrew Murray 2020-04-24 18:48:10 +10:00
parent 556c87c904
commit f5e9252b12
2 changed files with 87 additions and 23 deletions

View File

@ -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():

View File

@ -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 = [