Skip to content

fix width calculation for draw.aacircle()#3699

Open
Fantastair wants to merge 2 commits intopygame-community:mainfrom
Fantastair:fix-aacircle-width
Open

fix width calculation for draw.aacircle()#3699
Fantastair wants to merge 2 commits intopygame-community:mainfrom
Fantastair:fix-aacircle-width

Conversation

@Fantastair
Copy link
Contributor

For more details, please refer to the discussion in #3682 .

@Fantastair Fantastair requested a review from a team as a code owner February 3, 2026 10:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Modified circle drawing calls in src_c/draw.c to use adjusted thickness parameters by passing width - 1 instead of width, with added comments clarifying that internal drawing logic applies thickness + 1 for final rendered width.

Changes

Cohort / File(s) Summary
Circle Rendering Thickness Adjustment
src_c/draw.c
Adjusted all aacircle-related function calls to use width - 1 as the thickness parameter. Added explanatory comments noting that the internal draw_circle_xiaolinwu logic handles final thickness as thickness + 1, clarifying the relationship between parameter and actual drawn width.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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: fixing width calculation for the aacircle drawing function, which directly corresponds to the adjusted circle drawing calls in the changeset.
Description check ✅ Passed The description references issue #3682 which provides context for the width calculation fix in draw.aacircle(), relating directly to the changeset.

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

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

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


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.

@Fantastair
Copy link
Contributor Author

As for why I ultimately chose to modify the parameter passing on the calling side rather than the underlying implementation, it's because draw_circle_xiaolinwu() also handles drawing solid circles. Modifying the width here would cause the center pixels of solid circles to be left empty. Therefore, passing width - 1 when drawing the circle border in draw.aacircle() represents the smallest possible change.

Additionally, I added an explanatory comment inside the ‘draw_circle_xiaolinwu()’ function to serve as a reminder for future developers.

/* The final drawn thickness will be 1 pixel greater than the value of the
* “thickness” parameter, as the iteration is performed over a closed
* interval. */
for (int layer_radius = radius - thickness; layer_radius <= radius;
Copy link
Member

@ankith26 ankith26 Feb 9, 2026

Choose a reason for hiding this comment

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

I wonder if it would be better to just fix the logic here instead, maybe we should do a radius - thickness + 1 initialization?

EDIT: Just saw your comment about centre of solid circles, but I'm still not convinced. This function should ideally do the "right thing" and the centre special case could be handled separately? I need to do a bit more testing though to understand things in more detail.

Copy link
Member

Choose a reason for hiding this comment

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

Okay I played around a bit with this, and now I have a clearer understanding.

Basically the main issue is that draw.aacircle always draws an extra pixel at the centre, so a 1 radius circle needs a 3x3 box, a 2 radius circle needs a 5x5 box and so on (yes, just like #1487). So there's always going to be a jump somewhere and this PR is just shifting that jump from 1 -> 3 to (r - 2) -> r. I personally think this is a reasonable compromise given the status quo.

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