Drawing Graphics: 2.8 Shapes: Polylines and Polygons

Up: GEOS SDK TechDocs| Up | Prev: 2.7 Rounded Rectangles | Next: 2.9 Bézier Curves and Splines
GrDrawPolyline(), GrDrawPolygon(), GrFillPolygon(), GrBrushPolyline(), GrTestPointInPolygon()

Polylines and polygons are drawings made up of chains of connected lines. They are defined as lists of points, or corners. After drawing a polyline or polygon, the pen position will be at the last point of the shape.

GrDrawPolyline() draws a polyline using the current line attributes. GrDrawPolygon() draws a polygon using the current line attributes.

To draw a closed figure with GrDrawPolyline() , the first and last point must have the same coordinates. GrDrawPolygon() draws figures as closed automatically; having the same beginning and ending point is unnecessary.

GrFillPolygon() fills the interior of a polygon. It does so using the current area attributes. It also uses a fill rule, describing how the polygon should be filled. The odd/even fill rule decides whether a point is within a polygon by seeing how many times a ray drawn from the point to the exterior of the polygon crosses an edge of that polygon. If the result is odd, the point is considered to be in the interior and is filled. If the result is even, the point is outside the polygon and is left alone. The winding rule works in a similar manner, but whenever the ray crosses an edge, the rule looks at the direction of that edge: if it crosses the ray left to right, an accumulator is incremented; if it crosses the ray right to left, the accumulator is decremented. Those points for which the ray's accumulator is non-zero are considered inside the region.

GrBrushPolyline() is an optimized routine. It provides a fast, simple way to draw thick polylines. Instead of specifying a line width in points, the caller passes the dimensions of a rectangle of pixels. This rectangle will be used as a sort of brush, dragged along the course of the polyline. The result is a polyline drawn very quickly. However, this function is not display-independent, and is therefore not WYSIWYG. Because the rectangle dimensions are specified in pixels instead of points, the polyline will be thicker or thinner depending on the display's resolution. In the system software, this routine provides the "ink" feedback for pen-based systems, where speed is a top priority.

To find out whether a given point falls within a polygon, call GrTestPointInPolygon() .


Up: GEOS SDK TechDocs| Up | Prev: 2.7 Rounded Rectangles | Next: 2.9 Bézier Curves and Splines