-- CGVector.mesa
-- Last changed by Doug Wyatt, August 23, 1982 3:33 pm

DIRECTORY
GraphicsBasic USING [Vec];

CGVector: CEDAR DEFINITIONS = {

Vec: TYPE = GraphicsBasic.Vec;

-- Operations on Vecs

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] };

}.