error cases for fixedpoint drawline

Started by
-1 comments, last by fir 10 years ago

Times a go i was to lazy to get and test bressenham drawline routine

so i just took it strightforward, counted dx, dy slope on each pixels

and used fixedpoints (16-16 bit over 32 bit int)


void DrawLineUnsafe(int xs, int ys, int xk, int yk, unsigned color)
{
 
   int abs_width  = abs(xk-xs);
   int abs_height = abs(yk-ys);
 
   int how_many_segmants =  max(abs_width, abs_height);
 
   SetPixel(xs, ys, color);
 
   if(how_many_segments==0) return;
 
   int x = xs<<16;
   int y = ys<<16;
 
   int dx =  ((xk-xs)<<16)/how_many_segments;
   int dy =  ((yk-ys)<<16)/how_many_segments;
 
 
   for(int i=0; i<how_many_segments; i++)
   {
      x += dx ;
      y += dy ;
 
      SetPixel(x>>16, y>>16, color); 
 
                 //setpixel is inline routine bitmap[y*width+x]=color
 
   }
 
}

1) is this code in general usable? can it be optymized? (Imo it should
be probably ok not sure if it is slower compered to bressenham and how much?
2) I cannot count the error that come from the fact that there are used 16 bit fixedpoints here - Is someone able to count/show some corner cases where error in drawing will show - or there is some range or x/y where it is errorless
and works like bressenham? I culd not find thie error - is maybe someone able to say something about it?
(the natural range for line begin and end it should work seem to me could be 0 to 65535 or -32768 to 32 767 but will it work okay for this range?)
tnx

This topic is closed to new replies.

Advertisement