GGMeasureImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Last edited by Bier on January 28, 1987
Contents: Routines for computing measurements on Gargoyle objects.
DIRECTORY
GGAngle, GGBasicTypes, GGLines, GGMeasure, GGSegmentTypes, GGVector;
GGMeasureImpl: CEDAR PROGRAM
IMPORTS GGAngle, GGLines, GGVector
EXPORTS GGMeasure =
BEGIN
Line: TYPE = GGBasicTypes.Line;
Point: TYPE = GGBasicTypes.Point;
Segment: TYPE = GGSegmentTypes.Segment;
Vector: TYPE = GGBasicTypes.Vector;
SlopeOfSegment: PUBLIC PROC [seg: Segment] RETURNS [degrees: REAL] = {
direction: Vector;
direction ← GGVector.VectorFromPoints[seg.lo, seg.hi];
degrees ← GGAngle.Normalize[GGVector.AngleFromVector[direction]];
only positive slopes, please
IF degrees<0.0 THEN degrees ← degrees+180.0;
IF degrees=360.0 THEN degrees ← 0.0;
};
SlopeOfPoints: PUBLIC PROC [p0, p1: Point] RETURNS [degrees: REAL] = {
degrees ← GGAngle.Normalize[SlopeFromTwoPoints[p0, p1]];
};
SlopeFromTwoPoints: PROC [p0, p1: Point] RETURNS [degrees: REAL] = {
v0: GGBasicTypes.Vector ← GGVector.VectorFromPoints[p0, p1];
degrees ← GGVector.AngleFromVector[v0];
};
CounterClockwiseBetweenSegments: PUBLIC PROC [seg1, seg2: Segment] RETURNS [degreesSeg1ToSeg2: REAL] = {
v1, v2: Vector;
v1 ← GGVector.VectorFromPoints[seg1.lo, seg1.hi];
v2 ← GGVector.VectorFromPoints[seg2.lo, seg2.hi];
degreesSeg1ToSeg2 ← GGAngle.Normalize[GGVector.AngleCCWBetweenVectors[v1, v2]];
IF degreesSeg1ToSeg2=360.0 THEN degreesSeg1ToSeg2 ← 0.0;
};
SmallestAngleOfPoints: PUBLIC PROC [a, b, c: Point] RETURNS [degreesAngleABC: REAL] = {
v0, v1: GGBasicTypes.Vector;
v0 ← GGVector.VectorFromPoints[b, a];
v1 ← GGVector.VectorFromPoints[b, c];
degreesAngleABC ← GGVector.SmallestAngleBetweenVectors[v0, v1];
};
LengthOfSegment: PUBLIC PROC [seg: Segment] RETURNS [lengthInPoints: REAL] = {
lengthInPoints ← GGVector.Distance[seg.lo, seg.hi];
};
DistanceBetweenPoints: PUBLIC PROC [p0, p1: Point] RETURNS [lengthInPoints: REAL] = {
lengthInPoints ← GGVector.Distance[p0, p1];
};
DistanceFromPointToSegment: PUBLIC PROC [p: Point, seg: Segment] RETURNS [distanceInPoints: REAL] = {
Caution: this computes distance from p to the straight line incident with both endpoints of seg. It does not find the distance from p to seg, unless seg is straight.
};
DistanceFromPointToLine: PUBLIC PROC [p: Point, p1, p2: Point] RETURNS [distance: REAL] = {
Computes distance from p to the straight line incident with p1 and p2.
line: Line;
line ← GGLines.LineFromPoints[p1, p2];
distance ← GGLines.LineDistance[p, line];
};
END.