Graphics Reference
In-Depth Information
procedure
M_Clip (
ref pnt2ds
inpts;
integer
numin);
ref pnt2ds
outpts;
ref integer
numout)
{ inpts[0..numin-1] defines the input polygon with inpts[numin-1] = inpts[0] .
The clipped polygon is returned in outpts[0..numout-1]. It is assumed that
the array outpts is big enough. }
begin
integer
i;
numout := 0;
{ Compute status of first point. If it is visible, it is stored in outpts array. }
if
CS_StartClip () > 0
then
begin
outpts[numout] := startPt;
Inc (numout);
end
;
{ Now the rest of the points }
for
i:=1
to
numin-1
do
begin
cflag := CS_EndClip (i);
startC0 := endC; { endC may get changed }
if
SegMetWindow (cflag)
then
begin
if
Clipped (cflag)
then
begin
outpts[numout] := startPt;
Inc (numout);
end
;
outpts[numout] := endPt;
Inc (numout);
end
else if
TwoBitCase (endC)
then
TwoBitEndPoint ()
else
OneBitEndPoint ();
{ The basic turning point test }
if
TwoBitCase (endC)
then
begin
outpts[numout] := clipRegion[Cra[endC
and not
(TWOBITS)]];
Inc (numout);
end
;
startPt := inpts[i];
end
;
Algorithm 3.3.4.2.
Continued