Vector.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Last changed by Michael Plass, August 4, 1982 11:58 am
Written by Doug Wyatt, September 12, 1980 11:49 AM
Tim Diebert May 20, 1985 2:05:49 pm PDT
DIRECTORY
Vector2 USING [VEC],
RealFns USING[SqRt];
Vector: CEDAR DEFINITIONS IMPORTS RealFns = {
VEC: TYPE = Vector2.VEC;
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]
};
Mag:PROCEDURE[v:Vector.VEC] RETURNS[REAL] = INLINE { 
RETURN[RealFns.SqRt[v.x*v.x+v.y*v.y]]
};
Unit:PROCEDURE[v:Vector.VEC] RETURNS [VEC] = INLINE { 
m:REAL;
IF (mŽMag[v]) = 0 THEN RETURN[[0,0]] ELSE RETURN[[v.x/m,v.y/m]]
};
Normal:PROCEDURE[v:Vector.VEC] RETURNS [VEC] = INLINE {
RETURN[[-v.y,v.x]]
};
Matrix operations
Det: PROC[m: Matrix] RETURNS[REAL] = INLINE {
RETURN[m.a11*m.a22-m.a12*m.a21]
};
}.
Michael Plass, August 4, 1982 11:58 am. Made VEC the same as GraphicsBasic.VEC