-- File: SVLines2d.mesa
-- Last edited by Bier on December 18, 1982 1:08 am
-- Author: Eric Bier on October 1, 1982 9:02 pm
-- Contents: Routines for finding the intersections of various types of lines and line segments used in the SolidViews package.

DIRECTORY
 SV2d;

SVLines2d: DEFINITIONS =
BEGIN

LineSeg: TYPE = REF LineSegObj;
LineSegObj: TYPE = SV2d.LineSegObj;
Point2d: TYPE = SV2d.Point2d;
Ray2d: TYPE = REF Ray2dObj;
Ray2dObj: TYPE = SV2d.Ray2dObj;
TrigLine: TYPE = REF TrigLineObj;
TrigLineObj: TYPE = SV2d.TrigLineObj;
TrigLineSeg: TYPE = REF TrigLineSegObj;
TrigLineSegObj: TYPE = SV2d.TrigLineSegObj;


-- TRIGLINES

CreateEmptyTrigLine: PUBLIC PROC RETURNS [line: TrigLine];
FillTrigLineFromPoints: PROC [v1, v2: Point2d, line: TrigLine];
FillTrigLineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL, line: TrigLine];
FillTrigLineAsNormal: PROC [line: TrigLine, pt: Point2d, normalLine: TrigLine];
CopyTrigLine: PROC [from: TrigLine, to: TrigLine];
TrigLineFromPoints: PROC [v1, v2: Point2d] RETURNS [line: TrigLine];
TrigLineFromCoefficients: PROC [sineOfTheta, cosineOfTheta, distance: REAL] RETURNS [line: TrigLine];
TrigLineNormalToTrigLineThruPoint: PROC [line: TrigLine, pt: Point2d] RETURNS [normalLine: TrigLine];
TrigLineMeetsTrigLine: PROC [line1, line2: TrigLine] RETURNS [intersection: Point2d, parallel: BOOL];
TrigLineMeetsYAxis: PROC [line: TrigLine] RETURNS [yInt: REAL, parallel: BOOL];
TrigLineMeetsTrigLineSeg: PROC [line: TrigLine, seg: TrigLineSeg] RETURNS [intersection: Point2d, noHit: BOOL];
TrigLineDistance: PROC [pt: Point2d, line: TrigLine] RETURNS [d: REAL];
PointProjectedOntoTrigLine: PROC [pt: Point2d, line: TrigLine] RETURNS [projectedPt: Point2d];


-- TRIGLINESEGS

CreateTrigLineSeg: PROC [v1, v2: Point2d] RETURNS [seg: TrigLineSeg];
CreateEmptyTrigLineSeg: PROC RETURNS [seg: TrigLineSeg];
FillTrigLineSeg: PROC [v1, v2: Point2d, seg: TrigLineSeg];
CopyTrigLineSeg: PROC [from: TrigLineSeg, to: TrigLineSeg];
TrigLinePointOnTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [BOOL];
-- assumes pt is on seg.line. Is it on seg?
NearestEndpoint: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [endpoint: Point2d];
DistanceSquaredToNearestEndpoint: PUBLIC PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distanceSquared: REAL];
-- faster than DistancePointToPoint[pt, NearestEndpoint[pt, seg]] (if you don't care what the endpoint is).
DistancePointToTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distance: REAL];
-- perpendicular distance if possible, else distance to nearest endpoint.
DistanceSquaredPointToTrigLineSeg: PROC [pt: Point2d, seg: TrigLineSeg] RETURNS [distanceSquared: REAL];


-- POINT2DS

DistancePointToPoint: PROC [p1, p2: Point2d] RETURNS [distance: REAL];
DistanceSquaredPointToPoint: PROC [p1, p2: Point2d] RETURNS [distance: REAL];
PointLeftOfTrigLine: PROC [distance: REAL, pOnLine: Point2d, line: TrigLine] RETURNS [point: Point2d];
-- point is a point to the left of the directed line, on the normal to the line which intersects the line at pOnLine. If distance is negative, the point will be to the right of the directed line.

-- LINESEGS

CreateLineSeg: PROC [v1, v2: Point2d] RETURNS [seg: LineSeg];

-- RAYS

RightHorizontalRay: PROC [point: Point2d] RETURNS [horizRayThruPoint: Ray2d];
UpVerticalRay: PROC [point: Point2d] RETURNS [vertRayThruPoint: Ray2d];


END.