Vector2Impl.mesa
Copyright Ó 1984, 1985, 1991 by Xerox Corporation. All rights reserved.
Doug Wyatt, March 7, 1985 5:22:25 pm PST
DIRECTORY
RealFns USING [SqRt],
Vector2 USING [VEC];
Vector2Impl: CEDAR PROGRAM
IMPORTS RealFns
EXPORTS Vector2
~ BEGIN
VEC: TYPE ~ Vector2.VEC;
Add: PUBLIC PROC[v1, v2: VEC] RETURNS[VEC] ~ { RETURN[[v1.x+v2.x, v1.y+v2.y]] };
Sub: PUBLIC PROC[v1, v2: VEC] RETURNS[VEC] ~ { RETURN[[v1.x-v2.x, v1.y-v2.y]] };
Neg: PUBLIC PROC[v: VEC] RETURNS[VEC] ~ { RETURN[[-v.x, -v.y]] };
Mul: PUBLIC PROC[v: VEC, s: REAL] RETURNS[VEC] ~ { RETURN[[v.x*s, v.y*s]] };
Div: PUBLIC PROC[v: VEC, s: REAL] RETURNS[VEC] ~ { RETURN[[v.x/s, v.y/s]] };
MulC: PUBLIC PROC[v1, v2: VEC] RETURNS[VEC] ~ { RETURN[[v1.x*v2.x, v1.y*v2.y]] };
DivC: PUBLIC PROC[v1, v2: VEC] RETURNS[VEC] ~ { RETURN[[v1.x/v2.x, v1.y/v2.y]] };
Dot: PUBLIC PROC[v1, v2: VEC] RETURNS[REAL] ~ { RETURN[v1.x*v2.x+v1.y*v2.y] };
Cross: PUBLIC PROC[v1, v2: VEC] RETURNS[REAL] ~ { RETURN[v1.x*v2.y-v1.y*v2.x] };
Square: PUBLIC PROC[v: VEC] RETURNS[REAL] ~ { RETURN[v.x*v.x+v.y*v.y] };
Length: PUBLIC PROC[v: VEC] RETURNS[REAL] ~ { RETURN[RealFns.SqRt[v.x*v.x+v.y*v.y]] };
Unit: PUBLIC PROC[v: VEC] RETURNS[VEC] ~ {
m: REAL ~ RealFns.SqRt[v.x*v.x+v.y*v.y];
RETURN[[v.x/m, v.y/m]]
};
END.