SFInline.mesa
Copyright Ó 1986, 1987, 1991 by Xerox Corporation. All rights reserved.
Michael Plass, August 16, 1991 4:40 pm PDT
Fixed-print box inline operations.
Vec operations
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=v2];
};
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
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[box1.max.s <= box2.min.s OR box2.max.s <= box1.min.s OR box1.max.f <= box2.min.f OR box2.max.f <= box1.min.f];
};
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: MAX[box.max.s-box.min.s, 0], f: MAX[box.max.f-box.min.f, 0]]]
};
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) ]
};