& RIGHT) { // point is to the right of clip window y = y0 + (y1 - y0) * (xmax - x0) / (x1 - x0); x = xmax; } else if (outcodeOut & LEFT) { // point is to the left of clip window y = y0 + (y1 - y0) * (xmin - x0) / (x1 - x0); x = xmin; } // Now we move outside point to intersection point to clip // and get ready for next pass. if (outcodeOut == outcode0) { x0 = x; y0 = y; outcode0 = ComputeOutCode(x0, y0); } else { x1 = x; y1 = y; outcode1 = ComputeOutCode(x1, y1); } } } return accept; } Notes See also Algorithms used for the same purpose: Liang–Barsky algorithm Cyrus–Beck algorithm Nicholl–Lee–Nicholl algorithm Fast clipping References James D. Foley. Computer graphics: principles and practice. Addison-Wesley Professional, 1996. p. 113. External links JavaScript polyline clipping library using Cohen-Sutherland algorithm Animated JavaScript implementation Delphi implementation Stata implementation Line clipping algorithms