Vector2Impl.mesa
Copyright © 1984, Xerox Corporation. All rights reserved.
Doug Wyatt, August 15, 1984 5:12:25 pm PDT
DIRECTORY
Real USING [SqRt],
Vector2 USING [VEC];
Vector2Impl: CEDAR PROGRAM
IMPORTS Real
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]] };
Square:
PUBLIC
PROC[v:
VEC]
RETURNS[
REAL] ~ {
RETURN[v.x*v.x+v.y*v.y] };
Length:
PUBLIC
PROC[v:
VEC]
RETURNS[
REAL] ~ {
RETURN[Real.SqRt[v.x*v.x+v.y*v.y]] };
Unit:
PUBLIC
PROC[v:
VEC]
RETURNS[
VEC] ~ {
m: REAL ~ Real.SqRt[v.x*v.x+v.y*v.y]; RETURN[[v.x/m, v.y/m]] };
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] };
END.