-- beadsInlines.mesa
DIRECTORY BeadsDefs:FROM"BeadsDefs", InlineDefs:FROM"InlineDefs";
BeadsInlines:DEFINITIONS IMPORTS BeadsDefs, InlineDefs =BEGIN OPEN BeadsDefs;
Basic:TYPE=PROCEDURE[i:Desc] RETURNS[BOOLEAN];
Basic2:TYPE=PROCEDURE[i,j:Desc] RETURNS[BOOLEAN];
Basic3:TYPE=PROCEDURE[i:Desc] RETURNS[Desc];
Get:PROCEDURE[i:CARDINAL]RETURNS[BeadPtr]=INLINE
BEGIN RETURN[bead+InlineDefs.LongMult[i,SIZE[Bead]]]; END;
GetW:PROCEDURE[i:CARDINAL]RETURNS[WorkPtr]=INLINE
BEGIN RETURN[work+InlineDefs.LongMult[i,SIZE[Work]]]; END;
Getw:PROCEDURE[i:Desc]RETURNS[WorkPtr]=INLINE
BEGIN RETURN[work+InlineDefs.LongMult[i.z,SIZE[Work]]]; END;
GetDesc:PROCEDURE[i:CARDINAL]RETURNS[Desc]=INLINE {RETURN[[i,Get[i]]]};
DescR:Basic3=INLINE
{t:CARDINAL←i.p.beadR; RETURN[[t,bead+InlineDefs.LongMult[t,SIZE[Bead]]]]};
DescL:Basic3=INLINE
{t:CARDINAL←i.p.beadL; RETURN[[t,bead+InlineDefs.LongMult[t,SIZE[Bead]]]]};
DescU:Basic3=INLINE
{t:CARDINAL←i.p.beadU; RETURN[[t,bead+InlineDefs.LongMult[t,SIZE[Bead]]]]};
DescD:Basic3=INLINE
{t:CARDINAL←i.p.beadD; RETURN[[t,bead+InlineDefs.LongMult[t,SIZE[Bead]]]]};
DescT:Basic3=INLINE
{t:CARDINAL←i.p.beadT; RETURN[[t,bead+InlineDefs.LongMult[t,SIZE[Bead]]]]};
Trans:Basic=INLINE
{RETURN[SELECT i.p.t FROM tt,dd,ttV,ddV=>TRUE, ENDCASE=>FALSE]};
Junction:Basic=INLINE
{RETURN[SELECT i.p.t FROM jctnG,jctnR,jctnB=>TRUE, ENDCASE=>FALSE]};
End:Basic=INLINE
{RETURN[SELECT i.p.t FROM endG,endR,endB=>TRUE, ENDCASE=>FALSE]};
Wire:Basic=INLINE
{RETURN[SELECT i.p.t FROM wireG,wireR,wireB,wireO=>TRUE, ENDCASE=>FALSE]};
Contact:Basic=INLINE
{RETURN[SELECT i.p.t FROM bg,rb,bf=>TRUE, ENDCASE=>FALSE]};
VerticalWire:Basic =INLINE BEGIN RETURN[i.p.wire AND i.p.beadR=noBead]; END;
HorizontalWire:Basic=INLINE BEGIN RETURN[i.p.wire AND i.p.beadU=noBead]; END;
NoBead:Basic=INLINE {RETURN[i.z=noBead]};
NoBeadR:Basic=INLINE {RETURN[i.p.beadR=noBead]};
NoBeadL:Basic=INLINE {RETURN[i.p.beadL=noBead]};
NoBeadU:Basic=INLINE {RETURN[i.p.beadU=noBead]};
NoBeadD:Basic=INLINE {RETURN[i.p.beadD=noBead]};
NoBeadT:Basic=INLINE {RETURN[i.p.beadT=noBead]};
TouchingBeads:Basic2= INLINE BEGIN
SELECT j.z FROM
i.p.beadR,i.p.beadL,i.p.beadU,i.p.beadD,i.p.beadT=>RETURN[TRUE];
ENDCASE=>RETURN[j.p.beadT=i.z];
END;
TiedBeads:Basic2=INLINE {RETURN[i.z=j.p.beadT OR j.z=i.p.beadT]};
SameLevel:Basic2=INLINE {RETURN[desP[i.p.t].lessLevel=desP[j.p.t].lessLevel]};
SameCircuit:Basic2=INLINE {RETURN[i.p.circuit=j.p.circuit]};
BracketBead:Basic2=INLINE {RETURN[i.p.beadL=j.p.beadR AND i.p.beadL#noBead]};
LeftOf:Basic2=INLINE {RETURN[i.z=j.p.beadL]};
NoWidths:Basic2=INLINE {RETURN[j.p.w<0 OR i.p.w<0]};
Unrelated:Basic2=INLINE {RETURN[
(i.p.beadL=j.p.beadR AND i.p.beadL#noBead)
OR (j.p.beadL=i.p.beadR AND j.p.beadL#noBead)
OR desP[i.p.t].lessLevel#desP[j.p.t].lessLevel]};
Interact:Basic2= INLINE BEGIN
amt:INTEGER←Des6[desP[j.p.t].short][desP[i.p.t].short];
RETURN[j.p.x-i.p.x IN (-j.p.w-amt..i.p.w+amt)];
END;
Delta:PROCEDURE[i,j:Desc] RETURNS[Coord]=INLINE {RETURN[DeltaZ[i.z,j.z]]};
InteractH:PROCEDURE[i,j:Desc,amt:INTEGER] RETURNS[BOOLEAN]= INLINE
BEGIN RETURN[j.p.x-i.p.x IN (-j.p.w-amt..i.p.w+amt)]; END;
InteractV:PROCEDURE[i,j:Desc,amt:INTEGER] RETURNS[BOOLEAN]= INLINE
BEGIN RETURN[j.p.y-i.p.y IN (-j.p.h-amt..i.p.h+amt)]; END;
IfTran:PUBLIC PROCEDURE[i:Desc,a:INTEGER] RETURNS[INTEGER] =INLINE BEGIN
RETURN[SELECT i.p.t FROM tt,dd,ttV,ddV=>a, ENDCASE=>0]; END;
IfTranL:PUBLIC PROCEDURE[i:Desc,a:INTEGER] RETURNS[INTEGER] =INLINE BEGIN
RETURN[SELECT Get[i.p.beadL].t FROM tt,dd,ttV,ddV=>a, ENDCASE=>0]; END;
IfTranR:PUBLIC PROCEDURE[i:Desc,a:INTEGER] RETURNS[INTEGER] =INLINE BEGIN
RETURN[SELECT Get[i.p.beadR].t FROM tt,dd,ttV,ddV=>a, ENDCASE=>0]; END;
Top:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.y+b.p.h]; END;
Rtm:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.x+b.p.w]; END;
Bot:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.y]; END;
Lfm:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.x]; END;
Wir:PROCEDURE[b:Desc] RETURNS[BOOLEAN]=INLINE BEGIN RETURN[b.p.wire]; END;
Circuit:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE {RETURN[b.p.circuit]};
IncrementX:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.x←b.p.x+d; END;
IncrementY:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.y←b.p.y+d; END;
SetX:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.x←d; END;
SetY:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.y←d; END;
SetW:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.w←d; END;
SetH:PROCEDURE[b:Desc,d:INTEGER]=INLINE BEGIN b.p.h←d; END;
Height:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.h]; END;
Width:PROCEDURE[b:Desc] RETURNS[INTEGER]=INLINE BEGIN RETURN[b.p.w]; END;
Type:PROCEDURE[b:Desc] RETURNS[BeadType]=INLINE BEGIN RETURN[b.p.t]; END;
HookLR:PROCEDURE[a,b:Desc]=INLINE {a.p.beadR←b.z; b.p.beadL←a.z};
HookUD:PROCEDURE[a,b:Desc]=INLINE {a.p.beadU←b.z; b.p.beadD←a.z};
LeftEdge:PROCEDURE[i:Desc] RETURNS[a:INTEGER]=INLINE
BEGIN a←Lfm[i]-Height[i]+IfTranL[i,Height[i]+2]; END;
RightEdge:PROCEDURE[i:Desc] RETURNS[a:INTEGER]=INLINE
BEGIN a←Rtm[i]-IfTranR[i,Height[i]+2]; END;
END..