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


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFInteraction,
  MFMath,
  MFMemory,
  MFSymbols,
  MFPaths,
  MFParsing;

MFPathsImpl2: PROGRAM IMPORTS MFProcArray, MFInteraction, MFMath, MFSymbols, MFPaths, MFParsing EXPORTS MFPaths = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFInteraction, MFMath, MFMemory, MFSymbols, MFPaths, MFParsing;
--:299-- SolveChoices: PROCEDURE[P,Q: Halfword,N: Halfword] = 
BEGIN 
 K:PascalInteger[0..PathSize];R, S, T:Halfword;--286:--Aa, Bb, Cc, Ff, Acc:Fraction;
Dd, Ee:Scaled;Lt, Rt:Scaled;--:286-- K←0;S←P;
{{WHILE TRUE DO BEGIN T←Mem[S]↑.Hh.Rh;IF K=0  THEN--285:
SELECT Mem[S]↑.Hh.B1 FROM 2 =>IF Mem[T]↑.Hh.B0=2  THEN--301:
BEGIN Aa←NArg[DeltaX↑[0],DeltaY↑[0]];NSinCos[Mem[ INT[P]+5]↑.Int-Aa];
Ct←NCos;St←NSin;NSinCos[Mem[ INT[Q]+3]↑.Int-Aa];Cf←NCos;Sf←-NSin;
SetControls[P,Q,0]; GOTO Label10; END--:301-- ELSE--293:
BEGIN Vv↑[0]←Mem[ INT[S]+5]↑.Int-NArg[DeltaX↑[0],DeltaY↑[0]];
IF ABS[Vv↑[0]]>188743680  THEN IF Vv↑[0]>0  THEN Vv↑[0]←Vv↑[0]-377487360  ELSE
Vv↑[0]←Vv↑[0]+377487360;Uu↑[0]←0;Ww↑[0]←0; END--:293--;
3 =>IF Mem[T]↑.Hh.B0=3  THEN--302:--BEGIN Mem[P]↑.Hh.B1←1;Mem[Q]↑.Hh.B0←1;
Lt←ABS[Mem[ INT[Q]+4]↑.Int];Rt←ABS[Mem[ INT[P]+6]↑.Int];
IF Rt=65536  THEN BEGIN IF DeltaX↑[0]>=0  THEN Mem[ INT[P]+5]↑.Int←
Mem[ INT[P]+1]↑.Int+( (DeltaX↑[0]+1)/3) ELSE Mem[ INT[P]+5]↑.Int←Mem[ INT[P]+1]↑.Int+(
(DeltaX↑[0]-1)/3);
IF DeltaY↑[0]>=0  THEN Mem[ INT[P]+6]↑.Int←Mem[ INT[P]+2]↑.Int+( (DeltaY↑[0]+1)/3)
 ELSE Mem[ INT[P]+6]↑.Int←Mem[ INT[P]+2]↑.Int+( (DeltaY↑[0]-1)/3);
 END  ELSE BEGIN Ff←MakeFraction[65536,3*Rt];
Mem[ INT[P]+5]↑.Int←Mem[ INT[P]+1]↑.Int+TakeFraction[DeltaX↑[0],Ff];
Mem[ INT[P]+6]↑.Int←Mem[ INT[P]+2]↑.Int+TakeFraction[DeltaY↑[0],Ff]; END;
IF Lt=65536  THEN BEGIN IF DeltaX↑[0]>=0  THEN Mem[ INT[Q]+3]↑.Int←
Mem[ INT[Q]+1]↑.Int-( (DeltaX↑[0]+1)/3) ELSE Mem[ INT[Q]+3]↑.Int←Mem[ INT[Q]+1]↑.Int-(
(DeltaX↑[0]-1)/3);
IF DeltaY↑[0]>=0  THEN Mem[ INT[Q]+4]↑.Int←Mem[ INT[Q]+2]↑.Int-( (DeltaY↑[0]+1)/3)
 ELSE Mem[ INT[Q]+4]↑.Int←Mem[ INT[Q]+2]↑.Int-( (DeltaY↑[0]-1)/3);
 END  ELSE BEGIN Ff←MakeFraction[65536,3*Lt];
Mem[ INT[Q]+3]↑.Int←Mem[ INT[Q]+1]↑.Int-TakeFraction[DeltaX↑[0],Ff];
Mem[ INT[Q]+4]↑.Int←Mem[ INT[Q]+2]↑.Int-TakeFraction[DeltaY↑[0],Ff]; END; GOTO Label10;
 END--:302-- ELSE--294:--BEGIN Cc←Mem[ INT[S]+5]↑.Int;Lt←ABS[Mem[ INT[T]+4]↑.Int];
Rt←ABS[Mem[ INT[S]+6]↑.Int];
IF(Rt=65536)AND (Lt=65536) THEN Uu↑[0]←MakeFraction[Cc+Cc+65536,Cc+131072
] ELSE Uu↑[0]←CurlRatio[Cc,Rt,Lt];Vv↑[0]←-TakeFraction[Psi↑[1],Uu↑[0]];
Ww↑[0]←0; END--:294--;4 =>BEGIN Uu↑[0]←0;Vv↑[0]←0;Ww↑[0]←268435456; END;
 ENDCASE--:285-- ELSE SELECT Mem[S]↑.Hh.B0 FROM 5,4 =>--287:--BEGIN--288:
IF ABS[Mem[ INT[R]+6]↑.Int]=65536  THEN BEGIN Aa←134217728;Dd←2*Delta↑[K];
 END  ELSE BEGIN Aa←MakeFraction[65536,3*ABS[Mem[ INT[R]+6]↑.Int]-65536];
Dd←TakeFraction[Delta↑[K],805306368-MakeFraction[65536,ABS[Mem[ INT[R]+6]↑.
Int]]]; END;IF ABS[Mem[ INT[T]+4]↑.Int]=65536  THEN BEGIN Bb←134217728;
Ee←2*Delta↑[K-1];
 END  ELSE BEGIN Bb←MakeFraction[65536,3*ABS[Mem[ INT[T]+4]↑.Int]-65536];
Ee←TakeFraction[Delta↑[K-1],805306368-MakeFraction[65536,ABS[Mem[ INT[T]+4]↑.
Int]]]; END;Cc←268435456-TakeFraction[Uu↑[K-1],Aa]--:288--;--289:
Dd←TakeFraction[Dd,Cc];Lt←ABS[Mem[ INT[S]+4]↑.Int];Rt←ABS[Mem[ INT[S]+6]↑.Int];
IF Lt#Rt  THEN IF Lt<Rt  THEN BEGIN Ff←MakeFraction[Lt,Rt];
Ff←TakeFraction[Ff,Ff];Dd←TakeFraction[Dd,Ff];
 END  ELSE BEGIN Ff←MakeFraction[Rt,Lt];Ff←TakeFraction[Ff,Ff];
Ee←TakeFraction[Ee,Ff]; END;Ff←MakeFraction[Ee,Ee+Dd]--:289--;
Uu↑[K]←TakeFraction[Ff,Bb];--290:--Acc←-TakeFraction[Psi↑[K+1],Uu↑[K]];
IF Mem[R]↑.Hh.B1=3  THEN BEGIN Ww↑[K]←0;
Vv↑[K]←Acc-TakeFraction[Psi↑[1],268435456-Ff];
 END  ELSE BEGIN Ff←MakeFraction[268435456-Ff,Cc];
Acc←Acc-TakeFraction[Psi↑[K],Ff];Ff←TakeFraction[Ff,Aa];
Vv↑[K]←Acc-TakeFraction[Vv↑[K-1],Ff];
IF Ww↑[K-1]=0  THEN Ww↑[K]←0  ELSE Ww↑[K]←-TakeFraction[Ww↑[K-1],Ff];
 END--:290--;IF Mem[S]↑.Hh.B0=5  THEN--291:--BEGIN Aa←0;Bb←268435456;
DO K←K-1;IF K=0  THEN K←N;Aa←Vv↑[K]-TakeFraction[Aa,Uu↑[K]];
Bb←Ww↑[K]-TakeFraction[Bb,Uu↑[K]]; IF K=N THEN EXIT; ENDLOOP;
Aa←MakeFraction[Aa,268435456-Bb];Theta↑[N]←Aa;Vv↑[0]←Aa;
FOR i:INT    IN [ INT[1 ].. INT[ INT[N]-1 ]] DO  K ← i; Vv↑[K]←Vv↑[K]+TakeFraction[Aa,Ww↑[K]] ENDLOOP; GOTO Label40;
 END--:291--; END--:287--;3 =>--295:--BEGIN Cc←Mem[ INT[S]+3]↑.Int;
Lt←ABS[Mem[ INT[S]+4]↑.Int];Rt←ABS[Mem[ INT[R]+6]↑.Int];
IF(Rt=65536)AND (Lt=65536) THEN Ff←MakeFraction[Cc+Cc+65536,Cc+131072]
 ELSE Ff←CurlRatio[Cc,Lt,Rt];
Theta↑[N]←-MakeFraction[TakeFraction[Vv↑[ INT[N]-1],Ff],
268435456-TakeFraction[Ff,Uu↑[ INT[N]-1]]]; GOTO Label40; END--:295--;2 =>--292:
BEGIN Theta↑[N]←Mem[ INT[S]+3]↑.Int-NArg[DeltaX↑[ INT[N]-1],DeltaY↑[ INT[N]-1]];
IF ABS[Theta↑[N]]>188743680  THEN IF Theta↑[N]>0  THEN Theta↑[N]←Theta↑[N]
-377487360  ELSE Theta↑[N]←Theta↑[N]+377487360; GOTO Label40; END--:292--; ENDCASE;R←S;
S←T;K←K+1; END ENDLOOP ;EXITS Label40 => NULL};--297:
FOR i:INT    DECREASING IN [ INT[0 ].. INT[ INT[N]-1 ]] DO  K ← i; Theta↑[K]←Vv↑[K]-TakeFraction[Theta↑[K+1],Uu↑[K]] ENDLOOP;
S←P;K←0;DO T←Mem[S]↑.Hh.Rh;NSinCos[Theta↑[K]];St←NSin;
Ct←NCos;NSinCos[-Psi↑[K+1]-Theta↑[K+1]];Sf←NSin;Cf←NCos;
SetControls[S,T,K];K←K+1;S←T; IF K=N--:297-- THEN EXIT; ENDLOOP;EXITS Label10 => NULL}; END;--:284
 MakeChoices: PROCEDURE[Knots: Halfword] = 
BEGIN  H:Halfword;
P, Q:Halfword;--280:--K, N:PascalInteger[0..PathSize];S, T:Halfword;Delx, Dely:Scaled;
Sine, Cosine:Fraction;--:280--  BEGIN IF ArithError  THEN ClearArith[];
 END;IF Internal↑[4]>0  THEN PrintPath[Knots,394,TRUE];--271:--P←Knots;
DO Q←Mem[P]↑.Hh.Rh;
IF Mem[ INT[P]+1]↑.Int=Mem[ INT[Q]+1]↑.Int  THEN IF Mem[ INT[P]+2]↑.Int=Mem[ INT[Q]+2]↑.Int  THEN IF
 INT[Mem[P]↑.Hh.B1]>1  THEN BEGIN Mem[P]↑.Hh.B1←1;
IF Mem[P]↑.Hh.B0=4  THEN BEGIN Mem[P]↑.Hh.B0←3;Mem[ INT[P]+3]↑.Int←65536; END;
Mem[Q]↑.Hh.B0←1;IF Mem[Q]↑.Hh.B1=4  THEN BEGIN Mem[Q]↑.Hh.B1←3;
Mem[ INT[Q]+5]↑.Int←65536; END;Mem[ INT[P]+5]↑.Int←Mem[ INT[P]+1]↑.Int;
Mem[ INT[Q]+3]↑.Int←Mem[ INT[P]+1]↑.Int;Mem[ INT[P]+6]↑.Int←Mem[ INT[P]+2]↑.Int;
Mem[ INT[Q]+4]↑.Int←Mem[ INT[P]+2]↑.Int; END;P←Q; IF P=Knots--:271-- THEN EXIT; ENDLOOP;--272:--H←Knots;
{WHILE TRUE DO BEGIN IF Mem[H]↑.Hh.B0#4  THEN  GOTO Label30;
IF Mem[H]↑.Hh.B1#4  THEN  GOTO Label30;H←Mem[H]↑.Hh.Rh;
IF H=Knots  THEN BEGIN Mem[H]↑.Hh.B0←5; GOTO Label30; END; END ENDLOOP ;EXITS Label30 => NULL};--:272--P←H;
DO--273:--Q←Mem[P]↑.Hh.Rh;
IF  INT[Mem[P]↑.Hh.B1]>=2  THEN BEGIN WHILE(Mem[Q]↑.Hh.B0=4)AND (Mem[Q]↑.Hh.B1=4)DO
Q←Mem[Q]↑.Hh.Rh ENDLOOP ;--278:----281:--K←0;S←P;N←PathSize;
DO T←Mem[S]↑.Hh.Rh;DeltaX↑[K]←Mem[ INT[T]+1]↑.Int-Mem[ INT[S]+1]↑.Int;
DeltaY↑[K]←Mem[ INT[T]+2]↑.Int-Mem[ INT[S]+2]↑.Int;
Delta↑[K]←PythAdd[DeltaX↑[K],DeltaY↑[K]];
IF  INT[K]>0  THEN BEGIN Sine←MakeFraction[DeltaY↑[K-1],Delta↑[K-1]];
Cosine←MakeFraction[DeltaX↑[K-1],Delta↑[K-1]];
Psi↑[K]←NArg[TakeFraction[DeltaX↑[K],Cosine]+TakeFraction[DeltaY↑[K],
Sine],TakeFraction[DeltaY↑[K],Cosine]-TakeFraction[DeltaX↑[K],Sine]];
 END;K←K+1;S←T;IF K=PathSize  THEN Overflow[399,PathSize];
IF S=Q  THEN N←K; IF( INT[K]>=N)AND (Mem[S]↑.Hh.B0#5) THEN EXIT; ENDLOOP;
IF K=N  THEN Psi↑[N]←0  ELSE Psi↑[K]←Psi↑[1]--:281--;--282:
IF Mem[Q]↑.Hh.B0=4  THEN BEGIN Delx←Mem[ INT[Q]+5]↑.Int-Mem[ INT[Q]+1]↑.Int;
Dely←Mem[ INT[Q]+6]↑.Int-Mem[ INT[Q]+2]↑.Int;
IF(Delx=0)AND (Dely=0) THEN BEGIN Mem[Q]↑.Hh.B0←3;Mem[ INT[Q]+3]↑.Int←65536;
 END  ELSE BEGIN Mem[Q]↑.Hh.B0←2;Mem[ INT[Q]+3]↑.Int←NArg[Delx,Dely]; END; END;
IF(Mem[P]↑.Hh.B1=4)AND (Mem[P]↑.Hh.B0=1) THEN BEGIN Delx←Mem[ INT[P]+1]↑.Int-Mem[ INT[P
]+3]↑.Int;Dely←Mem[ INT[P]+2]↑.Int-Mem[ INT[P]+4]↑.Int;
IF(Delx=0)AND (Dely=0) THEN BEGIN Mem[P]↑.Hh.B1←3;Mem[ INT[P]+5]↑.Int←65536;
 END  ELSE BEGIN Mem[P]↑.Hh.B1←2;Mem[ INT[P]+5]↑.Int←NArg[Delx,Dely]; END;
 END--:282--;SolveChoices[P,Q,N]--:278--; END;P←Q--:273--; IF P=H THEN EXIT; ENDLOOP;
IF Internal↑[4]>0  THEN PrintPath[Knots,395,TRUE];
IF ArithError  THEN--270:--BEGIN BEGIN IF Interaction=3  THEN NULL;
PrintNl[133];Print[396]; END;BEGIN HelpPtr←2;HelpLine↑[1]←397;
HelpLine↑[0]←398; END;PutGetError[];ArithError←FALSE; END--:270--; END;

END.