pygame-ce
pygame-ce copied to clipboard
Deprecating gfxdraw module
These functions must be implemented to pygame.draw module in order to deprecate pygame.gfxdraw module:
- [X] #2800
- [X] thickness
- [X] filled
- [X] draw.aaline
- [x] #3191
- [X] draw.aalines
- [x] #2912
- [ ] #3154
- [ ] #3016
- [ ] thickness
- [ ] filled
- [ ] #3126
- [ ] thickness
- [ ] filled
- [ ] #3158
- [ ] draw.textured_polygon
- [ ] #3009
- [x] #3008
- [ ] #3010 (deprecation warning + notice in the docs)
gfxdraw can be deprecated after implementing all above listed functions and it gets removed in pygame-ce 3 or later.
Deprecating gfxdraw closes:
- #2463
- #2450
- #2082
- #1728
- #1487
- #679
- #586
- #172
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.
Ok, removing draw.pie from the list, because it can be drawn with draw.arc and 2 draw.lines.
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.
Ok, removing
draw.piefrom the list, because it can be drawn withdraw.arcand 2draw.lines.
that's how I replaced it in my shim
https://github.com/pygame-community/pygame-ce/issues/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],
#586 turned out to still be related to gfxdraw.
Partually fixed in #3008
The problem was with get_antialiased_color.
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)
...
aapolygon will be added in #3126
draw.poylgon and gfxdraw.aapolygon or draw.aalines cannot be overlapped without issues:
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:
Same thing is happening when using draw.polygon and gfxdraw.aapolygon.