-- File: SVCoordSys2d.mesa
-- Last edited by Bier on December 18, 1982 1:03 am
-- Author: Eric Bier on December 18, 1982 1:12 am
-- Contents: Routines for manipulating coordinate systems with respect to each other in 2 dimensions

DIRECTORY
 SV2d,
 SVMatrix2d,
 SVVector2d;

SVCoordSys2d: DEFINITIONS =
BEGIN

Matrix3by3: TYPE = SVMatrix2d.Matrix3by3;
Point2d: TYPE = SV2d.Point2d;
Vector2d: TYPE = SVVector2d.Vector2d;

CoordSystem2d: TYPE = REF CoordSystem2dObj;
CoordSystem2dObj: TYPE = RECORD [
 mat: Matrix3by3,
 localWRTPad: Matrix3by3,
 padWRTLocal: Matrix3by3,
 withRespectTo: CoordSystem2d];

CreateCoordSys: PROC [mat: Matrix3by3, withRespectTo: CoordSystem2d] RETURNS [newCS: CoordSystem2d];

TellCoordSysAboutPad: PROC [cs: CoordSystem2d];

PadToScreen: PROC [padPoint: Point2d, screen: CoordSystem2d] RETURNS [screenPoint: Point2d];
ScreenToPad: PROC [screenPoint: Point2d, screen: CoordSystem2d] RETURNS [padPoint: Point2d];

FindInTermsOfPad: PROC [cs: CoordSystem2d] RETURNS [mat: Matrix3by3];
FindAinTermsOfB: PROC [a: CoordSystem2d, b: CoordSystem2d] RETURNS [aInTermsOfb: Matrix3by3];
FindTranslationOfAinTermsOfB: PROC [a: CoordSystem2d, b: CoordSystem2d] RETURNS [displacements: Vector2d];

PutAinTermsOfB: PROC [a: CoordSystem2d, b: CoordSystem2d] RETURNS [aInTermsOfb: Matrix3by3];
-- finds the matrix and redefines CoordSystem a to be in terms of b from now on.

PlaceAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL, aWRTb: Matrix3by3];
-- places a in PAD so that the transform from b to a is aWRTb. Updates a with respect to its immediate reference (a.withRespectTo) accordingly.
PlaceTranslationAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL, origin: Point2d];
-- places a in PAD so that the rotation from a to b remains as it is, but the translation is set to origin. Updates a with respect to its immediate reference (a.withRespectTo) accordingly.

TranslateAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL, tx, ty: REAL];
RotateCCWAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL, degrees: REAL];
AlignAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL];
-- rotate A as little as possible to align its two axes parallel to two of the axes of B (though not necessarily the same two).
AbutAwrtB: PROC [a: CoordSystem2d, b: CoordSystem2d ← NIL];
-- equivalent to PlaceTranslationAwrtB where origin = [0, 0]

-- these perform the named transform but do not change the coordinate system with respect to which CoordSystem a is defined.
-- when b is NIL, assumes b = PAD.
-- for local transforms, let b = a.


END.