[A89] Re: ellipses again


[Prev][Next][Index][Thread]

[A89] Re: ellipses again




I think this might work for XOR and be a bit faster (horizontal ellipses
will see a bigger speed change than vertical ones):

> void bresenham_ellipse(int a, int b, int cx, int cy, short Attr)
> {
>  long int S, T,a2,b2;
>  int x,y;
>
>  a2 = a*a;
>  b2 = b*b;
>  x = 0;
>  y = b;
>  S = a2*(1-2*b) + 2*b2;
>  T = b2 - 2*a2*(2*b-1);
>  symmetry(x,y,cx,cy,Attr);
>  do
>    {
>     if (S<0)
>        {
>         S += 2*b2*(2*x+3);
>         T += 4*b2*(x+1);
>         x++;
>        }
>       else if (T<0)
>           {
>            S += 2*b2*(2*x+3) - 4*a2*(y-1);
>            T += 4*b2*(x+1) - 2*a2*(2*y-3);
>            x++;
>            y--;

add this:
>             symmetry(x,y,cx,cy,Attr);
---

>           }
>          else
>           {
>            S -= 4*a2*(y-1);
>            T -= 2*a2*(2*y-3);
>            y--;

and this:
>             symmetry(x,y,cx,cy,Attr);
---

>           }

delete this:
>     symmetry(x,y,cx,cy,Attr);
---

>    }
>  while (y>0);
> }

    -Scott




Follow-Ups: