Drawing an antialiased circle as described by Xaolin Wu
<p>I'm tyring to implement the “Fast Anti-Aliased Circle Generator” routine that was described by Xiaolin Wu in his paper “An Efficient Antialiasing Technique” from Siggraph '91.</p>

<p>This is the code that I wrote using Python 3 and PySDL2:</p>

<pre><code>def draw_antialiased_circle(renderer, position, radius):
    def _draw_point(renderer, offset, x, y):
        sdl2.SDL_RenderDrawPoint(renderer, offset.x - x, offset.y + y)
        sdl2.SDL_RenderDrawPoint(renderer, offset.x + x, offset.y + y)
        sdl2.SDL_RenderDrawPoint(renderer, offset.x - x, offset.y - y)
        sdl2.SDL_RenderDrawPoint(renderer, offset.x + x, offset.y - y)

    i = 0
    j = radius
    d = 0
    T = 0

    sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, sdl2.SDL_ALPHA_OPAQUE)
    _draw_point(renderer, position, i, j)

    while i &lt; j + 1:
        i += 1
        s = math.sqrt(max(radius * radius - i * i, 0.0))
        d = math.floor(sdl2.SDL_ALPHA_OPAQUE * (math.ceil(s) - s) + 0.5)

        if d &lt; T:
            j -= 1

        T = d

        if d &gt; 0:
            alpha = d
            sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, alpha)
            _draw_point(renderer, position, i, j)
            if i != j:
                _draw_point(renderer, position, j, i)

        if (sdl2.SDL_ALPHA_OPAQUE - d) &gt; 0:
            alpha = sdl2.SDL_ALPHA_OPAQUE - d
            sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, alpha)
            _draw_point(renderer, position, i, j + 1)
            if i != j + 1:
                _draw_point(renderer, position, j + 1, i)
</code></pre>

<p>This is a naive implementation of what I believe is being described in his paper, at the exception that I assigned the radius value to <code>j</code> instead of <code>i</code> because either I misunderstand something or there's a mistake in his paper. Indeed, he initializes <code>i</code> with the radius value, <code>j</code> with <code>0</code>, and then defines the loop condition <code>i &lt;= j</code> which can only be true when the radius is <code>0</code>. This change led me to make some other minor modifications from what's described, and I also changed <code>if d &gt; T</code> to <code>if d &lt; T</code> simply because it looked broken otherwise.</p>

<p>This implementation works mostly well except at the start and the end of each octant, where some glitches appear.</p>

<p><a href="https://i.stack.imgur.com/gbNyZ.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/gbNyZ.gif" alt="circle"></a></p>

<p>The circle above has a radius of 1. As you can see at the start of each octant (such as in the (0, 1) area), the pixels drawn within the loop are not aligned to the first pixel that is drawn before the loop starts. Also something goes awfully wrong towards the end of each octant (such as in the <code>(sqrt(2) / 2, sqrt(2) / 2)</code> area). I managed to make this last issue disappear by changing the <code>if d &lt; T</code> condition to <code>if d &lt;= T</code>, but the same problem then shows up at the start of each octant.</p>

<p><strong>Question 1</strong>: What am I doing wrong?</p>

<p><strong>Question 2</strong>: Would there be any gotcha if I wanted the input position and radius to be floating points?</p>