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


DIRECTORY
  PascalBasic,
  PascalWizardFiles,
  MFTypes,
  MFProcArray,
  MFMath,
  MFOctants,
  MFEnvelopes;

MFEnvelopesImpl2: PROGRAM IMPORTS MFProcArray, MFMath, MFOctants EXPORTS MFEnvelopes = PUBLIC
BEGIN OPEN PascalBasic, PascalWizardFiles, MFTypes, MFProcArray, MFMath, MFOctants, MFEnvelopes;
 SplitForOffset: PROCEDURE[P: Halfword,T: Fraction] = 
BEGIN Q:Halfword;
R:Halfword; Q←Mem[P]↑.Hh.Rh;
SplitCubic[P,T,Mem[ INT[Q]+1]↑.Int,Mem[ INT[Q]+2]↑.Int];R←Mem[P]↑.Hh.Rh;
IF Mem[ INT[R]+2]↑.Int<Mem[ INT[P]+2]↑.Int  THEN Mem[ INT[R]+2]↑.Int←Mem[ INT[P]+2]↑.Int  ELSE IF Mem
[ INT[R]+2]↑.Int>Mem[ INT[Q]+2]↑.Int  THEN Mem[ INT[R]+2]↑.Int←Mem[ INT[Q]+2]↑.Int;
IF Mem[ INT[R]+1]↑.Int<Mem[ INT[P]+1]↑.Int  THEN Mem[ INT[R]+1]↑.Int←Mem[ INT[P]+1]↑.Int  ELSE IF Mem
[ INT[R]+1]↑.Int>Mem[ INT[Q]+1]↑.Int  THEN Mem[ INT[R]+1]↑.Int←Mem[ INT[Q]+1]↑.Int; END;--:493----497:
 FinOffsetPrep: PROCEDURE[P: Halfword,K: Halfword,W: Halfword,
X0,X1,X2,Y0,Y1,Y2: PascalInteger,Rising: PascalBoolean,N: PascalInteger] = 
BEGIN 
 Q, Ww:Halfword;Du, Dv:Scaled;T0, T1, T2:PascalInteger;T:Fraction;S:Fraction;
V:PascalInteger; {WHILE TRUE DO BEGIN Q←Mem[P]↑.Hh.Rh;Mem[P]↑.Hh.B1←K;
IF Rising  THEN IF K=N  THEN  GOTO Label10  ELSE Ww←Mem[W]↑.Hh.Rh  ELSE IF K=1
 THEN  GOTO Label10  ELSE Ww←Mem[W]↑.Hh.Lh;--498:--Du←Mem[ INT[Ww]+1]↑.Int-Mem[ INT[W]+1]↑.Int;
Dv←Mem[ INT[Ww]+2]↑.Int-Mem[ INT[W]+2]↑.Int;
IF ABS[Du]>=ABS[Dv] THEN BEGIN S←MakeFraction[Dv,Du];
T0←TakeFraction[X0,S]-Y0;T1←TakeFraction[X1,S]-Y1;
T2←TakeFraction[X2,S]-Y2; END  ELSE BEGIN S←MakeFraction[Du,Dv];
T0←X0-TakeFraction[Y0,S];T1←X1-TakeFraction[Y1,S];
T2←X2-TakeFraction[Y2,S]; END--:498--;T←CrossingPoint[T0,T1,T2];
IF T>=268435456  THEN  GOTO Label10;--499:--BEGIN SplitForOffset[P,T];
Mem[P]↑.Hh.B1←K;P←Mem[P]↑.Hh.Rh;V←X0-TakeFraction[X0-X1,T];
X1←X1-TakeFraction[X1-X2,T];X0←V-TakeFraction[V-X1,T];
V←Y0-TakeFraction[Y0-Y1,T];Y1←Y1-TakeFraction[Y1-Y2,T];
Y0←V-TakeFraction[V-Y1,T];T1←T1-TakeFraction[T1-T2,T];
IF T1>0  THEN T1←0;T←CrossingPoint[0,-T1,-T2];
IF T<268435456  THEN BEGIN SplitForOffset[P,T];
Mem[Mem[P]↑.Hh.Rh]↑.Hh.B1←K;V←X1-TakeFraction[X1-X2,T];
X1←X0-TakeFraction[X0-X1,T];X2←X1-TakeFraction[X1-V,T];
V←Y1-TakeFraction[Y1-Y2,T];Y1←Y0-TakeFraction[Y0-Y1,T];
Y2←Y1-TakeFraction[Y1-V,T]; END; END--:499--;
IF Rising  THEN K← INT[K]+1  ELSE K← INT[K]-1;W←Ww; END ENDLOOP ;EXITS Label10 => NULL}; END;--:497

END.