From 5490e44e40dd6fa00661abd8d303fe2dc6fc443a Mon Sep 17 00:00:00 2001 From: Paul Vincent Craven Date: Tue, 24 Mar 2020 10:13:38 -0500 Subject: [PATCH] Fix for issue #616, create line strip command is exiting early. Also add in unit test to catch the error in the future. --- arcade/buffered_draw_commands.py | 6 ++-- tests/unit2/test_buffered_line_strip.py | 47 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/unit2/test_buffered_line_strip.py diff --git a/arcade/buffered_draw_commands.py b/arcade/buffered_draw_commands.py index a3a950beb..aa6ef0f29 100644 --- a/arcade/buffered_draw_commands.py +++ b/arcade/buffered_draw_commands.py @@ -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: @@ -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, diff --git a/tests/unit2/test_buffered_line_strip.py b/tests/unit2/test_buffered_line_strip.py new file mode 100644 index 000000000..9b0caa268 --- /dev/null +++ b/tests/unit2/test_buffered_line_strip.py @@ -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()