Originally Posted by
paul_nicholls
Also if anyone wants to do some timing tests, here is a bresenham version I translated from C code:
Yes, this is one variant of Bresenham algorithm. However, your own algorithm can be adapted to give Bresenham lines without branching. Something like this (very short example):
Code:
Span:= Max(Abs(y2 - y1), Abs(x2 - x1));
if (Abs(y2 - y1) > Abs(x2 - x1)) then
begin // vertical line
y:= Min(y1, y2);
x := x1 * 65536;
dx:= (x2 - x1) * 65536 div Span;
// !! if y2 < y1, set x to x2 and invert dx here
for i:= 0 to Span - 1 do
begin
PutPixel(x div 65536, y + i);
Inc(x, dx);
end;
end else // do the same, but on x axis
end;
In the above example, the inner loop has no branching and produces clean lines like the Bresenham algorithm.
Bookmarks