Resources:


A clipping algorithm to decide which pixels get rasterized.


We assign each endpoint a 4-bit code according to the following test

Where bit is decided according to:

  1. Set to 1 for , else set to 0
  2. Set to 1 for , else set to 0
  3. Set to 1 for , else set to 0
  4. Set to 1 for , else set to 0

The endpoints of a line segment are given by and . The extent tests are then:

  • If , then the line segment is entirely inside.
  • If , then the line segment is entirely outside.

If the extent tests are not conclusive, we need to find an intersection point between the line segment, and one of the lines that define the clipping window, and recursively to the extent tests as done in the figure below until convergence.