Repository navigation
Name the bad point when a draw function gets malformed points - #2972
Merged
Merged
Conversation
draw_lines, draw_points, draw_line_strip, draw_polygon_filled and draw_polygon_outline raise a ValueError naming the first point that isn't 2 numbers. Before, a bad point raised errors like "'int' object is not iterable", and a point with 1 or 3 numbers silently shifted the rest of the data. The check is one length comparison per call; the slow scan only runs after something went wrong. Points are now flattened with tuple(chain.from_iterable(...)), which is about twice as fast as the generator it replaces, so drawing 1,000 lines or points got faster. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2215
draw_lines,draw_points,draw_line_strip,draw_polygon_filledanddraw_polygon_outlinenow raise aValueErrornaming the first bad point:Before:
'int' object is not iterable,'int' object is not subscriptable, orValue after * must be an iterable, not int, depending on the function.draw_lines,draw_pointsand thindraw_line_strip, a point with 1 or 3 numbers (such as aVec3) didn't raise anything. It shifted every number after it, so the drawing came out scrambled.No cost to drawing speed
_flatten_points()inarcade/draw/helpers.pywraps the existing conversion intry, then compares the array's length with twice the number of points. That's one comparison per call, however many points there are, and it catches 1- and 3-number points. The scan that finds which point is bad only runs after something went wrong.array.array("f", tuple(chain.from_iterable(point_list))), which is about twice as fast as the generatordraw_linesanddraw_pointsused. So drawing got faster.Measured in a hidden window, µs per call (best of 5 × 300 calls;
draw_line_stripis the median of 15 runs, from two rounds):draw_lines, 4 pointsdraw_lines, 1,000 pointsdraw_points, 1,000 pointsdraw_line_strip, 100 pointsdraw_line_strip, 1,000 pointsMost of a small call is fixed GPU overhead (about 50 µs), so the speedup shows with many points.
Notes
draw_line_stripwith a width other than 1,draw_polygon_outline) anddraw_polygon_filledreadpoint[0]andpoint[1], so a 3-number point still works there by ignoring z, as before. They only raise for points that aren't at least 2 numbers.draw_polygon_outlineused to fail on aVec3with an argument-count error. It now raises the clear error, because the polygon loop unpacks the whole point.TypeErrortoValueError, as the issue asked.arcade.shape_list.create_linesand so on) aren't changed.Tests
tests/unit/draw/test_point_validation.py:_flatten_pointswith tuples,Vec2, an empty list, and the bad cases (a non-point, 1 number, 3 numbers, a string).draw_line_strippaths) with good tuples, goodVec2s, and a bad point.developmentthe 6 draw-function tests fail with the oldTypeErrors.The full test suite (1851), ruff, mypy and pyright pass.
🤖 Generated with Claude Code