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


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFMath,
  MFOctants,
  MFContours,
  MFSymbols;

MFOctantsImpl5: PROGRAM IMPORTS PascalBasic, MFProcArray, MFMath, MFOctants, MFContours, MFSymbols EXPORTS MFOctants = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFMath, MFOctants, MFContours, MFSymbols;
 XyRound: PROCEDURE = 
BEGIN P, Q:Halfword;B, A:Scaled;PenEdge:Scaled;
Alpha:Fraction; CurGran←ABS[Internal↑[37]];
IF CurGran=0  THEN CurGran←65536;P←CurSpec;CurRoundingPtr←0;
DO Q←Mem[P]↑.Hh.Rh;--434:
IF PascalODD[Mem[P]↑.Hh.B1]#PascalODD[Mem[Q]↑.Hh.B1] THEN BEGIN IF PascalODD[Mem[Q]↑.Hh.B1]
 THEN B←Mem[ INT[Q]+1]↑.Int  ELSE B←-Mem[ INT[Q]+1]↑.Int;
IF(ABS[Mem[ INT[Q]+1]↑.Int-Mem[ INT[Q]+5]↑.Int]<655)OR (
ABS[Mem[ INT[Q]+1]↑.Int+Mem[ INT[Q]+3]↑.Int]<655) THEN--435:
BEGIN IF CurPen=3  THEN PenEdge←0  ELSE IF CurPathType=0  THEN
PenEdge←Compromise[Mem[ INT[Mem[ INT[CurPen]+5]↑.Hh.Rh]+2]↑.Int,Mem[ INT[Mem[ INT[CurPen]+7]↑.
Hh.Rh]+2]↑.Int] ELSE IF PascalODD[Mem[Q]↑.Hh.B1] THEN PenEdge←Mem[ INT[Mem[ INT[CurPen]+7]↑.
Hh.Rh]+2]↑.Int  ELSE PenEdge←Mem[ INT[Mem[ INT[CurPen]+5]↑.Hh.Rh]+2]↑.Int;
A←GoodVal[B,PenEdge]; END--:435-- ELSE A←B;
IF ABS[A]>MaxAllowed  THEN IF A>0  THEN A←MaxAllowed  ELSE A←
-MaxAllowed;BeforeAndAfter[B,A,Q]; END--:434--;P←Q; IF P=CurSpec THEN EXIT; ENDLOOP;
IF  INT[CurRoundingPtr]>0  THEN--436:--BEGIN MakeSafe[];
DO CurRoundingPtr←CurRoundingPtr-1;
IF(After↑[CurRoundingPtr]#Before↑[CurRoundingPtr])OR (After↑
[CurRoundingPtr+1]#Before↑[CurRoundingPtr+1]) THEN BEGIN P←
NodeToRound↑[CurRoundingPtr];
IF PascalODD[Mem[P]↑.Hh.B1] THEN BEGIN B←Before↑[CurRoundingPtr];
A←After↑[CurRoundingPtr]; END  ELSE BEGIN B←-Before↑[CurRoundingPtr];
A←-After↑[CurRoundingPtr]; END;
IF Before↑[CurRoundingPtr]=Before↑[CurRoundingPtr+1] THEN Alpha←
268435456  ELSE Alpha←MakeFraction[After↑[CurRoundingPtr+1]-After↑
[CurRoundingPtr],Before↑[CurRoundingPtr+1]-Before↑[CurRoundingPtr]];
DO Mem[ INT[P]+1]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+1]↑.Int-B]+A;
Mem[ INT[P]+5]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+5]↑.Int-B]+A;P←Mem[P]↑.Hh.Rh;
Mem[ INT[P]+3]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+3]↑.Int-B]+A;
 IF P=NodeToRound↑[CurRoundingPtr+1] THEN EXIT; ENDLOOP; END; IF CurRoundingPtr=0 THEN EXIT; ENDLOOP;
 END--:436--;P←CurSpec;CurRoundingPtr←0;DO Q←Mem[P]↑.Hh.Rh;--437:
IF( INT[Mem[P]↑.Hh.B1]>2)#( INT[Mem[Q]↑.Hh.B1]>2) THEN BEGIN IF  INT[Mem[Q]↑.Hh.B1]<=2  THEN B
←Mem[ INT[Q]+2]↑.Int  ELSE B←-Mem[ INT[Q]+2]↑.Int;
IF(ABS[Mem[ INT[Q]+2]↑.Int-Mem[ INT[Q]+6]↑.Int]<655)OR (
ABS[Mem[ INT[Q]+2]↑.Int+Mem[ INT[Q]+4]↑.Int]<655) THEN--438:
BEGIN IF CurPen=3  THEN PenEdge←0  ELSE IF CurPathType=0  THEN
PenEdge←Compromise[Mem[ INT[Mem[ INT[CurPen]+2]↑.Hh.Rh]+2]↑.Int,Mem[ INT[Mem[ INT[CurPen]+1]↑.
Hh.Rh]+2]↑.Int] ELSE IF  INT[Mem[Q]↑.Hh.B1]<=2  THEN PenEdge←Mem[ INT[Mem[ INT[CurPen]+1]↑.
Hh.Rh]+2]↑.Int  ELSE PenEdge←Mem[ INT[Mem[ INT[CurPen]+2]↑.Hh.Rh]+2]↑.Int;
A←GoodVal[B,PenEdge]; END--:438-- ELSE A←B;
IF ABS[A]>MaxAllowed  THEN IF A>0  THEN A←MaxAllowed  ELSE A←
-MaxAllowed;BeforeAndAfter[B,A,Q]; END--:437--;P←Q; IF P=CurSpec THEN EXIT; ENDLOOP;
IF  INT[CurRoundingPtr]>0  THEN--439:--BEGIN MakeSafe[];
DO CurRoundingPtr←CurRoundingPtr-1;
IF(After↑[CurRoundingPtr]#Before↑[CurRoundingPtr])OR (After↑
[CurRoundingPtr+1]#Before↑[CurRoundingPtr+1]) THEN BEGIN P←
NodeToRound↑[CurRoundingPtr];
IF  INT[Mem[P]↑.Hh.B1]<=2  THEN BEGIN B←Before↑[CurRoundingPtr];
A←After↑[CurRoundingPtr]; END  ELSE BEGIN B←-Before↑[CurRoundingPtr];
A←-After↑[CurRoundingPtr]; END;
IF Before↑[CurRoundingPtr]=Before↑[CurRoundingPtr+1] THEN Alpha←
268435456  ELSE Alpha←MakeFraction[After↑[CurRoundingPtr+1]-After↑
[CurRoundingPtr],Before↑[CurRoundingPtr+1]-Before↑[CurRoundingPtr]];
DO Mem[ INT[P]+2]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+2]↑.Int-B]+A;
Mem[ INT[P]+6]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+6]↑.Int-B]+A;P←Mem[P]↑.Hh.Rh;
Mem[ INT[P]+4]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+4]↑.Int-B]+A;
 IF P=NodeToRound↑[CurRoundingPtr+1] THEN EXIT; ENDLOOP; END; IF CurRoundingPtr=0 THEN EXIT; ENDLOOP;
 END--:439--; END;--:433----440:-- DiagRound: PROCEDURE = 
BEGIN P, Q, Pp:Halfword;
B, A, Bb, Aa, D, C, Dd, Cc:Scaled;PenEdge:Scaled;Alpha, Beta:Fraction;
NextA:Scaled;AllSafe:PascalBoolean;K:PascalInteger[0..MaxWiggle];FirstX, FirstY:Scaled;
 InnerDiagRound: PROCEDURE = 
BEGIN--441:
IF Mem[P]↑.Hh.B1#Mem[Q]↑.Hh.B1  THEN BEGIN IF  INT[Mem[Q]↑.Hh.B1]>4  THEN B←-Mem[
 INT[Q]+1]↑.Int  ELSE B←Mem[ INT[Q]+1]↑.Int;
IF ABS[Mem[Q]↑.Hh.B1-Mem[P]↑.Hh.B1]=4  THEN IF(ABS[Mem[ INT[Q]+1]↑.Int-Mem[ INT[Q]+5]↑.
Int]<655)OR (ABS[Mem[ INT[Q]+1]↑.Int+Mem[ INT[Q]+3]↑.Int]<655) THEN--442:
BEGIN IF CurPen=3  THEN PenEdge←0  ELSE IF CurPathType=0  THEN--443:
SELECT Mem[Q]↑.Hh.B1 FROM 1,5 =>PenEdge←Compromise[Mem[ INT[Mem[Mem[ INT[CurPen]+1]↑.Hh.
Rh]↑.Hh.Lh]+1]↑.Int,-Mem[ INT[Mem[Mem[ INT[CurPen]+4]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int];
4,8 =>PenEdge←-Compromise[Mem[ INT[Mem[Mem[ INT[CurPen]+1]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int,
-Mem[ INT[Mem[Mem[ INT[CurPen]+4]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int];
6,2 =>PenEdge←Compromise[Mem[ INT[Mem[Mem[ INT[CurPen]+2]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int,-Mem
[ INT[Mem[Mem[ INT[CurPen]+3]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int];
7,3 =>PenEdge←-Compromise[Mem[ INT[Mem[Mem[ INT[CurPen]+2]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int,
-Mem[ INT[Mem[Mem[ INT[CurPen]+3]↑.Hh.Rh]↑.Hh.Lh]+1]↑.Int]; ENDCASE--:443
 ELSE IF  INT[Mem[Q]↑.Hh.B1]<=4  THEN PenEdge←Mem[ INT[Mem[Mem[ INT[CurPen]+Mem[Q]↑.Hh.B1]↑
.Hh.Rh]↑.Hh.Lh]+1]↑.Int  ELSE PenEdge←-Mem[ INT[Mem[Mem[ INT[CurPen]+Mem[Q]↑.Hh.B1]↑.
Hh.Rh]↑.Hh.Lh]+1]↑.Int;
IF PascalODD[Mem[Q]↑.Hh.B1] THEN A←GoodVal[B, PenEdge+PascalDIVPower2[(CurGran),1]] ELSE A←
GoodVal[B-1, PenEdge+PascalDIVPower2[(CurGran),1]]; END--:442-- ELSE A←B  ELSE A←B;
BeforeAndAfter[B,A,Q]; END--:441--; END; P←CurSpec;
CurRoundingPtr←0;DO Q←Mem[P]↑.Hh.Rh;InnerDiagRound[];P←Q;
 IF P=CurSpec THEN EXIT; ENDLOOP;IF  INT[CurRoundingPtr]>0  THEN--444:
BEGIN P←NodeToRound↑[0];FirstX←Mem[ INT[P]+1]↑.Int;FirstY←Mem[ INT[P]+2]↑.Int;
--446:--Before↑[CurRoundingPtr]←Before↑[0];
NodeToRound↑[CurRoundingPtr]←NodeToRound↑[0];
DO After↑[CurRoundingPtr]←After↑[0];AllSafe←TRUE;
NextA←After↑[0];FOR i:INT    IN [ INT[0 ].. INT[CurRoundingPtr-1 ]] DO  K ← i;  A←NextA;
B←Before↑[K];NextA←After↑[K+1];Aa←NextA;Bb←Before↑[K+1];
IF(A#B)OR (Aa#Bb) THEN BEGIN P←NodeToRound↑[K];Pp←NodeToRound↑[K+1];
--445:
IF Aa=Bb  THEN BEGIN IF Pp=NodeToRound↑[0] THEN Unskew[FirstX,FirstY,
Mem[Pp]↑.Hh.B1] ELSE Unskew[Mem[ INT[Pp]+1]↑.Int,Mem[ INT[Pp]+2]↑.Int,Mem[Pp]↑.Hh.B1];
Skew[CurX,CurY,Mem[P]↑.Hh.B1];Bb←CurX;Aa←Bb;Dd←CurY;Cc←Dd;
IF  INT[Mem[P]↑.Hh.B1]>4  THEN BEGIN B←-B;A←-A; END;
 END  ELSE BEGIN IF  INT[Mem[P]↑.Hh.B1]>4  THEN BEGIN Bb←-Bb;Aa←-Aa;B←-B;A←-A;
 END;IF Pp=NodeToRound↑[0] THEN Dd←FirstY-Bb  ELSE Dd←Mem[ INT[Pp]+2]↑.Int-Bb;
IF PascalODD[Aa-Bb] THEN IF  INT[Mem[P]↑.Hh.B1]>4  THEN Cc← Dd-PascalDIVPower2[(Aa-Bb+1),1] ELSE Cc←
 Dd-PascalDIVPower2[(Aa-Bb-1),1] ELSE Cc← Dd-PascalDIVPower2[(Aa-Bb),1]; END;D←Mem[ INT[P]+2]↑.Int;
IF PascalODD[A-B] THEN IF  INT[Mem[P]↑.Hh.B1]>4  THEN C← D-PascalDIVPower2[(A-B-1),1] ELSE C← D-PascalDIVPower2[(A-B
+1),1] ELSE C← D-PascalDIVPower2[(A-B),1];
IF(Aa<A)OR (Cc<C)OR (Aa-A>2*(Bb-B))OR (Cc-C>2*(Dd-D)) THEN BEGIN AllSafe←
FALSE;After↑[K]←Before↑[K];
IF K=CurRoundingPtr-1  THEN After↑[0]←Before↑[0] ELSE After↑[K+1]←Before↑
[K+1]; END; END; ENDLOOP; IF AllSafe--:446-- THEN EXIT; ENDLOOP;
FOR i:INT    IN [ INT[0 ].. INT[CurRoundingPtr-1 ]] DO  K ← i;  A←After↑[K];B←Before↑[K];
Aa←After↑[K+1];Bb←Before↑[K+1];
IF(A#B)OR (Aa#Bb) THEN BEGIN P←NodeToRound↑[K];Pp←NodeToRound↑[K+1];
--445:
IF Aa=Bb  THEN BEGIN IF Pp=NodeToRound↑[0] THEN Unskew[FirstX,FirstY,
Mem[Pp]↑.Hh.B1] ELSE Unskew[Mem[ INT[Pp]+1]↑.Int,Mem[ INT[Pp]+2]↑.Int,Mem[Pp]↑.Hh.B1];
Skew[CurX,CurY,Mem[P]↑.Hh.B1];Bb←CurX;Aa←Bb;Dd←CurY;Cc←Dd;
IF  INT[Mem[P]↑.Hh.B1]>4  THEN BEGIN B←-B;A←-A; END;
 END  ELSE BEGIN IF  INT[Mem[P]↑.Hh.B1]>4  THEN BEGIN Bb←-Bb;Aa←-Aa;B←-B;A←-A;
 END;IF Pp=NodeToRound↑[0] THEN Dd←FirstY-Bb  ELSE Dd←Mem[ INT[Pp]+2]↑.Int-Bb;
IF PascalODD[Aa-Bb] THEN IF  INT[Mem[P]↑.Hh.B1]>4  THEN Cc← Dd-PascalDIVPower2[(Aa-Bb+1),1] ELSE Cc←
 Dd-PascalDIVPower2[(Aa-Bb-1),1] ELSE Cc← Dd-PascalDIVPower2[(Aa-Bb),1]; END;D←Mem[ INT[P]+2]↑.Int;
IF PascalODD[A-B] THEN IF  INT[Mem[P]↑.Hh.B1]>4  THEN C← D-PascalDIVPower2[(A-B-1),1] ELSE C← D-PascalDIVPower2[(A-B
+1),1] ELSE C← D-PascalDIVPower2[(A-B),1];
IF B=Bb  THEN Alpha←268435456  ELSE Alpha←MakeFraction[Aa-A,Bb-B];
IF D=Dd  THEN Beta←268435456  ELSE Beta←MakeFraction[Cc-C,Dd-D];
DO Mem[ INT[P]+1]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+1]↑.Int-B]+A;
Mem[ INT[P]+2]↑.Int←TakeFraction[Beta,Mem[ INT[P]+2]↑.Int-D]+C;
Mem[ INT[P]+5]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+5]↑.Int-B]+A;
Mem[ INT[P]+6]↑.Int←TakeFraction[Beta,Mem[ INT[P]+6]↑.Int-D]+C;P←Mem[P]↑.Hh.Rh;
Mem[ INT[P]+3]↑.Int←TakeFraction[Alpha,Mem[ INT[P]+3]↑.Int-B]+A;
Mem[ INT[P]+4]↑.Int←TakeFraction[Beta,Mem[ INT[P]+4]↑.Int-D]+C; IF P=Pp THEN EXIT; ENDLOOP; END; ENDLOOP;
 END--:444--; END;--:440----451:--
END.