Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add early return when angles are equal in DrawCircleSector and DrawCircleSectorLine functions. #4843

Merged

Conversation

theundergroundsorcerer
Copy link
Contributor

@theundergroundsorcerer theundergroundsorcerer commented Mar 18, 2025

This change adds early return to circle sector drawing functions DrawCircleSector and DrawCircleSectorLines
when startAngle equals endAngle, matching the existing behavior in DrawRing and
DrawRingLines functions.

Benefits:

  • Prevents unnecessary calculations when there's nothing to draw
  • Avoids potential division by zero when angles are equal and segments=0
  • Makes behavior consistent with the ring drawing functions

I've tested these changes on a Mac (no access to a Windows machine at the moment) and they don't break the build.
(In particular, shapes_draw_circle_sector example works the same way as before).

A Suggestion - perhaps comparing the difference to EPSILON defined in raylib.h is a better approach for all these functions.

Prevents unnecessary work and division by zero (when segments=0) in DrawCircleSector/DrawCircleSectorLines when startAngle equals endAngle, matching existing behavior in DrawRing/DrawRingLines.
@raysan5 raysan5 merged commit cd92069 into raysan5:master Mar 18, 2025
@theundergroundsorcerer theundergroundsorcerer deleted the DrawCircleSector-quickfix branch March 18, 2025 10:29
@raysan5
Copy link
Owner

raysan5 commented Mar 18, 2025

@theundergroundsorcerer Merged this quick fix because there are already other functions using same approach but:

  • Comparing two float with == is not reliable, EPSILON should be used.
  • I try to avoid early returns in raylib as much as possible, unfortunately in the last few years many have been added...

@theundergroundsorcerer
Copy link
Contributor Author

theundergroundsorcerer commented Mar 18, 2025

Is it okay if I update all these functions to use EPSILON instead of 0? Or leave it as it is for now?

Just for the curiosity:
These functions do not return anything, using early return is equivalent to not drawing anything if there is nothing to draw. Is it still considered as an"early return"?

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