-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Optimzation: code consolidation in drawCircle() #4302
base: 0_15
Are you sure you want to change the base?
Conversation
DedeHai
commented
Nov 22, 2024
- replaced repeated function calls with loops
- saves about 600bytes of flash
- speed tradoff: drawing is now a tiny bit slower but insignificant in my tests
- saves about 600bytes of flash - speed tradoff: drawing is now a tiny bit slower but insignificant in my tests
What device have you tested it on? We need to make sure it doesn't pose an issue on the slowest supported devices. |
it won't pose any issue, as I mentioned, the slowdown is insignificant, tested on C3. The function is currently only used by ripple FX. |
setPixelColorXY(cx-y, cy+x, col); | ||
setPixelColorXY(cx+y, cy-x, col); | ||
setPixelColorXY(cx-y, cy-x, col); | ||
for (int i = 0; i < 4; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be to compact the "soft" Wu's algo (as you did), but keep Bresenham's code untouched.
Why: in some cases speed does matter, so I'd like to have the basic circle drawing as fast as possible. Also you did not save much code on Bresenham.
The "soft" algorithm is much slower any way, so I'd agree with you that making the code more compact here is better for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran a few more tests: there is no measureable difference in speed using the Bresenham's code, the "overhead" added by the loop is really small when comparing it to a setPixelColorXY()
call. I got the exact same FPS with and without the changes using a modified ripple FX drawing about 100 circles. Also: there is no FX currently using the Bresenham's circle version.
With the Wu's algorithm, there is a slight drop in speed. Using the same modified ripple FX frame rate drops by 0.6FPS from 42FPS to 41.4FPS worst case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: there is no FX currently using the Bresenham's circle version.
There's an open PR that uses it.