Polygon:
CEDAR
PROGRAM
IMPORTS CGArea, CGClipper, CGReducer
EXPORTS PolygonDefs =
BEGIN OPEN PolygonDefs;
PolyCreate:
PUBLIC
PROCEDURE
RETURNS [polygon: PolygonDescriptor] =
Create new polygon
BEGIN
polygon ← CGReducer.New[size: 4];
CGClipper.Load[self: clipper, reducer: polygon];
END;
PolyVertex:
PUBLIC
PROCEDURE [polygon: PolygonDescriptor, x, y:
REAL] =
Add vertex to polygon
{CGReducer.Vertex[self: polygon, v: [x: x, y: y]]};
PolyGenerate:
PUBLIC
PROCEDURE [
polygon: PolygonDescriptor,
outputTrapezoid: PROCEDURE [llx, lrx, ly, ulx, urx, uy: REAL]] =
Generate the polygon defined up to last PolyVertex
BEGIN
tiling: CGArea.Ref = CGArea.New[size: 4];
CGReducer.Close[polygon];
CGReducer.Generate[self: polygon, area: tiling];
UNTIL CGArea.Empty[tiling]
DO
t: GraphicsBasic.Trap = CGArea.Remove[tiling];
outputTrapezoid[llx: t.xbotL, lrx: t.xbotR, ly: t.ybot, ulx: t.xtopL, urx: t.xtopR, uy: t.ytop];
ENDLOOP;
END;
PolyDestroy:
PUBLIC
PROCEDURE [polygon: PolygonDescriptor] =
Destroy polygon
{NULL};
huge: REAL ← 1.0E20;
clipper: CGClipper.Ref ← CGClipper.New[size: 4];
CGClipper.SetBox[self: clipper, box: [xmin: -huge, ymin: -huge, xmax: huge, ymax: huge]];
END.