pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Deprecating gfxdraw module

Open mzivic7 opened this issue 1 year ago • 8 comments
trafficstars

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

mzivic7 avatar Jul 18 '24 18:07 mzivic7

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.

bilhox avatar Jul 18 '24 18:07 bilhox

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

mzivic7 avatar Jul 18 '24 18:07 mzivic7

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.

mzivic7 avatar Jul 19 '24 14:07 mzivic7

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

damusss avatar Jul 19 '24 14:07 damusss

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],

bilhox avatar Jul 19 '24 17:07 bilhox

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

mzivic7 avatar Jul 19 '24 18:07 mzivic7

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)
    ...

gresm avatar Sep 27 '24 09:09 gresm

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.

mzivic7 avatar Sep 27 '24 10:09 mzivic7