Skip to content

Draw large and long and thin ellipses without overflow - #10611

Open
aclark4life wants to merge 2 commits into
mainfrom
ellipse-large-and-thin
Open

aclark4life wants to merge 2 commits into
mainfrom
ellipse-large-and-thin

Conversation

@aclark4life

Copy link
Copy Markdown
Member

The ellipse walk shared by ellipse(), circle(), arc(), chord() and pieslice() calculated a²y² + b²x² - a²b² in int64_t. For large ellipses, that overflowed, and the walk could fail to finish. It also visited every point along the ellipse, so time grew with the size of the ellipse rather than the image.

This

  • calculates the walk with wrapping uint64_t arithmetic. The result is exact while the values compared fit in int64_t, so large circles draw as before. Ellipses too large for that, more than about 830,000 pixels across, draw nothing.
  • skips long horizontal runs of the walk with a binary search, since only the first and last point of each row are used.
  • skips rows above the image the same way, and stops after the last row that can be on the image.
On a 16x16 image main This PR
ellipse((0, 0, 2**30, 1)) 16.4 s < 1 ms
ellipse((0, 0, 1, 2**30)) 7.6 s < 1 ms
ellipse((0, 0, 2**28, 2**28)) 13.8 s < 1 ms

The output is unchanged: comparing with main across 67,834 ellipses, arcs, chords and pieslices with fills and outline widths, including partly visible ones and circles up to 700,000 pixels across, all were pixel-identical.

🤖 Generated with Claude Code

Calculate the ellipse walk with wrapping unsigned arithmetic, so that
large circles draw correctly without signed overflow, and draw nothing
for ellipses too large for 64-bit arithmetic.

Skip long horizontal runs of the walk, and rows above the image, so that
drawing takes time proportional to the image rather than the ellipse.
Output is otherwise unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aclark4life aclark4life added Bug Any unexpected behavior, until confirmed feature. Performance 🤖-assisted AI-assisted labels Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted Bug Any unexpected behavior, until confirmed feature. Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant