Polygon Clipping
 Discard whole polygon if any vertex lies outside of canvas boundaries.
Scan conversion
  • Read section 3.6
  • All special cases should be covered automatically by the correct implementation of the algorithm (concave, degenerate).
  • Floating point coordinates.
  • Initial point calculation:

    DX = X2 - X1
    DY = Y2 - Y1

    P_initial = ( X1 + Xd, ceil(Y1) )

    Using similar triangles:

    Xd  /  ( ceil(Y1) - Y1 )  =  DX / DY  =>

    Xd = ( ceil(Y1) - Y1) * DX / DY

    Updating Edge intersection for next scan line:

    Current P = ( X, Y )
    Next      P = ( X + Xinc, Y + 1 )

    Xinc =  DX / DY