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
Angles2d, GGBasicTypes, Lines2d, GGMeasure, GGSegmentTypes, Vectors2d;
GGMeasureImpl:
CEDAR
PROGRAM
IMPORTS Angles2d, Lines2d, Vectors2d
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 ← Vectors2d.VectorFromPoints[seg.lo, seg.hi];
degrees ← Angles2d.AsSlope[Vectors2d.AngleFromVector[direction]];
};
SlopeOfPoints:
PUBLIC
PROC [p0, p1: Point]
RETURNS [degrees:
REAL] = {
degrees is an angle in 0 <= degrees < 180.
direction: Vector;
direction ← Vectors2d.VectorFromPoints[p0, p1];
degrees ← Angles2d.AsSlope[Vectors2d.AngleFromVector[direction]];
};
CounterClockwiseBetweenSegments:
PUBLIC
PROC [seg1, seg2: Segment]
RETURNS [degreesSeg1ToSeg2:
REAL] = {
v1, v2: Vector;
v1 ← Vectors2d.VectorFromPoints[seg1.lo, seg1.hi];
v2 ← Vectors2d.VectorFromPoints[seg2.lo, seg2.hi];
degreesSeg1ToSeg2 ← Angles2d.Normalize[Vectors2d.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 ← Vectors2d.VectorFromPoints[b, a];
v1 ← Vectors2d.VectorFromPoints[b, c];
degreesAngleABC ← Vectors2d.SmallestAngleBetweenVectors[v0, v1];
};
LengthOfSegment:
PUBLIC
PROC [seg: Segment]
RETURNS [lengthInPoints:
REAL] = {
lengthInPoints ← Vectors2d.Distance[seg.lo, seg.hi];
};
DistanceBetweenPoints:
PUBLIC
PROC [p0, p1: Point]
RETURNS [lengthInPoints:
REAL] = {
lengthInPoints ← Vectors2d.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 ← Lines2d.LineFromPoints[p1, p2];
distance ← Lines2d.LineDistance[p, line];
};
END.