An E.

advertisement
A Mtdpotnt Cltpping Alqorithm
An Honors Thesis (ID 499)
by
Kristine E. Boerper
Thesis Director
Dr. Milton M. Underkoffler
Ball State University
Muncte, Indiana
May, 1974
This project has hee~ accepted in
the requirements for ID499 Senior
of
Project.
ful!tl1me~t
Ho~ors
-.iJJ~.
:tV&i
.
Advisor
TABLE OF CONTENTS
A Mtdpoint Cltpping Algorithm
Ir.~troduction.
• • • • • • • • • • • • • • • • • • 1
Using the Alporithm • • • • • • • • • • • • • • •
J
• • • • • • • • • 4• • • • • • • • • • • • • • • • • .1 J
Horra t 1.ves aM F 1 owcn,a r ts • • •
A Sam.ple Run.
B1.b1 igoraphy
• • • • • • • • • • • • • • • • • • • • .17
AppernH.x • • • • • • • • • • • • • • • • • • •
• • .18
A MIDPOINT CLIPPING ALGORITHM
INTRODUCTION
The a.biltty to tntera.ct wi.th the computer a.nd to
dyna.mica.lly cha.nge pictures displa.yed on a screen ha.s
greatly increa.sed the potential of the computer.
With the
aid of a. graphical display device, the computer can be
used to design a variety of objects, from buildings to
political boundaries.
It can be used to Qain instght into
the structure of molecules and the inner workings of the
compute'r itself.
rotated"
The picture, or design, can be scaled,
a,nd transformed to such an extent that it can be
viewed from any angle or perspective.
Problems can arise
when ma,ntpulating the picture in thts manner, though.
ptcture~,
The
or parts of it, may be moved to a posttion which
is off the screen.
Tll,ere are severo,l dtfferent ooys in which computers
cope
~
W,,.
it
t~~
fHS
pro b1 em..
I "one me t~(~o d , ca. 11 e
d sH c i ss or ~.,n9 H , 1
only the portion which is on the screen ts in.tenslfied.
However, the com.puter continues to tra.ce the entire picture,
tnclud,i.ng the invistble portton.
result in flickering even though
simple.
This UXtstes time and could
t~e
visible portion is very
A more efficient method is to "C1iP»2 the picture.
lWil1iam M. Newman and Robert F. Sproull, princi.ples
ot Interactive Com-outer Graphics. McGraw-Hill, New York,
1973, p. 121.
2 NeUJl'1l,On
and Sproull, p. 121.
The clipping alportthm traces and intensifies only the
visible portion of the picture, thus savinp time and reducing
the chances of fl
mtdpotn~~
tc~ertnp.
On.e such algorithm, called the
cl ipping algorithm" performs a logartthmic search
for the endpoints of the visible segment by continually
subdtviJ\g the 1 tne segments at thetr m.idpoints.
The program was mritten. in PLI1.
Its method of handlin.g
IF s tatf~ments and the flextbil ity offered through DO groups
and bui.lt-in functions made PLll the most suitable language
to use.
The main concern was determining when. to stop the
process J• that is, determining when the visible se!Jment had
been found.
Thts should be when the midpoint coincided with
an edpe of the screen" but this posed another problem.
Since
distances on the display graph were measured in integers"
the mtdpoints needed to be integers also.
However" the
danger gxisted tnat rounding would distort the line so m.uch
that th,g visible
~egment
thus determined would bear 1 tttle
relationship to the original line.
Because of this" floattng-
point arithm.etic was used for all calculations, and the
rounded integer portion for all comparisons.
A special
roundtng function had to be written for this purpose as the
PLI1 built-tn function, ROUND, did not accept floatingpoint arguments.
-2-
USING THE ALGORITHM
CLIPl
CGJ 1 tng this subroutine int t tal tzes the coordin.a tes of
the screen edoes.
CLIPl expects the origin, (0,0), to be
at the center of the screen.
Cal1inp Sequence:
CA.l..L CLIP1 (XR, YT)
XR
is the x-coordinate of the ri9ht-hand edge
of the screen.
YT
is the y-coordinate of the top edge of the
screen.
CLIP
This subroutine clips the piven line to the dimensions
of the screen, as tnitta1i7.ed by CLIP1.
Callino Sequence:
CALL CLIP(Xl,Y1,X2,Y2)
Xl,
are the x- and y-coordtnates of one endpoin.t
Y1
of the line to he clipped.
X2,
are the x- and y-coordinates of the other
Y2
endpoint.
-3-
NARRATIVES AND FLOWCHARTS
CLIP1
The ftrst pa.rt of thts subrouttne, entered o,t CLIPl,
intttalizes the
u~lues
the rtC'ht-hand edne,
to
CLIl~
of the screen edges.
M\.d
The x-value of
the y-ualue of the top, are
by the calling procedure.
pa.s~ed
The x-ualue of the left-
hand ed.ge of the screen is then set equal to the nepa tiue of
the x-u·alue of the rtght-hand edqe.
The y-ualue of th.e
bottom is set equal to the negattve of the top.
Th.e logtc for the second part of CLIP1, entered at
CLIP, j'ollol.DS the narrattue set forth in NelJJlTl,(l,n and, Sproull's
Principles 01 InterBctiue Computer Graphics.
1001
The space occupied by the uncl ipped picture
ts dtuided tnto nine reptons by extending
the edces of the screen (see figure 1).
The
endpotnts of the line are assianed four-bit
1000
1010
SCREEN
0001
0000
0010
0101
0100
0110
fig. 1
binnry codes correspondtng to the repions in which they lte.
(For an. explanation of these codes see the narrattue for the
function proced,ure CODE, page 10.)
b~th
If th.e four-bit codes fo",
endpoints are zeroes, the line ltes entirely within the
boundaries of the screen.
If the logical intersection of
the two codes is not zero, the line must lie entirely offscreen, and is rejected.
If the line cannot be triuially accepted or rejected,
it is subdivided at its midpolnt.
The algorithm 1.s then
applied to each of these segments, with th.e followinq
restriction.s:
-4-
1.
One endpoint of tne oriainal line
(see fioure 2, lines A and B).
may
nave been visible
If so, one of its nalves
must either be entirely visible (line A), or else a
trivial reject (line B).
Tnis naIf is
discarded, and the alaoritnm. is
to the other half.
2.
If bo tn endpoints of the ortpina 1 line
were i.nvisible (l i.nes C, D, and E Of
ficure 2), eacn of the two halves is
trented on its oum mertts.
fip. 2
Botn halves m.ay be trivtal
rejects in which case the entire line is invisible (line C);
onlM one seqment m.ay be trtvially rejected (line D); or
the midpoint
can
is
he
may
be visihle, in which case neither half
rejected (line E).
~pplied
In this last case the alporithm
to botn halves.
The search stops when hoth nalves of the line are rejected,
or when the midpoint coincides witn one of the edpes of the
screen..
Subroutine Procedures Called:
VINV - Internal, recursive.
DISPLN - External.
Fun.ction, Procedures Called:
COPE - Internal.
SCOnE - Internal.
ROUND -
In terna 1.
-5-
t:
F 1 OTncha."
Sta.rt
CLIP1
)
PROCEDUR~
(XR.YT)
XL
YB
Start
CLIP
J
= -Xli
= -Y1'
ENTRY
(Xl,X2,
Y1, Y2)
--I
M=(fl+Y2) /2
=
=
C1
CODE
(ROUND(Xll
ROUND(Y1 )
8M
C2 = CODE
(ROUND ( X2)
ROUND(Y? ))
eM =
L-_-,--_..____ '
RETURN)
M=OC1+X2)/2
8CODE
(ROUND(X14
ROUND (YM))
'CODE
(ROUND (XM),
ROUND (YM) )
C
RETURN
No
-6-
FlolM:~~hart
"
(con,t.):
X2
Y2
Xl = XM
= XM
= YM
Y1
No
CALL VINV
(XM, YM,
X2, Y2)
X2
Y2
=
=
XMJ
Xl
Yl
YM
CALL VI1JV
(X1,Y1,
X2, Y2)
= XM
= YM
CALL VINV
(X2,Y2,
Xl, Y1 )
-7-
= YM
~
Flowchart (cont.):
rrCA
I
DISPLN; I(ROUND
(Xl ),1
ROUND(Yl ),1
J_I ROUND (X2) ,~~
ROUND(Y2)
CALL
V;NV\:I
(XII, YM
JI
Xl, Yl )
r-xr = XM-----]
Ii Y1 = YM
ct = CM
I
I
i
Gt!--)
I
I
~----------'
- -----*----jCALL VINV
(XM, YM"
X2, Y2)
~-----~
XM=~l+X;) /J
YM=<Y1+Y2)j
------
/v.
-
I
///~~
Xl
- X2_ ~No
es
'---
Y1
=
"",
Y2;>-=:N.;....;;;10----l"'.......
//
I
CM !CODE]
[ROUND(XM ),
ROUN~!YM»
~
-8-
ROUND
This function procedure rounds a floating-point
number to the nearest integer.
at the decimal point.
The number is first truncated
The two numbers are then subtracted.
If the absolute value of the difference is less than .5 the
trunca'ted value ts returned.
If it is qreater
to .5, a positive or
1, depending on the sian of
nea~tive
tr~an
or equal
the or'Lginal num.ber, is added to the truncated value hefore
returning to the calling procedure.
SubrouH,ne Proced.ures Called:
None.
Function Proced.ures Called:
None.
Fl owchc~rt:
o
.
XFLT '('~O.'~.' -
PROCEDURF:
(XFLT)
."'-M.-.t
./
~
-L-.
XFXD=XFLT .
...
_-
NO
FXD=XFXD+l
----,
ABS"
No
rXFLT-XF,,{.rz,..f----4
RETURN(XFXD)
~-~
\. Stop ~
-9-
XFXD=XFXD •
CODE
This !unctton procedure recteves a point from the
calling procedure and returns a tour-bit code correspondtnq
to the repion in which the point lies.
The four bits mean
the following, 1.! set:
t1.rs t btt - po1.nt is a.bove the top edpe of the screen.
second bit - point is be 1 OlD the bottom edpe.
third bit - point is to the rtpht of the ripht-oond edqe.
fcurth bit - point
t~
to the left of th.e 1eft-hand earle.
Subroutine Procedures Called:
Function Procedures Called:
Flo we ha, r t :
r
- - -.'
-----·-l
RETURN
(BOOL(C,
PROCEDUPE
(X, Y)
'0100'B,
, 0111 ' B»)
I
________1
>--=-==-1~ C= '
noo 1 ' B
>-"'-'............~
(BOOL(C,
,
1 000' B,
(BOOL(C,
' 001 0 ' B
'OOOO'B,r------~~-------~
'0111 'B»
c~.oooo~
I
____ ' 0 11__~~_B) )
________ J
>-A-~__ C=
I
I
-10-
SCODE
This
fu~ctlon
procedure recleves
G
point from the
calling procedure and returns one of the followIng codes:
o-
point does not lie on an edge of the screen.
1 - point lies on the top edge.
2 - point lies on the bottom edge.
J - point lies on the right-hand edpe.
4 .• point lieS on the left-hand edge.
Subrouttne Procedures CGlled:
Non,e.
Functto~
Procedures Called:
None.
FlomcMrt:
'~
RETURN( 1 )
Y
= y;~,
X
= XR
RETURN( J)
I
____. ___J
No
iROCEDURE
(X, Y)
X
RETURN(2 )
= Xl
Yes
RETURN(4)
-~--
ABS(X)
<=XR
RETURN(O)
RETURN(O)
Stop
-11-
VIlIV
This recursive subroutine procedure finds the visible
portion o! a line sepment, which ha~ one visible endpoint,
and one tnvtsihle one.
The sepment is divided at its mid-
The hal! which then meets the criterton o! one
point.
visible, and one invisible, endpoint is passed to VINV.
This cYI,le is broken when. the midpoint coincf.des 1.Dith a
screen edoe.
SHh·rout tne Procedures Called:
VINV - Recursive.
Function. Procedures Called:
CODE - Bx terMl •
SCODE - External.
ROUND
ExterMl.
Flomchart:
--~
S tfl. r t
VINV
)
---./
/~-f('fM=CODE~
SM > 0 ~.
ROUND(XU),,\
//
ROUND (YM) )
Y'es
PROCEDURj
(XV, YV,
XI,YI)
_._-...,..--_.
XII=lllr.xI)
[-;~
I
= XM
= YM
I
CALL VINV
(XV, YV,
I
i
XM, YM)
CM=ZEROE
I
I
II
~
.J
/~
CALL VINV
(XM, YM,
XI, YI)
YM=rtV+YJ) /
---
..
SC~
SII
=
(ROUND(XM)
ROUND(YM)
_-----
~-
\
"_#_-----
-12-
I
J
--.-'.~-----
Stop
)
=
YI =
XI
XM
YM
--~
A SAMPLE RUN
The drtver program !or thts sample run rea,as the screen
size !Tom cards and intttaltzes the screen eanes.
It then
reads from cards the endpoint coordinates !or the line whtch
is to he clipped.
The coordinates are printed out he!ore
beinl/ passed. to CLIP so the output from the alaorithm cnn be
more easily checked.
After the call to CLIP, the procedure
hranche::; back to read the endpoint coordin0tes ot the next
line to be cltpped.
On end-at-file, the procedure brances to
the end Gnd stops executton.
In a real Situation, the suhroutine procedure DISPLN,
called by the clipping alqortthm, would display the visible
portion of the line sepment on the araphtcal display device.
However, tor this sample, it displays upon the printer the
coordinates o! the endpoints.
Figures J-A and J-p on papes 15 and 16, show graphically
the input and output for this sample.
The positive x- and
y-coordinates of the screen edges were initialized to 16,
mith each. untt square on the gra,ph representinq one unit
sauare on the display screen.
The lines have heen numhered
to correIa, te the two araphs with the orderinq ot the followtnq
1 is t-
of output from the sample run:
ENDPOINTS OF GIVEN LINE: (
4,
ENDPOINTS OF VISIBLE SEGMENT: (
4,
ENDPOINTS OF GIVEN LINE: (
4,
ENDPOINTS OF VIS rr~LE SEGMENT: (
4,
ENDPOINTS OF GIVEN
LIN~::
(
12,
ENDPOINTS OF GIVEN LINE: (
10,
ENDPOINT.C: OF VISIBLE SEGMlENT: (
-1J-
16), (
8) ,
16,
16), (
(
-28), (
6)
-12,
8), ( -12,
16,
-7 ), (
28,
-7 ), (
10,
8)
16,
8)
6)
-20)
-lJ)
16,
-9)
10,
ENDPOINTS OF GIVEN LINE: (
ENDPOINTS OF VISIBLE SEGMENT: (
ENDPOINTS OF GIVEN LINE: (
-27,
20,
-8), (
-8), (
10,
10), (
-18)
-14)
16,
26)
-9,
-8,
17) , ( -28,
7)
ENDPOINTS OF GIVEN LINk;: (
16), ( -16,
ENDPOINTS OF VISIBLE SEGMENT: ( -11,
ENDPOINTS
ENDPOINTS
OF
OF
GIVEN LINE: ( -24,
24,
-6), (
VISIBLE SEGMENT: ( -16,
-4), (
ENDPOINTS OF GIVEN LINE: (
7,
ENDPOINTS OF VISIBLE SEGMENT: (
-20), (
-5,
-20,
-16), (
13)
6)
16,
4)
-11)
-16,
-12)
The first Gnd second lines are trivial accepts; the third, a
trivial reject.
In the fourth and fifth lines, one endpotRt
is visible, while the other one is invisible.
In the sixth,
seventh, and eighth lines both endpoints are invisible.
The
last line of this sample is an example of a line which does
not cress the screen edqe at a prid intersection.
points of the visible portion of this last line
to the nearest arid intersection.
~re
The endrounded
Even when the line crosses
at a prid intersection, snme distortion, due to roundtnp,
mrLJ.j
ocnur.
This distortion is minor, thouph., and would be
unnoticeable on most displays.
-14-
Before Cli.ppi.ng
SCREEN
2
-
----
fi.g. 3-A
After Clipping
SCREEN
2
--,
'j
',\1\
fig.
'
i.!h"
3-B
BIBLIOGRAPHY
Newman, William M. and Robert F. Sproull. Pri.nciples ot
InterGctive Computer Graphics. McGrGw-Hill. New York.
1973.
Pollac~,
S. V. and T. D. Sterling. A Guide to PL!1. Holt,
Rinehart, and Winston, Inc. Chicago. 1969.
-17-
1"4
*1
1*
*1
1*
1*
*1
*1
It;
1"1*
*1
*/
tFPE~[IX
'*1
1*
*1
It;
'*1
I"-PRCCE[LRE ~~I~F
1* lrIS PRCGRA~ REACS I~ ltf
I*P~5SE5 T~E~ 1C T~E ClIFFI~(
I*I~ITI~lIZES
l~E
CCCR[I~~IES
*1
E~[PCI~TS
CF
~lGCRIT~~.
CF
l~E
T~E
CRIGI~Al
l~E
C~ll
SCREE~
lI~E
TC CllFl
A~C
EC(ES.
1*
fiAI~P:
l~EE:
*1
*1
PRCCEC~RE
[ECLARE
REte:
*'
*'
CPTIC~~(~AI~);
FlCAl(15),
eXl.Yll FIXEC(5.C);
(~1,Yl,)2,~2)
GEl LISTOL.~l);
Ctll ClIFl(~l,~LI;
GET lIST(Xl,Yl,)2,~2);
C~ ENCFIlE(SYSI~) G(
I( ltEE;
FLT SKIPe3' ECll('E~CFCI~lS CF GIvEN lI~E: (' ,Xl,',',Yl,
• I, (', ~ 2 , • , • , Y2, • I')
()(1"te2t),F(t,C),ACl),f(t,C),AC4),
Fet,C',ACl),F(t,C',A(l));
(tLl CLIPeXl,Yl,)2,Y2);
G( Te RE~[;
E~[ "..AINP;
-18-
1"4
*1
1"4
*1
1*
*1
I*SLBR(LTl~E
1* TtIS
I*CF
1*
CISPLf\:
l~E
F~CCECLRE
SUEMCLTI~E
VISIELE
C15FL~
FRI~lS
S~G~E~l
ltE (CCRClhATES CF l~E
CC~fllEC e~ CLIP.
E~CP(l~TS
t~
FIHCE[LRE(xl,Yl,)t2,~2);
CEClARE(Xl,Yl,X2,Y2) fIXEC(S,C);
FlT SKIP
Et..:Ilt'E~CFCII\TS
'),
Cf 'IIISIELE
SEGt'Ef\T: (',XI,',',YI,
('t)2,',',~2,')')
( X ( 1 ) , A ( 3 1 , , f ( t: ,C , , /J ( 1 ) , F ( t , C ) , /J ( 4 ) ,
f(t,C),/J(I',f(t,C),ACI»;
H[
CISPlh;
-19-
*1
*1
*1
*1
*1
1*
*1
1*
1*
*1
*1
*1
FRCCECLRE CLIfl
I*Sle~CLTI~E
CETER~I~ES T~E ~ISIeLE FCRTIC~ CF ~ LI~E
f~E lI~E C'~~C1 EE E~TIRELY REJECIEC CR 'C(EFIEC *1
~1 ITS ~I[FCI~1.
T~E 4LGCRI1~~ IS 1HE~ ~FPLIEC *1
l*lC EtC~ ~~LF.
1~E FR(CE~S STCPS ~~E~ I~E ~ICPCI~1 CCI~CICES
*1
1*~I1~ AN ECGE CF T~E S(REE~.
,~eRE eC~FLETE CIS(LSSIC~ CF T~E*I
I*ALG[~ITH~ eA~ EE FCl~[ I~ FRI~(IPLES CF I~ltR~CII~E CCl~PLTER *1
1*
T~15
SUeRCLTI~E
IF
1*11 IS CIVICE(
I*SEG~E~T.
I*GR~F~Ies
E~
~IllIt~
~.
~E~~~~
~~c
R(EERI F. SPRClLL.
1*
LSEC:
I*SLERCLTl~ES
1*
1*
1*
1*
1*
1*
1*
1*
RCl~C
-
eCCE -
CLIFl:
T~E
sceeE -
R(L~CS
PCI~l
-
FCI~T
CEFt~CI~G
fL~CTIC~,
I~TER~4l,
RECL~SIvE
CF
EXTER~~L,
KECIE~E[
C~
T~E
A FCLR-ClfIT
REGIC~
I~
*1
eCCE.!
IT LIES.*I
el~ARY
~~IC~
~SSIG~S
~
LI~E
(~
SLeRCLll~E,
~~Ie~
CLIF,
CECI~Al
SCREE~
CCCE*J
CN
*1
*1
SLERCL1I~E,
FR(~
T~E
A (~E-CIGII
ECGE (F T~E
C~
IS
PARTI~Ll~
CISPl~~S
T~E
\ISIElE
*1
*!
~ISIElE.
*1
FI~CS
l~E
~ISIElE
~FFR(FRI~TE
FCRTIC~
CEvI(E.
*!
*1
*1
*1
FR(CECLIH(XR,~T);
(XR,Xl,~l,~E)
1*
I~ITI4LIZE
XL
=
T~E
E[(ES Cf
FIXE[(5.C);
T~E
5CREE~.
*1
*1
*!
-)cR;
= -VT;
fCE1LKl\;
YE
CLIP:
~u~eER
*1
PCRTIC~
[ISFL~
FL(AII~G
*1
~SSIG~S
TC ~ FCI~l CEFE~(I~G
~~Ie~ 11 LIES.
vI~~
A
I~1EGER.
fL~(lIC~,
I~TER~'L,
(ECLARE
1*
1*
FL~(lI(~,
~EAREST
I~IER~Al,
TC A
1*
1*
1*
1*
1*
1*
1*
1*
1*
I~lER~AL,
Te
*1
*1
*1
*1
*1
E~lRY(Xl,~I,X2,~2);
[ECLARE
~[L~C
E~TR~(FLCA1(l5)REllRl\S(FI)(EC(5,C»,
CCCE E~TRY(fI)E(5,C),FI)cEC(5,C')
RETLRl\S(FIXE( EI~~RY(4,c»),
sceCE E~TR~(FI)(EC(5tC),FIXEC(5,C)
IHTlR""S (F DEC (2 ,C»,
CISFll\ E~TRV(FIXEC(5,C),FIXEC(5,C),
FIXEC(5,C),fIXEC(S,C»;
CECLARE (Xl,~l,)2,~2t)~,~~) FLCAl(15),
((1,(2,(,.) FDEC EI~~RY(4,C),
-20-
1*
*1
ZEHCES FI~EC EI~~R~(4,C) INIII~L('C((C'e),
ltl\[ FDE[ e"'~~~(4,C) If\ITUl('CCC}lE),
~fI FIXEC(2,C);
(1 =
(2 =
1*
1*
C[CE(RCLNC(~1),R(LI\[(~1');
CCCE(~CLt\[D2),f«(Lf\[(,{2»;
REJECT.
TRI~IAL
I'll
IF
1*
It
1*
I"
1*
1*
eCCL(Cl,C2,lt~[)~=lER(E5
lRI~I~L
X~
Y~
S~
C~
RElLRI\;
*1
*1
~CCEPI.
IF (Cl=lERCES) & (C2=lERCES)
FI~(
T~Et\
*1
*1
*1
T~EI\
GC IC FRl;
*1
*1
~I[FCIf\I.
*1
= (Xl + X2'/2;
= (Yl + Y2)/2;
= SCC[E(ICCL"[()cfv"I<CLI\[(Yfv»;
= CCCE(RCLN[()",),ICCLI\[(Y~»;
1*
*1
*1
I'll C"E E"CFCl"T ~tY ~t~E fEEl'. ~ISIelE, CI\E rALF CF T~E LIl\E C~" *1
I'll l~E" BE EIIrER ACCEFTEC CR ICfJECTE[ Af\[ TrE ALf(ICITr~ AFFlIEC*'
1* TC TrE SECCI\C
1*
~ALF.
*1
IF Cl=ZER(ES TrE" [(;
IF SfI>C Tt-EN [C;
X2 = xt-';
Y2 = YPI;
GC TC FRT;
ENe;
ELSE;
IF Cfv=lERCE5 T~E~ C(;
CALL ~1f\~(Xfv,y~,);,Y2);
GC TC PRT;
EI\C;
ELSE CC;
X2 = XP';
Y2 = Yt-';
CALL ~I~~(~I,Yl,X2,Y2);
GC TC PR T ;
E1\[
;
E~[;
IF C2=ZERCES T~E" CC;
IF S,..>( TrEN [C;
Xl = XP';
Yl = Y"';
-21-
*1
*1
1*
GC TC PRI;
EtliU;
ELSE;
IF C~=ZE~CES
C~lL
I~E~
[C;
~I~~()~9~~9)1,~1);
GC TC PRY;
Ef\C ;
ELSE CC;
Xl = )(~;
YI = YPI;
CAll ~If\~(X29Y2,Xl,~I';
GC TC PRI;
Ef\C;
EI\[;
1*
1* ECT~ ENCPCIf\TS ARE I~~I~IeLE.
IF T~E ~ICFCI~T IS ~ISIeLE
IF f\Cl, Cf\E r~lF (F l~E
1* E~(~ ~AlF IS TRE~TE[ SE~ERAIElY.
1* Llf\E (Af\ eE CIS(AR[E[ ~I\C T~E CTrER rALF FASSEC TC ~If\v.
1*
T~C:
IF CM=ZERCES TrEf\ [C;
CALL vIf\v(X~9Y~tXI,'I);
CALL vINv()(flty~,X2,'2);
(;e TC Fin;
*1
*1
*1
*1
*1
HC;
IF
eCCL«(l,(~,LAI\C)~=lE~(ES
)11 =
)(~;
YI =
~~;
TrE~
CC;
IbEf\
ce;
(1 = (tv;
EI\C;
IF
80CL«(2,(~,LAI\C)~=ZERCES
X2
't2
(2
= XPl;
= ~PI;
= C~;
EI\C;
"1[:
IF
(XI=X2) 6 ('Vl::Y2)
+ X2)/2;
+ Y2)/2;
xt- = (Xl
Y" = (YI
CtS,.
(C
l~Ef\
RETlR~;
= CCCE(RCLf\[()I~),RClf\[('t~»;
= SCCCE(RCLf\[(X,.),~CLf\[(YPI);
TO
T~C;
1*
I*FL~CIICN
SLE~CLTIf\E
RCLf\(
1* RCLI\CS A FLCATIf\G FCI~l f\L"EER TC IrE f\EA~EST
1*
RCLf\[:
FRCCECLRE(XFlT) REILRf\S(FIXEC(5,C)';
CECLARE XFlT FlCtT(I5),
XFXC FIXEC(5,();
-22-
I~TEGER.
*1
*1
*1
.1
*1
XFXC = }(FLT'
IF (ABS(}(FLT-}(FH) ... <.~) HEI\ CC;
IF XFX[<C T~E~ XFX[=)F)[-I;
ELSE XFXC=XF}([il;
E1\ [ ;
RETLRI\(XFXC);
HC RClI\C;
1*
*1
CCCE
*1
a FCLR-CIGIT- EII\~RV CCCE TC A PCI~I. l~E FClR
*1
1* C1GIlS ~EA~ TrE F(llC~I~G, IF SET:
*1
I.
FIRST BIT - T~E PCII\T 15 A~C~E IrE TCF ECGE CF T~E SC~EEI\.*I
1*
SECCN[ ell - TrE FCII\T IS EELC~ IrE BCI1(~ ECEE.
*1
1*
TrlRC 81T - TrE FCll\l IS lC TrE RIGrl CF RIGrT-rAI\C ECGE. *1
I.
FCLRr~ eIT - TrE FCYI\T IS IC TrE LEFT CF lEFT-rAI\( ECGE.
*1
1*
*1
eCCE:
F~ceEClRE(X,V) RETlRI\S(EIl\tRY FIXEC(4,C»);
CECLARE C),V) FI)ECCS,C),
( FIXEC EII\ARV(4,C);
If X<XL TrE" (='(CC1'£;
ELSE
IF X)XR TrEN C='CClc'e;
ELSE C='CCCC'E;
IF Y<VB TrEI\ REIlR~(E(CL(C,'CICC'E,'Clll'E»;
El SE
IF V>YT TrEN RETlRI\(ECCl(C,'lCCC'B,'Clll'E";
ELSE RETLRI\(E(CL(C,'cccc'e,'Clll'e,,;
EI\[ CCCE;
1*
*1
I*FlI\CTICN SlERCllll\E SCC[E
*1
1* ~SSICI\S A (I\E-[ICI1 eCCE Te A PCII\T AS FCLLC~S:
*1
1*
C - TrE FCII\I CCES I\C1 LIE (1\ AI\ ECGE (F IrE SCREE".
*1
1*
1 - TrE PCII\T LIES CI\ TrE ICP ECGE CF IrE SCREEI\.
*1
1*
~ - TrE FCII\T lIES CI\ TrE ECTTC~ ECCE CF I~E SCREEI\.
*1
1*
3 - r~E F(I~T LIES (1\ l~E RIG~T-rAI\C E(GE.
*1
1*
4 - T~E PCI~T LIES C~ IrE LEFT-rAI\C ECGE~
*1
1*
*1
5C([E: FRCCECLRE(X,~) RfllRI\S(FIXEC(2,C));
[ECLARE (),Vl FDE[(~,C);
IF ~8S(X'<=X~ TrE~
IF V=Yl TrE~ REIlR~(l);
ELSE IF V=YB TrE~ RETlR~(2);
IF ~eS(V)<=VT 1rEI\
IF }(=XR TrE~ ~EIlR~(3);
ELSE IF X=XL IrEI\ RETl~~(4';
RETLRI\(C) ;
EI\[ SCCCE;
I.FL~CTICN
1* ~SSI(I\S
s~eRCLTII\E
-23-
---------------------"',----_._,--
_.
1*
*1
1*
*1
*1
I*SLE~(LTI~E ~I~~
1* T~I5 RECLRSI~E
1*
1*
1*
1*
1*
1*
1*
vI~V:
SLERCLTI~E [E1ER~I~ES T~E ~ISIelE PCRTIC~ CF
PART CF ~~IC~ 15 ~ISIElE.
IF T~E ~l[FCI~T
C(I~CICES ~IT~ ~~ ECGE (F l~E SCREE~ (S~=C' 11, ~L(~G ~IT~
T~E ~ISIelE E~CP(I~l, ~tRK T~E E~[S CF T~E ~ISIELE PCRTI(N.
IF ~CT, CNE-~~lF (F T~E LI~E C~~ EE CISC~R[E[ (R S~VE[,
ll~E
SEG~E~T,
[EFE~CI~G
~fLf
C~
l~E
FASSE[ T(
~ISIeIlIl~
~I~~
fCR
(f
FLR1~ER
T~E
~ICFCI~l,
~~C
l~E
(T~ER
SLe[IVICI~G.
,REClRSlvE;
FLCAl(15',
FIXE[(2,C),
fIXEC 8I~~~~(4,c);
~*I
*1
*1
*1
*1
*1
*1
*1
FP(CEC~RE(XV,'1~,)I,~I
CECLARE
(XV,'1V,)It~I,)~,~~)
S~
C~
X,.
=
(Xv
-+ XI,/2;
V~
=
(Yv
..
s,. =
1F
'11)/2;
SCC[E(RCL~[(X,.',~(L~[('1");
S~DC
T~E~
CC;
XI = xp.;
VI = '1fJ;
RETLRN;
EI\[;
c,. = CC[E(R(L~()fJ"R(L~[(V~)';
IF C~=ZERCES T~EI\ CAll vI~~(X~,YP.,XI,'1I);
ELSE CC;
C~Ll
•
RET:
..
VI~v(.xV,yv,)fJ,'fJ';
XI = Xp.;
'vI = '1~;
HE;
1*
1*
1*
EI\E V!f\V;
EISFl~Y
TrE vISIElE PCRlI(" CF TrE
PRT:
C~ll
H-E:
Ef\E ClIPl;
lI~E.
CISPl~(R(LI\[(Xl"R(L"[(Yl',R(C"[(.x2),R(l"C(Y2»;
-24-
*1
*1
.,
Download