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]]; 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] = { }; DistanceFromPointToLine: PUBLIC PROC [p: Point, p1, p2: Point] RETURNS [distance: REAL] = { line: Line; line _ GGLines.LineFromPoints[p1, p2]; distance _ GGLines.LineDistance[p, line]; }; END. ΠGGMeasureImpl.mesa Copyright c 1986 by Xerox Corporation. All rights reserved. Last edited by Bier on January 28, 1987 Contents: Routines for computing measurements on Gargoyle objects. only positive slopes, please 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. Computes distance from p to the straight line incident with p1 and p2. ΚΫ˜J˜Icodešœ™Kšœ Οmœ1™