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

Deprecating gfxdraw module #3005

Open
7 of 19 tasks
mzivic7 opened this issue Jul 18, 2024 · 8 comments
Open
7 of 19 tasks

Deprecating gfxdraw module #3005

mzivic7 opened this issue Jul 18, 2024 · 8 comments
Assignees
Labels
Milestone

Comments

@bilhox
Copy link
Contributor

bilhox commented Jul 18, 2024

Hello,

First of all, thank you for the list. IMO, gfxdraw.pie shouldn't be ported to draw as it can be reproduced easily with existing draw functions.

@mzivic7
Copy link
Contributor Author

mzivic7 commented Jul 18, 2024

Ok, removing draw.pie from the list, because it can be drawn with draw.arc and 2 draw.lines.

@mzivic7
Copy link
Contributor Author

mzivic7 commented Jul 19, 2024

Idea for draw.aapolygon:

If width == 1:
    1. Draw closed aalines with width=1 
Else:
    1. Draw closed aalines with width=1
    2. Now for each point:
        3. calculate bisecting vector of angle at that point such that it points toward inside of polygon
        4. Get point moved by 1px along that vector in its direction
        This will result in 1px smaller polygon
    5. With new points draw another aalines
    If filled:
        6. Draw regular filled polygon with same points from 5.
    Else:
        6. Repeat 2.-5. with draw.lines until layer == width-2, in ecah iteration with each layer polygon will get smaller
        7. Draw another aalines with 1px smaller polygon than previous
        8. Repeat 7.

Why this:
Closed shapes must expand width towards inside, and it is expected for polygon to have sharp edges.
Step 1. alone is enough to deprecate gfxdraw.aapolygon. Other steps are for width and filled, which is IMO more important than just aapolygon.

@damusss
Copy link
Member

damusss commented Jul 19, 2024

Ok, removing draw.pie from the list, because it can be drawn with draw.arc and 2 draw.lines.

that's how I replaced it in my shim

@bilhox
Copy link
Contributor

bilhox commented Jul 19, 2024

#586 - draw.aacircle is also segfaulting
It doesn't segfault for me both on Windows and Ubuntu (In the case of pygame.draw.aacircle), it tells me this on Windows : 💀

pygame-ce 2.5.0 (SDL 2.30.3, Python 3.12.0)
Traceback (most recent call last):
  File "c:\Users\...\pygame-ce\a.py", line 8, in <module>
    aacircle(
OverflowError: Python int too large to convert to C long

and this on Ubuntu :

pygame-ce 2.5.1.dev1 (SDL 2.30.0, Python 3.12.3)
Traceback (most recent call last):
  File "/home/rakoon/pygame-ce/a.py", line 8, in <module>
    aacircle(
OverflowError: signed integer is greater than maximum

Update :
Nevermind, it appeared that pygame.draw.aacircle had a different signature than pygame.gfxdraw.aacircle, it segfaults now.

what I found while debugging :

Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
get_antialiased_color (surf=0xf0c6b0, x=317, y=255, original_color=224, brightness=1) at ../src_c/draw.c:1135
1135        SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, &background_color[0],

@mzivic7
Copy link
Contributor Author

mzivic7 commented Jul 19, 2024

#586 turned out to still be related to gfxdraw.
Partually fixed in #3008
The problem was with get_antialiased_color.

@gresm
Copy link
Contributor

gresm commented Sep 27, 2024

I think that draw.aapolygon doesn't need the filled property. If the exact signature with draw.polygon is needed, this option can be emulated with (pseudo-code):

def aapolygon(..., filled: bool = False):
    if filled:
        pygame.draw.polygon(..., filled=True)
    ...

@mzivic7
Copy link
Contributor Author

mzivic7 commented Sep 27, 2024

aapolygon will be added in #3126
draw.poylgon and gfxdraw.aapolygon or draw.aalines cannot be overlapped without issues:
Screenshot_from_2024-07-18_19-16-18
Top: first drawn draw.polygon, then with same points draw.aalines.
Bottom: just draw.aalines with same points.

Notice those pixels not being antialiased at some places. That is because draw.polygon is sometimes filling pixels outside midline.

Here, red line is midline, outer is draw.aalines, inner is draw.polygon+draw.aalines:
Screenshot From 2024-09-27 12-01-47

Same thing is happening when using draw.polygon and gfxdraw.aapolygon.

@bilhox bilhox added this to the 3.0.0 milestone Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants