pygame.draw.ellipse does not draw ellipses with odd sizes

Issue #233 resolved
donLorenzo created an issue

Reported by Florian Krause on the pygame mailing list:

I was actually wrong. It seems even worse. Pygama is not capable to draw ellipses with odd sizes at all. It will always be the same ellipse as x-1, y-1.
E.g. an elipse with size 3,3 will result in the same ellipse as the one with size 2,2.
Can anyone reproduce this?

Code to reproduce:

import pygame
screen = pygame.display.set_mode((100, 100))
pygame.draw.ellipse(screen, (255,0,0), (0,0,5,5))

The resulting ellipse will have a 4x4 size

Comments (7)

  1. Aleksandar Petrovic

    It's very small ellipse, its very diificult seen difference. Elipse for same size x and y are circle.I think there is no bug.

  2. donLorenzo reporter

    Well here is a larger ellipse with a vertical line as visual aid.

    import pygame
    screen = pygame.display.set_mode((200,200))
    pygame.draw.line(screen, (127,127,127), (61,0), (61,120))
    pygame.draw.ellipse(screen, (255,255,255), (0,0,61,61))
    pygame.draw.ellipse(screen, (255,255,255), (0,62,60,60))

    Notice that the two ellipses have the same distance from the vertical line but the upper one should be one pixel larger (touching the line).

    So, there is a bug unless you can show me otherwise and not just assert it. issue233.png

  3. Aleksandar Petrovic

    Its not bug, its beacuce line of both ellipse have aliansing efects and diferenc of 1 pixel is invisible. If 2. elipse have size 59, difference is visible.

  4. donLorenzo reporter

    I drew two ellipses one with 20x20 and one with 21x21 size. I did this twice. once in the GIMP and once with pygame


    By looking at the code I understand why pygame draws two ellipses of identical size. What I don't understand is why we consider this okay.

    I think if the API was draw.ellipse(center, x_radius, y_radius) you might have a point that we cannot have floating point radii but given the current API of draw.ellipse(x,y,w,h) I certainly would expect a result similar to the GIMP's output.

  5. Florian Krause

    Absolutely, yes.

    I would argue to either

    1) Make all valid diameter integer values produce the expected output


    2) Make the ellipse work with radii only

    I strongly prefer 1) though.

  6. Log in to comment