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] = { 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] = { }; DistanceFromPointToLine: PUBLIC PROC [p: Point, p1, p2: Point] RETURNS [distance: REAL] = { line: Line; line _ Lines2d.LineFromPoints[p1, p2]; distance _ Lines2d.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. degrees is an angle in 0 <= degrees < 180. 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™