Xiaolin Wu's line algorithm: Difference between revisions

Content deleted Content added
m Algorithm: Remove unused round() function, no longer needed after endpoint fix.
Algorithm: Replaced ipart() with floor() to avoid ambiguity around rounding.
Line 21:
function plot(x, y, c) is
plot the pixel at (x, y) with brightness c (where 0 ≤ c ≤ 1)
 
// integer part of x
function ipart(x) is
return floor(x)
 
// fractional part of x
function fpart(x) is
return x - ipartfloor(x)
 
function rfpart(x) is
Line 59 ⟶ 55:
xgap := 1 - (x0 - xend)
xpxl1 := xend // this will be used in the main loop
ypxl1 := ipartfloor(yend)
if steep then
plot(ypxl1, xpxl1, rfpart(yend) * xgap)
Line 74 ⟶ 70:
xgap := 1 - (xend - x1)
xpxl2 := xend //this will be used in the main loop
ypxl2 := ipartfloor(yend)
if steep then
plot(ypxl2 , xpxl2, rfpart(yend) * xgap)
Line 87 ⟶ 83:
for x from xpxl1 + 1 to xpxl2 - 1 do
begin
plot(ipartfloor(intery) , x, rfpart(intery))
plot(ipartfloor(intery)+1, x, fpart(intery))
intery := intery + gradient
end
Line 94 ⟶ 90:
for x from xpxl1 + 1 to xpxl2 - 1 do
begin
plot(x, ipartfloor(intery), rfpart(intery))
plot(x, ipartfloor(intery)+1, fpart(intery))
intery := intery + gradient
end