Added test for horizontal lines

Notice that the expansion of the line width depends on the order of the
points:
  * If the bigger axis value is provided as the *second* point the line
    expand first to the *positive* side of the axis.
  * If the bigger axis value is provided as the *first* point the line
    expand first to the *negative* side of the axis.
  * If the line's width is odd this doesn't matter, as the line will
    expand the same amount to both sides.

This behavior should be consistent in both horizontal and vertical lines.
This commit is contained in:
Terseus 2014-04-04 12:35:26 +02:00
parent e2cb2195eb
commit fee2faa8dc
4 changed files with 25 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

View File

@ -70,3 +70,28 @@ def test_triangle_right():
img, draw = create_base_image_draw((20, 20))
draw.polygon([(3, 5), (17, 5), (10, 12)], BLACK)
assert_image_equal(img, expected)
def test_line_horizontal():
# Normal 2px line
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w2px_normal.png'))
expected.load()
img, draw = create_base_image_draw((20, 20))
draw.line((5, 5, 14, 5), BLACK, 2)
assert_image_equal(img, expected)
# Inverted 2px line
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w2px_inverted.png'))
expected.load()
img, draw = create_base_image_draw((20, 20))
draw.line((14, 5, 5, 5), BLACK, 2)
assert_image_equal(img, expected)
# Normal 3px line
expected = Image.open(os.path.join(IMAGES_PATH, 'line_horizontal_w3px.png'))
expected.load()
img, draw = create_base_image_draw((20, 20))
draw.line((5, 5, 14, 5), BLACK, 3)
assert_image_equal(img, expected)
# Inverted 3px line
img, draw = create_base_image_draw((20, 20))
draw.line((14, 5, 5, 5), BLACK, 3)
assert_image_equal(img, expected)