Vector2Impl.mesa
Copyright © 1984, 1985, 1986 by Xerox Corporation. All rights reserved.
Doug Wyatt, January 20, 1986 2:04:40 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]] };
Equal:
PUBLIC
PROC [v1, v2:
VEC]
RETURNS [
BOOL] ~ {
RETURN[v1.x=v2.x
AND v1.y=v2.y] };
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.