Skip to content

Commit c1fe0b4

Browse files
committed
Use hypot function
1 parent b667fd8 commit c1fe0b4

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

557 Bytes
Loading

Tests/test_imagedraw.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,19 @@ def test_wide_line_dot():
887887
assert_image_similar(im, Image.open(expected), 1)
888888

889889

890+
def test_wide_line_larger_than_int():
891+
# Arrange
892+
im = Image.new("RGB", (W, H))
893+
draw = ImageDraw.Draw(im)
894+
expected = "Tests/images/imagedraw_wide_line_larger_than_int.png"
895+
896+
# Act
897+
draw.line([(0, 0), (32768, 32768)], width=3)
898+
899+
# Assert
900+
assert_image_similar(im, Image.open(expected), 1)
901+
902+
890903
@pytest.mark.parametrize(
891904
"xy",
892905
[

src/libImaging/Draw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
683683
return 0;
684684
}
685685

686-
big_hypotenuse = sqrt((double) (dx*dx + dy*dy));
686+
big_hypotenuse = hypot(dx, dy);
687687
small_hypotenuse = (width - 1) / 2.0;
688688
ratio_max = ROUND_UP(small_hypotenuse) / big_hypotenuse;
689689
ratio_min = ROUND_DOWN(small_hypotenuse) / big_hypotenuse;

0 commit comments

Comments
 (0)