2
$Id: clip.inc,v 1.4 2002/09/07 15:07:46 peter Exp $
3
This file is part of the Free Pascal run time library.
4
Copyright (c) 1999-2000 by the Free Pascal development team
6
This include implements the different clipping algorithms
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
17
LEFT = 1; { Left window }
18
RIGHT = 2; { Right window }
19
BOTTOM = 4; { Bottom window }
20
TOP = 8; { Top window }
29
function LineClipped(var x1, y1,x2,y2: smallint; xmin, ymin,
30
xmax, ymax:smallint): boolean;
31
{********************************************************}
32
{ Function LineClipped() }
33
{--------------------------------------------------------}
34
{ This routine clips the line coordinates to the }
35
{ min. and max. values of the window. Returns TRUE if }
36
{ the ENTIRE line was clipped. Updated }
37
{ clipped line endpoints are also returned. }
38
{ This algorithm is the classic Cohen-Sutherland line }
39
{ clipping algorithm. }
40
{--------------------------------------------------------}
42
code1, code2: longint;
48
function outcode(x,y:smallint): longint;
49
{********************************************************}
50
{ Function OutCode() }
51
{--------------------------------------------------------}
52
{ This routine determines if the specified end point }
53
{ of a line lies within the visible window, if not it }
54
{ determines in which window the point is. }
55
{--------------------------------------------------------}
75
code1:= OutCode(x1,y1);
76
code2:= OutCode(x2,y2);
81
{ both points are in window }
82
if ((code1=0) and (code2=0)) then
90
{ Neither points are in window }
91
if (code1 and code2) <> 0 then
99
{ Some points are partially out of the window }
100
{ find the new end point of the lines... }
105
if (code and LEFT) <> 0 then
107
newy:=y1+((y2-y1)*(xmin-x1)) div (x2-x1);
111
if (code and RIGHT) <> 0 then
113
newy:=y1+((y2-y1)*(xmax-x1)) div (x2-x1);
117
if (code and BOTTOM) <> 0 then
119
newx:=x1+((x2-x1)*(ymax-y1)) div (y2-y1);
123
if (code and TOP) <> 0 then
125
newx:=x1+((x2-x1)*(ymin-y1)) div (y2-y1);
128
if (code1 = code) then
130
x1 := newx; y1:= newy;
131
code1:=outcode(x1,y1)
135
x2:= newx; y2:= newy;
136
code2:=outcode(x2,y2);
145
Revision 1.4 2002/09/07 15:07:46 peter
146
* old logs removed and tabs fixed