Use hypot function

This commit is contained in:
Andrew Murray 2020-06-23 19:17:00 +10:00
parent b667fd83cf
commit c1fe0b4e0c
3 changed files with 14 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

View File

@ -887,6 +887,19 @@ def test_wide_line_dot():
assert_image_similar(im, Image.open(expected), 1)
def test_wide_line_larger_than_int():
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)
expected = "Tests/images/imagedraw_wide_line_larger_than_int.png"
# Act
draw.line([(0, 0), (32768, 32768)], width=3)
# Assert
assert_image_similar(im, Image.open(expected), 1)
@pytest.mark.parametrize(
"xy",
[

View File

@ -683,7 +683,7 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
return 0;
}
big_hypotenuse = sqrt((double) (dx*dx + dy*dy));
big_hypotenuse = hypot(dx, dy);
small_hypotenuse = (width - 1) / 2.0;
ratio_max = ROUND_UP(small_hypotenuse) / big_hypotenuse;
ratio_min = ROUND_DOWN(small_hypotenuse) / big_hypotenuse;