Skip to content

Commit

Permalink
Fix for issue pythonarcade#616, create line strip command is exiting …
Browse files Browse the repository at this point in the history
…early. Also add in unit test to catch the error in the future.
  • Loading branch information
pvcraven committed Mar 24, 2020
1 parent bffe5ff commit 5490e44
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
6 changes: 4 additions & 2 deletions arcade/buffered_draw_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def create_line_strip(point_list: PointList,
Create a multi-point line to be rendered later. This works faster than draw_line because
the vertexes are only loaded to the graphics card once, rather than each frame.
Internally, thick lines are created by two triangles.
:param PointList point_list:
:param Color color:
:param PointList line_width:
Expand All @@ -214,8 +216,8 @@ def create_line_strip(point_list: PointList,
new_color_list += color1, color2, color1, color2
triangle_point_list += points[1], points[0], points[2], points[3]

shape = create_triangles_filled_with_colors(triangle_point_list, new_color_list)
return shape
shape = create_triangles_filled_with_colors(triangle_point_list, new_color_list)
return shape


def create_line_loop(point_list: PointList,
Expand Down
47 changes: 47 additions & 0 deletions tests/unit2/test_buffered_line_strip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import arcade

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600


class MyGame(arcade.Window):
""" Main application class. """

def __init__(self, width, height):
"""
Initializer
"""
super().__init__(width, height)

arcade.set_background_color(arcade.color.WHITE)

point_list = ([0, 100],
[100, 100],
[100, 300],
[300, 300])
self.line_strip = arcade.create_line_strip(point_list, arcade.csscolor.BLACK, 10)

def on_draw(self):
arcade.start_render()
self.line_strip.draw()
p = arcade.get_pixel(0, 100)
assert p == (0, 0, 0)
p = arcade.get_pixel(0, 95)
assert p == (0, 0, 0)
p = arcade.get_pixel(0, 94)
assert p == (255, 255, 255)
p = arcade.get_pixel(50, 100)
assert p == (0, 0, 0)
p = arcade.get_pixel(100, 200)
assert p == (0, 0, 0)
p = arcade.get_pixel(150, 300)
assert p == (0, 0, 0)
p = arcade.get_pixel(301, 300)
assert p == (255, 255, 255)


def test_main():
""" Main method """
window = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT)
window.test()
window.close()

0 comments on commit 5490e44

Please sign in to comment.