-- TSTypes.mesa
-- Basic types used all over the typesetter.
-- Written by Michael Plass

TSTypes: DEFINITIONS =
BEGIN

Badness: TYPE = REAL;
infBadness: Badness = 1.0E+20;
Penalty: TYPE = INTEGER;

-- dimensions

-- All operations that deal with dimensions should do so only through this interface, so if the representation changes in the future, the only places that will need to be changed are here and in TSTypesImpl.
Dimn: TYPE = RECORD [texPts: REAL]; -- a dimension, measured in micas
nilDimn: Dimn = [-999999]; -- for default dimensions in rules
zeroDimn: Dimn = [0];
RealDimn: PROCEDURE [value: REAL, unit: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[value*unit.texPts]]};
IntDimn: PROCEDURE [value: LONG INTEGER, unit: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[value*unit.texPts]]}; 
RatDimn: PROCEDURE [num,denom: LONG INTEGER, unit: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[num*unit.texPts/denom]]};
DimnRatio: PROCEDURE [num,denom: Dimn] RETURNS [REAL] = INLINE
    {RETURN[num.texPts/denom.texPts]};
DimnInt: PROCEDURE [num,denom: Dimn] RETURNS [INTEGER];
AddDimn: PROCEDURE [a,b: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[a.texPts+b.texPts]]};
SubDimn: PROCEDURE [a,b: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[a.texPts-b.texPts]]};
DivDimn: PROCEDURE [num: Dimn, denom: LONG INTEGER] RETURNS [Dimn] = INLINE
    {RETURN[[num.texPts/denom]]};
NegDimn: PROCEDURE [a: Dimn] RETURNS [BOOLEAN] = INLINE {RETURN[a.texPts<0]};
MaxDimn: PROCEDURE [a,b: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[MAX[a.texPts,b.texPts]]]};
AbsDimn: PROCEDURE [a: Dimn] RETURNS [Dimn] = INLINE
    {RETURN[[ABS[a.texPts]]]};

pt: Dimn = [1.0];
bp: Dimn = [1.00375];
in: Dimn = [72.27];
cm: Dimn = [28.452755];
mm: Dimn = [2.8452755];
mica: Dimn = [2.8452755e-2];

Direction: TYPE = {left, right, up, down};
Dimensions: TYPE = ARRAY Direction OF Dimn;

END.