Merge pull request #4580 from radarhere/curve

Fixed drawing a jointed line with a sequence of numeric values
This commit is contained in:
Hugo van Kemenade 2020-06-04 12:03:25 +03:00 committed by GitHub
commit 52c66bbcfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 17 deletions

View File

@ -873,13 +873,10 @@ def test_wide_line_dot():
assert_image_similar(im, Image.open(expected), 1)
def test_line_joint():
im = Image.new("RGB", (500, 325))
draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_line_joint_curve.png"
# Act
xy = [
@pytest.mark.parametrize(
"xy",
[
[
(400, 280),
(380, 280),
(450, 280),
@ -894,7 +891,75 @@ def test_line_joint():
(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
draw.line(xy, GRAY, 50, "curve")
# Assert

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