Graphics Reference
In-Depth Information
{ Constants }
RIGHTBDRY = 1;
TOPBDRY = 2;
LEFTBDRY = 4;
BOTTOMBDRY = 8;
boolean function CS_Clip ( ref real x0, y0, x1, y1; real xmin, ymin, xmax, ymax)
{ This function clips the segment from (x0, y0) to (x1, y1) against the window
[xmin, xmax]¥[ymin, ymax]. It returns false if the segment is entirely outside the
window and true otherwise. In the latter case the variables x0, y0, x1, and y1 will
also have been modified to specify the final clipped segment. }
begin
byte c0, c1, c;
real x, y;
{ First encode the points }
c0 := RegionCode (x0,y0);
c1 := RegionCode (x1,y1);
{ Next the main loop }
while (c0 or c1) π 0 do
if (c0 and c1) π 0
then
return ( false );
else
begin
{ Choose the first point not in the window }
c := c0;
if c = 0 then c := c1;
{ Now clip against line corresponding to first nonzero bit }
if (LEFTBDRY and c) π 0
then
begin
{ Clip against left bdry }
x := xmin;
y := y0 + (y1 - y0)*(xmin - x0)/(x1 - x0);
end
else if (RIGHTBDRY and c) π 0
then
begin
{ Clip against right bdry }
x := xmax;
y := y0 + (y1 -
y0)*(xmax x0)/(x1 - x0);
-
end
else if (BOTTOMBDRY and c) π 0
then
Algorithm 3.2.1.1.
The Cohen-Sutherland line-clipping algorithm.
Search WWH ::




Custom Search