-
-
Notifications
You must be signed in to change notification settings - Fork 158
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 draw.aapolygon #3126
base: main
Are you sure you want to change the base?
Add draw.aapolygon #3126
Conversation
What about adding a kwarg called |
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.
good job
First of all, font antialiasing should have been an attribute. Secondly, while it would technically be better imo, it would surely be incosistent with the other 3 antialiased draw functions. |
While we are at it, let's make it a kwarg. I believe ankith or starbuck told us we should make it kwarg now. we're not in C, we're on python, so let's make it more friendly. |
it sounds good. what about aacircle, aaline and aalines? |
@bilhox only problem is that aapolygon has filled argument while polygon has width argument. they are not compatible |
okay then I agree with keeping it a different function. |
I suppose if this one has no width there must be a specific reason, which I'm curious to know |
Currently there is no implementation with antialiased line, however, I hope the man who made the video I sent on discord will make a video for antialiased line with width. |
Implementing line width is much more complex, because it has to grow inwards. The problem is in finding points inside polygon, and this is not simple thing. There is a whole library for shrinking polygons: https://pypi.org/project/shapely/ I can make For |
Also, note on merging |
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.
Now it works fine ! Good job :)
Before approving it, I would like to see some code refactoring (requested changes).
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.
LGTM 👍
I noticed one small issue in the docs, where they are technically correct - but still wrong.
I tested this locally and it all works well in my tinkering around, tests all pass locally as well. I like the interface chosen, it should neatly replace everything gfxdraw.aapolygon()
does and adds filling as well which is great. 👍👍
@mzivic7 I see this version has the filled argument. Do you plan on replacing it with a width, based on your testing, or do you think it's not possible/not worth it/other reason? Just curious, to make sure you intend for the PR to be ready |
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.
Good job for C part ! :)
Just left some minor requested changes concerning docs, and a question.
:param Surface surface: surface to draw on | ||
:param color: color to draw with, the alpha value is optional if using a | ||
tuple ``(RGB[A])`` | ||
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int]) |
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.
Here it would be interesting to refer to ColorLike
from pygame.typing
, using a link to its paragraph in the docs.
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 would be better to add this to all functions in docs at once, in one separate PR. Like just one find-and-replace.
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.
Why it should be in a different PR when it concerns directly aapolygon
?
I finished width for |
Maybe I didn't see correctly, why is the PR reverting the changes of |
Forgot to sync all my branches. Sorry. |
These are the two tests failing:
|
It looks like the change is clipping off the right hand side for this test comparing the draw polygon 'diamond' versus the 'gfxdraw' one: Test program: import pygame
import pygame.gfxdraw
pygame.init()
screen = pygame.display.set_mode((640, 480), 0)
white_background = pygame.Surface(screen.get_rect().size)
white_background.fill((255, 255, 255))
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.blit(white_background, (0, 0))
pygame.draw.aapolygon(
screen, pygame.Color("#70AA70"), [(1, 3), (3, 5), (5, 3), (3, 1)], filled=False
)
pygame.gfxdraw.aapolygon(
screen, [(11, 13), (13, 15), (15, 13), (13, 11)], pygame.Color("#70AA70")
)
pygame.display.flip()
pygame.quit() |
Actually its not |
Ok to fix it I just have to disable my overlapping-aalines-fix when this and/or previous point coordinates are ints.
|
New PR I think.
…On Sat, 5 Oct 2024, 17:34 Marko Zivic, ***@***.***> wrote:
Ok to fix it I just have to disable my overlapping-aalines-fix when this
and/or previous point coordinates are ints.
Should I:
- Open new PR with new branch for this (its just ~15 lines),
- Do it in upcoming PR for draw.aalines width, because it will get
significantly modifying
- or just do it here?
—
Reply to this email directly, view it on GitHub
<#3126 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADGDGGUZYWGAF6ENRWUOQATZ2AIIZAVCNFSM6AAAAABPAUPQRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJVGEYTAOBSGQ>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
I was told on discord by Mzivic they are planning to modify the algorithm for this, so I am marking as a draft. |
This PR adds
draw.aapolygon
function, with filled option.It was not possible to overlap
draw.poylgon
anddraw.aalines
without issues:function
draw_fillpoly
sometimes draws polygon slightly larger, and those fully opaque pixels are hiding antialiased pixels fromaalines
So I made separate, modified,
draw_fillpoly_for_aapolygon
that makes borders slightly thinner at those problematic places.I didn't want to change original
draw_fillpoly
: to not add extra arguments andif
-s inside loops, which would make it slower.draw.aapolygon
is added to docs, examples and tests.Left:
draw.polygon
+draw.aalines
Right:
draw.aapolygon
Sample code