# Polygon and Polyline

One of the most flexible graphics algorithms are polygon and polyline. Both are defined by a list of points, through which the a line is drawn. The differences between polygon and polyline are:

- A polygon is always closed, meaning that there is a line from the last point of the first point. A polyline can be open.
- A polygon is filled by default, but can also be not filled. A polyline can never be filled.

Use one of the methods in IGaService to create a polygon or polyline.

Please avoid using polygon and polyline if you can use simple shapes like rectangle or rounded-rectangle. The reason is that simple shapes can be optimized regarding memory consumption and performance.

You can see an example implementation of creating a triangle polygon here:

// triangle through points: top-middle, bottom-right, bottom-left
int xy[] = new int[] { 50, 0, 100, 100, 0, 100 };
IGaService gaService = Graphiti.getGaService();
Polygon p = gaService.createPolygon(container, xy);

The result will look like this:

Figure: Example screenshot of a triangle polygon

## Rounded Edges

The edges of a polygon and polyline can be rounded. For each edge a different rounding can be defined.

Let us first have a look at the result, before going into the details. You can see an example implementation of creating a partly rounded triangle polygon here:

// triangle through points: top-middle, bottom-right, bottom-left
int xy[] = new int[] { 50, 0, 100, 100, 0, 100 };
int beforeAfter[] = new int[] { 0, 0, 40, 20, 20, 40 };
IGaService gaService = Graphiti.getGaService();
Polygon p = gaService.createPolygon(container, xy, beforeAfter);

Figure: Example screenshot of a partly rounded triangle polygon

The idea for defining the rounding is, that for each point you define the distance on the line before the point where the rounding begins and the distance on the line after the point where the rounding ends. In our example we defined, that 40 pixels before the bottom-right point the rounding starts and 20 pixels after the bottom-right point the rounding ends. You can see this best by comparing the results you get with and without rounding:

Figure: Explanation of the rounding parameters for polygon and polyline

When you use rounded polygons or polylines you have to keep the following issues in mind:

- The attributes before/after are actually part of the class Point and not of polygon or polyline. However, if a Point is used outside polygon or polyline those attributes are ignored.
- The rounding can only be specified for shapes (polygon or polyline). For connections the rounding can not be specified, because connections are always rounded using standard values.