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:

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: