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.1 2002/02/19 08:25:31 sasu
148 Revision 1.1 2000/07/13 06:30:50 michael
151 Revision 1.9 2000/01/07 16:41:37 daniel
154 Revision 1.8 2000/01/07 16:32:25 daniel
155 * copyright 2000 added
157 Revision 1.7 1999/12/20 11:22:35 peter
158 * integer -> smallint to overcome -S2 switch needed for ggi version
160 Revision 1.6 1999/09/27 12:35:27 jonas
161 * execute multiplications before divisions in lineclipped to avoid rounding errors
163 Revision 1.5 1999/09/18 22:21:09 jonas
164 + hlinevesa256 and vlinevesa256
165 + support for not/xor/or/andput in vesamodes with 32k/64k colors
166 * lots of changes to avoid warnings under FPC
168 Revision 1.4 1999/09/12 17:28:59 jonas
169 * several changes to internalellipse to make it faster
170 and to make sure it updates the ArcCall correctly
171 (not yet done for width = 3)
172 * Arc mostly works now, only sometimes an endless loop, don't know
175 Revision 1.3 1999/07/12 13:27:09 jonas
176 + added Log and Id tags
177 * added first FPC support, only VGA works to some extend for now
178 * use -dasmgraph to use assembler routines, otherwise Pascal
180 * use -dsupportVESA to support VESA (crashes under FPC for now)
181 * only dispose vesainfo at closegrph if a vesa card was detected
182 * changed int32 to longint (int32 is not declared under FPC)
183 * changed the declaration of almost every procedure in graph.inc to
184 "far;" becquse otherwise you can't assign them to procvars under TP
185 real mode (but unexplainable "data segnment too large" errors prevent
186 it from working under real mode anyway)