-- File: SVAngle.mesa
-- Last edited by Bier on December 18, 1982 1:02 am
-- Author: Eric Bier on October 19, 1982 1:35 pm
-- Contents: Solidviews requires a precise set of angle operations defined with angle "theta" in the range -180 < theta <= 180. "theta" is an absolute angle (ie a position around the circle measured from the positive x axis). Given two positions angles T1 and T2 we can find the incremental clockwise angle CT between them or the incremental counter-clockwise angle CCT where -360 < CT <= 0 and 0 <= CCT < 360.
When we add two angles, we are adding an incremental angle to a position angle to get a new position angle. We subtract two position angles to get an incremental angle. All angles are in degrees.

SVAngle: DEFINITIONS =
BEGIN

Normalize: PROC [anyRange: REAL] RETURNS [range180: REAL];
-- takes an angle in degrees and puts it in 180 < theta <= 180 form.
Add: PROC [position, increment: REAL] RETURNS [finalPosition: REAL];
-- all angles in degrees
ClockwiseAngle: PROC [fromPosition, toPostion: REAL] RETURNS [increment: REAL];
-- all angles in degrees. -360 < increment <= 0
CounterClockwiseAngle: PROC [fromPosition, toPostion: REAL] RETURNS [increment: REAL];
-- all angles in degrees. 0 <= increment < 360.
 -- For example, if the clockwise angle is -90, the counter-clockwise angle will be 270.

ShortestDifference: PROC [position1, position2: REAL] RETURNS [pos1MinusPos2: REAL];
-- all angles in degrees. RETURNS ClockwiseAngle or CounterClockwiseAngle. Whichever is smaller. -180< pos1MinusPos2 <= 180.
Scale: PROC [angle: REAL, scalar: REAL] RETURNS [angleTimesScalar: REAL];
-- all angles in degrees. Think of angle as the increment from 0 degrees to angle degrees. Scale this and normalize.

ArcTan: PROC [numerator, denominator: REAL] RETURNS [degrees: REAL];
-- has the effect of calling RealFns.ArcTanDegrees and normalizing the result.

END.