File: PolygonDefs.mesa
Written by Martin Newell, Sept 1979
Last edited: October 5, 1979 1:56 PM
This package decomposes arbitrary polygons into minimum sets of trapezoids having
horizontal top and bottom boundaries, and covering the inside of the polygon exactly
once. The semantics of inside and outside is determined as follows:
to determine if a point is inside the polgon consider drawing a line from the point
to infinity in any direction; initialize a counter to zero; for each polygon edge
that is crossed count +1 when crossing an edge whose direction is to the right and
-1 for the others; if, on reaching infinity, the count is non-zero then the given
point is inside the polygon.
Polygons may have multiple boundaries (see PolyNewBoundary)
The package may be reentered from the procedure passed to PolyGenerate
Last Edited by: McCreight, February 8, 1985 9:23:00 am PST
PolygonDefs: CEDAR DEFINITIONS =
BEGIN
PolygonDescriptor: TYPE = CGReducer.Ref;
PolyCreate: PROCEDURE RETURNS [polygon: PolygonDescriptor];
Create new polygon
PolyVertex: PROCEDURE [polygon: PolygonDescriptor, x, y: REAL];
Add vertex to polygon
PolyGenerate:
PROCEDURE [
polygon: PolygonDescriptor,
outputTrapezoid: PROCEDURE [REAL, REAL, REAL, REAL, REAL, REAL]];
Generate the polygon defined up to last PolyVertex
Parameters of outputTrapezoid are:
lower left x, lower right x, lower y, upper left x, upper right x, upper y
This procedure PolyDestroys the polygon, which therefore is no longer valid
PolyDestroy: PROCEDURE [polygon: PolygonDescriptor];
Destroy polygon
END.