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


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

MFEnvelopesImpl3: PROGRAM IMPORTS PascalBasic, MFProcArray, MFInteraction, MFMath, MFSymbols, MFPaths, MFMoves, MFEdges, MFOctants, MFContours, MFEnvelopes EXPORTS MFEnvelopes = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFInteraction, MFMath, MFSymbols, MFPaths, MFMoves, MFEdges, MFOctants, MFContours, MFEnvelopes;
 FillEnvelope: PROCEDURE[SpecHead: Halfword] = 
BEGIN 
 P, Q, R, S:Halfword;H:Halfword;Www: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-- InnerFill: PROCEDURE = 
BEGIN--508:--W←Mem[H]↑.Hh.Rh;
IF Mem[ INT[P]+4]↑.Int=1  THEN W←Mem[W]↑.Hh.Lh;IF Internal↑[10]>65536  THEN--509:
BEGIN PrintNl[448];Print[OctantDir↑[Octant]];Print[426];
PrintInt[Mem[H]↑.Hh.Lh];Print[449];
IF Mem[H]↑.Hh.Lh#1  THEN PrintChar[115];Print[450];
Unskew[Mem[ INT[P]+1]↑.Int+Mem[ INT[W]+1]↑.Int,Mem[ INT[P]+2]↑.Int+Mem[ INT[W]+2]↑.Int,Octant];
PrintTwo[CurX,CurY];Ww←Mem[H]↑.Hh.Rh;
IF Mem[ INT[Q]+6]↑.Int=1  THEN Ww←Mem[Ww]↑.Hh.Lh;Print[451];
Unskew[Mem[ INT[Q]+1]↑.Int+Mem[ INT[Ww]+1]↑.Int,Mem[ INT[Q]+2]↑.Int+Mem[ INT[Ww]+2]↑.Int,Octant];
PrintTwo[CurX,CurY]; END--:509--;Ww←Mem[H]↑.Hh.Rh;Www←Ww;
IF PascalODD[OctantNumber↑[Octant]] THEN Www←Mem[Www]↑.Hh.Lh  ELSE Ww←Mem[Ww]↑.
Hh.Lh;IF W#Ww  THEN SkewLineEdges[P,W,Ww];
EndRound[Mem[ INT[P]+1]↑.Int+Mem[ INT[Ww]+1]↑.Int,Mem[ INT[P]+2]↑.Int+Mem[ INT[Ww]+2]↑.Int];M0←M1;
N0←N1;D0←D1;
EndRound[Mem[ INT[Q]+1]↑.Int+Mem[ INT[Www]+1]↑.Int,Mem[ INT[Q]+2]↑.Int+Mem[ INT[Www]+2]↑.Int];
IF N1-N0>=MoveSize  THEN Overflow[408,MoveSize]--:508--; END;
 IF Internal↑[10]>0  THEN BeginEdgeTracing[];P←SpecHead;
DO Octant←Mem[ INT[P]+3]↑.Int;H← INT[CurPen]+Octant;--466:--Q←P;
WHILE Mem[Q]↑.Hh.B1#0 DO Q←Mem[Q]↑.Hh.Rh--:466-- ENDLOOP ;InnerFill[];
OffsetPrep[P,H];--466:--Q←P;
WHILE Mem[Q]↑.Hh.B1#0 DO Q←Mem[Q]↑.Hh.Rh--:466-- ENDLOOP ;--512:
IF PascalODD[OctantNumber↑[Octant]] THEN BEGIN--513:--K←0;W←Mem[H]↑.Hh.Rh;
Ww←Mem[W]↑.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[0 ].. INT[N1-N0 ]] DO  N ← i; EnvMove↑[N]←Mm0 ENDLOOP;EnvMove↑[N1-N0]←Mm1;MovePtr←0;
M←Mm0--:513--;R←P;Mem[Q]↑.Hh.B1← INT[Mem[H]↑.Hh.Lh]+1;
{WHILE TRUE DO BEGIN IF R=Q  THEN SmoothTop←MovePtr;
WHILE Mem[R]↑.Hh.B1#K DO--515:--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.Rh;
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--516:--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 Tx←TakeFraction[Delx,MakeFraction[Yy,Dely]];
IF AbVsCd[Tx,Dely,Delx,Yy]+XyCorr↑[Octant]>0  THEN Tx←Tx-1;
M←FloorUnscaled[Xx+Tx];
IF M>EnvMove↑[MovePtr] THEN EnvMove↑[MovePtr]←M;Ty←Ty-65536;
IF Ty<65536  THEN  GOTO Label31;Yy←Yy+65536;MovePtr←MovePtr+1; END ENDLOOP ;EXITS Label31 => NULL}; END;
 END--:516--; END  ELSE 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; 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--:515-- 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]];--514:
DO M←M+Move↑[N]-1;IF M>EnvMove↑[N] THEN EnvMove↑[N]←M;N←N+1;
 IF N>MovePtr--:514-- THEN EXIT; ENDLOOP;R←S; END ENDLOOP ;EXITS Label30 => NULL};--517:
IF(M#Mm1)OR (MovePtr#N1-N0) THEN Confusion[49];
Move↑[0]←D0+EnvMove↑[0]-Mm0;
FOR i:INT    IN [ INT[1 ].. INT[MovePtr ]] DO  N ← i; Move↑[N]←EnvMove↑[N]-EnvMove↑[N-1]+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=0  THEN BEGIN W←Mem[H]↑.Hh.Rh;
SkewLineEdges[Q,Mem[W]↑.Hh.Lh,W]; END--:517--; END  ELSE DualMoves[H,P,Q];
Mem[Q]↑.Hh.B1←0--:512--;P←Mem[Q]↑.Hh.Rh; IF P=SpecHead THEN EXIT; ENDLOOP;
IF Internal↑[10]>0  THEN EndEdgeTracing[];TossKnotList[SpecHead]; END;

END.