-- Vector.mesa
-- Last changed by Doug Wyatt, September 12, 1980 11:49 AM
Vector: DEFINITIONS = {
Vec: TYPE = RECORD[x,y: REAL];
Matrix: TYPE = RECORD[a11,a12,a21,a22: REAL];
-- Vector operations
Add: PROC[a: Vec, b: Vec] RETURNS[Vec] = INLINE {
RETURN[[a.x+b.x,a.y+b.y]]
};
Sub: PROC[a: Vec, b: Vec] RETURNS[Vec] = INLINE {
RETURN[[a.x-b.x,a.y-b.y]]
};
Neg: PROC[a: Vec] RETURNS[Vec] = INLINE {
RETURN[[-a.x,-a.y]]
};
Mul: PROC[a: Vec, s: REAL] RETURNS[Vec] = INLINE {
RETURN[[a.x*s,a.y*s]]
};
Div: PROC[a: Vec, s: REAL] RETURNS[Vec] = INLINE {
RETURN[[a.x/s,a.y/s]]
};
Ls: PROC[a: Vec, b: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a.x<b.x AND a.y<b.y]
};
Le: PROC[a: Vec, b: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a.x<=b.x AND a.y<=b.y]
};
Ge: PROC[a: Vec, b: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a.x>=b.x AND a.y>=b.y]
};
Gr: PROC[a: Vec, b: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a.x>b.x AND a.y>b.y]
};
Eq: PROC[a: Vec, b: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a=b]
};
In: PROC[a: Vec, b: Vec, c: Vec] RETURNS[BOOLEAN] = INLINE {
RETURN[a.x IN[b.x..c.x] AND a.y IN[b.y..c.y]]
};
Min: PROC[a: Vec, b: Vec] RETURNS[Vec] = INLINE {
RETURN[[MIN[a.x,b.x],MIN[a.y,b.y]]]
};
Max: PROC[a: Vec, b: Vec] RETURNS[Vec] = INLINE {
RETURN[[MAX[a.x,b.x],MAX[a.y,b.y]]]
};
Dot: PROC[a: Vec, b: Vec] RETURNS[REAL] = INLINE {
RETURN[a.x*b.x+a.y*b.y]
};
Cross: PROC[a: Vec, b: Vec] RETURNS[REAL] = INLINE {
RETURN[a.x*b.y-a.y*b.x]
};
-- Matrix operations
Det: PROC[m: Matrix] RETURNS[REAL] = INLINE {
RETURN[m.a11*m.a22-m.a12*m.a21]
};
}.