-
-
Notifications
You must be signed in to change notification settings - Fork 183
Border radius for pygame.draw.polygon (resolves #1527) #2610
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
base: main
Are you sure you want to change the base?
Conversation
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 see lots of undocumented math that isn't immediately obvious. Please make sure you're leaving enough comments that someone else can come in later and make fixes/changes without having to reinvent your entire thought process.
I also don't see any tests written. You should write tests to make sure that your code is behaving as expected. They live in the test
directory.
Please update documentation (as I outline in one of my comments)
Formatting of the code can be wacky in a few places, please run python setup.py format
No stub updates. Since you're changing the signature of a function, you should update the appropriate stub in buildconfig/stubs/pygame
@@ -721,19 +725,20 @@ polygon(PyObject *self, PyObject *arg, PyObject *kwargs) | |||
Uint32 color; | |||
int *xlist = NULL, *ylist = NULL; | |||
int width = 0; /* Default width. */ | |||
int border_radius = 0; /* Default border_radius. */ |
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.
This isn't a super important nitpick, but is there a reason this should be a signed integer vs unsigned? What do you expect to happen if a negative border_radius
is fed in?
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 unresolved this because you didn't actually respond to it. If you're going to resolve a comment, there better be some kind of followup. If it doesn't warrant a change, then add a comment to reply. Since I was asking a question, I would expect an answer. Marking this as resolved without doing that signifies to me that you've done something to address it. In this case, you have done nothing, and my questions are still valid.
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 apologize for any confusion. I provided an explanation in the draw.rst file regarding the behavior of the function when border_radius is negative. I assumed this information would be visible and that it would be enough to resolve the comment. I'll make sure to be clearer in my responses.
Regarding the border_radius parameter, similar to the approach with the width parameter, negative values are not considered, and the function does not apply any radius while still drawing the polygon. The border_radius parameter becomes active only when it is positive.
If you need to raise exceptions from your helper function, I would suggest making it return |
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.
Still got quite a few things I'd like to see changed. You also still have a bunch of implicit conversion warnings which get treated as errors in some of our CI.
src_c/draw.c(3110): error C2220: the following warning is treated as an error
src_c/draw.c(3110): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
src_c/draw.c(3111): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
src_c/draw.c(3112): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
src_c/draw.c(3113): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
src_c/draw.c(3114): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
src_c/draw.c(3115): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data
@@ -721,19 +725,20 @@ polygon(PyObject *self, PyObject *arg, PyObject *kwargs) | |||
Uint32 color; | |||
int *xlist = NULL, *ylist = NULL; | |||
int width = 0; /* Default width. */ | |||
int border_radius = 0; /* Default border_radius. */ |
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 unresolved this because you didn't actually respond to it. If you're going to resolve a comment, there better be some kind of followup. If it doesn't warrant a change, then add a comment to reply. Since I was asking a question, I would expect an answer. Marking this as resolved without doing that signifies to me that you've done something to address it. In this case, you have done nothing, and my questions are still valid.
…rror handling and return types.
I've implemented the test cases for rounded polygons within separate functions inside the |
I think it's fine if they are in that class. As for arc tests, that will have to be added in a different PR. You can still check for rounded corners with your polygon though, because it also does a bit of implicit arc testing which just adds extra tests as a safety measure pretty much. Testing is one of those places where redundancy is fine. |
In this context, is it necessary to test for the precise radius of roundness, or would it suffice to confirm that the corners are indeed rounded? |
I don't get why the circleci failed while all i did is just add some tests. |
That is not your PRs fault, don't worry. It was a separate issue that has been fixed now |
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.
It looks like the rounded corners are being calculated in the wrong place:
The outside edge of the corner is lining up with the middle of the sides rather than the outside edge of them and that is throwing it off. I'm guessing there is a wrong parameter somewhere. Otherwise things look alright.
I'm going to put this on 'request changes'. If the original author doesn't want to work on it anymore (this has been stuck since December I think) then somebody else feel free to take it over and fix that bug.
surface = pygame.Surface((surfw, surfh)) | ||
surface.fill(surface_color) | ||
|
||
self.draw_polygon(surface, polygon_color, LARGE_SQUARE, 1, 5) |
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'm guessing we need some tests like this with a width other than "1"
Hi @ezzakri-anas , do you want to revive this PR ? |
This pull request resolves the enhancement issue #1527 (previously #3011) about implementing the border radius for pygame.draw.polygon
Overview
Geometry Calculations:
draw_round_polygon Function:
**static void draw_round_polygon(SDL_Surface *surf, int *pts_x, int pts_y, int radius, int num_points, Uint32 color, int drawn_area)
Purpose:
This function is responsible for drawing a rounded polygon with a specified border radius. It calculates and draws circular segments at each corner of the polygon.
Parameters:
Details:
Path calculation loop:
Drawing loop:
Debugging Output: