[A89] Re: ellipses again
[Prev][Next][Index][Thread]
[A89] Re: ellipses again
----- Original Message -----
> The bresenham algorithm is kinda slow, but it does get the ellipse right.
The speed also is > not too obvious for smaller sizes.
Strange. bresenham ellipse should be very fast.
> All filling attributes work except for XOR. This is not much of a
> problem for me now, but I don't like leaving it with something that
doesn't work.
Should be possible to fix.
I'll do a try on it in the dark now (I am not at home) and if that doesn't
work, I will try when I come home in about a week and can testrun it.
A great speedup to this should also be to make a custom horizontal line
routine, since the slowdown is most probably not the bresenham, but the
DrawLine.
Another thing to check is that tigcc really optimizes those *2 and *4 to
shifts, and not uses mul:s. if not, change them to explicit shifts in the
algoritm.
This should work:
(looks a lot like Scotts, but he forgot that he needs to do the draw before
the x and y changes)
> void symmetry(int x, int y, int cx, int cy, short Attr)
> {
> DrawLine(cx+x,cy+y,cx+x,cy-y,Attr);
> if(y!=0) DrawLine(cx-x,cy+y,cx-x,cy-y,Attr);
> }
>
> 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);
symmetry(x,y,cx,cy,Attr);
> x++;
> y--;
> }
> else
> {
> S -= 4*a2*(y-1);
> T -= 2*a2*(2*y-3);
symmetry(x,y,cx,cy,Attr);
> y--;
> }
> }
> while (y>0);
> }
>
hope it works :)
///Olle
References: