DEFINITION MODULE GKSTrans;

(*
    Title: 	GKS Transformation Module
    LastEdit:	"Mon Feb 25 18:15:10 1985"
    Author: 	jd
		Cambridge University Computer Laboratory
*)

(* This module deals with general 2-D Cartesian transformations *)

FROM Vector IMPORT RVEC, RBOX;

FROM GKSTypes IMPORT TRANSFORM, WS, SEGMENT;

EXPORT QUALIFIED
    IdentityBox, IdentityTransform, ValidBox, ConstructTransform, 
    TranslationTransform, ScalingTransform, RotationTransform,
    ComposeTransforms, CheckIdentity,
    TransformPoint, UnTransformPoint, 
    TransformVector, TransformBox, TransformPolyLine;


        (********** Procedures for manipulating Transformations **********)

VAR IdentityBox: RBOX; (*  [0.0, 0.0] to [1.0, 1.0]  *)

VAR IdentityTransform: TRANSFORM; (* the identity transformation *)


PROCEDURE ValidBox (VAR r: RBOX): BOOLEAN;
        (* ensures that LowerLeft and UpperRight are what they say,
           and returns BoxArea (r) > 0.0
        *)

PROCEDURE ConstructTransform (VAR window, viewport: RBOX; 
    EqualScale: BOOLEAN; VAR T: TRANSFORM);
        (* finds the (non-rotating) transformation corrresponding to the
           window/viewport combination. If EqualScale, then the transformation
           generated will transform window into the largest box of
           identical aspect which lies entirely in the viewport
        *)

PROCEDURE TranslationTransform (Dx, Dy: REAL; VAR T: TRANSFORM);
        (* Constructs the transform which translates by Dx and Dy *)

PROCEDURE ScalingTransform (Sx, Sy: REAL; VAR T: TRANSFORM);
        (* Constructs the transform which scales by Sx and Sy *)

PROCEDURE RotationTransform (degrees: REAL; VAR T: TRANSFORM);
        (* constructs the transform corresponding to a counter-clockwise
           rotation about the origin. 
        *)

PROCEDURE ComposeTransforms (T1, T2: TRANSFORM; VAR T: TRANSFORM);
        (* The matrix product T := T1 x T2 *)

PROCEDURE CheckIdentity (VAR T: TRANSFORM);
        (* sets T's boolean if it is the identity transformation.
           Need only be called if a transformation is constructed or modified
           NOT using one of the three preceding procedures.
        *)

PROCEDURE TransformPoint (VAR T: TRANSFORM; VAR p: RVEC);

PROCEDURE UnTransformPoint (VAR T: TRANSFORM; VAR p: RVEC): BOOLEAN;
        (* this works only for non-rotating transformations - the BOOLEAN
           result indicates success.  p is unchanged on failure.
        *)

PROCEDURE TransformVector (VAR T: TRANSFORM; VAR v: RVEC);
        (* transform the vector from (0,0) -> v under T, then translate the
           result into a vector from the origin again.
        *)

PROCEDURE TransformBox (VAR T: TRANSFORM; VAR r: RBOX;
        VAR parallelogram: ARRAY OF RVEC);
        (* applies T to transform a box into a parallelogram *)

PROCEDURE TransformPolyLine (VAR T: TRANSFORM;
        high: INTEGER; VAR points: ARRAY OF RVEC);

END GKSTrans.
