-- file: MFEnvelopesImpl4.mesa
-- Pascal-to-Mesa translator output, translated at October 31, 1985 4:28:01 pm PST


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFInteraction,
  MFMath,
  MFSymbols,
  MFMoves,
  MFEdges,
  MFOctants,
  MFContours,
  MFEnvelopes;

MFEnvelopesImpl4: PROGRAM IMPORTS MFProcArray, MFInteraction, MFMath, MFSymbols, MFMoves, MFEdges, MFOctants, MFContours, MFEnvelopes EXPORTS MFEnvelopes = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFInteraction, MFMath, MFSymbols, MFMoves, MFEdges, MFOctants, MFContours, MFEnvelopes;
 DualMoves: PROCEDURE[H,P,Q: Halfword] = 
BEGIN  R, S:Halfword;--511:
M, N:PascalInteger;Mm0, Mm1:PascalInteger;K:PascalInteger;W, Ww:Halfword;
SmoothBot, SmoothTop:PascalInteger[0..MoveSize];Xx, Yy, Xp, Yp, Delx, Dely, Tx, Ty:Scaled;
--:511----519:--K← INT[Mem[H]↑.Hh.Lh]+1;Ww←Mem[H]↑.Hh.Rh;W←Mem[Ww]↑.Hh.Lh;
Mm0←FloorUnscaled[Mem[ INT[P]+1]↑.Int+Mem[ INT[W]+1]↑.Int-XyCorr↑[Octant]];
Mm1←FloorUnscaled[Mem[ INT[Q]+1]↑.Int+Mem[ INT[Ww]+1]↑.Int-XyCorr↑[Octant]];
FOR i:INT    IN [ INT[1 ].. INT[N1-N0+1 ]] DO  N ← i; EnvMove↑[N]←Mm1 ENDLOOP;EnvMove↑[0]←Mm0;MovePtr←0;
M←Mm0--:519--;R←P;{WHILE TRUE DO BEGIN IF R=Q  THEN SmoothTop←MovePtr;
WHILE Mem[R]↑.Hh.B1#K DO--521:--BEGIN Xx←Mem[ INT[R]+1]↑.Int+Mem[ INT[W]+1]↑.Int;
Yy←Mem[ INT[R]+2]↑.Int+Mem[ INT[W]+2]↑.Int+32768;
IF Internal↑[10]>65536  THEN BEGIN PrintNl[453];PrintInt[K];Print[454];
Unskew[Xx,Yy-32768,Octant];PrintTwo[CurX,CurY]; END;
IF Mem[R]↑.Hh.B1<K  THEN BEGIN K←K-1;W←Mem[W]↑.Hh.Lh;
Xp←Mem[ INT[R]+1]↑.Int+Mem[ INT[W]+1]↑.Int;Yp←Mem[ INT[R]+2]↑.Int+Mem[ INT[W]+2]↑.Int+32768;
IF Yp#Yy  THEN--522:--BEGIN Ty←FloorScaled[Yy-YCorr↑[Octant]];
Dely←Yp-Yy;Yy←Yy-Ty;Ty←Yp-YCorr↑[Octant]-Ty;
IF Ty>=65536  THEN BEGIN Delx←Xp-Xx;Yy←65536-Yy;
{WHILE TRUE DO BEGIN IF M<EnvMove↑[MovePtr] THEN EnvMove↑[MovePtr]←M;
Tx←TakeFraction[Delx,MakeFraction[Yy,Dely]];
IF AbVsCd[Tx,Dely,Delx,Yy]+XyCorr↑[Octant]>0  THEN Tx←Tx-1;
M←FloorUnscaled[Xx+Tx];Ty←Ty-65536;MovePtr←MovePtr+1;
IF Ty<65536  THEN  GOTO Label31;Yy←Yy+65536; END ENDLOOP ;
EXITS Label31 => NULL};IF M<EnvMove↑[MovePtr] THEN EnvMove↑[MovePtr]←M; END; END--:522--;
 END  ELSE BEGIN K←K+1;W←Mem[W]↑.Hh.Rh;Xp←Mem[ INT[R]+1]↑.Int+Mem[ INT[W]+1]↑.Int;
Yp←Mem[ INT[R]+2]↑.Int+Mem[ INT[W]+2]↑.Int+32768; END;
IF Internal↑[10]>65536  THEN BEGIN Print[451];Unskew[Xp,Yp-32768,Octant];
PrintTwo[CurX,CurY];PrintNl[157]; END;
M←FloorUnscaled[Xp-XyCorr↑[Octant]];
MovePtr←FloorUnscaled[Yp-YCorr↑[Octant]]-N0;
IF M<EnvMove↑[MovePtr] THEN EnvMove↑[MovePtr]←M; END--:521-- ENDLOOP ;
IF R=P  THEN SmoothBot←MovePtr;IF R=Q  THEN  GOTO Label30;Move↑[MovePtr]←1;
N←MovePtr;S←Mem[R]↑.Hh.Rh;
MakeMoves[Mem[ INT[R]+1]↑.Int+Mem[ INT[W]+1]↑.Int,Mem[ INT[R]+5]↑.Int+Mem[ INT[W]+1]↑.Int,Mem[ INT[S]+3]↑.
Int+Mem[ INT[W]+1]↑.Int,Mem[ INT[S]+1]↑.Int+Mem[ INT[W]+1]↑.Int,Mem[ INT[R]+2]↑.Int+Mem[ INT[W]+2]↑.Int
+32768,Mem[ INT[R]+6]↑.Int+Mem[ INT[W]+2]↑.Int+32768,Mem[ INT[S]+4]↑.Int+Mem[ INT[W]+2]↑.Int+32768,
Mem[ INT[S]+2]↑.Int+Mem[ INT[W]+2]↑.Int+32768,XyCorr↑[Octant],YCorr↑[Octant]];--520:
DO IF M<EnvMove↑[N] THEN EnvMove↑[N]←M;M←M+Move↑[N]-1;N←N+1;
 IF N>MovePtr--:520-- THEN EXIT; ENDLOOP;R←S; END ENDLOOP ;EXITS Label30 => NULL};--523:
IF(M#Mm1)OR (MovePtr#N1-N0) THEN Confusion[50];
Move↑[0]←D0+EnvMove↑[1]-Mm0;
FOR i:INT    IN [ INT[1 ].. INT[MovePtr ]] DO  N ← i; Move↑[N]←EnvMove↑[N+1]-EnvMove↑[N]+1 ENDLOOP;
Move↑[MovePtr]←Move↑[MovePtr]-D1;
IF Internal↑[35]>0  THEN SmoothMoves[SmoothBot,SmoothTop];
MoveToEdges[M0,N0,M1,N1];IF Mem[ INT[Q]+6]↑.Int=1  THEN BEGIN W←Mem[H]↑.Hh.Rh;
SkewLineEdges[Q,W,Mem[W]↑.Hh.Lh]; END--:523--; END;--:518

END.