INTERFACE R2; (* Linear algebra in R^2. Created 94-05-04 by J. Stolfi. Last edited by stolfi *) IMPORT Wr; TYPE T = ARRAY [0..1] OF REAL; CONST N = 2; Zero = T{0.0, ..}; Ones = T{1.0, ..}; Axis = ARRAY [0..1] OF T{ T{1.0, 0.0}, T{0.0, 1.0} }; PROCEDURE Add(READONLY a, b: T): T; (* Returns "a + b". *) PROCEDURE Sub(READONLY a, b: T): T; (* Returns "a - b". *) PROCEDURE Neg(READONLY a: T): T; (* Returns "-a" *) PROCEDURE Scale(s: LONGREAL; READONLY a: T): T; (* Returns "s * a"; *) PROCEDURE Weigh(READONLY a, b: T): T; (* Returns "a" times "b" componentwise. *) PROCEDURE Mix(s: LONGREAL; READONLY a: T; t: LONGREAL; READONLY b: T): T; (* Returns "s * a + t * b". *) PROCEDURE Length(READONLY a: T): LONGREAL; (* Returns the Euclidean norm (length) of vector "a". *) PROCEDURE LInfLength(READONLY a: T): REAL; (* Returns the L_infinity norm of vector "a", i.e. the max absolute coordinate. *) PROCEDURE LengthSqr(READONLY a: T): LONGREAL; (* Returns the square of the Euclidean length of vector "a", i.e. Dot(a,a). *) PROCEDURE Dist(READONLY a, b: T): LONGREAL; (* Returns the Euclidean distance between points "a" and "b". *) PROCEDURE DistSqr(READONLY a, b: T): LONGREAL; (* Returns the square of the Euclidean distance between points "a" and "b". *) PROCEDURE LInfDist(READONLY a, b: T): REAL; (* Returns the max absolute difference between the coordinates of "a" and "b". *) PROCEDURE Dir(READONLY a: T): T; (* Returns the vector "a" scaled to unit Euclidean norm. *) PROCEDURE LInfDir(READONLY a: T): T; (* Returns the vector "a" scaled to unit L_infinity norm. *) PROCEDURE Dot(READONLY a, b: T): LONGREAL; (* Returns the dot product of vectors "a" and "b". *) PROCEDURE Det(READONLY a, b: T): LONGREAL; (* Returns the determinant of the matrix whose rows are "a" and "b". *) PROCEDURE Cross(READONLY a: T): T; (* Returns the `cross product' of "a": a vector such that "Dot(Cross(a), b) = Det(a, b)" for all "b". This is just "a" rotated 90 degrees counterclockwise. *) PROCEDURE Project(READONLY a, u: T): T; (* Returns the component of vector "a" that is parallel to "u". *) PROCEDURE Orthize(READONLY a, u: T): T; (* Returns the component of vector "a" that is orthogonal to "u". *) PROCEDURE Print(wr: Wr.T; READONLY a: T); (* Prints "a" to the given writer. *) END R2.