RTBasicImpl.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
last edited by Bryan Preas April 19, 1987 4:08:10 pm PDT
DIRECTORY
Basics, DABasics, Rope, RTBasic;
RTBasicImpl: CEDAR PROGRAM
EXPORTS RTBasic = BEGIN
Signals and Errors
Error: PUBLIC ERROR[errorType: RTBasic.ErrorType ← callingError, explanation: Rope.ROPENIL] = CODE;
Signal: PUBLIC SIGNAL[signalType: RTBasic.ErrorType ← callingError, explanation: Rope.ROPENIL] = CODE;
Procedures
OtherSide: PUBLIC PROCEDURE [side: RTBasic.Side]
RETURNS [RTBasic.Side] = {
RETURN[otherSide[side]]};
OtherDirection: PUBLIC PROCEDURE [direction: RTBasic.Direction]
RETURNS [RTBasic.Direction] = {
RETURN[otherDirection[direction]]};
OtherRelation: PUBLIC PROCEDURE [aboveOrBelow: RTBasic.AboveOrBelow]
RETURNS [RTBasic.AboveOrBelow] = {
RETURN[otherRelation[aboveOrBelow]]};
SimpleCompare: PUBLIC PROCEDURE [result1, result2: DABasics.Number]
RETURNS [result: Basics.Comparison] = {
result ← IF result1 < result2 THEN less
ELSE IF result1 > result2 THEN greater
ELSE equal};
PQ Procedures
XYToPQ: PUBLIC PROC [pDir: RTBasic.Direction, pos: DABasics.Position] RETURNS [pqPos: RTBasic.PQPos] = {
convert a position from x-y to p-q space.
SELECT pDir FROM
horizontal => pqPos ← [pos.x, pos.y];
vertical => pqPos ← [pos.y, pos.x];
ENDCASE};
PQToXY: PUBLIC PROC [pDir: RTBasic.Direction, pqPos: RTBasic.PQPos] RETURNS [pos: DABasics.Position] = {
convert a position from p-q to x-y space.
SELECT pDir FROM
horizontal => pos ← [pqPos.p, pqPos.q];
vertical => pos ← [pqPos.q, pqPos.p];
ENDCASE};
Range Procedures
Overlap: PUBLIC PROC [r1, r2: RTBasic.Range] RETURNS [overlap: RTBasic.Range] = {
get the overlap of seg1, seg2
IF r2.l <= r1.l AND r1.l <= r2.r THEN
overlap ← [r1.l, MIN[r1.r, r2.r]]
ELSE IF r1.l <= r2.l AND r2.l <= r1.r THEN
overlap ← [r2.l, MIN[r1.r, r2.r]]
ELSE
overlap ← [MAX[r1.r, r2.r], MIN[r1.r, r2.r]]};
Gap: PUBLIC PROC [r1, r2: RTBasic.Range] RETURNS [gap: RTBasic.Range] = {
get the gap of seg1, seg2
IF r2.r < r1.l THEN
gap ← [r2.r, r1.l]
ELSE IF r1.r < r2.l THEN
gap ← [r1.r, r2.l]
ELSE gap ← [MAX[r1.r, r2.r], MIN[r1.r, r2.r]]};
Span: PUBLIC PROC [r1, r2: RTBasic.Range] RETURNS [result: RTBasic.Range] = {
determnie span of ranges 1 and 2
result ← [MIN[r1.l, r2.l], MAX[r1.r, r2.r]]};
Variables
sideName: PUBLIC ARRAY RTBasic.Side OF Rope.ROPE ← ["bottom", "top", "left", "right"];
otherRelation: ARRAY RTBasic.AboveOrBelow OF RTBasic.AboveOrBelow ← [below, above];
otherDirection: ARRAY RTBasic.Direction OF RTBasic.Direction ← [vertical, horizontal];
otherSide: ARRAY RTBasic.Side OF RTBasic.Side ← [top, bottom, right, left];
END.