SF.mesa
Copyright Ó 1986 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 7, 1986 1:43:32 pm PST
Michael Plass, November 21, 1986 10:05:29 am PST
SF: CEDAR DEFINITIONS
~ BEGIN
Vec operations
Vec: TYPE ~ RECORD [s, f: INTEGER];
minVec: Vec ~ [s: INTEGER.FIRST, f: INTEGER.FIRST];
maxVec: Vec ~ [s: INTEGER.LAST, f: INTEGER.LAST];
zeroVec: Vec ~ [s: 0, f: 0];
NonNegative: PROC [v: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: NAT[v.s], f: NAT[v.f]]];
};
Neg: PROC [v: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: -v.s, f: -v.f]];
};
Add: PROC [v1, v2: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: v1.s+v2.s, f: v1.f+v2.f]];
};
Sub: PROC [v1, v2: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: v1.s-v2.s, f: v1.f-v2.f]];
};
Min: PROC [v1, v2: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: IF v1.s<=v2.s THEN v1.s ELSE v2.s, f: IF v1.f<=v2.f THEN v1.f ELSE v2.f]];
};
Min3: PROC [v1, v2, v3: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: MIN[v1.s, v2.s, v3.s], f: MIN[v1.f, v2.f, v3.f]]];
};
Max: PROC [v1, v2: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: IF v2.s>=v1.s THEN v2.s ELSE v1.s, f: IF v2.f>=v1.f THEN v2.f ELSE v1.f]];
};
Max3: PROC [v1, v2, v3: Vec] RETURNS [Vec] ~ INLINE {
RETURN[[s: MAX[v1.s, v2.s, v3.s], f: MAX[v1.f, v2.f, v3.f]]];
};
Eq: PROC [v1, v2: Vec] RETURNS [BOOL] ~ INLINE {
RETURN[v1.s=v2.s AND v1.f=v2.f];
};
Lt: PROC [v1, v2: Vec] RETURNS [BOOL] ~ INLINE {
RETURN[v1.s<v2.s AND v1.f<v2.f];
};
Le: PROC [v1, v2: Vec] RETURNS [BOOL] ~ INLINE {
RETURN[v1.s<=v2.s AND v1.f<=v2.f];
};
Gt: PROC [v1, v2: Vec] RETURNS [BOOL] ~ INLINE {
RETURN[v1.s>v2.s OR v1.f>v2.f];
};
Ge: PROC [v1, v2: Vec] RETURNS [BOOL] ~ INLINE {
RETURN[v1.s>=v2.s OR v1.f>=v2.f];
};
Box operations
Box: TYPE ~ RECORD [min, max: Vec ← zeroVec];
b: Box denotes all v: Vec that satisfy v.s IN[b.min.s..b.max.s) AND v.f IN[b.min.f..b.max.f)
maxBox: Box ~ [min: minVec, max: maxVec];
BoxAction: TYPE ~ PROC [box: Box];
BoxGenerator: TYPE ~ PROC [boxAction: BoxAction];
Nonempty: PROC [box: Box] RETURNS [BOOL] ~ INLINE {
RETURN[Lt[box.min, box.max]];
};
Empty: PROC [box: Box] RETURNS [BOOL] ~ INLINE {
RETURN[Ge[box.min, box.max]];
};
Intersect: PROC [box1, box2: Box] RETURNS [Box] ~ INLINE {
RETURN[[min: Max[box2.min, box1.min], max: Min[box1.max, box2.max]]];
};
Disjoint: PROC [box1, box2: Box] RETURNS [BOOL] ~ INLINE {
RETURN[Empty[Intersect[box1, box2]]];
};
SizeF: PROC [box: Box] RETURNS [CARDINAL] ~ INLINE {
RETURN[IF box.min.f<box.max.f THEN LOOPHOLE[box.max.f-box.min.f] ELSE 0]
};
SizeS: PROC [box: Box] RETURNS [CARDINAL] ~ INLINE {
RETURN[IF box.min.s<box.max.s THEN LOOPHOLE[box.max.s-box.min.s] ELSE 0]
};
Size: PROC [box: Box] RETURNS [Vec] ~ INLINE {
RETURN[[s: NAT[SizeS[box]], f: NAT[SizeF[box]]]]
};
Displace: PROC [box: Box, t: Vec] RETURNS [Box] ~ INLINE {
RETURN[[min: Add[box.min, t], max: Add[box.max, t]]]
};
Inside: PROC [inner, outer: Box] RETURNS [BOOL] ~ INLINE {RETURN[
inner.min.s >= outer.min.s AND inner.min.f >= outer.min.f AND
inner.max.s <= outer.max.s AND inner.max.f <= outer.max.f
]};
In: PROC [vec: Vec, box: Box] RETURNS [BOOL] ~ INLINE {
RETURN[ vec.s IN [box.min.s..box.max.s) AND vec.f IN [box.min.f..box.max.f) ]
};
END.