Skip to content

Avoid modulo in Polygon pixel test - #11623

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:vectorio-polygon-modulo
Oct 17, 2026
Merged

dhalbert merged 1 commit into
adafruit:mainfrom
MakerClassCZ:vectorio-polygon-modulo

Conversation

@lynt-smitka

Copy link
Copy Markdown

Polygon did two % operations per edge for every pixel it drew. They were only needed to wrap around on the last edge. The RP2040 has no divide instruction, so these took most of the drawing time.

Time to refresh a star-shaped polygon:

Board 6 vertices 48 vertices
PicoPad (RP2040) 231 → 120 ms 1965 → 621 ms
Fruit Jam (RP2350) 78 → 68 ms 530 → 437 ms

The edges are visited in the same order as before, so the output is the same. Flash is 16–48 bytes smaller.

Tested on both boards.

get_pixel did two modulo operations per edge for every pixel, only to wrap around on the last edge. The RP2040 has no divide instruction, so this was most of the drawing time.

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!

@dhalbert
dhalbert enabled auto-merge October 16, 2026 21:42
@dhalbert
dhalbert merged commit dcad81e into adafruit:main Oct 17, 2026
584 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants