pygame-ce
pygame-ce copied to clipboard
Add draw.aaellipse
This PR adds draw.aaellipse function, with width and thickness options.
It is completely interchangeable with draw.ellipse in terms of arguments.
Algorithm used is adapted from Xiaolin Wu's general fast antialiasing algorithm, and is very similar to draw.aacircle.
Only notable difference: in aacircle, 8 pixels are drawn at once, but here, only 4, because ellipse has 2 symmetries. Because of that aaelipse has additional vertical drawing (aacircle has only horizontal but because of extra symmetries it is vertical at the same time).
It is added to docs too.
Sample code
import pygame
pygame.init()
screen = pygame.display.set_mode((512, 512))
clock = pygame.time.Clock()
run = True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
screen.fill("black")
pygame.draw.aaellipse(screen, "red", [100, 100, 100, 50], 1)
pygame.draw.aaellipse(screen, "red", [100, 160, 100, 50])
pygame.draw.aaellipse(screen, "red", [100, 220, 100, 50], 4)
pygame.display.flip()
clock.tick(60)
pygame.quit()
Note: before merging, correct versionadded in docs/reST/ref/draw.rst, if needed.
I moved ellipse and aaellipse functions bellow circle and aacircle, because aacircle is called in aaellipse and aa* functions should always be bellow regular one.
I see holes around the edges of the ellipse in this test case.
import pygame
screen = pygame.display.set_mode((600,600))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_w:
pygame.image.save(screen, "output.png")
screen.fill("purple")
pygame.draw.aaellipse(screen, "red", [100,200,300,400])
pygame.display.flip()
pygame.quit()
Other things I see.
- [x]
pygame.draw.aaellipse(screen, "red", [100,200,30,200000], width=0)crashes the app - [x] putting in a rect with negative dimensions leads to weird stuff being drawn
- [x] if the width and the height are equal the surface being drawn on cannot be blitted in the future (you forgot to unlock it in this case)
๐ Walkthrough
Walkthrough
Adds a new public API pygame.draw.aaellipse, implements antialiased ellipse/circle rendering in C using Xiaolin Wu variants, updates bindings and stubs, updates an example, and extends tests to cover aaellipse parity with ellipse.
Changes
| Cohort / File(s) | Summary |
|---|---|
Public stub / API declarationbuildconfig/stubs/pygame/draw.pyi |
Adds aaellipse(surface: Surface, color: ColorLike, rect: RectLike, width: int = 0) -> Rect declaration (versionadded 2.5.6). |
C implementation & bindingssrc_c/draw.c |
Adds aaellipse Python entrypoint and docstring; introduces Xiaolin Wu AA ellipse/circle routines (draw_aaellipse_xiaolinwu, _thin), renames circle Wu paths, adds symmetric-pixel helpers (draw_four_symmetric_pixels, draw_eight_symmetric_pixels, swap_int), updates clipping/bounds and 64-bit-safe arithmetic, routes square rects to aacircle, and registers method in _draw_methods. |
Documentation exampledocs/reST/ref/code_examples/draw_module_example.py |
Adjusts example ellipse x positions (+10) and adds two pygame.draw.aaellipse(...) examples (outlined and filled). |
Teststest/draw_test.py |
Adds draw_aaellipse alias, DrawAAEllipseMixin and DrawAAEllipseTest, and extensive tests mirroring ellipse coverage for aaellipse (args, keywords, color formats, widths, rect formats, bounds, edge/off-screen cases). |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant App
participant Draw as pygame.draw
participant AA as aaellipse()
participant Clip as Clip/Bounds
participant Algo as Wu AA Ellipse/Circle
participant Sym as Symmetric Helpers
participant Surf as Surface
App->>Draw: aaellipse(surface, color, rect, width?)
Draw->>AA: parse args & kwargs
AA->>Clip: validate rect, compute bounding box, clip
Clip-->>AA: clipped bounds
alt rect is square
AA->>Algo: route to aacircle (thin if width==1)
else rect is non-square
AA->>Algo: AA ellipse (thin if width==1)
end
Algo->>Sym: compute symmetric pixel positions & coverage
Sym->>Surf: blend/plot pixels
Algo-->>AA: return bounding Rect
AA-->>Draw: Rect
Draw-->>App: Rect
Estimated code review effort
๐ฏ 4 (Complex) | โฑ๏ธ ~60 minutes
[!TIP]
๐ Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
โจ Finishing Touches
- [ ] ๐ Generate Docstrings
๐งช Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
๐ชง Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.