Skip to content

Add draw.aarect() to draw anti-aliased and rounded rectangles#3701

Open
Fantastair wants to merge 4 commits intopygame-community:mainfrom
Fantastair:add-aarect
Open

Add draw.aarect() to draw anti-aliased and rounded rectangles#3701
Fantastair wants to merge 4 commits intopygame-community:mainfrom
Fantastair:add-aarect

Conversation

@Fantastair
Copy link
Contributor

Implemented the enhancement mentioned in #3700.

  • Added the following to src_c/draw.c:

    • draw_round_rect_xiaolinwu() function, used to draw anti-aliased rounded rectangles (corresponding to the functionality of draw_round_rect(), but internally uses draw_circle_xiaolinwu() to draw the rounded corners).
    • The aarect() function serves as the Python API interface. Its parameters and functionality are identical to the draw.rect() function, except it draws anti-aliased rounded rectangles. Internally, it calls draw_round_rect_xiaolinwu().
  • Added example code related to aarect() in docs/reST/ref/code_examples/draw_module_example.py.

  • Added function annotations for aarect() in buildconfig/stubs/pygame/draw.pyi.

  • Added aarect()-related unit tests to test/draw_test.py. (Incidentally, I noticed the test_color_validation subtest in the DrawModuleTest class lacked coverage for draw.rect(), so I added it as well.)

@Fantastair Fantastair requested a review from a team as a code owner February 5, 2026 08:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • docs/reST/ref/code_examples/draw_module_example.png is excluded by !**/*.png

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
📝 Walkthrough

Walkthrough

Adds a new public drawing function, pygame.draw.aarect, implemented in C (Xiaolin Wu anti-aliasing), with pyi stub, documentation examples, and tests; binds the C implementation to the draw module and exposes it in the test suite.

Changes

Cohort / File(s) Summary
Type Definitions
buildconfig/stubs/pygame/draw.pyi
Added aarect signature with parameters for surface, color, rect, width, and per-corner border radii.
Documentation
docs/reST/ref/code_examples/draw_module_example.py
Added three example calls demonstrating pygame.draw.aarect with various widths and rounded-corner configurations.
Core Implementation
src_c/draw.c
Added aarect Python-exposed function, argument parsing/validation, surface lock/unlock, and draw_round_rect_xiaolinwu helper implementing anti-aliased rounded-rectangle rendering; registered aarect in module method table.
Tests
test/draw_test.py
Added DrawAARectMixin and DrawAARectTest, exposed draw_aarect alias on DrawTestCase, and extended tests to validate argument forms, clipping, widths, colors, and bounding rectangles for aarect.

Sequence Diagram(s)

sequenceDiagram
    participant Py as Python caller
    participant DrawMod as draw module binding
    participant CImpl as C implementation (aarect)
    participant SDL as SDL_Surface

    Py->>DrawMod: pygame.draw.aarect(surface, color, rect, ...)
    DrawMod->>CImpl: call aarect(...) (args parsed)
    CImpl->>CImpl: validate args & compute radii/area
    CImpl->>SDL: lock surface
    CImpl->>CImpl: if rounded -> draw_round_rect_xiaolinwu(...)
    CImpl->>SDL: blit/modify pixels within drawn area
    CImpl->>SDL: unlock surface
    CImpl-->>DrawMod: return drawn Rect
    DrawMod-->>Py: return Rect
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Issue #3700: Implements the requested pygame.draw.aarect API (C implementation, binding, stub, docs, tests).
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 68.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding the draw.aarect() function for anti-aliased and rounded rectangles, which is the primary focus of all modifications across the codebase.
Description check ✅ Passed The description is directly related to the changeset, detailing the specific files modified, functions added (draw_round_rect_xiaolinwu and aarect), and additional documentation and test coverage provided.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src_c/draw.c`:
- Around line 4259-4268: Run the formatter to fix clang-format issues affecting
draw_round_rect_xiaolinwu and surrounding declarations: execute "python3 dev.py
format" (or "python3 dev.py all" to catch all files), review the changes to the
draw_round_rect_xiaolinwu function signature and local variable declarations
(pts, q_top, q_left, q_bottom, q_right, f) to ensure only style changes were
applied, then stage and commit the formatted changes.

In `@test/draw_test.py`:
- Around line 5173-5180: The tests assign to an unused variable bounds_rect
inside assertRaises blocks causing F841 lint errors; remove the assignments so
the calls to self.draw_aarect(...) are executed only for their exception check
(e.g., change "bounds_rect = self.draw_aarect(...)" to "self.draw_aarect(...)"
in the assertRaises blocks). Apply the same change for all occurrences mentioned
(other blocks around lines referencing draw_aarect and bounds_rect).

Comment on lines +5173 to +5180
with self.assertRaises(TypeError):
bounds_rect = self.draw_aarect(surface, pygame.Color("white"))

with self.assertRaises(TypeError):
bounds_rect = self.draw_aarect(surface)

with self.assertRaises(TypeError):
bounds_rect = self.draw_aarect()
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix F841 lint errors from unused bounds_rect assignments.

Ruff/Flake8 flag these as unused locals; this can fail CI. Drop the assignments inside the assertRaises blocks.

✅ Suggested fix (apply similarly to the other blocks)
-            with self.assertRaises(TypeError):
-                bounds_rect = self.draw_aarect(surface, pygame.Color("white"))
+            with self.assertRaises(TypeError):
+                self.draw_aarect(surface, pygame.Color("white"))

Also applies to: 5196-5201, 5241-5249, 5358-5360, 5383-5385, 5473-5477, 5518-5522

🧰 Tools
🪛 Flake8 (7.3.0)

[error] 5180-5180: local variable 'bounds_rect' is assigned to but never used

(F841)

🪛 Ruff (0.14.14)

[error] 5180-5180: Local variable bounds_rect is assigned to but never used

Remove assignment to unused variable bounds_rect

(F841)

🤖 Prompt for AI Agents
In `@test/draw_test.py` around lines 5173 - 5180, The tests assign to an unused
variable bounds_rect inside assertRaises blocks causing F841 lint errors; remove
the assignments so the calls to self.draw_aarect(...) are executed only for
their exception check (e.g., change "bounds_rect = self.draw_aarect(...)" to
"self.draw_aarect(...)" in the assertRaises blocks). Apply the same change for
all occurrences mentioned (other blocks around lines referencing draw_aarect and
bounds_rect).

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.

1 participant