-- File: IPBasicOpsImpl.mesa
-- Last Edited by: CSChow, January 5, 1985 8:28:13 am PST
--Documentation will come later after consolidating the design --
DIRECTORY
IP,
IPOrient,
IPBasicOps;
IPBasicOpsImpl: CEDAR PROGRAM
IMPORTS IPOrient, IPBasicOps
EXPORTS IPBasicOps = BEGIN OPEN IPBasicOps;
ETCombineFailed: PUBLIC ERROR = CODE;
CTOrient: PUBLIC PROC[ct: CornerTypes, operation: IP.Orientation] RETURNS [CornerTypes] ={
ct ← CTRotate[ct, operation/2];
ct ← CTRotate[ct, IPOrient.OrientD2[operation]];
IF IPOrient.IncludesMirrorX[operation]
THEN RETURN [CTMirror[ct, ver]]
ELSE RETURN [ct]
}; --CTOrient
CTMirror: PUBLIC PROC[ct: CornerTypes, mirrorOrient: OrientationTypes] RETURNS [CornerTypes] ={
SELECT mirrorOrient FROM
hor => RETURN [(SELECT ct FROM sw => nw, se => ne, ne => se, nw => sw, ENDCASE => ERROR)];
ver => RETURN [(SELECT ct FROM sw => se, se => sw, ne => nw, nw => ne, ENDCASE => ERROR)];
ENDCASE => ERROR;
}; --CTMirror
CTRotate: PUBLIC PROC[ct: CornerTypes, cnt: INT ← 1] RETURNS[CornerTypes] ={
cnt ← cnt MOD 4;
SELECT ct FROM
sw => RETURN [(SELECT cnt FROM 0 => sw, 1, -3 => se, -1, 3 => nw, 2, -2 => ne, ENDCASE => ERROR)];
se => RETURN [(SELECT cnt FROM 0 => se, 1, -3 => ne, -1, 3 => sw, 2, -2 => nw, ENDCASE => ERROR)];
ne => RETURN [(SELECT cnt FROM 0 => ne, 1, -3 => nw, -1, 3 => se, 2, -2 => sw, ENDCASE => ERROR)];
nw => RETURN [(SELECT cnt FROM 0 => nw, 1, -3 => sw, -1, 3 => ne, 2, -2 => se, ENDCASE => ERROR)];
ENDCASE => ERROR;}; --CTRotate--
CTFindRotDirectn: PUBLIC PROC[ct: CornerTypes, ot: OrientationTypes] RETURNS [PolarityTypes] ={
SELECT ct FROM
sw, ne => RETURN [IF ot = hor THEN neg ELSE pos];
se, nw => RETURN [IF ot = hor THEN pos ELSE neg];
ENDCASE => ERROR;
}; --CTFindRotDirectn--
CTResolve: PUBLIC PROC[ct: CornerTypes] RETURNS [hor, ver: EdgeTypes]= {
SELECT ct FROM
sw => {hor ← south; ver ← west};
se => {hor ← south; ver ← east};
ne => {hor ← north; ver ← east};
nw => {hor ← north; ver ← west};
ENDCASE => ERROR}; --CTResolve--
CTResolveFor: PUBLIC PROC[ct: CornerTypes, ot: OrientationTypes] RETURNS [EdgeTypes] = {RETURN [IF ot = hor THEN CTResolve[ct].hor ELSE CTResolve[ct].ver]};
CTDirectn: PUBLIC PROC[ct: CornerTypes] RETURNS [hor, ver: PolarityTypes]= {
SELECT ct FROM
sw => {hor ← neg; ver ← neg};
se => {hor ← pos; ver ← neg};
ne => {hor ← pos; ver ← pos};
nw => {hor ← neg; ver ← pos};
ENDCASE => ERROR}; --CTDirectn--
CTDirectnFor: PUBLIC PROC[ct: CornerTypes, ot: OrientationTypes] RETURNS [PolarityTypes] = {RETURN [IF ot = hor THEN CTDirectn[ct].hor ELSE CTDirectn[ct].ver]};
CTFromPTs: PUBLIC PROC[hor, ver: PolarityTypes] RETURNS [CornerTypes] = {
SELECT ver FROM
neg => RETURN [IF hor = neg THEN sw ELSE se];
pos => RETURN [IF hor = neg THEN nw ELSE ne];
ENDCASE => ERROR;
}; --CTFromPTs--
ETRotate: PUBLIC PROC[et: EdgeTypes, cnt: INT ← 1] RETURNS[EdgeTypes]= {
cnt ← cnt MOD 4;
SELECT et FROM
south => RETURN [(SELECT cnt FROM 0 => south, 1, -3 => east, -1, 3 => west, 2, -2 => north, ENDCASE => ERROR)];
east => RETURN [(SELECT cnt FROM 0 => east, 1, -3 => north, -1, 3 => south, 2, -2 => west, ENDCASE => ERROR)];
north => RETURN [(SELECT cnt FROM 0 => north, 1, -3 => west, -1, 3 => east, 2, -2 => south, ENDCASE => ERROR)];
west => RETURN [(SELECT cnt FROM 0 => west, 1, -3 => south, -1, 3 => north, 2, -2 => east, ENDCASE => ERROR)];
ENDCASE => ERROR;
}; --ETRotate--
ETOrient: PUBLIC PROC[et: EdgeTypes] RETURNS [OrientationTypes] ={
SELECT et FROM
south, north => RETURN [hor];
east, west => RETURN [ver];
ENDCASE => ERROR;}; --ETOrient--
ETCombine: PUBLIC PROC[et1, et2: EdgeTypes] RETURNS [CornerTypes]= {
SELECT et1 FROM
south => RETURN [(SELECT et2 FROM east => se, west => sw, ENDCASE => ERROR ETCombineFailed)];
east => RETURN [(SELECT et2 FROM south => se, north => ne, ENDCASE => ERROR ETCombineFailed)];
north => RETURN [(SELECT et2 FROM east => ne, west => nw, ENDCASE => ERROR ETCombineFailed)];
west => RETURN [(SELECT et2 FROM south => sw, north => nw, ENDCASE => ERROR ETCombineFailed)];
ENDCASE => ERROR;
}; --ETCombine--
ETDirectn: PUBLIC PROC[et: EdgeTypes] RETURNS [PolarityTypes] = {
SELECT et FROM
south, west => RETURN [neg];
east, north => RETURN [pos];
ENDCASE => ERROR;}; --ETDirectn--
Copy1Shape: PUBLIC PROC[oShape: REF IP.ShapeRep] RETURNS [REF IP.ShapeRep] = {
IF oShape = NIL THEN RETURN [NIL];
RETURN [NEW[IP.ShapeRep ← [oShape.dim, oShape.cornerSpaces]]];
}; --Copy1Shape
Copy2Shape: PUBLIC PROC[oShape: REF IP.ShapeRep] RETURNS [REF IP.ShapeRep] = {
dim, sw, se, ne, nw: REF IP.NatVector;
IF oShape = NIL THEN RETURN [NIL];
BEGIN OPEN oCS: oShape.cornerSpaces;
IF oShape.dim # NIL THEN dim ← NuNatVector[oShape.dim.x, oShape.dim.y];
IF oCS.sw # NIL THEN sw ← NuNatVector[oCS.sw.x, oCS.sw.y];
IF oCS.se # NIL THEN se ← NuNatVector[oCS.se.x, oCS.se.y];
IF oCS.ne # NIL THEN ne ← NuNatVector[oCS.ne.x, oCS.ne.y];
IF oCS.nw # NIL THEN nw ← NuNatVector[oCS.nw.x, oCS.nw.y];
END;
RETURN [NEW[IP.ShapeRep ←[dim, [sw, se, ne, nw]]]]
}; --Copy2Shape
END.