Last modified on Wed May 12 12:16:38 PDT 1993 by swart modified on Mon Nov 18 22:13:40 PST 1991 by gnelson modified on Thu Nov 2 18:28:28 1989 by muller modified on Mon Oct 2 09:30:53 1989 by kalsow modified on Thu Dec 3 0:04:41 PST 1987 by luca
MODULE; IMPORT Word, Axis; PROCEDURE Point FromCoords (h, v: INTEGER): T RAISES {} = VAR p: T; BEGIN p.h := h; p.v := v; RETURN p; END FromCoords; PROCEDUREFromAxes (axis: Axis.T; n, m: INTEGER): T RAISES {} = VAR p: T; BEGIN CASE axis OF | Axis.T.Hor => p.h := n; p.v := m; | Axis.T.Ver => p.h := m; p.v := n; END; RETURN p; END FromAxes; PROCEDUREDistSquare (READONLY p, q: T): INTEGER RAISES {} = VAR dh, dv: INTEGER; BEGIN dh := p.h - q.h; dv := p.v - q.v; RETURN dh * dh + dv * dv; END DistSquare; PROCEDUREMinus (READONLY p: T): T RAISES {} = VAR q: T; BEGIN q.h := -p.h; q.v := -p.v; RETURN q; END Minus; PROCEDUREAdd (READONLY p, q: T): T RAISES {} = VAR r: T; BEGIN r.h := p.h + q.h; r.v := p.v + q.v; RETURN r; END Add; PROCEDURESub (READONLY p, q: T): T RAISES {} = VAR r: T; BEGIN r.h := p.h - q.h; r.v := p.v - q.v; RETURN r; END Sub; PROCEDUREMul (READONLY p: T; n: INTEGER): T RAISES {} = VAR q: T; BEGIN q.h := p.h * n; q.v := p.v * n; RETURN q; END Mul; PROCEDUREDiv (READONLY p: T; n: INTEGER): T RAISES {} = VAR q: T; BEGIN q.h := p.h DIV n; q.v := p.v DIV n; RETURN q; END Div; PROCEDUREMod (READONLY p: T; n: INTEGER): T RAISES {} = VAR q: T; BEGIN q.h := p.h MOD n; IF q.h < 0 THEN q.h := q.h + n END; q.v := p.v MOD n; IF q.v < 0 THEN q.v := q.v + n END; RETURN q; END Mod; PROCEDUREScale (READONLY p: T; num, den: INTEGER): T RAISES {} = VAR q: T; BEGIN q.h := (p.h * num) DIV den; q.v := (p.v * num) DIV den; RETURN q; END Scale; PROCEDUREMin (READONLY p, q: T): T RAISES {} = VAR r: T; BEGIN r.h := MIN (p.h, q.h); r.v := MIN (p.v, q.v); RETURN r; END Min; PROCEDUREMax (READONLY p, q: T): T RAISES {} = VAR r: T; BEGIN r.h := MAX (p.h, q.h); r.v := MAX (p.v, q.v); RETURN r; END Max; PROCEDUREMove (READONLY p, dp: T): T RAISES {} = VAR r: T; BEGIN r.h := p.h + dp.h; r.v := p.v + dp.v; RETURN r; END Move; PROCEDUREMoveH (READONLY p: T; dh: INTEGER): T RAISES {} = VAR r: T; BEGIN r.h := p.h + dh; r.v := p.v; RETURN r; END MoveH; PROCEDUREMoveV (READONLY p: T; dv: INTEGER): T RAISES {} = VAR r: T; BEGIN r.h := p.h; r.v := p.v + dv; RETURN r; END MoveV; PROCEDUREMoveHV (READONLY p: T; dh, dv: INTEGER): T RAISES {} = VAR r: T; BEGIN r.h := p.h + dh; r.v := p.v + dv; RETURN r; END MoveHV; PROCEDURETranspose (READONLY p: T; ax := Axis.T.Ver): T = BEGIN IF ax = Axis.T.Hor THEN RETURN p ELSE RETURN T{p.v,p.h} END END Transpose; PROCEDUREEqual (READONLY p, q: T): BOOLEAN RAISES {} = BEGIN RETURN (p.h = q.h) AND (p.v = q.v); END Equal; PROCEDURELess (READONLY p, q: T): BOOLEAN RAISES {} = BEGIN RETURN (p.h < q.h) AND (p.v < q.v); END Less; PROCEDURELessEq (READONLY p, q: T): BOOLEAN RAISES {} = BEGIN RETURN (p.h <= q.h) AND (p.v <= q.v); END LessEq; PROCEDURECompare (READONLY a, b: T): [-1..1] = BEGIN IF (a.h < b.h) THEN RETURN -1; ELSIF (a.h > b.h) THEN RETURN +1; ELSIF (a.v = b.v) THEN RETURN 0; ELSIF (a.v < b.v) THEN RETURN -1; ELSE RETURN +1; END; END Compare; PROCEDUREHash (READONLY a: T): INTEGER = BEGIN RETURN Word.Xor (a.h, a.v); END Hash; BEGIN END Point.